Issue #6284 has been updated by Paul Mucur.

File proc-compose.patch added

With the recent addition of `Hash#to_proc` and performance improvements to `Proc`s in 2.3.0, I have rebased my patch (attached) to add composition between `Proc`s, `Method`s and other objects responding to `call` with `*` in the hope of reviving this proposal.

c.f. https://github.com/ruby/ruby/pull/935

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

* 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--------------------------------
proc-compose.patch (10.3 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>