3 ms·
The unintuitive part is the choice of operator `<<` instead of `>>`. in your example `f << g` means do `g` first (i.e. 2 + 4 = 6) then do `f` on the result (i.e
by vorg 8y ago
The unintuitive part is the choice of operator `<<` instead of `>>`. in your example `f << g` means do `g` first (i.e. 2 + 4 = 6) then do `f` on the result (i.e. 6 * 3 = 18). I would have expected `f >> g` for this behavior.
- zmmmmm 8y agoIt's following the semantics of wider use of `<<`` in groovy which denotes forwarding contents of one object into another, eg: adding to a list list << x or writing to a stream: new File('test.txt') << 'hello world' So if you read it as "forward the result of g into f" then it makes a little more sense. But I agree, it's still not very intuitive and for readability I would normally just write: h = { f(g(it)) } Which I think is far clearer. But that's partly an argument against functional programming style itself which would ordinarily see function composition as more idiomatic.
- dllthomas 8y agoI really don't follow your expectation here. "Data moves in the direction of the arrows" seems natural to me. Can you unpack it at all? I'd like to understand where you're coming from.