From: zverok.offline@... Date: 2020-11-17T16:28:59+00:00 Subject: [ruby-core:100911] [Ruby master Feature#17312] New methods in Enumerable and Enumerator::Lazy: flatten, product, compact Issue #17312 has been updated by zverok (Victor Shepelev). > But even with Enumerator the recursive aspect still represents a compatibility problem. I am not sure about its severity, though. I mean, Universe is big and sure somewhere in it there should be a code which has an *array of enumerators* and then does `flatten` on them... But I am not sure there is much of this code in the wild. I believe that this situation has the similar rarity class as the situation with code which does `unless obj.respond_to?(:except)` and will be broken by newly introduced `Hash#except` method... Like, *every* change is incompatibility for somebody, as https://xkcd.com/1172/ points, but `Enumerator#flatten` seems quite innocent. > So as long as the behavior of Array#flatten is not modified I think all this is trivial to implement: ```ruby def flatten(...); to_a.flatten(...); end ``` Note that this ticket is a follow-up of #16987. What I interested in, is more usages for `.lazy`, and *eager* implementation of `Enumerator::Lazy#flatten` is definitely a no-go. So, I actually *could* propose just `Enumerator::Lazy#flatten`, but it seems quite weird that lazy enumerator can be flattened, while regular one can't. ---------------------------------------- Feature #17312: New methods in Enumerable and Enumerator::Lazy: flatten, product, compact https://bugs.ruby-lang.org/issues/17312#change-88563 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal ---------------------------------------- (The offspring of #16987, which was too vague/philosophical) I propose to add to `Enumerable` and `Enumerator::Lazy` the following methods: * `compact` * `product` * `flatten` All of them can be performed with a one-way enumerator. All of them make sense for situations other than "just an array". All of them can be used for processing large sequences, and therefore meaningful to add to `Lazy`. -- https://bugs.ruby-lang.org/ Unsubscribe: