(assoc-first coll where v)
Finds the first element in collection matching where parameter and
replaces that with v.
Implementation depends on collection type.
Finds the first element in collection matching where parameter and replaces that with `v.` Implementation depends on collection type.
(assoc-if m key val)
(assoc-if m key val & kvs)
Assoc key-value pairs with non-nil values into map.
Assoc key-value pairs with non-nil values into map.
(assoc-in-path-vals c)
Re-created a map from it's path-vals extracted with (path-vals).
Re-created a map from it's path-vals extracted with (path-vals).
(build-tree {:keys [parent-fn id-fn assoc-children-fn] :as opts} items)
Builds a tree from given items collections.
ID is what is used to match parents and children. Root items are those where parent-fn returns nil.
Options:
Example: (build-tree {:id-fn :id, :parent-fn :parent, :assoc-children-fn #(assoc %1 :children %2)} [{:id 1} {:id 2 :parent 1} {:id 3 :parent 1}]) => [{:id 1 :children [{:id 2} {:id 3}]}]
Check test file for more examples.
Builds a tree from given items collections. ID is what is used to match parents and children. Root items are those where parent-fn returns nil. Options: - :parent-fn (required) Used to create a map from ID => children - :id-fn (required) Used to get the ID from an item - :assoc-children-fn (required) Attach the children to an item - :item-fn (optional) Called for each item, after children has been attached to the item - :children-fn (optional) Called for each children collection Example: (build-tree {:id-fn :id, :parent-fn :parent, :assoc-children-fn #(assoc %1 :children %2)} [{:id 1} {:id 2 :parent 1} {:id 3 :parent 1}]) => [{:id 1 :children [{:id 2} {:id 3}]}] Check test file for more examples.
(condas-> expr name & clauses)
(condas-> &form &env expr name & clauses)
A mixture of cond-> and as-> allowing more flexibility in the test and step forms
A mixture of cond-> and as-> allowing more flexibility in the test and step forms
(conjv coll el)
Append an element to a collection. If collection is nil
, creates vector
instead of sequence. The appending might happen on different places
depending on the type of collection.
Examples:
(conjv nil 5) => [5]
(conjv [1] 2) => [1 2]
(update-in {} [:a] conjv 5) => {:a [5]}
(-> [] (conjv 5)) => [5]
Append an element to a collection. If collection is `nil`, creates vector instead of sequence. The appending might happen on different places depending on the type of collection. Examples: (conjv nil 5) => [5] (conjv [1] 2) => [1 2] (update-in {} [:a] conjv 5) => {:a [5]} (-> [] (conjv 5)) => [5]
(consv coll el)
Prepend an element to a collection. Returns a vector.
Examples:
(consv nil 1) => [1]
(consv [2] 1) => [1 2]
(update-in {:a 2} [:a] consv 1) => {:a [1 2]}
(-> [2] (consv 5)) => [1 2]
Prepend an element to a collection. Returns a vector. Examples: (consv nil 1) => [1] (consv [2] 1) => [1 2] (update-in {:a 2} [:a] consv 1) => {:a [1 2]} (-> [2] (consv 5)) => [1 2]
(deep-merge values)
(deep-merge strategy & values)
(deep-merge & values)
Recursively merges maps.
If the first parameter is a keyword it tells the strategy to use when merging non-map collections. Options are
:replace
, the default, the last value is used:into
, if the value in every map is a collection they are concatenated
using into. Thus the type of (first) value is maintained.Examples:
(deep-merge {:a {:c 2}} {:a {:b 1}}) => {:a {:b 1 :c 2}}
(deep-merge :replace {:a [1]} {:a [2]}) => {:a [2]}
(deep-merge :into {:a [1]} {:a [2]}) => {:a [1 2]}
(deep-merge {:a 1} nil) => nil
See also: meta-merge.
Recursively merges maps. If the first parameter is a keyword it tells the strategy to use when merging non-map collections. Options are - `:replace`, the default, the last value is used - `:into`, if the value in every map is a collection they are concatenated using into. Thus the type of (first) value is maintained. Examples: (deep-merge {:a {:c 2}} {:a {:b 1}}) => {:a {:b 1 :c 2}} (deep-merge :replace {:a [1]} {:a [2]}) => {:a [2]} (deep-merge :into {:a [1]} {:a [2]}) => {:a [1 2]} (deep-merge {:a 1} nil) => nil See also: [meta-merge](https://github.com/weavejester/meta-merge).
(dissoc-in m [k & ks :as keys])
Dissociates an entry from a nested associative structure returning a new
nested structure. keys
is a sequence of keys. Any empty maps that result
will not be present in the new structure.
Dissociates an entry from a nested associative structure returning a new nested structure. `keys` is a sequence of keys. Any empty maps that result will not be present in the new structure.
(filter-entries pred coll)
Filter given associative collection using function on the values.
Filter given associative collection using function on the values.
(filter-keys pred coll)
Filter given associative collection using function on the keys.
Filter given associative collection using function on the keys.
(filter-vals pred coll)
Filter given associative collection using function on the values.
Filter given associative collection using function on the values.
(find-first coll where)
Find first value from collection which mathes the where parameter.
If where parameter is:
Examples:
(find-first [1 2 3] even?) => 2
(find-first [{:id 1} {:id 2, :foo :bar}] {:id 2}) => {:id 2, :foo :bar}
(find-first [{:a 1} {:b 2, :foo :bar}] :b) => {:b 2, :foo :bar}
(find-first [1 2 3] #{3}) => 3
(find-first [1 2 3] 3) => 3
(-> [1 2 3] (find-first odd?)) => 1
Find first value from collection which mathes the where parameter. If where parameter is: - a fn, it's used as predicate as is - a map, a predicate is created which checks if value in collection has same values for each key in where map - Something which implements IFn, e.g. keywords and sets, is used as is - any value, a predicate is created which checks if value is identitical Examples: (find-first [1 2 3] even?) => 2 (find-first [{:id 1} {:id 2, :foo :bar}] {:id 2}) => {:id 2, :foo :bar} (find-first [{:a 1} {:b 2, :foo :bar}] :b) => {:b 2, :foo :bar} (find-first [1 2 3] #{3}) => 3 (find-first [1 2 3] 3) => 3 (-> [1 2 3] (find-first odd?)) => 1
(find-index coll where)
Find index of vector which matches the where parameter.
If where parameter is:
Examples:
(find-index [1 2 3] even?) => 1
(find-index [{:id 1} {:id 2}] {:id 2}) => 1
(find-index [{:a 1} {:b 2}] :b) => 1
(find-index [1 2 3] #{3}) => 2
(find-index [1 2 3] 3) => 2
(-> [1 2 3] (find-index odd?)) => 0
Find index of vector which matches the where parameter. If where parameter is: - a fn, it's used as predicate as is - a map, a predicate is created which checks if value in collection has same values for each key in where map - Something which implements IFn, e.g. keywords and sets, is used as is - any value, a predicate is created which checks if value is identitical Examples: (find-index [1 2 3] even?) => 1 (find-index [{:id 1} {:id 2}] {:id 2}) => 1 (find-index [{:a 1} {:b 2}] :b) => 1 (find-index [1 2 3] #{3}) => 2 (find-index [1 2 3] 3) => 2 (-> [1 2 3] (find-index odd?)) => 0
(fn-> & body)
(fn-> &form &env & body)
Creates a function that threads on input with some->
Creates a function that threads on input with `some->`
(fn->> & body)
(fn->> &form &env & body)
Creates a function that threads on input with some->>
Creates a function that threads on input with `some->>`
(if-all-let bindings then)
(if-all-let bindings then else)
(if-all-let &form &env bindings then)
(if-all-let &form &env bindings then else)
bindings => [binding-form test, binding-form test ...]
If all tests are true
, evaluates then with binding-forms bound to the values of
tests, if not, yields else.
`bindings => [binding-form test, binding-form test ...]` If all tests are `true`, evaluates then with binding-forms bound to the values of tests, if not, yields `else.`
(index-by f coll)
Returns a map of the elements of coll keyed by the result of f on each element. The value at each key will the last item for given f result.
Returns a map of the elements of coll keyed by the result of f on each element. The value at each key will the last item for given f result.
(map-entries f coll)
Map the entries of given associative collection using function.
Map the entries of given associative collection using function.
(map-keys f coll)
Map the keys of given associative collection using function.
Map the keys of given associative collection using function.
(map-of & syms)
(map-of &form &env & syms)
Creates map with symbol names as keywords as keys and symbol values as values.
Creates map with symbol names as keywords as keys and symbol values as values.
(map-vals f coll)
Map the values of given associative collection using function.
Map the values of given associative collection using function.
(path-vals m)
Returns vector of tuples containing path vector to the value and the value.
Returns vector of tuples containing path vector to the value and the value.
(remove-entries pred coll)
Removes given associative collection using function on the values.
Removes given associative collection using function on the values.
(remove-keys pred coll)
Removes given associative collection using function on the keys.
Removes given associative collection using function on the keys.
(remove-vals pred coll)
Removes given associative collection using function on the values.
Removes given associative collection using function on the values.
(update-first coll where f & args)
Finds the first element in collection matching the where parameter
and updates that using f.
f
is called with current value and
rest of update-first params.
Implementation depends on collection type.
Finds the first element in collection matching the where parameter and updates that using `f.` `f` is called with current value and rest of update-first params. Implementation depends on collection type.
(wrap-into coll v)
Wrap non-collection values into given collection. Collections are only put into the collection (non-wrapped).
Examples:
(wrap-into [] :a) => [:a]
(wrap-into [] [:a]) => [:a]
(wrap-into #{} [:a]) => #{:a}
Wrap non-collection values into given collection. Collections are only put into the collection (non-wrapped). Examples: (wrap-into [] :a) => [:a] (wrap-into [] [:a]) => [:a] (wrap-into #{} [:a]) => #{:a}
(zip & colls)
Returns a sequence of vectors where the i-th vector contains the i-th element from each of the argument collections. The returned sequence is as long as the shortest argument.
Example:
(zip [1 2 3] [:a :b :c]) => ([1 :a] [2 :b] [3 :c])
(zip [1] [1 2] [1 2 3]) => ([1 1 1])
Returns a sequence of vectors where the i-th vector contains the i-th element from each of the argument collections. The returned sequence is as long as the shortest argument. Example: (zip [1 2 3] [:a :b :c]) => ([1 :a] [2 :b] [3 :c]) (zip [1] [1 2] [1 2 3]) => ([1 1 1])
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close