branch: externals/taxy
commit 6c5b7c77d0324cac1fa9ebc2a5a7ba4a1a6a69ca
Author: Adam Porter <[email protected]>
Commit: Adam Porter <[email protected]>
Add: taxy-apply
---
README.org | 2 +-
taxy.el | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index c06b0f4..0ccb801 100644
--- a/README.org
+++ b/README.org
@@ -131,7 +131,7 @@ The ~:then~ function determines what happens to an object
after being taken in:
After defining a taxy, call ~taxy-fill~ with it and a list of objects to fill
the taxy's hierarchy. *Note:* ~taxy-fill~ modifies the taxy given to it
(filling its ~:objects~ and those of its ~:taxys~), so when using a statically
defined taxy (e.g. one defined with ~defvar~), you should pass ~taxy-fill~ a
taxy copied with ~taxy-copy~, which recursively copies a taxy without
~:objects~.
-To return a taxy in a more human-readable format (with only relevant fields
included), use ~taxy-simple~.
+To return a taxy in a more human-readable format (with only relevant fields
included), use ~taxy-simple~. You may also use ~taxy-apply~ to replace objects
in a taxy with, e.g. a more useful representation.
** Dynamic taxys
diff --git a/taxy.el b/taxy.el
index 115beca..b3bdb3d 100644
--- a/taxy.el
+++ b/taxy.el
@@ -83,6 +83,17 @@ Clears TAXY's objects and those of its descendant taxys."
(taxy-taxys taxy) (mapcar #'taxy-copy (taxy-taxys taxy)))
taxy)
+(defun taxy-apply (fn taxy)
+ "Return TAXY, having applied FN to each object in it, including descendants.
+Used to apply side effects, e.g. to transform objects into a more
+useful form after classification."
+ ;; I can't seem to find a way to do this without consing new lists.
+ ;; Even using `cl-loop' with `in-ref' didn't work.
+ (setf (taxy-objects taxy) (mapcar fn (taxy-objects taxy))
+ (taxy-taxys taxy) (cl-loop for taxy in (taxy-taxys taxy)
+ collect (taxy-apply fn taxy)))
+ taxy)
+
;;;; Footer
(provide 'taxy)