ocaml: phase 6 List.take/drop/filter_map/flat_map (+6 tests, 400 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 37s

Common functional helpers written in OCaml. flat_map / concat_map
share an implementation. 400-test milestone.
This commit is contained in:
2026-05-08 15:30:29 +00:00
parent 86343345dc
commit 9f05e24c52
3 changed files with 54 additions and 0 deletions

View File

@@ -976,6 +976,20 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 2804)
(eval "(ocaml-run \"match Blue with | (Red | Green) -> 1 | Blue -> 2\")")
;; ── More List utilities (take/drop/filter_map/flat_map) ──────
(epoch 2900)
(eval "(ocaml-run \"List.take 3 [1;2;3;4;5]\")")
(epoch 2901)
(eval "(ocaml-run \"List.drop 2 [1;2;3;4;5]\")")
(epoch 2902)
(eval "(ocaml-run \"List.filter_map (fun x -> if x > 2 then Some (x * 10) else None) [1;2;3;4]\")")
(epoch 2903)
(eval "(ocaml-run \"List.flat_map (fun x -> [x; x]) [1;2;3]\")")
(epoch 2904)
(eval "(ocaml-run \"List.take 0 [1;2;3]\")")
(epoch 2905)
(eval "(ocaml-run \"List.take 100 [1;2;3]\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1544,6 +1558,14 @@ check 2802 "(1|2|3) match 5" '0'
check 2803 "(Red|Green) Red" '1'
check 2804 "(Red|Green) Blue" '2'
# ── List.take/drop/filter_map/flat_map ─────────────────────────
check 2900 "List.take 3" '(1 2 3)'
check 2901 "List.drop 2" '(3 4 5)'
check 2902 "List.filter_map" '(30 40)'
check 2903 "List.flat_map double" '(1 1 2 2 3 3)'
check 2904 "List.take 0" '()'
check 2905 "List.take overflow" '(1 2 3)'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"