add Syntax.list_filter_map
This commit is contained in:
parent
c8863e1a95
commit
08d18467f8
4 changed files with 76 additions and 72 deletions
|
|
@ -7,8 +7,6 @@ let unwrap_err_msg o = match o with Error (`Msg e) -> Error e | Ok v -> Ok v
|
|||
let unwrap_err_caqti o =
|
||||
match o with Error err -> Fmt.error "%a" Caqti_error.pp err | Ok v -> Ok v
|
||||
|
||||
(* TODO list_filter_map *)
|
||||
|
||||
let list_iter f l =
|
||||
let err = ref None in
|
||||
try
|
||||
|
|
@ -37,6 +35,20 @@ let list_map f l =
|
|||
l)
|
||||
with Exit -> ( match !err with None -> assert false | Some v -> v)
|
||||
|
||||
let list_filter_map f l =
|
||||
let err = ref None in
|
||||
try
|
||||
Ok
|
||||
(List.filter_map
|
||||
(fun v ->
|
||||
match f v with
|
||||
| Error _e as e ->
|
||||
err := Some e;
|
||||
raise Exit
|
||||
| Ok v -> v)
|
||||
l)
|
||||
with Exit -> ( match !err with None -> assert false | Some v -> v)
|
||||
|
||||
let list_fold_left f acc l =
|
||||
List.fold_left
|
||||
(fun acc v ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue