diff options
author | William Carroll <wpcarro@gmail.com> | 2022-08-02T20·10-0700 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-08-02T20·31+0000 |
commit | 44f520ccd176ef70f69a4e3bf9656d0198cfc5e8 (patch) | |
tree | 2ac9e36e8bfdf8b389f8173e4a2c88afcbeb0add /users/wpcarro/emacs/pkgs/struct/struct.el | |
parent | 9d475c5b9b037389abed5ab68f15fa34bd67a567 (diff) |
feat(wpcarro/emacs): Support struct-update! r/4370
Support mutable variant of `struct-update`. Also remove the `dash` dependency in `tests.el`. Change-Id: I76fc809e96b7cbbd3b39fd16db339cb62eab002c Reviewed-on: https://cl.tvl.fyi/c/depot/+/6027 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/emacs/pkgs/struct/struct.el')
-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 |