I agree that (f ∘ g)(x) is g(f(x)) is more intuitive from a purely programmatic point of view. It is "natural" for the operations to be applied left to right, exactly like method chaining. On 10 November 2012 13:06, duerst (Martin Dürst) wrote: > > Issue #6284 has been updated by duerst (Martin Dürst). > > > marcandre (Marc-Andre Lafortune) wrote: > > +1 for #* > > > > The symbol used in mathematics for function composition is a circle (∘); > the arrows are for the definitions of functions (like lambdas) only, so #<- > or whatever make no sense to me. > > Very good point. > > > Finally, the f ∘ g(x) is defined as f(g(x)), so there is no argument > there either. > > Not true. Depending on which field of mathematics you look at, either (f ∘ > g)(x) is either f(g(x)), or it is g(f(x)). The later is in particular true > in work involving relations, see e.g. > http://en.wikipedia.org/wiki/Composition_of_relations#Definition. > > Speaking from a more programming-related viewpoint, f(g(x)) is what is > used e.g. in Haskell, and probably in many other functional languages, and > so may be familiar with many programmers. > > However, we should take into account that a functional language writes > e.g. reverse(sort(array)), so it makes sense to define revsort = reverse * > sort (i.e. (f ∘ g)(x) is f(g(x))). But in Ruby, it would be > array.sort.reverse, so revsort = sort * reverseve may feel much more > natural (i.e. (f ∘ g)(x) is g(f(x))). > > ---------------------------------------- > Feature #6284: Add composition for procs > https://bugs.ruby-lang.org/issues/6284#change-32728 > > Author: pabloh (Pablo Herrero) > Status: Feedback > 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/ > > -- Matthew Kerwin, B.Sc (CompSci) (Hons) http://matthew.kerwin.net.au/ ABN: 59-013-727-651 "You'll never find a programming language that frees you from the burden of clarifying your ideas." - xkcd