Module: Lazily
- Defined in:
- lib/lazily/proxy.rb,
lib/lazily/merging.rb,
lib/lazily/version.rb,
lib/lazily/zipping.rb,
lib/lazily/dequeuing.rb,
lib/lazily/filtering.rb,
lib/lazily/threading.rb,
lib/lazily/enumerable.rb,
lib/lazily/associating.rb,
lib/lazily/prefetching.rb,
lib/lazily/concatenating.rb
Defined Under Namespace
Modules: Enumerable Classes: Concatenator, Dequeuer, Filter, Merger, Prefetcher, Proxy, TaggedElement, Zipper
Constant Summary collapse
- VERSION =
"0.2.1".freeze
Class Method Summary collapse
-
.associate(source_map, &block) ⇒ Enumerable
Associate “like” elements of two or more Enumerables.
-
.concat(*enumerables) ⇒ Enumerable
Concatenates two or more Enumerables.
- .dequeue(queue) ⇒ Object
-
.merge(*enumerables, &block) ⇒ Enumerable
Merge a number of sorted Enumerables into a single sorted collection.
- .zip(*enumerables) ⇒ Object
Class Method Details
.associate(source_map, &block) ⇒ Enumerable
Associate “like” elements of two or more Enumerables.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lazily/associating.rb', line 21 def associate(source_map, &block) labels = source_map.keys tagged_element_sources = source_map.map do |label, enumerable| enumerable.lazily.map do |value| key = block ? block.call(value) : value TaggedElement.new(key, value, label) end end tagged_elements = Lazily.merge(*tagged_element_sources) { |te| te.key } tagged_elements.chunk { |te| te.key }.map do |_, tagged_elements| association = {} labels.each { |label| association[label] = [] } tagged_elements.each do |te| association[te.label] << te.value end association end end |
.concat(*enumerables) ⇒ Enumerable
Concatenates two or more Enumerables.
17 18 19 |
# File 'lib/lazily/concatenating.rb', line 17 def concat(*enumerables) Concatenator.new(enumerables) end |
.dequeue(queue) ⇒ Object
7 8 9 |
# File 'lib/lazily/dequeuing.rb', line 7 def dequeue(queue) Dequeuer.new(queue) end |
.merge(*enumerables, &block) ⇒ Enumerable
Merge a number of sorted Enumerables into a single sorted collection.
Draws elements from enumerables as appropriate, to preserve the sort order. An optional block, if provided, is used for comparison of elements. Otherwise, natural element order is used.
20 21 22 |
# File 'lib/lazily/merging.rb', line 20 def merge(*enumerables, &block) Merger.new(enumerables, &block) end |