Module: Sequences
- Defined in:
- lib/totally_lazy/sequence.rb
Instance Method Summary collapse
- #drop(sequence, count) ⇒ Object
- #empty ⇒ Object
- #enumerate(fn, start) ⇒ Object
- #group(key, enumerator) ⇒ Object
- #map_concurrently(sequence, fn = nil, &block) ⇒ Object
- #repeat(item) ⇒ Object
- #repeat_fn(item) ⇒ Object
- #sequence(*items) ⇒ Object
- #sort(sequence, comparator = ascending) ⇒ Object
Instance Method Details
#drop(sequence, count) ⇒ Object
21 22 23 |
# File 'lib/totally_lazy/sequence.rb', line 21 def drop(sequence, count) Sequence.drop(sequence, count) end |
#empty ⇒ Object
13 14 15 |
# File 'lib/totally_lazy/sequence.rb', line 13 def empty Sequence.empty end |
#enumerate(fn, start) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/totally_lazy/sequence.rb', line 45 def enumerate(fn, start) Sequence.new(Enumerator.new do |y| current = start loop do result = current current = fn.(current) y << result end end.lazy) end |
#group(key, enumerator) ⇒ Object
33 34 35 |
# File 'lib/totally_lazy/sequence.rb', line 33 def group(key, enumerator) Group.new(key, enumerator) end |
#map_concurrently(sequence, fn = nil, &block) ⇒ Object
29 30 31 |
# File 'lib/totally_lazy/sequence.rb', line 29 def map_concurrently(sequence, fn=nil, &block) Sequence.map_concurrently(sequence, block_given? ? ->(value) { block.call(value) } : fn) end |
#repeat(item) ⇒ Object
37 38 39 |
# File 'lib/totally_lazy/sequence.rb', line 37 def repeat(item) Sequence.new(repeat_enumerator(item)) end |
#repeat_fn(item) ⇒ Object
41 42 43 |
# File 'lib/totally_lazy/sequence.rb', line 41 def repeat_fn(item) Sequence.new(repeat_fn_enumerator(item)) end |