Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Enumerator::Lazy#filter_map

lazy.filter_map { |obj| block } → lazy_enumerator

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

Example
(1..).lazy.filter_map { |i| i * 2 if i.even? }.first(5)
#=> [4, 8, 12, 16, 20]
See also #filter #find_all #enum_for #flat_map also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1