mirror of
https://github.com/fiddlerwoaroof/data-lens.git
synced 2025-11-08 10:16:32 +00:00
feat(transducers): add DATA-LENS.TRANSDUCERS:INTO, with tests
This commit is contained in:
@ -16,10 +16,19 @@
|
||||
seq)
|
||||
acc)))
|
||||
|
||||
#+(or)
|
||||
(defun document (&rest strings)
|
||||
(serapeum:string-join strings #.(format nil "~2%")))
|
||||
|
||||
(defgeneric init (client))
|
||||
(defgeneric stepper (client))
|
||||
(defgeneric unwrap (client obj)
|
||||
(:method (client obj) obj))
|
||||
(defgeneric builder-for-input (seq)
|
||||
(:documentation
|
||||
"Take a transducible sequence, return a builder and an init value for that builder.
|
||||
|
||||
CONSTRAINT: SEQ should be copied, not modified"))
|
||||
|
||||
(defun exit-early (acc)
|
||||
(throw 'done acc))
|
||||
@ -36,10 +45,29 @@
|
||||
transducer
|
||||
(init build)))))))
|
||||
|
||||
#+(or)
|
||||
(defun into (to xf from)
|
||||
(multiple-value-bind (builder init) (builder-for-input to)
|
||||
(let* ((xf (etypecase xf
|
||||
(list (apply 'alexandria:compose xf))
|
||||
((or function symbol) xf)))
|
||||
(transducer (funcall xf (stepper builder))))
|
||||
(unwrap builder
|
||||
(funcall transducer
|
||||
(catch 'done
|
||||
(reduce-generic from
|
||||
transducer
|
||||
init)))))))
|
||||
|
||||
(defmacro defdocumentation (name &body doc-specs)
|
||||
name doc-specs
|
||||
nil)
|
||||
|
||||
(defdocumentation transducer-protocol
|
||||
(:function transduce (xf build seq)
|
||||
)
|
||||
(:function transduce (xf builder seq)
|
||||
"Run a transducer XF over sequence SEQ using BUILDER to accumulate results.
|
||||
|
||||
Uses the generic function REDUCE-GENERIC so transducers work over lazy
|
||||
sequences and hash tables.")
|
||||
(:generic-function unwrap (client obj)
|
||||
)
|
||||
(:generic-function unwrap (client obj)
|
||||
|
||||
Reference in New Issue
Block a user