Namespace providing extensions to clojure's standard library
Namespace providing extensions to clojure's standard library
(apply-if x pred f)
Conditionally applies (f x)
if pred
returns true
, otherwise returns x
.
Conditionally applies `(f x)` if `pred` returns `true`, otherwise returns `x`.
(apply-when x pred f)
Conditionally applies (f x)
if pred
returns true
, otherwise returns nil
Conditionally applies `(f x)` if `pred` returns `true`, otherwise returns nil
(arg n)
Returns a function which will take any number of arguments and return
the 1-based index argument of n
. Mostly useful for composition.
user=> ((a 1) 1 2 3) 1
Returns a function which will take any number of arguments and return the 1-based index argument of `n`. Mostly useful for composition. user=> ((a 1) 1 2 3) 1
(arity n f & static-args)
Return a variant of f
that will only accept n
arguments.
Useful for coercing polyvariadic functions into fixed arity ones.
Optionally takes &args
which will be applied after the first n
arguments.
Return a variant of `f` that will only accept `n` arguments. Useful for coercing polyvariadic functions into fixed arity ones. Optionally takes `&args` which will be applied after the first `n` arguments.
(assert-args & pairs)
assert-args lifted from clojure.core. Mostly useful for writing other macros
assert-args lifted from clojure.core. Mostly useful for writing other macros
(assert-info expr msg info)
A variant of assert
that throws an ex-info
based exception.
A variant of `assert` that throws an `ex-info` based exception.
(assoc-some m & {:as kvs})
Like clojure.core/assoc
but only associates the key and value if the val
is some?
.
Like `clojure.core/assoc` but only associates the key and value if the `val` is `some?`.
(avg & args)
Variadic function which will average args
. Returns nil on empty collections
Variadic function which will average `args`. Returns nil on empty collections
(compr & fs)
Composes the provided reducer functions fs
.
This essentially behaves exactly as comp
but is variadic where additional arguments will be
passed to each function.
Composes the provided reducer functions `fs`. This essentially behaves exactly as `comp` but is variadic where additional arguments will be passed to each function.
(dedupe-by f)
(dedupe-by f coll)
Returns a lazy sequence of the elements of coll, removing any consecutive elements that return duplicate values when passed to a function f.
Returns a stateful transducer when no collection is provided.
See also distinct-by
Returns a lazy sequence of the elements of coll, removing any **consecutive** elements that return duplicate values when passed to a function f. Returns a stateful transducer when no collection is provided. See also `distinct-by`
(deep-merge x & [y & maps])
Similar to merge, but nested maps will be merged.
If any non-nested map value is duplicated, the right associated value will be kept. This includes scenarios where a left-bound map is merged with a right-bound primitive.
Similar to merge, but nested maps will be merged. If any non-nested map value is duplicated, the right associated value will be kept. This includes scenarios where a left-bound map is merged with a right-bound primitive.
(dissoc-in m path)
Like clojure.core/dissoc
but takes a path like clojure.core/get-in
Like `clojure.core/dissoc` but takes a path like `clojure.core/get-in`
(distinct-by f)
(distinct-by f coll)
Returns a lazy sequence of the elements of coll with elements that return non-distinct
values from f
removed.
Returns a stateful transducer when no collection is provided.
See also dedupe-by
.
Returns a lazy sequence of the elements of coll with elements that return non-distinct values from `f` removed. Returns a stateful transducer when no collection is provided. See also `dedupe-by`.
(ensure-ascending)
(ensure-ascending f)
(ensure-ascending coll)
(ensure-ascending f coll)
(ensure-ascending)
(ensure-ascending f-or-coll)
(ensure-ascending f coll)
Returns a stateful transducer that will ensure that only items that are ascending
(using compare
) will be emitted.
Optionally takes an f
which will be used to access the value.
If called with a coll
returns a lazy sequence.
Returns a stateful transducer that will ensure that only items that are ascending (using `compare`) will be emitted. Optionally takes an `f` which will be used to access the value. If called with a `coll` returns a lazy sequence.
(extract map keys)
Returns a tuple of a vector of the vals of keys
and map
with keys
removed.
Example:
(extract {:name "Bob" :age 42 :weight 200} [:age :weight]) ;; [[42 200] {:name "Bob"}]
Returns a tuple of a vector of the vals of `keys` and `map` with `keys` removed. Example: (extract {:name "Bob" :age 42 :weight 200} [:age :weight]) ;; [[42 200] {:name "Bob"}]
(fex f ex-val)
Similar clojure.core/fnil
. Returns a function which will call f
when called
and return ex-val
in the case that any exception occurs.
Similar `clojure.core/fnil`. Returns a function which will call `f` when called and return `ex-val` in the case that any exception occurs.
(filter-keys f)
(filter-keys f map)
Return a transducer which will only match map-entries for which the
pred
called on keys returned logical true
.
If called with map
, will return a new map executing the transducer.
Return a transducer which will only match map-entries for which the `pred` called on keys returned logical `true`. If called with `map`, will return a new map executing the transducer.
(filter-vals f)
(filter-vals f map)
Return a transducer which will only match map-entries for which the
pred
called on values returned logical true
.
If called with map
, will return a new map executing the transducer.
Return a transducer which will only match map-entries for which the `pred` called on values returned logical `true`. If called with `map`, will return a new map executing the transducer.
(find-first pred coll)
(find-first pred extract coll)
Returns the first item matching pred
in coll
.
Optionally takes an extract
function which will be applied iff the matching item is not nil
.
Example:
(find-first :primary :email [{:primary false :email "bob@gmail.com"} {:primary true :email "foo@bar.com"}])
Returns the first item matching `pred` in `coll`. Optionally takes an `extract` function which will be applied iff the matching item is not `nil`. Example: (find-first :primary :email [{:primary false :email "bob@gmail.com"} {:primary true :email "foo@bar.com"}])
(find-paths pred coll)
Returns a sequence of vector paths for which pred
returns true.
For nested maps, it will be called on the pred
will be called with the val
of the map entry.
Note that this performs a pre-walk and in the case of nested maps or vectors, pred
will be
called with them before traversing their children.
Returns a sequence of vector paths for which `pred` returns true. For nested maps, it will be called on the `pred` will be called with the `val` of the map entry. Note that this performs a pre-walk and in the case of nested maps or vectors, `pred` will be called with them before traversing their children.
(group-by f coll)
(group-by f g coll)
(group-by f g into coll)
Similar to clojure.core/group-by
. Returns a map with keys of
f
applied to items in coll
.
Optionally takes a function g
which will be applied to the values.
Lastly, takes an into
collection, which will be used to create the base collection at each key.
This allows you to specify grouping into sets or vectors.
Similar to `clojure.core/group-by`. Returns a map with keys of `f` applied to items in `coll`. Optionally takes a function `g` which will be applied to the values. Lastly, takes an `into` collection, which will be used to create the base collection at each key. This allows you to specify grouping into sets or vectors.
(guard pred)
(guard pred x)
Return nil
unless (pred x)
, then return x
.
The unary form returns a partially applied guard
.
Useful for condp
.
Return `nil` unless `(pred x)`, then return `x`. The unary form returns a partially applied `guard`. Useful for `condp`.
(index-by f coll)
(index-by f g coll)
Indexes a coll
by the value returned by f
. Returns a map.
Optionally takes a function g
which will be applied to the val in the map.
user=> (index-by :name [{:name "Bob" :age 42}]) {"Bob" {:name "Bob" :age 42}}
user=> (index-by :name :age [{:name "Bob" :age 42}]) {"Bob" 42}
Indexes a `coll` by the value returned by `f`. Returns a map. Optionally takes a function `g` which will be applied to the val in the map. user=> (index-by :name [{:name "Bob" :age 42}]) {"Bob" {:name "Bob" :age 42}} user=> (index-by :name :age [{:name "Bob" :age 42}]) {"Bob" 42}
(indistinct)
(indistinct coll)
Returns elements in a sequence that appear more than once.
Only returns successive elements that have been seen before.
If called without a collection, returns a stateful transducer.
user=> (indistinct [1 2 1 2 2 3 4 5 1]) (1 2 2 1)
Returns elements in a sequence that appear more than once. Only returns successive elements that have been seen before. If called without a collection, returns a stateful transducer. user=> (indistinct [1 2 1 2 2 3 4 5 1]) (1 2 2 1)
(inspect v)
(inspect msg v)
(inspect msg f v)
A function useful for println debugging. Prints the value (and an optional message) and returns it.
A function useful for println debugging. Prints the value (and an optional message) and returns it.
(make-map & args)
Packs a sequence of variables into a map with keywords bound to the same name as the variables
Packs a sequence of variables into a map with keywords bound to the same name as the variables
(map-keys f)
(map-keys f map)
Returns a transducer for mapping f
over all keys in a map-entry.
If called with map
, returns a new map with f
applied over all keys.
Returns a transducer for mapping `f` over all keys in a map-entry. If called with `map`, returns a new map with `f` applied over all keys.
(map-leaves f)
(map-leaves f map)
Returns a transducer for mapping f
over all leaf values in a map-entry. Nested maps will be
traversed.
If called with map
returns a new map with f
applied over all leaves.
Returns a transducer for mapping `f` over all leaf values in a map-entry. Nested maps will be traversed. If called with `map` returns a new map with `f` applied over all leaves.
(map-vals f)
(map-vals f map)
Returns a transducer for mapping f
over all values in a map-entry.
If called with map
, returns a new map with f
applied over all values.
Returns a transducer for mapping `f` over all values in a map-entry. If called with `map`, returns a new map with `f` applied over all values.
(ns-keys ns)
(ns-keys ns map)
Returns a transducer which will namespace all keys in a map.
If called with map
returns a new map executing the transducer.
Returns a transducer which will namespace all keys in a map. If called with `map` returns a new map executing the transducer.
(partition-keys map keys)
Similar to clojure.core/select-keys
but returns a vector of two maps. The first is
the map with the selected keys
, while the other is the original map
with the keys
removed.
Similar to `clojure.core/select-keys` but returns a vector of two maps. The first is the map with the selected `keys`, while the other is the original `map` with the `keys` removed.
(rand n)
(rand low high)
Behaves just like clojure.core/rand
but optionally accepts a lower bound.
Behaves just like `clojure.core/rand` but optionally accepts a lower bound.
(random-uuid)
Return a random-uuid. Cljc port of the clojurescript variant
Return a random-uuid. Cljc port of the clojurescript variant
(remove-keys f)
(remove-keys f map)
Return a transducer which will only match map-entries for which the
pred
called on keys returned logical false
.
If called with map
, will return a new map executing the transducer.
Return a transducer which will only match map-entries for which the `pred` called on keys returned logical `false`. If called with `map`, will return a new map executing the transducer.
(remove-vals f)
(remove-vals f map)
Return a transducer which will only match map-entries for which the
pred
called on values returned logical false
.
If called with map
, will return a new map executing the transducer.
Return a transducer which will only match map-entries for which the `pred` called on values returned logical `false`. If called with `map`, will return a new map executing the transducer.
(round n)
(round n precision)
Rounds n
to the given precision
Rounds `n` to the given `precision`
(standard-deviation & args)
Varidic function wheich will return the standard deviation of the provided args
. Returns nil
on empty collections
Varidic function wheich will return the standard deviation of the provided `args`. Returns `nil` on empty collections
(sum & args)
Variadic function which will sum args
. Treats nil as 0.
Variadic function which will sum `args`. Treats nil as 0.
(unfold f initial)
Produces a lazy sequence by invoking f with initial.
f
should return a tuple of an item and new state.
If the item is nil
nothing will be emitted.
If f
returns nil
the sequence will terminate.
See also: iterate
Produces a lazy sequence by invoking f with initial. `f` should return a tuple of an item and new state. If the item is `nil` nothing will be emitted. If `f` returns `nil` the sequence will terminate. See also: `iterate`
(update-if-exists m & {:as kfns})
Like clojure.core/update
, but only calls f
if the k
exists
in the m
.
Like `clojure.core/update`, but only calls `f` if the `k` exists in the `m`.
(update-if-some m & {:as kfns})
Like clojure.core/update
, but only calls f
if the k
exists
in the m
and it has a non-nil value.
Like `clojure.core/update`, but only calls `f` if the `k` exists in the `m` and it has a non-nil value.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close