stch.util documentation
Utility functions.
->map
(->map coll)
Convert a collection to a hash map.
and'
(and' x)
(and' x y)
(and' x y z)
(and' x y z & forms)
Functional equivalent of and. All arguments are
evaluated, but not necessarily checked.
and-fn
(and-fn p1)
(and-fn p1 p2)
(and-fn p1 p2 p3)
(and-fn p1 p2 p3 & ps)
Takes one or more predicates and returns a
function that takes a value, applies each
predicate to that value, and returns the result of
the last predicate if all predicates return a truthy
value.
deep-merge
(deep-merge & maps)
Merges maps recursively, returning the last item
when there's a non-map at a particular level.
(deep-merge {:a 1 :b {:c 1 :d 1}} {:a 2 :b {:c 2}})
deep-merge-with
(deep-merge-with f & maps)
Like merge-with, but merges maps recursively,
applying the given fn only when there's a non
map at a particular level.
(deep-merge-with + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4}
{:a {:b {:c 2 :d {:z 9} :z 3} :e 100}})
=> {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}
dissoc-in
(dissoc-in m [k & ks])
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.
dissoc-vec
(dissoc-vec v i)
Remove the element at index i and return a new
vector. Will throw if index does not exist.
first-index
(first-index needle coll)
Returns the first index where needle
is found in coll.
heap-mb
(heap-mb)
Report approx heap size in megabytes.
in?
(in? needle coll)
Is needle in coll?
indexed
(indexed s)
Returns a lazy sequence of [index, item] pairs,
where items come from s and indexes count up from zero.
(indexed '(a b c d)) => ([0 a] [1 b] [2 c] [3 d])
named?
(named? x)
Can the value be passed to name?
or'
(or' x)
(or' x y)
(or' x y z)
(or' x y z & forms)
Functional equivalent of or. All arguments are
evaluated, but not necessarily checked.
or-fn
(or-fn p1)
(or-fn p1 p2)
(or-fn p1 p2 p3)
(or-fn p1 p2 p3 & ps)
Takes one or more predicates, returns a
function that takes a value and applies each
predicate to that value, and returns the first
returned value that is truthy. Behavior is similar
to some-fn.
positions
(positions pred coll)
Returns a lazy sequence containing the positions
at which pred is true for items in coll.
with-private-fns
macro
(with-private-fns [ns vars] & body)
Refers private fns from ns and executes body.
(with-private-fns [org.foo.bar [fn1 fn2]]
(fn1)
(fn2))