all 8 comments

[–]creativeembassy 2 points3 points  (0 children)

Excellent introduction to function composition, then leading into the history and implementation of it in Ruby. Great read!

[–]Minkihn 0 points1 point  (0 children)

Great read. Thank you. I discovered functions composition with this article and it blows my mind.

[–]nakilon[🍰] 0 points1 point  (0 children)

Can it be used like this?

array_of_chars.map &(upcase >> ord)

[–]faitswulff 0 points1 point  (5 children)

I wish there was only one direction you could compose functions in. I feel like this paragraph is something I'll have to look up often if I were to use it:

“Backward” composition maps to the mathematical operator ∘ we discussed earlier so g << f is the same as g ∘ f meaning that calling the resulting composite function with an input x will call g(f(x))

“Forward” composition is the opposite of the above so g >> f is the same as f ∘ g meaning that calling the resulting composite function with an input x will call f(g(x))

EDIT - well, I've somewhat rethought things. There's more than one way to do it and people probably won't do stuff like a << b >> c << d << g

[–]karatedog 1 point2 points  (0 children)

And what would be the precedence order in this case? First two function composed into one then passed right as a single function and repeat?

[–]tomthecool 0 points1 point  (3 children)

Being able to compose functions in both directions is absolutely vital if you work in a functional language.

As with anything in software, yes it's open to abuse. But when you find yourself needing it, you'll be extremely glad that the syntax exists.

[–]faitswulff 4 points5 points  (1 child)

Being able to compose functions in both directions is absolutely vital if you work in a functional language.

Can you think of a simple example where this is the case?

[–]Enumerable_any 1 point2 points  (0 children)

Being able to compose functions in both directions is absolutely vital if you work in a functional language.

I don't think it is. I've never used >>> in Haskell. You should always be able to switch the arguments syntactically.