util: separated the monadic traverse into a utility module
This commit is contained in:
@@ -34,13 +34,7 @@ type top_level =
|
|||||||
|
|
||||||
(* we use result here to make things nicer *)
|
(* we use result here to make things nicer *)
|
||||||
let ( let* ) = Result.bind
|
let ( let* ) = Result.bind
|
||||||
let traverse f l =
|
let traverse = Util.traverse
|
||||||
let rec aux acc = function
|
|
||||||
| x :: xs ->
|
|
||||||
let* result = f x in
|
|
||||||
aux (result :: acc) xs
|
|
||||||
| [] -> Ok (List.rev acc) in
|
|
||||||
aux [] l
|
|
||||||
let map = List.map
|
let map = List.map
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
9
lib/compiler/util.ml
Normal file
9
lib/compiler/util.ml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
let ( let* ) = Result.bind
|
||||||
|
|
||||||
|
let traverse f l =
|
||||||
|
let rec aux acc = function
|
||||||
|
| x :: xs ->
|
||||||
|
let* result = f x in
|
||||||
|
aux (result :: acc) xs
|
||||||
|
| [] -> Ok (List.rev acc) in
|
||||||
|
aux [] l
|
||||||
Reference in New Issue
Block a user