From: shevegen@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95422] [Ruby master Feature#16261] Enumerable#each_tuple
Date: Fri, 18 Oct 2019 13:58:00 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-82175.20191018135800.4178a8ad1e2928b0@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16261.20191018101149@ruby-lang.org
Issue #16261 has been updated by shevegen (Robert A. Heiler).
Hmmmm.
A slight issue I see with the name "tuple", and then the implicit name addition
".each_tuple", which would then (indirectly) elevate the term tuple.
I know the word tuple from e. g. using tuple in python, but I much prefer ruby's
way to name things (not only because I used ruby for a longer time than python,
but because I think the names in ruby make more sense in general e. g. Array/Hashes
versus List/Dictionaries).
I am not sure if we have "tuples" in ruby core/stdlib yet. I did however google
and find it in Rinda ... so at the least Rinda in stdlib has tuples. :P
https://ruby-doc.org/stdlib-2.6.5/libdoc/rinda/rdoc/Rinda/Tuple.html
(Not sure about ruby core, though.)
There is also a slight issue with intrinsic complexity (in my opinion), but this
is a lot due to one's personal style and preferences, so I will not comment
much on that part - some ruby users prefer simplicity, others prefer more
flexibility in usage (aka more complex use cases). But I think the name itself
should be considered as well; for the use of .each_tuple, ruby users would
first have to understand what a tuple is. Compare this to e. g. .each_pair
which is a LOT simpler to understand even to genuinely new people. I also
admit that this is not a very strong argument per se, since we have other
variants of .each* already, such as .each_with_index - but I still think
we should be careful which .each* variants are added. I also have no
alternative name proposal, my apologies.
----------------------------------------
Feature #16261: Enumerable#each_tuple
https://bugs.ruby-lang.org/issues/16261#change-82175
* 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/
next prev parent reply other threads:[~2019-10-18 13:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-16261.20191018101149@ruby-lang.org>
2019-10-18 10:11 ` [ruby-core:95419] [Ruby master Feature#16261] Enumerable#each_tuple zverok.offline
2019-10-18 13:58 ` shevegen [this message]
2019-10-18 20:26 ` [ruby-core:95424] " shannonskipper
2019-10-22 13:44 ` [ruby-core:95464] " daniel
2019-10-22 14:10 ` [ruby-core:95465] " zverok.offline
2019-10-22 18:01 ` [ruby-core:95473] " daniel
2019-10-22 19:33 ` [ruby-core:95477] " eregontp
2019-10-22 20:52 ` [ruby-core:95479] " daniel
2019-10-22 22:52 ` [ruby-core:95483] " duerst
2019-10-23 7:33 ` [ruby-core:95493] " zverok.offline
2019-11-28 6:24 ` [ruby-core:96010] [Ruby master Feature#16261] Enumerable#each_splat and Enumerator#splat knu
2019-11-28 8:15 ` [ruby-core:96015] " matz
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.journal-82175.20191018135800.4178a8ad1e2928b0@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).