Missing OptionBuilder for F# filling the void to interop with C#'s ?.
usage.
It works with Nulls, Options, Nullables.
Build Statuses:
There are more C# devs relying on the safe nav operator ?.
and so nulls will only get worse on the C# side, making it more likely null's are going to drop out of APIs.
This project creates an option { }
computational expression and chooseSeq { }
computational expression that allows binding 'T option
/'T Nullable
/'T:null
thus either returns an option or a sequence respectively.
With chooseSeq
if you yield!
another chooseSeq it will work recursively flatten or any sequence of NonNullSeq
, list, or Set type. Any other sequence will be treated like a T:null
object yield!
and let!
work with 'T option
/'T Nullable
/'T:null
let x = Nullable(3)
let y = Nullable(3)
option {
let! x' = x
let! y' = y
return (x' + y')
} |> should equal (Some 6)
See more examples in Tests/RealWorld.fs.
This library also has some operators available when specifically included
using FSharp.Interop.NullOptAble.Operators
You can find examples of them in Tests/RealWorldOperators.fs.