mirror of
https://github.com/fiddlerwoaroof/data-lens.git
synced 2025-11-08 18:26:32 +00:00
feat(group-by): add group-by function
This commit is contained in:
14
lens.lisp
14
lens.lisp
@ -323,6 +323,20 @@
|
|||||||
it
|
it
|
||||||
(alexandria:iota it-length))))))))
|
(alexandria:iota it-length))))))))
|
||||||
|
|
||||||
|
(defun-ct group-by (fn &key (test 'equal))
|
||||||
|
(lambda (seq)
|
||||||
|
(let ((groups (make-hash-table :test test)))
|
||||||
|
(map nil
|
||||||
|
(lambda (it)
|
||||||
|
(push it
|
||||||
|
(gethash (funcall fn it)
|
||||||
|
groups)))
|
||||||
|
seq)
|
||||||
|
(mapcar (lambda (it)
|
||||||
|
(cons (car it)
|
||||||
|
(reverse (cdr it))))
|
||||||
|
(alexandria:hash-table-alist groups)))))
|
||||||
|
|
||||||
#+nil
|
#+nil
|
||||||
(defmacro <> (arity &rest funs)
|
(defmacro <> (arity &rest funs)
|
||||||
(let ((arg-syms (loop repeat arity collect (gensym))))
|
(let ((arg-syms (loop repeat arity collect (gensym))))
|
||||||
|
|||||||
Reference in New Issue
Block a user