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=AWL,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 75CD41F55B for ; Thu, 11 Jun 2020 01:47:18 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9E60B1209E9; Thu, 11 Jun 2020 10:46:48 +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 18AC11209E5 for ; Thu, 11 Jun 2020 10:46:45 +0900 (JST) Received: by filterdrecv-p3iad2-784dbb6bd8-m8bfj with SMTP id filterdrecv-p3iad2-784dbb6bd8-m8bfj-20-5EE18D1D-C 2020-06-11 01:47:09.157383527 +0000 UTC m=+625220.570594790 Received: from herokuapp.com (unknown) by ismtpd0045p1mdw1.sendgrid.net (SG) with ESMTP id gtsRxvIMQ4-HDvmBEqav5w for ; Thu, 11 Jun 2020 01:47:09.018 +0000 (UTC) Date: Thu, 11 Jun 2020 01:47:09 +0000 (UTC) From: nobu@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74517 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 16946 X-Redmine-Issue-Author: sos4nt X-Redmine-Sender: nobu 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?q8Dly+pU2+3ektTtZVXgZtbJPXwqo7p86jCsvYTW4BznEh+gz18zyfbmphkBHq?= =?us-ascii?Q?ZGN=2FcOCTSJ32hijlmYXBKwvRCEHV=2FsLDofpUsXg?= =?us-ascii?Q?HSHVn8+89BErq=2FpA8ouUr3VvjT=2FlC3Bbs9iQSoM?= =?us-ascii?Q?8Pkn2FOSNympwcZirhYEa4P2djw5kXrDGTiLJ4q?= =?us-ascii?Q?cYfE3dANalsk6=2F5s2oTrY2vKtFEfvEtv7vHIq0i?= =?us-ascii?Q?7F+ci9fOyefKchFqs=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 98726 Subject: [ruby-core:98726] [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 nobu (Nobuyoshi Nakada). The example for `Array` looks simple, but it would be more complicated for = `String`. Is it OK by "char", not by "grapheme cluster"? ---------------------------------------- Feature #16946: Add an `intersperse` method https://bugs.ruby-lang.org/issues/16946#change-86082 * 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: