group-by-car
public text v1 · immutable(require 'cl)
(defun* group-by-car (pairs &key (test #'equal))
"Group the values of pairs by their CARs."
(loop with keys
with data
for (key value) in pairs
for values = (cons value (assoc* key data :test test))
do (pushnew key keys :test test)
do (push (cons key values) data)
finally return
(loop for key in (nreverse keys)
collect (assoc key data))))