30 lines
688 B
OCaml
30 lines
688 B
OCaml
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
|
|
|
|
let print_int_sp x = print_int x; print_string " " in
|
|
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] |}];
|
|
|
|
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 |}];
|