Issue #15123 has been updated by marcandre (Marc-Andre Lafortune).
Assignee set to matz (Yukihiro Matsumoto)
Proposal seems acceptable to me.
Just to be clear: I imagine that `Lazy#compact` would still be lazy. Also `compact` is roughly `select(&:itself)`, not `reject(&:nil?)` which would wrongly reject `false`.
----------------------------------------
Bug #15123: Enumerable#compact proposal
https://bugs.ruby-lang.org/issues/15123#change-74049
* Author: printercu (Max Melentiev)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
* ruby -v:
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Hi!
While Enumerable does not provide `#compact` method, it requires changing code in some cases to substitute array with enumerator.
For example, to reduce memory usage it's usual to change `large_array.map { to_heavy_object }.chained_methods` to `large_array.lazy...`. However if `chained_methods` contains `compact`, this change will fail. Replacing `compact` with `reject(&:nil?)` fixes it.
What do you think about adding `#compact` to Enumerable?
--
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>