From: eregontp@... Date: 2019-10-22T19:33:36+00:00 Subject: [ruby-core:95477] [Ruby master Feature#16261] Enumerable#each_tuple Issue #16261 has been updated by Eregon (Benoit Daloze). FYI there is Enumerable#each_entry: > Calls block once for each element in self, passing that > element as a parameter, converting multiple values from yield to an array. I think many methods already yield multiple arguments rather than an Array of arguments, `zip` being one of the exception. So I'm not sure in how many cases such a method would be useful. ---------------------------------------- Feature #16261: Enumerable#each_tuple https://bugs.ruby-lang.org/issues/16261#change-82247 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- New method proposal. Prototype code: ```ruby module Enumerable def each_tuple return to_enum(__method__) unless block_given? each { |item| yield(*item) } # unpacking possible array into several args end end ``` Supposed documentation/explanation: > For enumerable with Array items, passes all items in the block provided as a separate arguments. t could be useful if the provided block has lambda semantics, e.g. doesn't unpack arguments automatically. For example: ```ruby files = ["README.md", "LICENSE.txt", "Contributing.md"] content = [fetch_readme, fetch_license, fetch_contributing] # somehow make a content for the files files.zip(content).each_tuple(&File.:write) # writes to each file its content ``` > When no block passed, returns enumerator of the tuples: ```ruby [1, 2, 3].zip([4, 5, 6]).each_tuple.map(&:+) # => [5, 7, 9] ``` -- https://bugs.ruby-lang.org/ Unsubscribe: