Simplify some Result.List.all

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-09-03 10:19:05 +04:00
parent b41f132fb0
commit 68f4147869
3 changed files with 19 additions and 25 deletions

View File

@ -66,19 +66,17 @@ module Backend = struct
{ info { info
; lib ; lib
; runner_libraries = ; runner_libraries =
Result.List.all (List.map info.runner_libraries ~f:resolve) Result.List.map info.runner_libraries ~f:resolve
; extends = ; extends =
let open Result.O in let open Result.O in
Result.List.all Result.List.map info.extends ~f:(fun ((loc, name) as x) ->
(List.map info.extends resolve x >>= fun lib ->
~f:(fun ((loc, name) as x) -> match get ~loc lib with
resolve x >>= fun lib -> | None ->
match get ~loc lib with Error (Errors.exnf loc "%S is not an %s"
| None -> (Lib_name.to_string name)
Error (Errors.exnf loc "%S is not an %s" (desc ~plural:false))
(Lib_name.to_string name) | Some t -> Ok t)
(desc ~plural:false))
| Some t -> Ok t))
} }
let dgen t = let dgen t =
@ -190,9 +188,7 @@ include Sub_system.Register_end_point(
>>= fun libs -> >>= fun libs ->
Lib.DB.find_many (Scope.libs scope) [Dune_file.Library.best_name lib] Lib.DB.find_many (Scope.libs scope) [Dune_file.Library.best_name lib]
>>= fun lib -> >>= fun lib ->
Result.List.all Result.List.map info.libraries ~f:(Lib.DB.resolve (Scope.libs scope))
(List.map info.libraries
~f:(Lib.DB.resolve (Scope.libs scope)))
>>= fun more_libs -> >>= fun more_libs ->
Lib.closure (lib @ libs @ more_libs) Lib.closure (lib @ libs @ more_libs)
in in

View File

@ -87,16 +87,14 @@ module Driver = struct
; lib = lazy lib ; lib = lazy lib
; replaces = ; replaces =
let open Result.O in let open Result.O in
Result.List.all Result.List.map info.replaces ~f:(fun ((loc, name) as x) ->
(List.map info.replaces resolve x >>= fun lib ->
~f:(fun ((loc, name) as x) -> match get ~loc lib with
resolve x >>= fun lib -> | None ->
match get ~loc lib with Error (Errors.exnf loc "%a is not a %s"
| None -> Lib_name.pp_quoted name
Error (Errors.exnf loc "%a is not a %s" (desc ~plural:false))
Lib_name.pp_quoted name | Some t -> Ok t)
(desc ~plural:false))
| Some t -> Ok t))
} }
let dgen t = let dgen t =

View File

@ -133,7 +133,7 @@ module Register_end_point(M : End_point) = struct
(match M.Info.backends info with (match M.Info.backends info with
| None -> Ok None | None -> Ok None
| Some l -> | Some l ->
Result.List.all (List.map l ~f:(M.Backend.resolve (Scope.libs c.scope))) Result.List.map l ~f:(M.Backend.resolve (Scope.libs c.scope))
>>| Option.some) >>| Option.some)
>>= fun written_by_user -> >>= fun written_by_user ->
M.Backend.Selection_error.or_exn ~loc:(M.Info.loc info) M.Backend.Selection_error.or_exn ~loc:(M.Info.loc info)