Module: Sequences

Defined in:
lib/totally_lazy/sequence.rb

Instance Method Summary collapse

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

#emptyObject



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

#sequence(*items) ⇒ Object



17
18
19
# File 'lib/totally_lazy/sequence.rb', line 17

def sequence(*items)
  Sequence.sequence(*items)
end

#sort(sequence, comparator = ascending) ⇒ Object



25
26
27
# File 'lib/totally_lazy/sequence.rb', line 25

def sort(sequence, comparator=ascending)
  Sequence.sort(sequence, comparator)
end