Add more helpers to Fantomas library (#7)

This commit is contained in:
Patrick Stevens
2024-10-06 19:45:13 +01:00
committed by GitHub
parent 8834d885de
commit f4da4cd2a1
9 changed files with 762 additions and 3 deletions

View File

@@ -0,0 +1,23 @@
namespace WoofWare.Whippet.Fantomas
[<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