I noticed in some code in this sample that contained the >> operator:
let printTree =
tree >> Seq.iter (Seq.fold (+) \"\" >> printfn \"%s\")
>
The composition operators, <<
and >>
are use to join two functions such that the result of one becomes the input of the other. Since functions are also values, unless otherwise note, they are treated as such so that the following expressions are equivalent:
f1 f2 f3 ... fn x = (..((f1 f2) f3) ... fn) x
Specifically, f2, f3, ...fn
and x
are treated as values and are not evaluated prior to being passed as parameters to their preceding functions. Sometimes that is what you want but other times you want to indicate that the result
of one function is to be the input of the other. This can be realized using the composition operators <<
and >>
thus:
(f1 << f2 << f3 ... << fn) x = f1(f2(f3 ... (fn x )..)
Similarly
(fn >> ... f3 >> f2 >> f1) x = f1(f2(f3 ... (fn x )..)
Since the composition operator returns a function, the explicit parameter, x
, is not required unlike in the pipe operators x |> fn ... |> f1
or f1 <| ... fn <| x