ofPair
Namespace: FsToolkit.ErrorHandling
Transforms a bool * 'T
value to 'T Option
.
Function Signature
bool * 'T -> 'T Option
Examples
Example 1
let opt = Option.ofPair (true, 1)
// Some 1
Example 2
let opt = Option.ofPair (false, 1)
// None
Example 3
Instead of using this code snippet,
match Int32.TryParse "12" with
| true, x -> x
| false, _ -> 0
// 12
you could use Option.ofPair
if it better suits your use case
match Int32.TryParse "12" |> Option.ofPair with
| Some x -> x
| None -> 0
// 12
Last updated