From: mudge@... Date: 2015-06-14T16:55:33+00:00 Subject: [ruby-core:69586] [Ruby trunk - Feature #6284] Add composition for procs Issue #6284 has been updated by Paul Mucur. File 0001-proc.c-Implement-Proc-for-Proc-composition.patch added File 0002-proc.c-Implement-Method-for-Method-composition.patch added Attached patches for `Proc#*` and `Method#*` for Proc and Method composition including test cases. Also raised as a pull request on GitHub at https://github.com/ruby/ruby/pull/935 One thing that might be worth discussing is the necessity of the type checking: should it be possible to compose any callable object (rather than explicitly `Proc`s and `Method`s)? This could be deferred to a later enhancement as I imagine it would complicate the implementation. ---------------------------------------- Feature #6284: Add composition for procs https://bugs.ruby-lang.org/issues/6284#change-52925 * 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-------------------------------- 0002-proc.c-Implement-Method-for-Method-composition.patch (2.71 KB) 0001-proc.c-Implement-Proc-for-Proc-composition.patch (3.73 KB) -- https://bugs.ruby-lang.org/