Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Enumerator::Lazy#_enumerable_collect_concat
_enumerable_collect_concat
enumerator.c
View on GitHub ↗
Alias of #collect_concat
Returns a new lazy enumerator with the concatenated results of running block once for every element in the lazy enumerator.
Example
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force #=> ["f", "o", "o", "b", "a", "r"]
A value x returned by block is decomposed if either of the following conditions is true:
-
xresponds to both each and force, which means thatxis a lazy enumerator. -
xis an array or responds to to_ary.
Otherwise, x is contained as-is in the return value.
Example
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force
#=> [{:a=>1}, {:b=>2}]
See also
#collect_concat
#_enumerable_collect
#_enumerable_drop
#eager
also in
4.0 · 3.4 · 3.2 · 3.1 · 3.0