Emacs Backstage: Transducers (publ. 2024-11-19)
Another gem you'll want to tune into or download is Woodbury's presentation on transducers:
Transducers: finally, ergonomic data processing for Emacs!
He ported transducers to Elisp. The presentation gives an explanation of what transducers are and demonstrations in Elisp. Basically, transducers are a (system? mechanism?) that allows you to do data transformations in a way that is efficient but still easy to understand. Each call to t-transduce requires three things:
- operations to apply, composed if more than one
- a reducer function, which does something with the results
- a data source, such as an infinite list of numbers
Here is an example:
(t-transduce
;; operations to apply
(t-comp
(t-filter #'cl-evenp) ;; select only even numbers
(t-take 8)) ;; take only 25 results
;; reducer: produce a list from the reusults
#'t-cons
;; source data: random numbers between 0 and 99
(t-random 100))
Here are results from evaluating the above:
You can change the output simply by changing your reducer to #'t-vector. On the next evaluation, this gave
I'll refer you to the presentation itself for more explanations and examples.
Copyright
This work © 2024 by Christopher Howard is licensed under Attribution-ShareAlike 4.0 International.
CC BY-SA 4.0 Deed