From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 6E8741F406 for ; Thu, 17 May 2018 05:56:58 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 0DF6C120A4B; Thu, 17 May 2018 14:56:55 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 238A1120A13 for ; Thu, 17 May 2018 14:56:51 +0900 (JST) Received: by filter0015p3las1.sendgrid.net with SMTP id filter0015p3las1-27690-5AFD19A1-3F 2018-05-17 05:56:49.922087812 +0000 UTC Received: from herokuapp.com (ec2-54-226-155-145.compute-1.amazonaws.com [54.226.155.145]) by ismtpd0010p1iad1.sendgrid.net (SG) with ESMTP id W3HCxcSPQnKxTiW0bwbpOA Thu, 17 May 2018 05:56:49.836 +0000 (UTC) Date: Thu, 17 May 2018 05:56:50 +0000 (UTC) From: matz@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 62462 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 6284 X-Redmine-Issue-Author: pabloh X-Redmine-Issue-Assignee: matz X-Redmine-Sender: matz 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: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4diIs6NfC7uayzTWCzXgV+ZgUVET7yJy2UHO +DZcZL3TFzMJSiwdr29I5Yx4sgk7NRE45VN+frCs+zzklCBwunKAAPGTpaJvxz2iXCy3xXK0v1Kn7n zbXgNDk8lPDeey/WtpFjfEPl81+Q9cq2/BPlL9Hbxe08c7M2/tQtRaA8HA== X-ML-Name: ruby-core X-Mail-Count: 87100 Subject: [ruby-core:87100] [Ruby trunk Feature#6284][Open] Add composition for procs 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 #6284 has been updated by matz (Yukihiro Matsumoto). Status changed from Feedback to Open Considering the combination of OOP and FP, it seems a good idea to adding both forward and reverse combination of procs. So we pick Groovy way (adding `<<` and `>>` methods to `Proc`). We need more discussion if we would add combination methods to the `Symbol` class. Matz. ---------------------------------------- Feature #6284: Add composition for procs https://bugs.ruby-lang.org/issues/6284#change-72069 * Author: pabloh (Pablo Herrero) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- It would be nice to be able to compose procs like functions in functional programming languages: ```ruby to_camel = :capitalize.to_proc add_header = ->val {"Title: " + val} format_as_title = add_header << to_camel << :strip ``` instead of: ```ruby format_as_title = lambda {|val| "Title: " + val.strip.capitalize } ``` It's pretty easy to implement in pure ruby: ```ruby class Proc def << block proc { |*args| self.call( block.to_proc.call(*args) ) } end end ``` ---Files-------------------------------- 0001-proc.c-Implement-Proc-for-Proc-composition.patch (3.65 KB) 0002-proc.c-Implement-Method-for-Method-composition.patch (2.67 KB) 0003-proc.c-Support-any-callable-when-composing-Procs.patch (3.97 KB) -- https://bugs.ruby-lang.org/