github-tui/lib/list_extra.ml

13 lines
272 B
OCaml
Raw Normal View History

2024-01-29 22:05:08 +03:00
let in_between ~sep list =
let rec loop = function
| [] -> []
| x :: xs -> sep :: x :: loop xs
in
match list with
2024-03-23 13:26:12 +03:00
| [] | [ _ ] -> list
2024-02-11 16:16:50 +03:00
| x :: xs -> x :: loop xs
let generate n f =
2024-03-23 13:26:12 +03:00
let rec loop i = if i = n then [] else f i :: loop (i + 1) in
loop 0