Issue #16261 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

As far as I understand, the code with the proposal `[1, 2, 3].zip([4, 5, 6]).each_tuple.map(&:+)` can be written as following with numbered parameters:

```ruby
[1, 2, 3].zip([4, 5, 6]).map{_1 + _2}
```

which is quite plain and shorter. So I reject the idea for the time being. Maybe we will revisit the idea once we re-introduce the method reference operator in the future.

Matz.


----------------------------------------
Feature #16261: Enumerable#each_splat and Enumerator#splat
https://bugs.ruby-lang.org/issues/16261#change-82856

* Author: zverok (Victor Shepelev)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
**UPD:** After discussion in comments, method names changed to "splat"-based.

New methods proposal.

Prototype code:
```ruby
module Enumerable
  def each_splat
    return to_enum(__method__) unless block_given?
    each_entry { |item| yield(*item) } # unpacking possible array into several args
  end
end

class Enumerator
  def splat
    return to_enum(:splat) unless block_given?
    each_entry { |item| yield(*item) }
  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_splat(&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_splat.map(&:+) # => [5, 7, 9] 
```



-- 
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>