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-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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 711FE1F55B for ; Wed, 10 Jun 2020 10:00:15 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id AF664120A43; Wed, 10 Jun 2020 18:59:48 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 2AC80120A42 for ; Wed, 10 Jun 2020 18:59:45 +0900 (JST) Received: by filter0076p3las1.sendgrid.net with SMTP id filter0076p3las1-19936-5EE0AF29-142 2020-06-10 10:00:09.508961023 +0000 UTC m=+143441.443875201 Received: from herokuapp.com (unknown) by ismtpd0089p1mdw1.sendgrid.net (SG) with ESMTP id jFFdndYbSQqQ9yCLYkrxLw for ; Wed, 10 Jun 2020 10:00:09.491 +0000 (UTC) Date: Wed, 10 Jun 2020 10:00:09 +0000 (UTC) From: mail@stefanschuessler.de Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74497 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 16946 X-Redmine-Issue-Author: sos4nt X-Redmine-Sender: sos4nt 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?YDaNDhyXQBf2M5=2Fl6Xjc5DPH5ABay9THJ4QwL7T4HmFtr2i5bD=2FZoFMiVYGJkx?= =?us-ascii?Q?Gb5fW0LPrjLN7bgvNtLizBt3vFgW3PEk=2FEXbwOw?= =?us-ascii?Q?YHyDJbFlS7lFMcr4nC4sq1+SiB6Z65xiFoqlB+2?= =?us-ascii?Q?TmAgME3VtOtLGlrMaLmrmTAeQ9E+5CfyZX3QbI4?= =?us-ascii?Q?5ekBfUs3phZULnUYqc5052yq8D7fvYvr8Lw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 98705 Subject: [ruby-core:98705] [Ruby master Feature#16946] Add an `intersperse` method 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 #16946 has been reported by sos4nt (Stefan Sch=FC=DFler). ---------------------------------------- Feature #16946: Add an `intersperse` method https://bugs.ruby-lang.org/issues/16946 * Author: sos4nt (Stefan Sch=FC=DFler) * Status: Open * Priority: Normal ---------------------------------------- Haskell has an `intersperse` function which adds a separator between elemen= ts of a list. It would be pretty useful to have such method(s) in Ruby, too. Examples for `Array` and `String`: ```ruby [1, 2, 3].intersperse(0) #=3D> [1, 0, 2, 0, 3] 'Hello'.intersperse('-') #=3D> "H-e-l-l-o" ``` I'm aware that I can achieve the above with built-in methods, but it's quit= e cumbersome: (requiring regular expressions / intermediate arrays) ```ruby [1, 2, 3].flat_map { |i| [i, 0] }[0...-1] #=3D> [1, 0, 2, 0, 3] 'Hello'.gsub(/(?<=3D.)./, '-\0') #=3D> "H-e-l-l-o" 'Hello'.chars.join('-') #=3D> "H-e-l-l-o" ``` -- = https://bugs.ruby-lang.org/ Unsubscribe: