mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-05 20:18:43 +00:00
34 lines
1.0 KiB
Forth
34 lines
1.0 KiB
Forth
namespace WoofWare.Myriad.Plugins
|
|
|
|
[<RequireQualifiedAccess>]
|
|
module private List =
|
|
let partitionChoice<'a, 'b> (xs : Choice<'a, 'b> list) : 'a list * 'b list =
|
|
let xs, ys =
|
|
(([], []), xs)
|
|
||> List.fold (fun (xs, ys) v ->
|
|
match v with
|
|
| Choice1Of2 x -> x :: xs, ys
|
|
| Choice2Of2 y -> xs, y :: ys
|
|
)
|
|
|
|
List.rev xs, List.rev ys
|
|
|
|
let allSome<'a> (l : 'a option list) : 'a list option =
|
|
let rec go acc (l : 'a option list) =
|
|
match l with
|
|
| [] -> Some (List.rev acc)
|
|
| None :: _ -> None
|
|
| Some head :: tail -> go (head :: acc) tail
|
|
|
|
go [] l
|
|
|
|
/// Return the first error encountered, or the entire list.
|
|
let allOkOrError<'ok, 'err> (l : Result<'ok, 'err> list) : Result<'ok list, 'err> =
|
|
let rec go acc l =
|
|
match l with
|
|
| [] -> Ok (List.rev acc)
|
|
| Error e :: _ -> Error e
|
|
| Ok o :: rest -> go (o :: acc) rest
|
|
|
|
go [] l
|