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=-4.1 required=3.0 tests=BAYES_00,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 A4EEE1F55B for ; Thu, 11 Jun 2020 01:09:22 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id EC56C120AAF; Thu, 11 Jun 2020 09:58:24 +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 81DD8120AAE for ; Thu, 11 Jun 2020 09:58:22 +0900 (JST) Received: by filterdrecv-p3iad2-784dbb6bd8-hwzn8 with SMTP id filterdrecv-p3iad2-784dbb6bd8-hwzn8-18-5EE181BF-2E 2020-06-11 00:58:39.781063283 +0000 UTC m=+622300.885257620 Received: from herokuapp.com (unknown) by ismtpd0050p1iad1.sendgrid.net (SG) with ESMTP id teEzH7lETMWisFtznDUCqQ for ; Thu, 11 Jun 2020 00:58:39.644 +0000 (UTC) Date: Thu, 11 Jun 2020 00:58:39 +0000 (UTC) From: shyouhei@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74515 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 16946 X-Redmine-Issue-Author: sos4nt X-Redmine-Sender: shyouhei 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?jcfQDMoo=2FMGCmP3uu1SeyLQUxUPXq5PjHpHz3xSFn159DJOj20jugRToFyLidc?= =?us-ascii?Q?+sWHgLZHf3e1SGxeJVNQrMDa9OUYwpYdFMhIBtc?= =?us-ascii?Q?vV8BMc483mmzd1uzVoYGZoDNB9+1U9kWEqx9GbD?= =?us-ascii?Q?nlgBjCZMNuNhnUQrsDsIz=2Fukt3o9nIu7rEvN9Qv?= =?us-ascii?Q?GzxrrxpL7+5GN7v82AzjnYK7mDHaAzFDFq4Z+dT?= =?us-ascii?Q?D8VoMuK1Tt2cg4Tic=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 98724 Subject: [ruby-core:98724] [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 updated by shyouhei (Shyouhei Urabe). Hello, this request sounds interesting to me. sos4nt (Stefan Sch=FC=DFler) wrote: > Haskell has an `intersperse` function which adds a separator between elem= ents of a list. > = > It would be pretty useful to have such method(s) in Ruby, too. This is the key point. Can you show us the "pretty useful"-ness a bit more= , possibly by telling us how it is practically used in Haskell? ---------------------------------------- Feature #16946: Add an `intersperse` method https://bugs.ruby-lang.org/issues/16946#change-86080 * 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: