From: "pabloh (Pablo Herrero)" Date: 2012-04-13T08:59:12+09:00 Subject: [ruby-core:44323] [ruby-trunk - Feature #6284] Add composition for procs Issue #6284 has been updated by pabloh (Pablo Herrero). =begin aprescott (Adam Prescott) wrote: > See also: http://web.archive.org/web/20101228224741/http://drmcawesome.com/FunctionCompositionInRuby Maybe #| could be a possibility. (Without implementing #> or #<). But I find the article's proposition about the chaining order a bit missleading: transform = add1 | sub3 | negate For me that feels more like "piping" ((|add1|)) to ((|sub3|)) to ((|negate|)), from left to right, not the other way around. If we choose to take that path I think the following code would be a plausible implementation: class Proc def | block proc { |*args| block.to_proc.call( self.call(*args) ) } end end class Symbol def | block self.to_proc | block end end =end ---------------------------------------- Feature #6284: Add composition for procs https://bugs.ruby-lang.org/issues/6284#change-25869 Author: pabloh (Pablo Herrero) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: 2.0.0 =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 -- http://bugs.ruby-lang.org/