Add unit tests for lib.functions.rev-map

This commit is contained in:
2025-02-21 14:05:46 +00:00
parent dc6b2f701b
commit 1edd618b42
2 changed files with 32 additions and 2 deletions

View File

@@ -37,11 +37,11 @@ each member is STEP distance apart."
(subseq lst n)))
(fn rev-map (indicator lst &key (key-eq #'eq))
(-> (function list &key (:key-eq function)) list)
(-> (function sequence &key (:key-eq function)) list)
"Given LST and INDICATOR: LST -> A, return an association list A -> 2^LST
where key x in A has associations {y in LST : INDICATOR(y) = x}."
(loop :with assoc-list := nil
:for element :in lst
:for element :in (coerce lst 'list)
:for key := (funcall indicator element)
:if (assoc key assoc-list :test key-eq)
:do (->> (alist-val key assoc-list)