ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: t.hirsch@web.de
To: ruby-core@ruby-lang.org
Subject: [ruby-core:79219] [Ruby trunk Feature#6284] Add composition for procs
Date: Sun, 22 Jan 2017 18:50:45 +0000	[thread overview]
Message-ID: <redmine.journal-62636.20170122185045.8c108b1e92e40a14@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-6284.20120412152125@ruby-lang.org

Issue #6284 has been updated by Thorsten Hirsch.


fyi: Composing procs is way faster now. It beats all other algorithms in Paul's benchmark on ruby 2.3.3:

~~~

Warming up --------------------------------------
     composing procs   135.483k i/100ms
      chaining procs    55.595k i/100ms
         single proc    84.448k i/100ms
         nested proc    48.095k i/100ms
Calculating -------------------------------------
     composing procs      2.363M (± 6.2%) i/s -     11.787M in   5.011859s
      chaining procs    701.936k (± 3.4%) i/s -      3.558M in   5.074972s
         single proc      1.207M (± 3.6%) i/s -      6.080M in   5.044891s
         nested proc    579.005k (± 2.9%) i/s -      2.934M in   5.071310s

Comparison:
     composing procs:  2362658.0 i/s
         single proc:  1206768.2 i/s - 1.96x  slower
      chaining procs:   701936.2 i/s - 3.37x  slower
         nested proc:   579005.4 i/s - 4.08x  slower
~~~

Tested on linux and macOS (same result).

----------------------------------------
Feature #6284: Add composition for procs
https://bugs.ruby-lang.org/issues/6284#change-62636

* Author: Pablo Herrero
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Target version: 
----------------------------------------
=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/

  parent reply	other threads:[~2017-01-22 18:21 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12  6:21 [ruby-core:44303] [ruby-trunk - Feature #6284][Open] Add composition for procs pabloh (Pablo Herrero)
2012-04-12 14:26 ` [ruby-core:44308] [ruby-trunk - Feature #6284] " trans (Thomas Sawyer)
2012-04-12 14:28 ` [ruby-core:44309] " trans (Thomas Sawyer)
2012-04-12 17:02 ` [ruby-core:44313] " pabloh (Pablo Herrero)
2012-04-12 21:26 ` [ruby-core:44319] " alexeymuranov (Alexey Muranov)
2012-04-12 21:39   ` [ruby-core:44320] " Adam Prescott
2012-04-12 22:53 ` [ruby-core:44321] [ruby-trunk - Feature #6284][Assigned] " mame (Yusuke Endoh)
2012-04-12 23:59 ` [ruby-core:44323] [ruby-trunk - Feature #6284] " pabloh (Pablo Herrero)
2012-04-13  5:56 ` [ruby-core:44327] " alexeymuranov (Alexey Muranov)
2012-04-15  8:10 ` [ruby-core:44365] " trans (Thomas Sawyer)
2012-04-16  2:59 ` [ruby-core:44373] " pabloh (Pablo Herrero)
2012-10-27  1:44 ` [ruby-core:48422] [ruby-trunk - Feature #6284][Feedback] " matz (Yukihiro Matsumoto)
2012-11-09  9:56 ` [ruby-core:49156] [ruby-trunk - Feature #6284] " jballanc (Joshua Ballanco)
2012-11-09 11:10 ` [ruby-core:49159] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-11-09 11:23 ` [ruby-core:49161] " rohitarondekar (Rohit Arondekar)
2012-11-09 16:25 ` [ruby-core:49169] " alexeymuranov (Alexey Muranov)
2012-11-09 17:42 ` [ruby-core:49171] " marcandre (Marc-Andre Lafortune)
2012-11-10  3:06 ` [ruby-core:49182] " duerst (Martin Dürst)
2012-11-10  4:00   ` [ruby-core:49184] " Matthew Kerwin
2012-11-10  9:23 ` [ruby-core:49190] " alexeymuranov (Alexey Muranov)
2012-11-10 12:33 ` [ruby-core:49197] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-11-24  1:31 ` [ruby-core:49947] " mame (Yusuke Endoh)
2012-12-01 19:54 ` [ruby-core:50461] " rits (First Last)
2012-12-05  3:13 ` [ruby-core:50563] " boris_stitnicky (Boris Stitnicky)
2012-12-05 10:47 ` [ruby-core:50568] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-12-05 11:23 ` [ruby-core:50569] " alexeymuranov (Alexey Muranov)
2015-06-14 16:55 ` [ruby-core:69586] [Ruby trunk " mudge
2015-06-23 14:47 ` [ruby-core:69712] " mudge
2015-06-29  8:39 ` [ruby-core:69768] " mudge
2015-06-29 21:32 ` [ruby-core:69777] " pablodherrero
2015-06-30  8:21 ` [ruby-core:69812] " duerst
2015-06-30  8:35 ` [ruby-core:69813] " eregontp
2015-06-30 11:37 ` [ruby-core:69816] " pablodherrero
2015-06-30 12:39 ` [ruby-core:69817] " mudge
2015-07-01 15:52 ` [ruby-core:69833] " tom
2015-08-07  7:21 ` [ruby-core:70264] " systho
2015-12-30 11:18 ` [ruby-core:72616] " mudge
2015-12-30 12:28 ` [ruby-core:72618] " mudge
2016-10-09 14:30 ` [ruby-core:77534] [Ruby trunk Feature#6284] " bigbadmath
2016-10-11 20:18 ` [ruby-core:77595] " mudge
2016-10-12  8:28 ` [ruby-core:77597] " mudge
2016-10-12  9:46 ` [ruby-core:77599] " duerst
2017-01-22 18:50 ` t.hirsch [this message]
2017-03-13  8:13 ` [ruby-core:80110] " matz
2017-04-28 19:47 ` [ruby-core:80931] " ritchie
2017-08-31  6:26 ` [ruby-core:82555] " ozaki
2018-01-29  7:49 ` [ruby-core:85213] " zverok.offline
2018-04-20 18:34 ` [ruby-core:86632] " keystonelemur
2018-04-30 18:51 ` [ruby-core:86780] " keystonelemur
2018-05-17  5:56 ` [ruby-core:87100] [Ruby trunk Feature#6284][Open] " matz
2018-07-30  8:13 ` [ruby-core:88188] [Ruby trunk Feature#6284] " melentievm
2018-08-08  5:41 ` [ruby-core:88339] " ko1
2018-08-08 18:37 ` [ruby-core:88356] " shannonskipper
2018-08-10 19:58 ` [ruby-core:88442] " shannonskipper
2018-11-12 12:43 ` [ruby-core:89775] " nobu
2018-11-14 17:33 ` [ruby-core:89796] " pablodherrero
2018-11-15  2:22 ` [ruby-core:89801] " nobu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-62636.20170122185045.8c108b1e92e40a14@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).