From: keystonelemur@... Date: 2019-10-30T19:30:47+00:00 Subject: [ruby-core:95592] [Ruby master Feature#15123] Enumerable#compact proposal Issue #15123 has been updated by baweaver (Brandon Weaver). @matz: Its presence in Array and Hash make it more of a common interface that I could see being defined for Enumerable in general, though the immediate usecases are around Lazy. As mentioned above, sometimes one wants to use Enumerators directly or returns one from an Enumerable method which can cause some conflicts of available methods. I believe it could be considered surprising that `compact` does not necessarily work with all collection-like types. ---------------------------------------- Feature #15123: Enumerable#compact proposal https://bugs.ruby-lang.org/issues/15123#change-82382 * Author: printercu (Max Melentiev) * Status: Feedback * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- 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: