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=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham 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 E5CC11F4C0 for ; Tue, 22 Oct 2019 22:52:16 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id F123A120A4B; Wed, 23 Oct 2019 07:52:06 +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 2948C120A4A for ; Wed, 23 Oct 2019 07:52:03 +0900 (JST) Received: by filter0043p3iad2.sendgrid.net with SMTP id filter0043p3iad2-1545-5DAF8814-74 2019-10-22 22:52:04.749958201 +0000 UTC m=+12705.123816834 Received: from herokuapp.com (unknown [52.91.158.104]) by ismtpd0064p1iad1.sendgrid.net (SG) with ESMTP id wzAS_Uh-Tba71L-YUyk-UQ for ; Tue, 22 Oct 2019 22:52:04.610 +0000 (UTC) Date: Tue, 22 Oct 2019 22:52:04 +0000 (UTC) From: duerst@it.aoyama.ac.jp Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71075 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16261 X-Redmine-Issue-Author: zverok X-Redmine-Sender: duerst 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?uQY=2F2xNrNfHHTWbKn6MBvvzfU5Pqk9I4lnOVb0CFDutiVDNTYmtZ47WEeo0fTc?= =?us-ascii?Q?WooL4TxL7wgyFCRe=2Fja9taJ3aKJP6dvqRHCViwO?= =?us-ascii?Q?WYfYvFFwM80vXXZDvpB3j0HcwsyRsvtBsFncgoM?= =?us-ascii?Q?V+oiqE10cUThwDdPkbABxh2YISUSk4gfZGESSF9?= =?us-ascii?Q?v0igqvD+JV87n6yaMLJHuB90jOMcbveI5aQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95483 Subject: [ruby-core:95483] [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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16261 has been updated by duerst (Martin D=FCrst). Dan0042 (Daniel DeLorme) wrote: > It's worth pointing out the desired difference with regards to lambdas a = bit more explicitly: > = > ```ruby > [1, 2, 3].zip([4, 5, 6]).map(&:+) # ArgumentError (wrong numbe= r of arguments (given 0, expected 1)) > [1, 2, 3].zip([4, 5, 6]).each_tuple.map(&:+) # =3D> [5, 7, 9] > ``` What you want to do here is in many other languages done with `zip_with`: ```ruby [1, 2, 3].zip_with([4, 5, 6], :+) # =3D> [5, 7, 9] ``` There is already an issue for this, issue #4539, which is open and waits fo= r Matz's approval. ---------------------------------------- Feature #16261: Enumerable#each_tuple https://bugs.ruby-lang.org/issues/16261#change-82255 * 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 ar= gs end end ``` Supposed documentation/explanation: > For enumerable with Array items, passes all items in the block provided a= s 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 =3D ["README.md", "LICENSE.txt", "Contributing.md"] content =3D [fetch_readme, fetch_license, fetch_contributing] # somehow mak= e a content for the files files.zip(content).each_tuple(&File.:write) # writes to each file its conte= nt ``` > When no block passed, returns enumerator of the tuples: ```ruby [1, 2, 3].zip([4, 5, 6]).each_tuple.map(&:+) # =3D> [5, 7, 9] = ``` -- = https://bugs.ruby-lang.org/ Unsubscribe: