chore(transducers): move functions around

This commit is contained in:
Edward
2021-01-04 20:19:19 -08:00
parent b158a4c759
commit 96cc36bb65
3 changed files with 35 additions and 21 deletions

View File

@ -22,12 +22,14 @@
(defpackage :data-lens.transducers.internals
(:use :cl)
(:export #:unwrap #:init #:reduce-generic #:stepper))
(:export #:unwrap #:init #:reduce-generic #:stepper #:transduce
#:exit-early))
(defpackage :data-lens.transducers
(:use :cl)
(:import-from :data-lens.transducers.internals
#:unwrap #:init #:reduce-generic #:stepper)
#:unwrap #:init #:reduce-generic #:stepper #:transduce
#:exit-early)
(:export #:mapping :filtering :deduping :catting :splitting
#:exit-early :taking :dropping :transduce
#:hash-table-builder :vector-builder :list-builder

View File

@ -1,10 +1,5 @@
(in-package :data-lens.transducers.internals)
(defgeneric unwrap (it obj)
(:method (it obj) obj))
(defgeneric init (it))
(defgeneric stepper (it))
(defgeneric reduce-generic (seq func init)
(:method ((seq sequence) (func function) init)
(reduce func seq :initial-value init))
@ -20,3 +15,34 @@
(setf acc (funcall func acc (list k v))))
seq)
acc)))
(defgeneric init (client))
(defgeneric stepper (client))
(defgeneric unwrap (client obj)
(:method (client obj) obj))
(defun exit-early (acc)
(throw 'done acc))
(defun transduce (xf build seq)
(let* ((xf (etypecase xf
(list (apply 'alexandria:compose xf))
((or function symbol) xf)))
(transducer (funcall xf (stepper build))))
(unwrap build
(funcall transducer
(catch 'done
(reduce-generic seq
transducer
(init build)))))))
#+(or)
(defdocumentation transducer-protocol
(:function transduce (xf build seq)
)
(:generic-function unwrap (client obj)
)
(:generic-function unwrap (client obj)
)
(:generic-function unwrap (client obj)
))

View File

@ -116,9 +116,6 @@
(let ((splitter (apply #'data-lens:juxt functions)))
(mapping splitter)))
(defun exit-early (acc)
(throw 'done acc))
(defun taking (n)
(lambda (rf)
(let ((taken 0))
@ -141,17 +138,6 @@
(funcall rf acc next)))
((it) (funcall rf it))))))
(defun transduce (xf build seq)
(let* ((xf (etypecase xf
(list (apply 'alexandria:compose xf))
((or function symbol) xf)))
(transducer (funcall xf (stepper build))))
(unwrap build
(funcall transducer
(catch 'done
(reduce-generic seq
transducer
(init build)))))))
(defun eduction (xf seq)
(lambda (build)
(unwrap