instance method Enumerator::Lazy#take_while

take_while -> Enumerator::Lazy[permalink][rdoc][edit]
take_while {|item| ... } -> Enumerator::Lazy

Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。



1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".."z":cycle>)>:take_while>

1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }.force.last(5)
# => [[99995, "y"], [99996, "z"], [99997, "a"], [99998, "b"], [99999, "c"]]

[SEE_ALSO] Enumerable#take_while