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/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>