erlang: lists foldr/3 + partition/2 + takewhile/dropwhile/splitwith (823/823)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m5s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m5s
Higher-order traversal family in lib/erlang/lists-ext.sx, registered
pure via the er-register-builtin-bifs! wrapper. foldr right-folds;
partition returns {Yes,No} order-preserved; splitwith = {takewhile,
dropwhile}. lists_ext suite 38 -> 52.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -154,3 +154,54 @@
|
||||
(er-lx-test "keysort stable on equal keys"
|
||||
(er-lx-nm
|
||||
"lists:keysort(1, [{a,1},{a,2},{a,3}]) =:= [{a,1},{a,2},{a,3}]") "true")
|
||||
|
||||
;; ── lists:foldr/3 ─────────────────────────────────────────────────
|
||||
(er-lx-test "foldr preserves order"
|
||||
(er-lx-nm
|
||||
"lists:foldr(fun(X,Acc) -> [X|Acc] end, [], [1,2,3]) =:= [1,2,3]") "true")
|
||||
|
||||
(er-lx-test "foldr sum"
|
||||
(erlang-eval-ast "lists:foldr(fun(X,A) -> X+A end, 0, [1,2,3,4])") 10)
|
||||
|
||||
(er-lx-test "foldr empty returns acc"
|
||||
(erlang-eval-ast "lists:foldr(fun(X,A) -> X+A end, 42, [])") 42)
|
||||
|
||||
;; ── lists:partition/2 ─────────────────────────────────────────────
|
||||
(er-lx-test "partition evens/odds"
|
||||
(er-lx-nm
|
||||
"lists:partition(fun(X) -> X rem 2 =:= 0 end, [1,2,3,4,5]) =:= {[2,4],[1,3,5]}")
|
||||
"true")
|
||||
|
||||
(er-lx-test "partition all satisfy"
|
||||
(er-lx-nm "lists:partition(fun(_) -> true end, [1,2]) =:= {[1,2],[]}") "true")
|
||||
|
||||
(er-lx-test "partition empty"
|
||||
(er-lx-nm "lists:partition(fun(_) -> true end, []) =:= {[],[]}") "true")
|
||||
|
||||
;; ── lists:takewhile/2 ─────────────────────────────────────────────
|
||||
(er-lx-test "takewhile prefix"
|
||||
(er-lx-nm "lists:takewhile(fun(X) -> X < 3 end, [1,2,3,4,1]) =:= [1,2]") "true")
|
||||
|
||||
(er-lx-test "takewhile none"
|
||||
(er-lx-nm "lists:takewhile(fun(X) -> X < 0 end, [1,2]) =:= []") "true")
|
||||
|
||||
(er-lx-test "takewhile all"
|
||||
(er-lx-nm "lists:takewhile(fun(X) -> X < 9 end, [1,2,3]) =:= [1,2,3]") "true")
|
||||
|
||||
;; ── lists:dropwhile/2 ─────────────────────────────────────────────
|
||||
(er-lx-test "dropwhile prefix"
|
||||
(er-lx-nm "lists:dropwhile(fun(X) -> X < 3 end, [1,2,3,4,1]) =:= [3,4,1]") "true")
|
||||
|
||||
(er-lx-test "dropwhile all"
|
||||
(er-lx-nm "lists:dropwhile(fun(X) -> X < 9 end, [1,2,3]) =:= []") "true")
|
||||
|
||||
(er-lx-test "dropwhile none"
|
||||
(er-lx-nm "lists:dropwhile(fun(X) -> X < 0 end, [1,2]) =:= [1,2]") "true")
|
||||
|
||||
;; ── lists:splitwith/2 ─────────────────────────────────────────────
|
||||
(er-lx-test "splitwith"
|
||||
(er-lx-nm
|
||||
"lists:splitwith(fun(X) -> X < 3 end, [1,2,3,4,1]) =:= {[1,2],[3,4,1]}") "true")
|
||||
|
||||
(er-lx-test "splitwith empty"
|
||||
(er-lx-nm "lists:splitwith(fun(_) -> true end, []) =:= {[],[]}") "true")
|
||||
|
||||
Reference in New Issue
Block a user