File tree Expand file tree Collapse file tree 3 files changed +12
-17
lines changed Expand file tree Collapse file tree 3 files changed +12
-17
lines changed Original file line number Diff line number Diff line change @@ -64,13 +64,8 @@ let parse l =
6464 | `Block rb -> Block. from_raw rb >> = fun b -> Ok (Block b))
6565 l
6666 in
67- let errors =
68- Util.List. concat_map (function Ok _ -> [] | Error l -> l) results
69- in
70- let ok =
71- List. filter_map (function Ok x -> Some x | Error _ -> None ) results
72- in
73- match errors with [] -> Ok ok | _ -> Error errors
67+ let ok, errors = Util.Result.List. split results in
68+ match errors with [] -> Ok ok | _ -> Error (List. concat errors)
7469
7570let parse_lexbuf file_contents syntax l =
7671 match syntax with
Original file line number Diff line number Diff line change @@ -45,6 +45,15 @@ module Result = struct
4545 let map ~f l =
4646 fold ~f: (fun acc elm -> f elm >> | fun elm' -> elm' :: acc) ~init: [] l
4747 >> | List. rev
48+
49+ let split l =
50+ let rec split_rec oks errors l =
51+ match l with
52+ | [] -> (List. rev oks, List. rev errors)
53+ | Ok x :: tl -> split_rec (x :: oks) errors tl
54+ | Error x :: tl -> split_rec oks (x :: errors) tl
55+ in
56+ split_rec [] [] l
4857 end
4958end
5059
@@ -95,15 +104,6 @@ module List = struct
95104 | h :: t -> ( match f h with Some x -> Some x | None -> aux t)
96105 in
97106 aux l
98-
99- let concat_map f l =
100- let rec aux f acc = function
101- | [] -> List. rev acc
102- | x :: l ->
103- let xs = f x in
104- aux f (List. rev_append xs acc) l
105- in
106- aux f [] l
107107end
108108
109109module Array = struct
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ module Result : sig
3636 ('acc , 'err ) result
3737
3838 val map : f :('a -> ('b , 'err ) result ) -> 'a list -> ('b list , 'err ) result
39+ val split : ('a , 'err ) result list -> 'a list * 'err list
3940 end
4041end
4142
5051
5152module List : sig
5253 val find_map : ('a -> 'b option ) -> 'a list -> 'b option
53- val concat_map : ('a -> 'b list ) -> 'a list -> 'b list
5454end
5555
5656module String : sig
You can’t perform that action at this time.
0 commit comments