From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 4261C1B00016 for ; Sun, 9 Oct 2016 22:58:57 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id BDE46B5D8BC for ; Sun, 9 Oct 2016 23:30:30 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id A0A0118CC821 for ; Sun, 9 Oct 2016 23:30:31 +0900 (JST) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E3557120479; Sun, 9 Oct 2016 23:30:29 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 25049120451 for ; Sun, 9 Oct 2016 23:30:25 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=pEw5KxTRHUzuD2OokGE41mJReio=; b=p2FC7UUDegcDAZLlfJ gaGvuBB1yfCoAhAi3YyVXJ+yIoOkQy1++aJRafNcA95idhJULersNpNiB0NUpqSK Br/Zr2mmTqWc1db7IqU4M/KDOSCV2XsPpIWhWDlDUBFM+l+sT1lvKLoPMiAtmXuW aI/Y4Z690p3v0atXxM/f2B39s= Received: by filter0605p1mdw1.sendgrid.net with SMTP id filter0605p1mdw1.30009.57FA547816 2016-10-09 14:30:16.353519269 +0000 UTC Received: from herokuapp.com (ec2-54-166-22-235.compute-1.amazonaws.com [54.166.22.235]) by ismtpd0003p1iad1.sendgrid.net (SG) with ESMTP id -VpjQDAvQLOV5NzJcaFHcw Sun, 09 Oct 2016 14:30:16.314 +0000 (UTC) Date: Sun, 09 Oct 2016 14:30:16 +0000 From: bigbadmath@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 52381 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 6284 X-Redmine-Issue-Author: pabloh X-Redmine-Issue-Assignee: matz X-Redmine-Sender: why-capslock-though 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7Jbuz7IvstTZtVQF62DTgIXYONTq5+wtiLLO yHg7AFt0AWtCpI/ooh1VI5bDEi+hho0T1y75ny4xkpF7HB6C4VmCZaEcu8HXe3rqbbsAFimbNgqBcu JELQM3oUEQAYfM3D1kyUqE96TErBLtcYnbKfIlW2XjGKfDnUX/K4U6oZlA== X-ML-Name: ruby-core X-Mail-Count: 77534 Subject: [ruby-core:77534] [Ruby trunk Feature#6284] 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 Alexander Moore-Niemi. I wrote a gem with a C extension of `Proc#compose`: https://github.com/mooreniemi/proc_compose#usage What motivated me was `map f (map g xs) = map (f . g) xs`, and what I still don't understand (being a newbie to extending Ruby or understanding its internals) is that `.map(&some_proc).map(&some_other_proc)` still behaves better than `.map(&(some_proc * some_other_proc))` given my current implementation of `compose`. Although I think composition has a lot of uses, the admittedly small but free performance benefit I expected to gain was top of my list. I do think emphasis on composition suggests a somewhat different style of writing Ruby, but I think it can be a good one, actually. Paul: what's the performance of your `compose`? If I have time later I can use https://github.com/mooreniemi/graph-function to try and see. ---------------------------------------- Feature #6284: Add composition for procs https://bugs.ruby-lang.org/issues/6284#change-60805 * Author: Pablo Herrero * Status: Feedback * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- =begin It would be nice to be able to compose procs like functions in functional programming languages: to_camel = :capitalize.to_proc add_header = ->val {"Title: " + val} format_as_title = add_header << to_camel << :strip instead of: format_as_title = lambda {|val| "Title: " + val.strip.capitalize } It's pretty easy to implement in pure ruby: class Proc def << block proc { |*args| self.call( block.to_proc.call(*args) ) } end 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/