let (|>) x f = f x
let (|>) x f = f x
(|>) :: Seq a -> a -> Seq a
O(1). Add an element to the right end of a sequence. Mnemonic: a triangle with the single element at the pointy end.
It seems to be in the containers package since 2005: [1][0]: http://hackage.haskell.org/package/containers-0.5.5.1/docs/D...
[1]: https://github.com/haskell/containers/commit/1e61853dbd4b9fc...
'|>' from F# is the same as 'flip $' in haskell, or (&) imported from the lens library
The following code computes the sum of squares of all positive numbers of a list:
list |> Enum.filter(&(&1 > 0)) |> Enum.map(&(&1 * &1)) |> Enum.reduce(0, &(&1 + &2))
let (|>) x f = f x
Is basically saying: x |> f is equal to f x
So in F# it's the same as Elixir, but the value x is applied to the function f (passed as the last argument). i.e. list |> List.filter (fun x -> x > 0)
|> List.map (fun x -> x * x)
|> List.reduce (fun s x -> s + x)I think the difference though is that the |> in Elixir is actually a macro that modifies the following function call's first argument.
So list |> Enum.filter(&(&1 > 0)) doesn't end up using filter as a curried function as one would find in Haskell:
Enum.filter(&(&1 > 0)) list
The end result is actually:
Enum.filter(list, &(&1 > 0))