Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xenum

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xenum

  • 0.1.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Xenum

Extend Enumerable

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add xenum

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install xenum

Usage

lazy_flatten

works like Array#flatten, but for all Enumerable, and it is lazy

[
  3.times,
  3,
  4,
  [5, [6,7]],
  (8..10),
  Enumerator.new{|e| n = 10; loop{e << n+=1}}
].lazy_flatten.first(15)
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

lazy_insert

works like Array#insert, but not limited to Array

10.times.lazy_insert(3, 'a', 'b').to_a
# [0, 1, 2, "a", "b", 3, 4, 5, 6, 7, 8, 9]

10.times.lazy_insert(-3, 'a', 'b').to_a
# [0, 1, 2, 3, 4, 5, 6, 7, "a", "b", 8, 9]

lazy_unshift

just like lazy_insert(0, ...)

lazy_product

works like Array#product, but not limited to Array

3.times.lazy_product(
  (3..5),
  [6,7,8]
).take(6)
# [[0, 3, 6], [0, 3, 7], [0, 3, 8], [0, 4, 6], [0, 4, 7], [0, 4, 8]]

merge_sort

lazily merge sort Enumerable

e = (6..8).merge_sort([3,4,5]).merge_sort(3.times)
# #<Enumerator: ...>

e.take(5)
# [0, 1, 2, 3, 4]

[(6..8), [3,4,5], 3.times].reduce(&:merge_sort).to_a
# [0, 1, 2, 3, 4, 5, 6, 7, 8]

# same result but faster
(6..8).merge_sort([3,4,5], 3.times).to_a
# [0, 1, 2, 3, 4, 5, 6, 7, 8]

FAQs

Package last updated on 25 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc