Last active
May 7, 2020 12:56
-
-
Save dburriss/946bebc844a0000345b5a68bcf7492d4 to your computer and use it in GitHub Desktop.
A lossy Result fold
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A lossy Result seq fold | |
let singleResult<'T,'U> (rs : Result<'T,'U> seq) : Result<'T seq,'U> = | |
let folder (ts, us) r = | |
match r with | |
| Ok t -> (Seq.append ts [|t|], us) | |
| Error u -> (ts, Seq.append us [|u|]) | |
rs | |
|> Seq.fold folder (Seq.empty, Seq.empty) | |
|> fun (ts, errs) -> | |
if(errs |> Seq.isEmpty) then | |
Ok ts | |
else Error errs | |
|> function | |
| Ok xs -> Ok xs | |
| Error errs -> Error (errs |> Seq.head) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment