feat: add hash-join

This commit is contained in:
Edward Langley
2023-10-22 11:15:22 -07:00
parent 2207631122
commit 989454fc28
2 changed files with 21 additions and 0 deletions

View File

@ -423,6 +423,26 @@
(reverse (cdr it))))
(alexandria:hash-table-alist groups)))))
(defun hash-join (probe join-fn &key (test 'eql) (key 'car))
(let* ((lookup (make-hash-table :test test :size (length probe)))
(lookup-fn (functionalize lookup)))
(map nil
(lambda (it)
(setf (gethash (funcall key it)
lookup)
it))
probe)
(lambda (collection)
(map (etypecase collection
(list 'list)
(vector 'vector)
(sequence 'list))
(lambda (it)
(let* ((key-value (funcall key it))
(matching-probe (funcall lookup-fn key-value)))
(funcall join-fn it matching-probe)))
collection))))
#+nil
(defmacro <> (arity &rest funs)
(let ((arg-syms (loop repeat arity collect (gensym))))

View File

@ -22,6 +22,7 @@
#: #:suffixp #:functionalize #:inc #:group-by #:keys
#:conj #:disj #:delay #:of-type #:transform #:calling*
#:calling
#:hash-join
#:tap))
(defpackage :data-lens.transducers.internals