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(1)

#drop(n = 1) ⇒ Object



11
12
13
14
15
16
# File 'lib/with_ease/iterator.rb', line 11

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

#drop_fnObject



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

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

#eachObject



20
21
22
23
24
25
# File 'lib/with_ease/iterator.rb', line 20

def each
  loop do
    yield value
    drop
  end
end

#take_fnObject



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

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