22 lines
430 B
OCaml
22 lines
430 B
OCaml
|
include Stdlib.List
|
||
|
|
||
|
let flat_map f xs =
|
||
|
let rec iter = function
|
||
|
| [] -> []
|
||
|
| x :: xs -> append_then_iter xs (f x)
|
||
|
[@@tail_mod_cons]
|
||
|
and append_then_iter xs = function
|
||
|
| [] -> iter xs
|
||
|
| y :: ys -> y :: append_then_iter xs ys
|
||
|
[@@tail_mod_cons]
|
||
|
in
|
||
|
iter xs
|
||
|
|
||
|
let iter_up_to f xs ~limit =
|
||
|
let rec iter n = function
|
||
|
| x :: xs when n > 0 ->
|
||
|
f x; iter (n - 1) xs
|
||
|
| _ -> ()
|
||
|
in
|
||
|
iter limit xs
|