4 ms·
> Except that Option<T> is a class not a struct There is ValueOption<T> now. It's a mouthful and you'll still have to deal with all the standard library, or o
by piaste 8y ago
> Except that Option<T> is a class not a struct
There is ValueOption<T> now.
It's a mouthful and you'll still have to deal with all the standard library, or other third-party libraries, which produces and consumes Option<T>, but you can address that with some aliases and conversion operators if you want to go all-in:
type 't voption = ValueOption<'t>
type VOption<'t> = ValueOption<'t>
let inline (!) opt =
if System.Object.ReferenceEquals(opt, null) then ValueNone else
match opt with None -> ValueNone | Some x -> ValueSome x
let inline (?) vopt =
match vopt with ValueNone -> None | ValueSome x -> Some x;;
// usage
let x = !(List.tryFind (fun x -> x = 0) [1]);;
// [<Struct>] val x : int voption = ValueNone