Liking cljdoc? Tell your friends :D

potpuri.core


assoc-firstclj/s

(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.
sourceraw docstring

assoc-ifclj/s

(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.
sourceraw docstring

assoc-in-path-valsclj/s

(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).
sourceraw docstring

build-treeclj/s

(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:

  • :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.

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.
sourceraw docstring

condas->clj/s≠macro

clj
(condas-> expr name & clauses)
cljs
(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
source (clj)source (cljs)raw docstring

conjvclj/s

(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]
sourceraw docstring

consvclj/s

(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]
sourceraw docstring

deep-mergeclj/s≠

clj
(deep-merge values)
(deep-merge strategy & values)
cljs
(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).
sourceraw docstring

dissoc-inclj/s

(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.
sourceraw docstring

filter-entriesclj/s

(filter-entries pred coll)

Filter given associative collection using function on the values.

Filter given associative collection using function on the values.
sourceraw docstring

filter-keysclj/s

(filter-keys pred coll)

Filter given associative collection using function on the keys.

Filter given associative collection using function on the keys.
sourceraw docstring

filter-valsclj/s

(filter-vals pred coll)

Filter given associative collection using function on the values.

Filter given associative collection using function on the values.
sourceraw docstring

find-firstclj/s

(find-first coll where)

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 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
sourceraw docstring

find-indexclj/s

(find-index coll where)

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
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
sourceraw docstring

fn->clj/s≠macro

clj
(fn-> & body)
cljs
(fn-> &form &env & body)

Creates a function that threads on input with some->

Creates a function that threads on input with `some->`
source (clj)source (cljs)raw docstring

fn->>clj/s≠macro

clj
(fn->> & body)
cljs
(fn->> &form &env & body)

Creates a function that threads on input with some->>

Creates a function that threads on input with `some->>`
source (clj)source (cljs)raw docstring

if-all-letclj/s≠macro

clj
(if-all-let bindings then)
(if-all-let bindings then else)
cljs
(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.`
source (clj)source (cljs)raw docstring

index-byclj/s

(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.
sourceraw docstring

map-entriesclj/s

(map-entries f coll)

Map the entries of given associative collection using function.

Map the entries of given associative collection using function.
sourceraw docstring

map-keysclj/s

(map-keys f coll)

Map the keys of given associative collection using function.

Map the keys of given associative collection using function.
sourceraw docstring

map-ofclj/s≠macro

clj
(map-of & syms)
cljs
(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.
source (clj)source (cljs)raw docstring

map-valsclj/s

(map-vals f coll)

Map the values of given associative collection using function.

Map the values of given associative collection using function.
sourceraw docstring

path-valsclj/s

(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.
sourceraw docstring

remove-entriesclj/s

(remove-entries pred coll)

Removes given associative collection using function on the values.

Removes given associative collection using function on the values.
sourceraw docstring

remove-keysclj/s

(remove-keys pred coll)

Removes given associative collection using function on the keys.

Removes given associative collection using function on the keys.
sourceraw docstring

remove-valsclj/s

(remove-vals pred coll)

Removes given associative collection using function on the values.

Removes given associative collection using function on the values.
sourceraw docstring

update-firstclj/s

(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.
sourceraw docstring

wrap-intoclj/s

(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}
sourceraw docstring

zipclj/s

(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])
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close