talircd/lib/data/test_list.ml

30 lines
688 B
OCaml
Raw Normal View History

2024-01-31 00:12:57 +00:00
let%expect_test _ =
let print_list print_ele xs =
let rec iter pre post = function
| [] -> print_string post
| x :: xs ->
print_string pre;
print_ele x;
iter ";" "]" xs
in
iter "[" "[]" xs
in
2024-01-31 16:27:27 +00:00
let print_int_sp x = print_int x; print_string " " in
2024-01-31 00:12:57 +00:00
let print_ints_nl xs = print_list print_int xs; print_newline () in
print_ints_nl
(List.flat_map
(function
| 1 -> [1;2;3]
| 2 -> [4;5;6]
| _ -> [7;8;9])
[1;2;3;1;2]);
[%expect {| [1;2;3;4;5;6;7;8;9;1;2;3;4;5;6] |}];
2024-01-31 16:27:27 +00:00
List.iter_up_to ~limit:5
print_int_sp
[1;2;3;4;5;6;7;8;9];
print_newline ();
[%expect {| 1 2 3 4 5 |}];