util: separated the monadic traverse into a utility module

This commit is contained in:
2026-02-11 23:40:17 +03:00
parent 36ef8f2a22
commit bd6acf89e0
2 changed files with 10 additions and 7 deletions

View File

@@ -34,13 +34,7 @@ type top_level =
(* we use result here to make things nicer *)
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
let traverse = Util.traverse
let map = List.map

9
lib/compiler/util.ml Normal file
View 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