emacs-diffs
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] master cbaa040 1/4: * lisp/emacs-lisp/map.el (map-merg


From: Nicolas Petton
Subject: Re: [Emacs-diffs] master cbaa040 1/4: * lisp/emacs-lisp/map.el (map-merge-with): New function
Date: Tue, 10 Nov 2015 19:29:22 +0100
User-agent: Notmuch/0.20.2 (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu)

Artur Malabarba <address@hidden> writes:

> +(defun map-merge-with (type function &rest maps)
> +  "Merge into a map of type TYPE all the key/value pairs in MAPS.
> +When two maps contain the same key, call FUNCTION on the two
> +values and use the value returned by it.
> +MAP can be a list, hash-table or array."
> +  (let (result)
> +    (while maps
> +      (map-apply (lambda (key value)
> +                (setf (map-elt result key)
> +                      (if (map-contains-key result key)
> +                          (funcall function (map-elt result key) value)
> +                        value)))
> +              (pop maps)))
>      (map-into result type)))

Looks great, thanks! (and with unit tests, that's awesome).

Nico

Attachment: signature.asc
Description: PGP signature


reply via email to

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