Last active
February 8, 2025 11:27
-
-
Save kawas44/a6beda359c0ec34dab74b635d40d00be to your computer and use it in GitHub Desktop.
assoc-some
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn assoc-some | |
"Assoc value in map if value is not nil." | |
([m k v] | |
(cond-> m | |
(some? v) (assoc k v))) | |
([m k v & kvs] | |
{:pre [(even? (count kvs))]} | |
(into (assoc-some m k v) | |
(comp | |
(partition-all 2) | |
(keep (fn [kv] (when (some? (nth kv 1)) kv)))) | |
kvs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment