Class: WithEase::Iterator
- Inherits:
-
Object
- Object
- WithEase::Iterator
- Includes:
- Enumerable
- Defined in:
- lib/with_ease/iterator.rb
Instance Attribute Summary collapse
-
#advancer ⇒ Object
readonly
Returns the value of attribute advancer.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #advance ⇒ Object
- #advance_fn ⇒ Object
- #call ⇒ Object
- #drop(n = 1) ⇒ Object
- #drop_fn ⇒ Object
- #drop_while(&blk) ⇒ Object
- #each ⇒ Object
- #map(&blk) ⇒ Object
- #take_fn ⇒ Object
- #take_while_fn ⇒ Object
- #to_proc ⇒ Object
Instance Attribute Details
#advancer ⇒ Object (readonly)
Returns the value of attribute advancer.
7 8 9 |
# File 'lib/with_ease/iterator.rb', line 7 def advancer @advancer end |
#value ⇒ Object (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
#advance ⇒ Object
9 |
# File 'lib/with_ease/iterator.rb', line 9 def advance = drop |
#advance_fn ⇒ Object
10 |
# File 'lib/with_ease/iterator.rb', line 10 def advance_fn = -> { drop } |
#call ⇒ Object
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_fn ⇒ Object
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 |
#each ⇒ Object
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_fn ⇒ Object
40 |
# File 'lib/with_ease/iterator.rb', line 40 def take_fn = -> (n) { take n } |
#take_while_fn ⇒ Object
41 |
# File 'lib/with_ease/iterator.rb', line 41 def take_while_fn = -> (&blk) { take_while(&blk) } |
#to_proc ⇒ Object
43 |
# File 'lib/with_ease/iterator.rb', line 43 def to_proc = ->(*) { value } |