bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#62068: 29.0.60; map-elt and map-insert for nested structures


From: Michael Heerdegen
Subject: bug#62068: 29.0.60; map-elt and map-insert for nested structures
Date: Fri, 10 Mar 2023 02:18:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Augusto Stoffel <arstoffel@gmail.com> writes:

> I would like to suggest the following two functions to deal with nested
> maps.  Let me know if you would like to see a patch.
>
> (defun map-elt-in (map keys &optional default)
>   "Look up a nested sequence of KEYS in MAP and return its associated value.
> KEYS is any sequence type supported by `seq'.  If a key is not
> found in any intermediate step, return DEFAULT, which defaults to
> nil."
>   (catch 'map--break
>     (seq-reduce (lambda (m k)
>                   (let ((v (map-elt m k 'map--default)))
>                     (if (eq v 'map--default)
>                         (throw 'map--break default)
>                       v)))
>                 keys
>                 map)))

Isn't this more or less the same as `map-nested-elt'?

Michael.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]