Random utils, map utilities.
Random utils, map utilities.
(assoc-existing)(assoc-existing coll)(assoc-existing coll k val)(assoc-existing coll k val & more)Associates keys and values only if keys exist in a map.
Associates keys and values only if keys exist in a map.
(assoc-if coll pred k val)(assoc-if coll pred k val & pairs)Associates k with val (and optional further pairs) in coll only when pred
is truthy. Returns coll unchanged otherwise.
Associates `k` with `val` (and optional further pairs) in `coll` only when `pred` is truthy. Returns `coll` unchanged otherwise.
(assoc-if-key coll k pred val)Associates k with val in coll only when the current value at k satisfies
predicate pred. Returns coll unchanged otherwise.
Associates `k` with `val` in `coll` only when the current value at `k` satisfies predicate `pred`. Returns `coll` unchanged otherwise.
(assoc-if-not coll pred k val)(assoc-if-not coll pred k val & pairs)Associates k with val (and optional further pairs) in coll only when pred
is falsy. Returns coll unchanged otherwise.
Associates `k` with `val` (and optional further pairs) in `coll` only when `pred` is falsy. Returns `coll` unchanged otherwise.
(assoc-if-not-key coll k pred val)Associates k with val in coll only when the current value at k does NOT
satisfy predicate pred. Returns coll unchanged otherwise.
Associates `k` with `val` in `coll` only when the current value at `k` does NOT satisfy predicate `pred`. Returns `coll` unchanged otherwise.
(assoc-missing)(assoc-missing coll)(assoc-missing coll k val)(assoc-missing coll k val & more)Associates keys and values only if keys do not yet exist in a map.
Associates keys and values only if keys do not yet exist in a map.
(dissoc-if m k pred)Removes key k from map m when the value at k satisfies predicate pred.
Returns m unchanged otherwise.
Removes key `k` from map `m` when the value at `k` satisfies predicate `pred`. Returns `m` unchanged otherwise.
(dissoc-in m [k & ks])Like clojure.core/assoc-in but removes entries. Leaves empty maps.
Like `clojure.core/assoc-in` but removes entries. Leaves empty maps.
(duplicate-keys map kmap)Returns a map map with the keys present in kmap duplicated under new names
according to the values in kmap.
Returns a map `map` with the keys present in `kmap` duplicated under new names according to the values in `kmap`.
(invert-in-sets m)(invert-in-sets m dst)Like clojure.set/map-invert but preserves all possible values in sets.
Like `clojure.set/map-invert` but preserves all possible values in sets.
(lazy)(lazy m)Creates a lazy map from a literal map. All values are unrealized.
Creates a lazy map from a literal map. All values are unrealized.
(lazy-get m k exp)Like clojure.core/get but the default value is an expression
that is going to be evaluated only if the associative structure
does not contain the given key.
Like `clojure.core/get` but the default value is an expression that is going to be evaluated only if the associative structure does not contain the given key.
(lazy? m)Returns true if the given argument is a lazy map.
Returns `true` if the given argument is a lazy map.
(map-keys f m)(map-keys f m dst)For each key and value of the given map m calls a function passed as the first argument (passing successive keys during calls to it) and generates a map with keys updated by results returned by the function. When the third argument is given then it should be a map on which operations are performed instead of using an empty map.
For each key and value of the given map m calls a function passed as the first argument (passing successive keys during calls to it) and generates a map with keys updated by results returned by the function. When the third argument is given then it should be a map on which operations are performed instead of using an empty map.
(map-keys-and-vals f m)(map-keys-and-vals f m dst)For each key and value of the given map m calls a function passed as the first argument (passing successive keys during calls to it) and generates a map with keys updated by results returned by the function and values also updated by results of the same function. The function should return a sequential collection of 2 elements: first containing a new value of a key and second containing a new value of a transformed value associated with that key. When the third argument is given then it should be a map on which operations are performed instead of using an empty map.
For each key and value of the given map m calls a function passed as the first argument (passing successive keys during calls to it) and generates a map with keys updated by results returned by the function and values also updated by results of the same function. The function should return a sequential collection of 2 elements: first containing a new value of a key and second containing a new value of a transformed value associated with that key. When the third argument is given then it should be a map on which operations are performed instead of using an empty map.
(map-keys-by-v f m)(map-keys-by-v f m dst)For each key and value of the given map m calls a function passed as the first argument (passing successive values during calls to it) and generates a map with key names generated by results returned by the function. When the third argument is given then it should be a map on which operations are performed instead of using and empty map.
For each key and value of the given map m calls a function passed as the first argument (passing successive values during calls to it) and generates a map with key names generated by results returned by the function. When the third argument is given then it should be a map on which operations are performed instead of using and empty map.
(map-of-sets-invert m)Like clojure.set/map-invert but for map of sets (as values) to preserve all
possible values (as keys of newly created map).
Like `clojure.set/map-invert` but for map of sets (as values) to preserve all possible values (as keys of newly created map).
(map-of-vectors-invert-flatten m)Like clojure.set/map-invert but for map of vectors (as values). Duplicated keys
are replaced.
Like `clojure.set/map-invert` but for map of vectors (as values). Duplicated keys are replaced.
(map-vals f m)(map-vals f m dst)For each key and value of the given map m calls a function passed as the first argument (passing successive values during calls to it) and generates a map with values updated by results returned by the function. When the third argument is given it should be a map on which operations are performed instead of using the original map. This may be helpful when we want to avoid merging the results with another map.
For each key and value of the given map m calls a function passed as the first argument (passing successive values during calls to it) and generates a map with values updated by results returned by the function. When the third argument is given it should be a map on which operations are performed instead of using the original map. This may be helpful when we want to avoid merging the results with another map.
(map-vals-by-k f m)(map-vals-by-k f m dst)For each key and value of the given map m calls a function passed as the first argument (passing successive keys during calls to it) and generates a map with values updated by results returned by the function. When the third argument is given it should be a map on which operations are performed instead of using the original map. This may be helpful when we want to avoid merging the results with another map.
For each key and value of the given map m calls a function passed as the first argument (passing successive keys during calls to it) and generates a map with values updated by results returned by the function. When the third argument is given it should be a map on which operations are performed instead of using the original map. This may be helpful when we want to avoid merging the results with another map.
(map-vals-by-kv f m)(map-vals-by-kv f m dst)For each key and value of the given map m calls a function passed as the first argument (passing successive keys and values during calls to it) and generates a map with values updated by results returned by the function. When the third argument is given it should be a map on which operations are performed instead of using the original map. This may be helpful when we want to avoid merging the results with another map.
For each key and value of the given map m calls a function passed as the first argument (passing successive keys and values during calls to it) and generates a map with values updated by results returned by the function. When the third argument is given it should be a map on which operations are performed instead of using the original map. This may be helpful when we want to avoid merging the results with another map.
(map-values f coll)Recursively transforms values of a map coll using function f. The function should take a value and return new value.
Recursively transforms values of a map coll using function f. The function should take a value and return new value.
(map-values-with-path f coll)Recursively transforms values of a map coll using function f. The function should take a value and a sequence of visited keys (stored in a vector), and return a new value.
Recursively transforms values of a map coll using function f. The function should take a value and a sequence of visited keys (stored in a vector), and return a new value.
(map-values-with-rpath f coll)Recursively transforms values of a map coll using function f. The function should take a value and a sequence of visited keys in reverse order (stored in a persistent list), and return a new value.
Recursively transforms values of a map coll using function f. The function should take a value and a sequence of visited keys in reverse order (stored in a persistent list), and return a new value.
(nil-existing-keys m keys)Sets the values of given keys to nil in map m, but only for keys that already
exist in the map. Returns nil when m is nil.
Sets the values of given `keys` to `nil` in map `m`, but only for keys that already exist in the map. Returns `nil` when `m` is `nil`.
(nil-keys m keys)Sets the values of all given keys to nil in map m, adding keys that did not
exist. Returns nil when m is nil.
Sets the values of all given `keys` to `nil` in map `m`, adding keys that did not exist. Returns `nil` when `m` is `nil`.
(or-map m)Returns an empty map if the argument is nil. Otherwise returns its argument.
Returns an empty map if the argument is `nil`. Otherwise returns its argument.
(qassoc mp)(qassoc mp a b)(qassoc mp a b c d)(qassoc mp a b c d e f)(qassoc mp a b c d e f g h)(qassoc mp a b c d e f g h i j)(qassoc mp a b c d e f g h i j k l)(qassoc mp a b c d e f g h i j k l m n)(qassoc mp a b c d e f g h i j k l m n o p)(qassoc mp a b c d e f g h i j k l m n o p q r)(qassoc mp a b c d e f g h i j k l m n o p q r & pairs)Faster version of assoc with some of the checks and conversions
disabled. Associates key a with value b in mp. If mp is nil it creates a
new map.
Faster version of `assoc` with some of the checks and conversions disabled. Associates key `a` with value `b` in `mp`. If `mp` is `nil` it creates a new map.
(qassoc* mp & kvs)Macro that expands into a chain of .assoc calls on mp for the given key–value
pairs kvs. Expects an even number of key–value arguments.
Macro that expands into a chain of `.assoc` calls on `mp` for the given key–value pairs `kvs`. Expects an even number of key–value arguments.
(qupdate m k f)(qupdate m k f x)(qupdate m k f x y)(qupdate m k f x y z)(qupdate m k f x y z c)(qupdate m k f x y z c v)(qupdate m k f x y z c v a)(qupdate m k f x y z c v a b)(qupdate m k f x y z c v a b & more)Similar to clojure.core/update, updates a value in an associative structure,
where k is a key and f is a function which will take the old value and any
supplied args and return the new value, and returns a new structure. Uses qassoc
instead of clojure.core/assoc internally.
If the key does not exist, nil is passed as the old value.
Similar to `clojure.core/update`, updates a value in an associative structure, where `k` is a key and `f` is a function which will take the old value and any supplied args and return the new value, and returns a new structure. Uses `qassoc` instead of `clojure.core/assoc` internally. If the key does not exist, `nil` is passed as the old value.
(remove-empty-values m)Removes all entries from map m whose values are nil or empty (in the seq sense).
Removes all entries from map `m` whose values are `nil` or empty (in the `seq` sense).
(remove-except m keyseq)Returns a map containing only the keys from keyseq. Equivalent to select-keys.
Returns a map containing only the keys from `keyseq`. Equivalent to `select-keys`.
(remove-if-value m pred)Removes all entries from map m whose values satisfy predicate pred.
Removes all entries from map `m` whose values satisfy predicate `pred`.
(remove-if-value-in m vals)Removes all entries from map m whose values are contained in the collection vals.
Removes all entries from map `m` whose values are contained in the collection `vals`.
(remove-if-value-not-in m vals)Removes all entries from map m whose values are NOT contained in the collection
vals. When vals is nil, returns an empty map.
Removes all entries from map `m` whose values are NOT contained in the collection `vals`. When `vals` is `nil`, returns an empty map.
(select-keys-lazy m keyseq)Like clojure.core/select-keys but preserves unrealized values as they are.
Like `clojure.core/select-keys` but preserves unrealized values as they are.
(to-lazy)(to-lazy m)Converts the given map to a lazy map.
Converts the given map to a lazy map.
(update-bytes-to-strings coll k)(update-bytes-to-strings coll k & keys)Converts the value(s) at the given key(s) in coll from byte arrays to strings
using bytes-to-string, skipping values that are not byte arrays.
Converts the value(s) at the given key(s) in `coll` from byte arrays to strings using `bytes-to-string`, skipping values that are not byte arrays.
(update-existing coll k fun)(update-existing coll k fun & more)Updates the given key k of coll by calling a function fun and passing optional
arguments specified as additional arguments. Will not perform any update if the
given key does not exist within the collection. Returns updated collection.
If fun is not a function it will be made one by using constantly.
Updates the given key `k` of `coll` by calling a function `fun` and passing optional arguments specified as additional arguments. Will not perform any update if the given key does not exist within the collection. Returns updated collection. If `fun` is not a function it will be made one by using `constantly`.
(update-if coll k pred fun)(update-if coll k pred fun & more)Updates the value at key k in coll by applying fun (with optional extra args)
only when the current value satisfies predicate pred. If k is absent or pred
returns false, coll is returned unchanged.
Updates the value at key `k` in `coll` by applying `fun` (with optional extra args) only when the current value satisfies predicate `pred`. If `k` is absent or `pred` returns false, `coll` is returned unchanged.
(update-if-not coll k pred fun)(update-if-not coll k pred fun & more)Updates the value at key k in coll by applying fun (with optional extra args)
only when the current value does NOT satisfy predicate pred. If k is absent or
pred returns true, coll is returned unchanged.
Updates the value at key `k` in `coll` by applying `fun` (with optional extra args) only when the current value does NOT satisfy predicate `pred`. If `k` is absent or `pred` returns true, `coll` is returned unchanged.
(update-missing coll k fun)(update-missing coll k fun & more)Updates the given key k of coll by calling a function fun and passing optional
arguments specified as additional arguments. Will not perform any update if the
given key exists within the collection, therefore the function will always receive
nil as its argument. Returns updated collection.
If fun is not a function it will be made one by using constantly.
Updates the given key `k` of `coll` by calling a function `fun` and passing optional arguments specified as additional arguments. Will not perform any update if the given key exists within the collection, therefore the function will always receive `nil` as its argument. Returns updated collection. If `fun` is not a function it will be made one by using `constantly`.
(update-to-bytes coll k)(update-to-bytes coll k & keys)Converts the value(s) at the given key(s) in coll to byte arrays using
normalize-to-bytes, skipping values that are already byte arrays.
Converts the value(s) at the given key(s) in `coll` to byte arrays using `normalize-to-bytes`, skipping values that are already byte arrays.
(update-values map vmap)(update-values map vmap create-keys?)(update-values map vmap create-keys? remove-key-mark)Returns a map with its values identified with keys from vmap updated with the associated functions from vmap.
Returns a map with its values identified with keys from vmap updated with the associated functions from vmap.
(update-values-or-seqs map vmap)(update-values-or-seqs map vmap create-keys?)Returns the map with its values identified with keys from vmap updated with the
associated functions from vmap.
Returns the map with its values identified with keys from `vmap` updated with the associated functions from `vmap`.
(update-values-or-seqs-recur map vmap)(update-values-or-seqs-recur map vmap create-keys?)Returns a map with its values identified with keys from vmap recursively updated
with the associated functions from vmap. Shape is not reflected, second
map (vmap) should be flat, searching for keys is recursive, including nested
vectors.
Returns a map with its values identified with keys from `vmap` recursively updated with the associated functions from `vmap`. Shape is not reflected, second map (`vmap`) should be flat, searching for keys is recursive, including nested vectors.
(update-values-recur map vmap)(update-values-recur map vmap create-keys?)Returns the map with its values identified with keys from vmap recursively updated with the associated functions from vmap. Shape is not reflected, second map (vmap) should be flat, searching for keys is recursive, including nested vectors.
Returns the map with its values identified with keys from vmap recursively updated with the associated functions from vmap. Shape is not reflected, second map (vmap) should be flat, searching for keys is recursive, including nested vectors.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |