Skip to content

Instantly share code, notes, and snippets.

@kawas44
Last active February 8, 2025 11:27
Show Gist options
  • Save kawas44/a6beda359c0ec34dab74b635d40d00be to your computer and use it in GitHub Desktop.
Save kawas44/a6beda359c0ec34dab74b635d40d00be to your computer and use it in GitHub Desktop.
assoc-some
(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