I think the best way to describe this is an example, as looking at a definition can be a bit confusing. Say you had this:
let isEven x = x % 2 = 0 [1 .. 99] |> List.filter (fun x -> not (isEven x))
Using composition operators, you can rewrite them as one of them:
[1 .. 99] |> List.filter (isEven >> not) [1 .. 99] |> List.filter (not << isEven)
More general, if you have something like this:
data |> a |> b |> c
You can rewrite it as follows:
data |> (a >> b >> c)
and interpret a >> b >> c in the same way as a, then do b and then c. If you prefer a more traditional reverse order:
(a (b (c data)))
you can rewrite it as
((a << b << c) data)
This is also called a dotless style. In normal cases, it may be harder to read than using the regular style, but when moving to higher-order functions, it is easier to read, since you don't need to add noise (fun x -> ) .
source share