Class: Enumerator
Direct Known Subclasses
Class Method Summary collapse
-
.unfold(seed, &blk) ⇒ Object
Creates an Enumerator that can unfold a sequence from a given seed.
Instance Method Summary collapse
-
#to_b ⇒ Object
Converts enum to a boolean.
Class Method Details
.unfold(seed, &blk) ⇒ Object
Creates an Enumerator that can unfold a sequence from a given seed.
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/mug/functional.rb', line 162 def unfold(seed, &blk) raise ArgumentError, 'no block given' unless block_given? Enumerator.new do |y| loop do result = blk.call(seed) break if result.nil? value, seed = result y << value end end end |