Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Enumerator::Lazy#map

[U] () { (E arg0) -> U } -> ::Array[U]
() -> ::Enumerator[E, ::Array[untyped]]
lazy.map { |obj| block } → lazy_enumerator

Like Enumerable#map, but chains operation to be lazy-evaluated.

Example
(1..Float::INFINITY).lazy.map {|i| i**2 }
#=> #<Enumerator::Lazy: #<Enumerator::Lazy: 1..Infinity>:map>
(1..Float::INFINITY).lazy.map {|i| i**2 }.first(3)
#=> [1, 4, 9]
See also #lazy #reject #grep_v #select also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0