Class: WithEase::Iterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/with_ease/iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#advancerObject (readonly)

Returns the value of attribute advancer.



7
8
9
# File 'lib/with_ease/iterator.rb', line 7

def advancer
  @advancer
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/with_ease/iterator.rb', line 7

def value
  @value
end

Instance Method Details

#advanceObject



9
# File 'lib/with_ease/iterator.rb', line 9

def advance = drop

#advance_fnObject



10
# File 'lib/with_ease/iterator.rb', line 10

def advance_fn = -> { drop }

#callObject



12
# File 'lib/with_ease/iterator.rb', line 12

def call = advance

#drop(n = 1) ⇒ Object



14
15
16
17
18
19
# File 'lib/with_ease/iterator.rb', line 14

def drop(n=1) 
  n.times do
    @value = @advancer.(value)
  end
  self
end

#drop_fnObject



20
# File 'lib/with_ease/iterator.rb', line 20

def drop_fn = -> (n=1) { drop n }

#drop_while(&blk) ⇒ Object



22
23
24
25
26
27
# File 'lib/with_ease/iterator.rb', line 22

def drop_while(&blk)
  loop do
    return self unless blk.(value)
    advance
  end
end

#eachObject



33
34
35
36
37
38
# File 'lib/with_ease/iterator.rb', line 33

def each
  loop do
    yield value
    advance
  end
end

#map(&blk) ⇒ Object



29
30
31
# File 'lib/with_ease/iterator.rb', line 29

def map(&blk)
  lazy.map(&blk)
end

#take_fnObject



40
# File 'lib/with_ease/iterator.rb', line 40

def take_fn = -> (n) { take n }

#take_while_fnObject



41
# File 'lib/with_ease/iterator.rb', line 41

def take_while_fn = -> (&blk) { take_while(&blk) }

#to_procObject



43
# File 'lib/with_ease/iterator.rb', line 43

def to_proc = ->(*) { value }