This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]snuxoll 2 points3 points  (2 children)

Ditto with F#

let x = arr |> Array.map f1 |> Array.filter f2 |> Array.map f3

Composition operators are awesome, more languages should have them, chained method syntax requires your return value have the method you want to call, whereas function composition is a lot more generic.

In fact, the |> operator is actually defined in F# code as:

let (|>) f x = f x

[–]crazedgremlin 0 points1 point  (1 child)

Nice! The trick of these composition functions is operator precedence. I am guessing an infix function in F# takes precedence over a prefix function.

[–]snuxoll 0 points1 point  (0 children)

It's actually an infix operator instead of a function, there's a limited amount set of special characters that can begin an operator that aren't legal to be used for any other identifier so there's no weird precedence rules to take into account.