From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 4CEAF1F4C0 for ; Fri, 18 Oct 2019 13:58:10 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 65A18120AD4; Fri, 18 Oct 2019 22:58:00 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id A4987120914 for ; Fri, 18 Oct 2019 22:57:58 +0900 (JST) Received: by filter0049p3iad2.sendgrid.net with SMTP id filter0049p3iad2-17463-5DA9C4E8-112 2019-10-18 13:58:00.811750553 +0000 UTC m=+45847.365673222 Received: from herokuapp.com (unknown [3.83.29.112]) by ismtpd0033p1mdw1.sendgrid.net (SG) with ESMTP id ZAI7JOqzTrqgAvcuN4U-DA for ; Fri, 18 Oct 2019 13:58:00.755 +0000 (UTC) Date: Fri, 18 Oct 2019 13:58:00 +0000 (UTC) From: shevegen@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71012 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16261 X-Redmine-Issue-Author: zverok X-Redmine-Sender: shevegen X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?6lbdtOg4RDRLuxD00eQtQKgoNAsge5d4xND7cbMQd0znkTzRxEbylKvquMv6q=2F?= =?us-ascii?Q?xPnSdPZvyPdvIXF1GpWb2C7u=2FfP=2FMtnlnJAsCXl?= =?us-ascii?Q?XwI7172QPsDFWAkweicJGCvtuEoZN09ej++Axps?= =?us-ascii?Q?qOBKukPFBsUOOTgMhddLYSXTZlhO8IeKE4wu0cx?= =?us-ascii?Q?atPSmQQDqve7VebrLoFTOXAka5tjN4mAJHw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95422 Subject: [ruby-core:95422] [Ruby master Feature#16261] Enumerable#each_tuple X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/