From: sawadatsuyoshi@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:94342] [Ruby master Feature#16102] `Symbol#call`
Date: Wed, 14 Aug 2019 06:59:46 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-16102.20190814065946.1ded566275a15d2a@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16102.20190814065946@ruby-lang.org
Issue #16102 has been reported by sawa (Tsuyoshi Sawada).
----------------------------------------
Feature #16102: `Symbol#call`
https://bugs.ruby-lang.org/issues/16102
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Since symbols have a `to_proc` method, it is natural to expect that they would appear in a method chain like:
```ruby
:some_symbol.to_proc.call(...)
```
In fact, I have use cases like this:
```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashes = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]
:product.to_proc.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.to_proc.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.to_proc.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.to_proc.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```
I request `Symbol#call` to be defined, which would implicitly call `to_proc` on the receiver and then the conventional `Proc#call` on the result. Then, I can do:
```ruby
:product.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```
Notice that proposals #12115 and #15301 ask for `Symbol#call`, but they ask for different things (a method that returns a proc), and are irrelevant to the current proposal.
--
https://bugs.ruby-lang.org/
next parent reply other threads:[~2019-08-14 6:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-16102.20190814065946@ruby-lang.org>
2019-08-14 6:59 ` sawadatsuyoshi [this message]
2019-08-14 7:00 ` [ruby-core:94343] [Ruby master Feature#16102] `Symbol#call` sawadatsuyoshi
2019-08-14 8:37 ` [ruby-core:94345] " shevegen
2019-08-14 9:00 ` [ruby-core:94347] " mame
2019-09-12 9:25 ` [ruby-core:94920] " joshua.goodall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-16102.20190814065946.1ded566275a15d2a@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).