Issue #17312 has been updated by Dan0042 (Daniel DeLorme).


I understand the thinking behind #flatten; if `ary.flatten` is possible then why not `ary.to_enum.flatten`? It should be isomorphic. But even with Enumerator the recursive aspect still represents a compatibility problem. So as long as the behavior of Array#flatten is not modified I think all this is trivial to implement:

    module Enumerable
      def compact(...); to_a.compact(...); end
      def product(...); to_a.product(...); end
      def flatten(...); to_a.flatten(...); end
    end

----------------------------------------
Feature #17312: New methods in Enumerable and Enumerator::Lazy: flatten, product, compact
https://bugs.ruby-lang.org/issues/17312#change-88561

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>