Simplify closure calculation with Result.iter

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-08-10 13:12:16 +03:00
parent f38edc22f0
commit 6a08e36f4b
3 changed files with 11 additions and 8 deletions

View File

@ -874,16 +874,10 @@ and closure_with_overlap_checks db ts ~stack =
>>= fun () ->
Dep_stack.push stack (to_id t) >>= fun stack ->
t.requires >>= fun deps ->
iter deps ~stack >>| fun () ->
Result.iter deps ~f:(loop ~stack) >>| fun () ->
res := t :: !res
and iter ts ~stack =
match ts with
| [] -> Ok ()
| t :: ts ->
loop t ~stack >>= fun () ->
iter ts ~stack
in
iter ts ~stack >>| fun () ->
Result.iter ts ~f:(loop ~stack) >>| fun () ->
List.rev !res
let closure_with_overlap_checks db l =

View File

@ -59,4 +59,11 @@ let concat_map =
in
fun l ~f -> loop f [] l
let rec iter t ~f =
match t with
| [] -> Ok ()
| x :: xs ->
f x >>= fun () ->
iter xs ~f
type ('a, 'error) result = ('a, 'error) t

View File

@ -23,6 +23,8 @@ val map_error : ('a, 'error1) t -> f:('error1 -> 'error2) -> ('a, 'error2) t
val all : ('a, 'error) t list -> ('a list, 'error) t
val iter : 'a list -> f:('a -> (unit, 'error) t) -> (unit, 'error) t
val concat_map
: 'a list
-> f:('a -> ('b list, 'error) t)