erlang: lists flatmap/2 + filtermap/2 + mapfoldl/3 + search/2 (862/862)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
Higher-order list ops in lib/erlang/lists-ext.sx. filtermap honours
true/false/{true,V}; mapfoldl returns {Mapped, Acc}; search returns
{value,E}|false. lists_ext suite 83 -> 91.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -310,3 +310,34 @@
|
||||
|
||||
(er-lx-test "droplast single"
|
||||
(er-lx-nm "lists:droplast([9]) =:= []") "true")
|
||||
|
||||
;; ── lists:flatmap/2 ───────────────────────────────────────────────
|
||||
(er-lx-test "flatmap duplicates"
|
||||
(er-lx-nm "lists:flatmap(fun(X) -> [X,X] end, [1,2]) =:= [1,1,2,2]") "true")
|
||||
|
||||
(er-lx-test "flatmap empty"
|
||||
(er-lx-nm "lists:flatmap(fun(X) -> [X] end, []) =:= []") "true")
|
||||
|
||||
;; ── lists:filtermap/2 ─────────────────────────────────────────────
|
||||
(er-lx-test "filtermap transform"
|
||||
(er-lx-nm
|
||||
"lists:filtermap(fun(X) -> case X rem 2 of 0 -> {true, X*10}; _ -> false end end, [1,2,3,4]) =:= [20,40]")
|
||||
"true")
|
||||
|
||||
(er-lx-test "filtermap bool keep"
|
||||
(er-lx-nm "lists:filtermap(fun(X) -> X > 2 end, [1,2,3,4]) =:= [3,4]") "true")
|
||||
|
||||
;; ── lists:mapfoldl/3 ──────────────────────────────────────────────
|
||||
(er-lx-test "mapfoldl map+acc"
|
||||
(er-lx-nm
|
||||
"lists:mapfoldl(fun(X,A) -> {X*2, A+X} end, 0, [1,2,3]) =:= {[2,4,6],6}") "true")
|
||||
|
||||
(er-lx-test "mapfoldl empty"
|
||||
(er-lx-nm "lists:mapfoldl(fun(X,A) -> {X,A} end, 5, []) =:= {[],5}") "true")
|
||||
|
||||
;; ── lists:search/2 ────────────────────────────────────────────────
|
||||
(er-lx-test "search hit"
|
||||
(er-lx-nm "lists:search(fun(X) -> X > 2 end, [1,2,3,4]) =:= {value,3}") "true")
|
||||
|
||||
(er-lx-test "search miss"
|
||||
(er-lx-nm "lists:search(fun(X) -> X > 9 end, [1,2,3])") "false")
|
||||
|
||||
Reference in New Issue
Block a user