Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
(partitiono pred l yes no) — yes is the elements of l where pred
succeeds; no is the rest. Conde dispatches on each element via the
predicate goal vs nafc-of-the-predicate, threading the head through
the matching output list.
Composes with intarith / membero / etc. for any predicate-shaped goal:
(partitiono (fn (x) (lto-i x 5)) (list 1 7 2 8 3) yes no)
yes -> (1 2 3); no -> (7 8)
5 new tests, 496/496 cumulative.
76 lines
1.2 KiB
Plaintext
76 lines
1.2 KiB
Plaintext
;; lib/minikanren/tests/partitiono.sx — partition list by predicate.
|
|
|
|
(mk-test
|
|
"partitiono-empty"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(yes no)
|
|
(partitiono (fn (x) (== x 1)) (list) yes no)
|
|
(== q (list yes no))))
|
|
(list (list (list) (list))))
|
|
|
|
(mk-test
|
|
"partitiono-by-equality"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(yes no)
|
|
(partitiono
|
|
(fn (x) (== x 2))
|
|
(list 1 2 3 2 4)
|
|
yes
|
|
no)
|
|
(== q (list yes no))))
|
|
(list
|
|
(list
|
|
(list 2 2)
|
|
(list 1 3 4))))
|
|
|
|
(mk-test
|
|
"partitiono-by-numeric-pred"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(yes no)
|
|
(partitiono
|
|
(fn (x) (lto-i x 5))
|
|
(list 1 7 2 8 3)
|
|
yes
|
|
no)
|
|
(== q (list yes no))))
|
|
(list
|
|
(list
|
|
(list 1 2 3)
|
|
(list 7 8))))
|
|
|
|
(mk-test
|
|
"partitiono-all-yes"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(yes no)
|
|
(partitiono
|
|
(fn (x) (lto-i x 100))
|
|
(list 1 2 3)
|
|
yes
|
|
no)
|
|
(== q (list yes no))))
|
|
(list (list (list 1 2 3) (list))))
|
|
|
|
(mk-test
|
|
"partitiono-all-no"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(yes no)
|
|
(partitiono
|
|
(fn (x) (lto-i 100 x))
|
|
(list 1 2 3)
|
|
yes
|
|
no)
|
|
(== q (list yes no))))
|
|
(list (list (list) (list 1 2 3))))
|
|
|
|
(mk-tests-run!)
|