I like to use the pipe operator '| > '. However, when mixing functions that return "simple" values with functions that return "values specified by a parameter", everything becomes a bit messy, for example:
let f (x: string) = x |> int |> foo |> bar
works, but it can throw "System.FormatException: ..."
Now suppose I want to fix this by making the 'int' function give an optional result:
let intOption x =
match System.Int32.TryParse x with
| (true, x) -> Some x
| (false,_) -> None
The only problem now is that of course the function
let g x = x |> intOption |> foo |> bar
will not compile due to input errors. Ok, just define the "optional" channel:
let ( |= ) x f =
match x with
| Some y -> Some (f y)
| None -> None
Now I can simply determine:
let f x = x |> intOption |= foo |= bar
and everything works like an enchantment.
OK, the question is: Is this an idiomatic F #? Acceptable? Bad style?
. , '| =' "" , , :
x |> ...|> divisionOption |= (fun y -> y*y) |=...|>...