Ruby 3.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Enumerator::Lazyクラス > filter_map
filter_map {|item| ... } -> Enumerator::Lazy
[permalink][rdoc]Enumerable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。
1.step.lazy.filter_map { |n| n * 2 if n.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: (1.step)>:filter_map>
1.step.lazy.filter_map { |n| n * 2 if n.even? }.take(10).force
# => [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]
[SEE_ALSO] Enumerable#filter_map