diff options
Diffstat (limited to '')
-rw-r--r-- | users/wpcarro/emacs/pkgs/struct/struct.el | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/users/wpcarro/emacs/pkgs/struct/struct.el b/users/wpcarro/emacs/pkgs/struct/struct.el index 36d9d4ac0b9e..e5b25c3836af 100644 --- a/users/wpcarro/emacs/pkgs/struct/struct.el +++ b/users/wpcarro/emacs/pkgs/struct/struct.el @@ -39,6 +39,16 @@ This is immutable." (setf (,accessor copy) (funcall ,f (,accessor copy))) copy))) +(defmacro struct-update! (type field f xs) + "Mutably apply F to FIELD in XS." + (let ((accessor (->> field + symbol-name + (s-prepend (s-concat (symbol-name type) "-")) + intern))) + `(progn + (setf (,accessor ,xs) (funcall ,f (,accessor ,xs))) + ,xs))) + (defmacro struct-set (type field x xs) "Immutably set FIELD in XS (struct TYPE) to X." (let ((copier (->> type |