parent
e77bd30681
commit
9943acb4dc
|
@ -29,3 +29,25 @@ module O = struct
|
||||||
let ( >>= ) t f = bind t ~f
|
let ( >>= ) t f = bind t ~f
|
||||||
let ( >>| ) t f = map t ~f
|
let ( >>| ) t f = map t ~f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
open O
|
||||||
|
|
||||||
|
let all =
|
||||||
|
let rec loop acc = function
|
||||||
|
| [] -> Ok (List.rev acc)
|
||||||
|
| t :: l ->
|
||||||
|
t >>= fun x ->
|
||||||
|
loop (x :: acc) l
|
||||||
|
in
|
||||||
|
fun l -> loop [] l
|
||||||
|
|
||||||
|
let concat_map =
|
||||||
|
let rec loop f acc = function
|
||||||
|
| [] -> Ok (List.rev acc)
|
||||||
|
| x :: l ->
|
||||||
|
f x >>= fun y ->
|
||||||
|
loop f (List.rev_append y acc) l
|
||||||
|
in
|
||||||
|
fun l ~f -> loop f [] l
|
||||||
|
|
||||||
|
type ('a, 'error) result = ('a, 'error) t
|
||||||
|
|
|
@ -16,3 +16,13 @@ val map : ('a, 'error) t -> f:('a -> 'b) -> ('b, 'error) t
|
||||||
val bind : ('a, 'error) t -> f:('a -> ('b, 'error) t) -> ('b, 'error) t
|
val bind : ('a, 'error) t -> f:('a -> ('b, 'error) t) -> ('b, 'error) t
|
||||||
|
|
||||||
val map_error : ('a, 'error1) t -> f:('error1 -> 'error2) -> ('a, 'error2) t
|
val map_error : ('a, 'error1) t -> f:('error1 -> 'error2) -> ('a, 'error2) t
|
||||||
|
|
||||||
|
val all : ('a, 'error) t list -> ('a list, 'error) t
|
||||||
|
|
||||||
|
val concat_map
|
||||||
|
: 'a list
|
||||||
|
-> f:('a -> ('b list, 'error) t)
|
||||||
|
-> ('b list, 'error) t
|
||||||
|
|
||||||
|
(** For compatibility with some other code *)
|
||||||
|
type ('a, 'error) result = ('a, 'error) t
|
||||||
|
|
Loading…
Reference in New Issue