Namespace: FsToolkit.ErrorHandling
Result<'ok, 'error>[] -> 'ok[] * 'error[]Separates an array of Result values into a tuple of the Ok values and the Error values, preserving order within each group.
let results = [| Ok 1; Error "bad"; Ok 2; Ok 3; Error "worse" |]
results |> Array.partitionResults
// ([| 1; 2; 3 |], [| "bad"; "worse" |])// string -> Result<int, string>
let tryParseInt str =
match System.Int32.TryParse str with
| true, x -> Ok x
| false, _ -> Error (sprintf "unable to parse '%s' to integer" str)
[| "1"; "foo"; "3"; "bar" |]
|> Array.map tryParseInt
|> Array.partitionResults
// ([| 1; 3 |], [| "unable to parse 'foo' to integer"; "unable to parse 'bar' to integer" |])All Ok values:
[| Ok 1; Ok 2; Ok 3 |] |> Array.partitionResults
// ([| 1; 2; 3 |], [||])All Error values:
[| Error "a"; Error "b" |] |> Array.partitionResults
// ([||], [| "a"; "b" |])