diff options
author | William Carroll <wpcarro@gmail.com> | 2022-07-30T01·12-0700 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-07-30T01·29+0000 |
commit | 6b3f4113cc6ffe79eff0fa0008a1d8d95f5a6bac (patch) | |
tree | 8a0b9d9948989fee65f839fdfaddd34368fb584f /users/wpcarro/emacs/pkgs/al/al.el | |
parent | 230c4bbb3e9f44875d6593a7c6cb0ca33bb63805 (diff) |
feat(wpcarro/emacs): Support default value for al-get r/4345
Similar to Elixir's `Map.get/3`. Change-Id: I736f7e618aafc786a32eeba46ca635cb27db18b6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6000 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/emacs/pkgs/al/al.el')
-rw-r--r-- | users/wpcarro/emacs/pkgs/al/al.el | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/users/wpcarro/emacs/pkgs/al/al.el b/users/wpcarro/emacs/pkgs/al/al.el index aa818941535f..4c37526c644a 100644 --- a/users/wpcarro/emacs/pkgs/al/al.el +++ b/users/wpcarro/emacs/pkgs/al/al.el @@ -111,10 +111,12 @@ Note that this doesn't append to the alist in the way that most alists handle (map-put! xs k v)) ;; Read -(defun al-get (k xs) - "Return the value at K in XS; otherwise, return nil. +(defun al-get (k xs &optional default) + "Return the value at K in XS; otherwise, return nil or DEFAULT (if set). Returns the first occurrence of K in XS since alists support multiple entries." - (cdr (assoc k xs))) + (if (not (al-has-key? k xs)) + default + (cdr (assoc k xs)))) (defun al-get-entry (k xs) "Return the first key-value pair at K in XS." |