(assoc-in-new m ks v)
only assoc-in if the value in the original map is nil
(assoc-in-new {} [:a :b] 2) => {:a {:b 2}}
(assoc-in-new {:a {:b 1}} [:a :b] 2) => {:a {:b 1}}
only assoc-in if the value in the original map is nil (assoc-in-new {} [:a :b] 2) => {:a {:b 2}} (assoc-in-new {:a {:b 1}} [:a :b] 2) => {:a {:b 1}}
(assoc-in-nnil m arr v)
assoc-in a nested key/value pair to a map only on non-nil values
(assoc-in-nnil {} [:a :b] 1) => {:a {:b 1}}
(assoc-in-nnil {} [:a :b] nil) => {}
assoc-in a nested key/value pair to a map only on non-nil values (assoc-in-nnil {} [:a :b] 1) => {:a {:b 1}} (assoc-in-nnil {} [:a :b] nil) => {}
(assoc-new m k v)
(assoc-new m k v & more)
only assoc if the value in the original map is nil
(assoc-new {:a 1} :b 2) => {:a 1 :b 2}
(assoc-new {:a 1} :a 2 :b 2) => {:a 1 :b 2}
only assoc if the value in the original map is nil (assoc-new {:a 1} :b 2) => {:a 1 :b 2} (assoc-new {:a 1} :a 2 :b 2) => {:a 1 :b 2}
(assoc-nnil m k v)
(assoc-nnil m k v & more)
assoc key/value pairs to the map only on non-nil values
(assoc-nnil {} :a 1) => {:a 1}
(assoc-nnil {} :a 1 :b nil) => {:a 1}
assoc key/value pairs to the map only on non-nil values (assoc-nnil {} :a 1) => {:a 1} (assoc-nnil {} :a 1 :b nil) => {:a 1}
(assocs m k v)
(assocs m k v sel func)
Similar to assoc
but conditions of association is specified
through sel
(default: identity
) and well as merging specified
through func
(default: combine
).
(assocs {:a #{1}} :a #{2 3 4})
=> {:a #{1 2 3 4}}
(assocs {:a {:id 1}} :a {:id 1 :val 1} :id merge) => {:a {:val 1, :id 1}}
(assocs {:a #{{:id 1 :val 2} {:id 1 :val 3}}} :a {:id 1 :val 4} :id merges) => {:a #{{:id 1 :val #{2 3 4}}}}
Similar to `assoc` but conditions of association is specified through `sel` (default: `identity`) and well as merging specified through `func` (default: `combine`). (assocs {:a #{1}} :a #{2 3 4}) => {:a #{1 2 3 4}} (assocs {:a {:id 1}} :a {:id 1 :val 1} :id merge) => {:a {:val 1, :id 1}} (assocs {:a #{{:id 1 :val 2} {:id 1 :val 3}}} :a {:id 1 :val 4} :id merges) => {:a #{{:id 1 :val #{2 3 4}}}}
(changed new old)
Outputs what has changed between the two maps
(changed {:a {:b {:c 3 :d 4}}} {:a {:b {:c 3}}}) => {:a {:b {:d 4}}}
Outputs what has changed between the two maps (changed {:a {:b {:c 3 :d 4}}} {:a {:b {:c 3}}}) => {:a {:b {:d 4}}}
(clean-nested m)
Returns a associative with nils and empty hash-maps removed.
(clean-nested {:a {:b {:c {}}}}) => {}
(clean-nested {:a {:b {:c {} :d 1 :e nil}}}) => {:a {:b {:d 1}}}
Returns a associative with nils and empty hash-maps removed. (clean-nested {:a {:b {:c {}}}}) => {} (clean-nested {:a {:b {:c {} :d 1 :e nil}}}) => {:a {:b {:d 1}}}
(combine)
(combine m)
(combine v1 v2)
(combine v1 v2 sel func)
takes v1
and v2
, which can be either
values or sets of values and merges them into a new set.
(combine 1 2) => #{1 2}
(combine #{1} 1) => #{1}
(combine #{{:id 1} {:id 2}} #{{:id 1 :val 1} {:id 2 :val 2}} :id merge) => #{{:id 1 :val 1} {:id 2 :val 2}}
takes `v1` and `v2`, which can be either values or sets of values and merges them into a new set. (combine 1 2) => #{1 2} (combine #{1} 1) => #{1} (combine #{{:id 1} {:id 2}} #{{:id 1 :val 1} {:id 2 :val 2}} :id merge) => #{{:id 1 :val 1} {:id 2 :val 2}}
(decombine v dv)
takes set or value v
and returns a set with
elements matching sel removed
(decombine 1 1) => nil
(decombine 1 2) => 1
(decombine #{1} 1) => nil
(decombine #{1 2 3 4} #{1 2}) => #{3 4}
(decombine #{1 2 3 4} even?) => #{1 3}
takes set or value `v` and returns a set with elements matching sel removed (decombine 1 1) => nil (decombine 1 2) => 1 (decombine #{1} 1) => nil (decombine #{1 2 3 4} #{1 2}) => #{3 4} (decombine #{1 2 3 4} even?) => #{1 3}
(diff m1 m2)
(diff m1 m2 reversible)
Finds the difference between two maps
(diff {:a 2} {:a 1}) => {:+ {} :- {} :> {[:a] 2}}
(diff {:a {:b 1 :d 3}} {:a {:c 2 :d 4}} true) => {:+ {[:a :b] 1} :- {[:a :c] 2} :> {[:a :d] 3} :< {[:a :d] 4}}
Finds the difference between two maps (diff {:a 2} {:a 1}) => {:+ {} :- {} :> {[:a] 2}} (diff {:a {:b 1 :d 3}} {:a {:c 2 :d 4}} true) => {:+ {[:a :b] 1} :- {[:a :c] 2} :> {[:a :d] 3} :< {[:a :d] 4}}
(dissoc-in m [k & ks])
(dissoc-in m [k & ks] keep)
disassociates keys from a nested map. Setting keep
to true
will
not remove a empty map after dissoc
(dissoc-in {:a {:b 10 :c 20}} [:a :b]) => {:a {:c 20}}
(dissoc-in {:a {:b 10}} [:a :b]) => {}
(dissoc-in {:a {:b 10}} [:a :b] true) => {:a {}}
disassociates keys from a nested map. Setting `keep` to `true` will not remove a empty map after dissoc (dissoc-in {:a {:b 10 :c 20}} [:a :b]) => {:a {:c 20}} (dissoc-in {:a {:b 10}} [:a :b]) => {} (dissoc-in {:a {:b 10}} [:a :b] true) => {:a {}}
(dissoc-nested m ks)
Returns m
without all nested keys in ks
.
(dissoc-nested {:a {:b 1 :c {:b 1}}} [:b]) => {:a {:c {}}}
Returns `m` without all nested keys in `ks`. (dissoc-nested {:a {:b 1 :c {:b 1}}} [:b]) => {:a {:c {}}}
(dissocs m k)
Similar to dissoc
but allows dissassociation of sets of values from a map.
(dissocs {:a 1} :a) => {}
(dissocs {:a #{1 2}} [:a #{0 1}]) => {:a #{2}}
(dissocs {:a #{1 2}} [:a #{1 2}]) => {}
Similar to `dissoc` but allows dissassociation of sets of values from a map. (dissocs {:a 1} :a) => {} (dissocs {:a #{1 2}} [:a #{0 1}]) => {:a #{2}} (dissocs {:a #{1 2}} [:a #{1 2}]) => {}
(dissocs-in m [k & ks :as all-ks])
Similiar to dissoc-in
but can move through sets.
(dissocs-in {:a #{{:b 1 :c 1} {:b 2 :c 2}}} [:a :b]) => {:a #{{:c 1} {:c 2}}}
(dissocs-in {:a #{{:b #{1 2 3} :c 1} {:b #{1 2 3} :c 2}}} [[:a [:c 1]] [:b 1]]) => {:a #{{:b #{2 3} :c 1} {:b #{1 2 3} :c 2}}}
Similiar to `dissoc-in` but can move through sets. (dissocs-in {:a #{{:b 1 :c 1} {:b 2 :c 2}}} [:a :b]) => {:a #{{:c 1} {:c 2}}} (dissocs-in {:a #{{:b #{1 2 3} :c 1} {:b #{1 2 3} :c 2}}} [[:a [:c 1]] [:b 1]]) => {:a #{{:b #{2 3} :c 1} {:b #{1 2 3} :c 2}}}
(element-of pred coll)
finds the element within an array
(element-of keyword? [1 2 :hello 4]) => :hello
finds the element within an array (element-of keyword? [1 2 :hello 4]) => :hello
(filter-keys pred m)
filters map based upon map keys
(filter-keys even? {0 :a 1 :b 2 :c}) => {0 :a, 2 :c}
filters map based upon map keys (filter-keys even? {0 :a 1 :b 2 :c}) => {0 :a, 2 :c}
(filter-vals pred m)
filters map based upon map values
(filter-vals even? {:a 1 :b 2 :c 3}) => {:b 2}
filters map based upon map values (filter-vals even? {:a 1 :b 2 :c 3}) => {:b 2}
(flatten-all x)
flattens all elements the collection
(flatten-all [1 2 #{3 {4 5}}]) => [1 2 3 4 5]
flattens all elements the collection (flatten-all [1 2 #{3 {4 5}}]) => [1 2 3 4 5]
(gets m k)
Returns the associated values either specified by a key or a key and predicate pair.
(gets {:a 1} :a) => 1
(gets {:a #{0 1}} [:a zero?]) => #{0}
(gets {:a #{{:b 1} {}}} [:a :b]) => #{{:b 1}}
Returns the associated values either specified by a key or a key and predicate pair. (gets {:a 1} :a) => 1 (gets {:a #{0 1}} [:a zero?]) => #{0} (gets {:a #{{:b 1} {}}} [:a :b]) => #{{:b 1}}
(gets-in m ks)
Similar in style to get-in
with operations on sets. returns a set of values.
(gets-in {:a 1} [:a]) => #{1}
(gets-in {:a 1} [:b]) => #{}
(gets-in {:a #{{:b 1} {:b 2}}} [:a :b]) => #{1 2}
Similar in style to `get-in` with operations on sets. returns a set of values. (gets-in {:a 1} [:a]) => #{1} (gets-in {:a 1} [:b]) => #{} (gets-in {:a #{{:b 1} {:b 2}}} [:a :b]) => #{1 2}
(index-of pred coll)
finds the index of the first matching element in an array
(index-of even? [1 2 3 4]) => 1
(index-of keyword? [1 2 :hello 4]) => 2
finds the index of the first matching element in an array (index-of even? [1 2 3 4]) => 1 (index-of keyword? [1 2 :hello 4]) => 2
(into-nnil to from)
like into but filters nil values for both key/value pairs and sequences
(into-nnil [] [1 nil 2 3]) => [1 2 3]
(into-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2}
like into but filters nil values for both key/value pairs and sequences (into-nnil [] [1 nil 2 3]) => [1 2 3] (into-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2}
(key-paths m)
(key-paths m max)
(key-paths m max arr)
The set of all paths in a map, governed by a max level of nesting
(key-paths {:a {:b 1} :c {:d 1}}) => (contains [[:c :d] [:a :b]] :in-any-order)
(key-paths {:a {:b 1} :c {:d 1}} 1) => (contains [[:c] [:a]] :in-any-order)
The set of all paths in a map, governed by a max level of nesting (key-paths {:a {:b 1} :c {:d 1}}) => (contains [[:c :d] [:a :b]] :in-any-order) (key-paths {:a {:b 1} :c {:d 1}} 1) => (contains [[:c] [:a]] :in-any-order)
(keys-nested m)
The set of all nested keys in a map
(keys-nested {:a {:b 1 :c {:d 1}}}) => #{:a :b :c :d}
The set of all nested keys in a map (keys-nested {:a {:b 1 :c {:d 1}}}) => #{:a :b :c :d}
(map-entries f m)
manipulates a map given the function
(map-entries (fn [[k v]] [(keyword (str v)) (name k)]) {:a 1 :b 2 :c 3}) => {:1 "a", :2 "b", :3 "c"}
manipulates a map given the function (map-entries (fn [[k v]] [(keyword (str v)) (name k)]) {:a 1 :b 2 :c 3}) => {:1 "a", :2 "b", :3 "c"}
(map-keys f m)
changes the keys of a map
(map-keys inc {0 :a 1 :b 2 :c}) => {1 :a, 2 :b, 3 :c}
changes the keys of a map (map-keys inc {0 :a 1 :b 2 :c}) => {1 :a, 2 :b, 3 :c}
(map-vals f m)
changes the values of a map
(map-vals inc {:a 1 :b 2 :c 3}) => {:a 2, :b 3, :c 4}
changes the values of a map (map-vals inc {:a 1 :b 2 :c 3}) => {:a 2, :b 3, :c 4}
(merge-nested)
(merge-nested m)
(merge-nested m1 m2)
(merge-nested m1 m2 & ms)
Merges nested values from left to right.
(merge-nested {:a {:b {:c 3}}} {:a {:b 3}}) => {:a {:b 3}}
(merge-nested {:a {:b {:c 1 :d 2}}} {:a {:b {:c 3}}}) => {:a {:b {:c 3 :d 2}}}
Merges nested values from left to right. (merge-nested {:a {:b {:c 3}}} {:a {:b 3}}) => {:a {:b 3}} (merge-nested {:a {:b {:c 1 :d 2}}} {:a {:b {:c 3}}}) => {:a {:b {:c 3 :d 2}}}
(merge-new)
(merge-new m)
(merge-new m1 m2)
(merge-new m1 m2 & more)
only merge if the value in the original map is nil
(merge-new {:a 1} {:b 2}) => {:a 1 :b 2}
(merge-new {:a 1} {:a 2}) => {:a 1}
only merge if the value in the original map is nil (merge-new {:a 1} {:b 2}) => {:a 1 :b 2} (merge-new {:a 1} {:a 2}) => {:a 1}
(merge-new-nested)
(merge-new-nested m)
(merge-new-nested m1 m2)
(merge-new-nested m1 m2 & more)
Merges nested values from left to right, provided the merged value does not exist
(merge-new-nested {:a {:b 2}} {:a {:c 2}}) => {:a {:b 2 :c 2}}
(merge-new-nested {:b {:c :old}} {:b {:c :new}}) => {:b {:c :old}}
Merges nested values from left to right, provided the merged value does not exist (merge-new-nested {:a {:b 2}} {:a {:c 2}}) => {:a {:b 2 :c 2}} (merge-new-nested {:b {:c :old}} {:b {:c :new}}) => {:b {:c :old}}
(merge-nnil)
(merge-nnil m)
(merge-nnil m1 m2)
(merge-nnil m1 m2 & more)
merges key/value pairs into a single map only if the value exists
(merge-nnil {:a nil :b 1}) => {:b 1}
(merge-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2}
(merge-nnil {:a 1} {:b nil} {:c 2}) => {:a 1 :c 2}
merges key/value pairs into a single map only if the value exists (merge-nnil {:a nil :b 1}) => {:b 1} (merge-nnil {:a 1} {:b nil :c 2}) => {:a 1 :c 2} (merge-nnil {:a 1} {:b nil} {:c 2}) => {:a 1 :c 2}
(merges m1 m2)
(merges m1 m2 sel)
(merges m1 m2 sel func)
Like merge
but works across sets and will also
combine duplicate key/value pairs together into sets of values.
(merges {:a 1} {:a 2}) => {:a #{1 2}}
(merges {:a #{{:id 1 :val 1}}} {:a {:id 1 :val 2}} :id merges) => {:a #{{:id 1 :val #{1 2}}}}
Like `merge` but works across sets and will also combine duplicate key/value pairs together into sets of values. (merges {:a 1} {:a 2}) => {:a #{1 2}} (merges {:a #{{:id 1 :val 1}}} {:a {:id 1 :val 2}} :id merges) => {:a #{{:id 1 :val #{1 2}}}}
(merges-nested)
(merges-nested m)
(merges-nested m1 m2)
(merges-nested m1 m2 sel)
(merges-nested m1 m2 sel func)
Like merges
but works on nested maps
(merges-nested {:a {:b 1}} {:a {:b 2}}) => {:a {:b #{1 2}}}
(merges-nested {:a #{{:foo #{{:bar #{{:baz 1}}}}}}} {:a #{{:foo #{{:bar #{{:baz 2}}}}}}} hash-map? merges-nested) => {:a #{{:foo #{{:bar #{{:baz 2}}} {:bar #{{:baz 1}}}}}}}
Like `merges` but works on nested maps (merges-nested {:a {:b 1}} {:a {:b 2}}) => {:a {:b #{1 2}}} (merges-nested {:a #{{:foo #{{:bar #{{:baz 1}}}}}}} {:a #{{:foo #{{:bar #{{:baz 2}}}}}}} hash-map? merges-nested) => {:a #{{:foo #{{:bar #{{:baz 2}}} {:bar #{{:baz 1}}}}}}}
(patch m diff)
Use the diff to convert one map to another in the forward direction based upon changes between the two.
(let [m1 {:a {:b 1 :d 3}} m2 {:a {:c 2 :d 4}} df (diff m2 m1)] (patch m1 df)) => {:a {:c 2 :d 4}}
Use the diff to convert one map to another in the forward direction based upon changes between the two. (let [m1 {:a {:b 1 :d 3}} m2 {:a {:c 2 :d 4}} df (diff m2 m1)] (patch m1 df)) => {:a {:c 2 :d 4}}
(positions pred coll)
find positions of elements matching the predicate
(positions even? [5 5 4 4 3 3 2 2]) => [2 3 6 7]
find positions of elements matching the predicate (positions even? [5 5 4 4 3 3 2 2]) => [2 3 6 7]
(remove-index coll i)
(remove-index coll i n)
removes element at the specified index
(remove-index [:a :b :c :d] 2) => [:a :b :d]
removes element at the specified index (remove-index [:a :b :c :d] 2) => [:a :b :d]
(retract-in m rels)
reversed the changes by transform-in
(retract-in {:b 2, :c {:d 1}} {[:c :d] [:a]}) => {:a 1 :b 2}
reversed the changes by transform-in (retract-in {:b 2, :c {:d 1}} {[:c :d] [:a]}) => {:a 1 :b 2}
(select-keys-nnil m ks)
selects only the non-nil key/value pairs from a map
(select-keys-nnil {:a 1 :b nil} [:a :b]) => {:a 1}
(select-keys-nnil {:a 1 :b nil :c 2} [:a :b :c]) => {:a 1 :c 2}
selects only the non-nil key/value pairs from a map (select-keys-nnil {:a 1 :b nil} [:a :b]) => {:a 1} (select-keys-nnil {:a 1 :b nil :c 2} [:a :b :c]) => {:a 1 :c 2}
(transform-in m rels)
moves values around in a map according to a table
(transform-in {:a 1 :b 2} {[:c :d] [:a]}) => {:b 2, :c {:d 1}}
moves values around in a map according to a table (transform-in {:a 1 :b 2} {[:c :d] [:a]}) => {:b 2, :c {:d 1}}
(transpose m)
sets the vals and keys and vice-versa
(transpose {:a 1 :b 2 :c 3}) => {1 :a, 2 :b, 3 :c}
sets the vals and keys and vice-versa (transpose {:a 1 :b 2 :c 3}) => {1 :a, 2 :b, 3 :c}
(unique m1 m2)
returns a map of all key/value pairs that differ from a second map
(unique {:a 1} {:a 2}) => {:a 1}
(unique {:a 1 :b 2} {:b 2}) => {:a 1}
(unique {:b 2} {:b 2 :a 1}) => nil
returns a map of all key/value pairs that differ from a second map (unique {:a 1} {:a 2}) => {:a 1} (unique {:a 1 :b 2} {:b 2}) => {:a 1} (unique {:b 2} {:b 2 :a 1}) => nil
(unique-nested m1 m2)
All nested values in m1
that are unique to those in m2
.
(unique-nested {:a {:b 1}} {:a {:b 1 :c 1}}) => {}
(unique-nested {:a {:b 1 :c 1}} {:a {:b 1}}) => {:a {:c 1}}
All nested values in `m1` that are unique to those in `m2`. (unique-nested {:a {:b 1}} {:a {:b 1 :c 1}}) => {} (unique-nested {:a {:b 1 :c 1}} {:a {:b 1}}) => {:a {:c 1}}
(unpatch m diff)
Use the diff to convert one map to another in the reverse direction based upon changes between the two.
(let [m1 {:a {:b 1 :d 3}} m2 {:a {:c 2 :d 4}} df (diff m2 m1 true)] (unpatch m2 df)) => {:a {:b 1 :d 3}}
Use the diff to convert one map to another in the reverse direction based upon changes between the two. (let [m1 {:a {:b 1 :d 3}} m2 {:a {:c 2 :d 4}} df (diff m2 m1 true)] (unpatch m2 df)) => {:a {:b 1 :d 3}}
(update-in-nnil m arr f & args)
update-in a nested key/value pair only if the value exists
(update-in-nnil {:a {:b 1}} [:a :b] inc) => {:a {:b 2}}
(update-in-nnil {} [:a :b] inc) => {}
update-in a nested key/value pair only if the value exists (update-in-nnil {:a {:b 1}} [:a :b] inc) => {:a {:b 2}} (update-in-nnil {} [:a :b] inc) => {}
(update-keys-in m arr f & args)
updates all keys in a map with given function
(update-keys-in {:x {["a" "b"] 1 ["c" "d"] 2}} [:x] string/joinl) => {:x {"ab" 1 "cd" 2}}
(update-keys-in {:a {:c 1} :b {:d 2}} 2 name) => {:b {"d" 2}, :a {"c" 1}}
updates all keys in a map with given function (update-keys-in {:x {["a" "b"] 1 ["c" "d"] 2}} [:x] string/joinl) => {:x {"ab" 1 "cd" 2}} (update-keys-in {:a {:c 1} :b {:d 2}} 2 name) => {:b {"d" 2}, :a {"c" 1}}
(update-vals-in m arr f & args)
updates all values in a map with given function
(update-vals-in {:a 1 :b 2} [] inc) => {:a 2 :b 3}
(update-vals-in {:a {:c 1} :b 2} [:a] inc) => {:a {:c 2} :b 2}
(update-vals-in {:a {:c 1} :b {:d 2}} 2 inc) => {:a {:c 2} :b {:d 3}}
(update-vals-in {:a 1 :b 2} 1 inc) => {:a 2, :b 3}
updates all values in a map with given function (update-vals-in {:a 1 :b 2} [] inc) => {:a 2 :b 3} (update-vals-in {:a {:c 1} :b 2} [:a] inc) => {:a {:c 2} :b 2} (update-vals-in {:a {:c 1} :b {:d 2}} 2 inc) => {:a {:c 2} :b {:d 3}} (update-vals-in {:a 1 :b 2} 1 inc) => {:a 2, :b 3}
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close