Macros and functions for handling nil under various circumstances.
Macros and functions for handling nil under various circumstances.
(alt)
(alt x)
(alt x & xs)
Selects the first non-nil value.
Being a macro, arguments are not evaluated until needed.
(alt nil
false
42)
false
Selects the first non-nil value. Being a macro, arguments are not evaluated until needed. ```clojure (alt nil false 42) false ```
(assoc hmap k v)
(assoc hmap k v & kvs)
Behaves like standard assoc
but associates v
only if it is not nil.
(assoc {:a 42}
:a nil
:b 42)
{:a 42
:b 42}
Behaves like standard `assoc` but associates `v` only if it is not nil. ```clojure (assoc {:a 42} :a nil :b 42) {:a 42 :b 42} ```
(assoc-in hmap path v)
Behaves like standard assoc-in
but associates v
only if it is not nil.
See also assoc
.
Behaves like standard `assoc-in` but associates `v` only if it is not nil. See also [[assoc]].
(assoc-strict hmap k v)
(assoc-strict hmap k v & kvs)
Similar to this namespace's version of assoc
but if v
is nil, not only is it not associated, the
involved key is actually removed from the map.
Similar to this namespace's version of [[assoc]] but if `v` is nil, not only is it not associated, the involved key is actually removed from the map.
(call f & args)
Calls f
with the given arguments only if f
is not nil.
Being a macro, the arguments are not evaluated until they are needed.
Calls `f` with the given arguments only if `f` is not nil. Being a macro, the arguments are not evaluated until they are needed.
(dissoc-in hmap path)
Deep dissoc, natural counterpart of Clojure's assoc-in
.
It is recursive, meaning that if dissociating a key results in an empty map, this map itself is removed from its parent (provided it is of course nested).
(dissoc-in {:a {:b {:c {:d 42}}
:e 42}}
[:a :b :c :d])
{:a {:e 42}}
Deep dissoc, natural counterpart of Clojure's `assoc-in`. It is recursive, meaning that if dissociating a key results in an empty map, this map itself is removed from its parent (provided it is of course nested). ```clojure (dissoc-in {:a {:b {:c {:d 42}} :e 42}} [:a :b :c :d]) {:a {:e 42}} ```
(dmerge & hmaps)
Deep merges the given maps.
Merging a key pointing to nil results in that key being dissociated. Similarly to dissoc-in
, empty maps are recursively
removed.
(dmerge {:a {:b {:c {:d 42}}
:e 42}}
{:a {:b {:c {:d nil}}
:f 42}})
{:a {:e 42
:f 42}}
Deep merges the given maps. Merging a key pointing to nil results in that key being dissociated. Similarly to [[dissoc-in]], empty maps are recursively removed. ```clojure (dmerge {:a {:b {:c {:d 42}} :e 42}} {:a {:b {:c {:d nil}} :f 42}}) {:a {:e 42 :f 42}} ```
(dmerge-with f & hmaps)
Is to dmerge
what this namespace's version of merge-with
is to merge
.
Is to [[dmerge]] what this namespace's version of [[merge-with]] is to [[merge]].
(dmerge-with* f hmaps)
(dmerge-with* f hmap-1 hmap-2)
Like dmerge-with
, but maps are provided in a collection.
Like [[dmerge-with]], but maps are provided in a collection.
(merge & hmaps)
Just like standard merge
, but a key pointing to nil in the right map means it must be dissociated.
(merge {:a 42
:b 42}
{:b nil
:c 42})
{:a 42
:c 42}
Just like standard `merge`, but a key pointing to nil in the right map means it must be dissociated. ```clojure (merge {:a 42 :b 42} {:b nil :c 42}) {:a 42 :c 42} ```
(merge-with f & hmaps)
Just like standard 'merge-with' but behaves like this namespace's version of merge
: a key pointing to a nil value in a
right map means it will be dissociated. The same applies when f
returns nil.
Just like standard 'merge-with' but behaves like this namespace's version of [[merge]]: a key pointing to a nil value in a right map means it will be dissociated. The same applies when `f` returns nil.
(merge-with* f hmaps)
Just like this namespace's version of merge-with
but maps are provided in a collection.
Just like this namespace's version of [[merge-with]] but maps are provided in a collection.
(no-op)
(no-op _)
(no-op _ _)
(no-op _ _ _)
(no-op _ _ _ _)
(no-op _ _ _ _ _)
(no-op _ _ _ _ _ _)
(no-op _ _ _ _ _ _ _)
(no-op _ _ _ _ _ _ _ _)
(no-op _ _ _ _ _ _ _ _ & _)
Does absolutely nothing, but efficiently.
Does absolutely nothing, but efficiently.
(prune node)
If node is a map, keys with nil values will be removed. In case of nested maps, the process is recursive.
(prune {:a 42
:b {:c 42
:d nil
:e {:f {:g nil}}}})
{:a 42
:b {:c 42}}
(prune 42)
42
If node is a map, keys with nil values will be removed. In case of nested maps, the process is recursive. ```clojure (prune {:a 42 :b {:c 42 :d nil :e {:f {:g nil}}}}) {:a 42 :b {:c 42}} (prune 42) 42 ```
(update hmap k f)
(update hmap k f a)
(update hmap k f a b)
(update hmap k f a b c)
(update hmap k f a b c & more)
Just like standard update
but returning a nil value results in the involved key being dissociated.
(update {:a 42
:b 42}
:b
(fn [x]
nil))
{:a 42}
Just like standard `update` but returning a nil value results in the involved key being dissociated. ```clojure (update {:a 42 :b 42} :b (fn [x] nil)) {:a 42}
(update-in hmap path f & args)
Just like standard update-in
but like this namespace's version of update
, returning nil
results in the involved key being dissociated.
Similarly to dissoc-in
, empty maps are then recursively removed as well.
When an empty path is provided, nothing happens.
(update-in {:a {:b {:c {:d 24}}
:e 42}}
[:a :b :c :d]
(fn [x]
(when (= x
42)
x)))
{:a {:e 42}}
Just like standard `update-in` but like this namespace's version of [[update]], returning nil results in the involved key being dissociated. Similarly to [[dissoc-in]], empty maps are then recursively removed as well. When an empty path is provided, nothing happens. ```clojure (update-in {:a {:b {:c {:d 24}} :e 42}} [:a :b :c :d] (fn [x] (when (= x 42) x))) {:a {:e 42}} ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close