(and-let bindings expr)
(and-let bindings expr else-expr)
Derived from Scheme's and-let, this macro will evaluate expr
should all of its bindings evaluate truthy.
Evaluates else-expr
if any of the bindings evaluate falsey or returns nil if else-expr
is not provided.
Evaluation of bindings
ceases upon a falsey result.
bindings
expects a binding-forms vector as in (let) and (loop) etc.
expr
expression to be evaluated if bindings evaluate truthy
else-expr
expression to be evaluated if any bindings evaluate falsey
Derived from Scheme's and-let, this macro will evaluate `expr` should all of its bindings evaluate truthy. Evaluates `else-expr` if any of the bindings evaluate falsey or returns nil if `else-expr` is not provided. Evaluation of `bindings` ceases upon a falsey result. `bindings` expects a binding-forms vector as in (let) and (loop) etc. `expr` expression to be evaluated if bindings evaluate truthy `else-expr` expression to be evaluated if any bindings evaluate falsey
(attempt expr f)
the expression expr
will be executed in a try/catch form.
if an exception is caught, a handler function of one argument, f
, will be executed
and will be passed the caught java exception object.
the expression `expr` will be executed in a try/catch form. if an exception is caught, a handler function of one argument, `f`, will be executed and will be passed the caught java exception object.
(divert & body)
derived from (with-out-str). Evaluates body, captures any output destined to out, and returns result
of body
and text output as a vector tuple, [~@body captured-output-string]
derived from (with-out-str). Evaluates body, captures any output destined to *out*, and returns result of `body` and text output as a vector tuple, [~@body captured-output-string]
(do-once fun)
Returns a closure which will execute the passed function, fun
, once.
Subsequent calls will return cached results of the function call.
fun
is expected to be a function without arguments.
The initial result of evaluating fun
will always be returned.
Different caches can be maintained simply by using separate invocations of do-once
Returns a closure which will execute the passed function, `fun`, once. Subsequent calls will return cached results of the function call. `fun` is expected to be a function without arguments. The initial result of evaluating `fun` will always be returned. Different caches can be maintained simply by using separate invocations of `do-once`
(fail-let binding expr)
conditional let form which expects binding expression to return a hashmap with {:success boolean} content.
fail-let
supports a single binding pair: binding
.
will evaluate 'expr' if (:success y#) is falsey.
passes binding symbol/value to expr
.
conditional let form which expects binding expression to return a hashmap with {:success boolean} content. `fail-let` supports a single binding pair: `binding`. will evaluate 'expr' if (:success y#) is falsey. passes binding symbol/value to `expr`.
(find-key-val k v mapseq)
searches mapseq
for an element with a matching key/value pair.
The key is specified by k
, and the value is specified by v
.
searches `mapseq` for an element with a matching key/value pair. The key is specified by `k`, and the value is specified by `v`.
(find-pred pred coll)
applies pred
to each element of a collection, coll
, until it returns a truthy value,
then returns the matching element (not the individual value). Compare with clojure.core/some
applies `pred` to each element of a collection, `coll`, until it returns a truthy value, then returns the matching element (*not* the individual value). Compare with `clojure.core/some`
(set-var-root v value)
convenience interface to clojure.core/alter-var-root
.
with the semantic of clojure.core/reset!
, will rebind a value, value
to a var v
.
v
- a var reference (e.g. #'state-example
).
value
- new value to bind to var v
.
convenience interface to `clojure.core/alter-var-root`. with the semantic of `clojure.core/reset!`, will rebind a value, `value` to a var `v`. `v` - a var reference (e.g. `#'state-example`). `value` - new value to bind to var `v`.
(shift f)
(shift f arg2)
(shift f arg2 arg3)
(shift f arg2 arg3 arg4 & args)
similar to partial, provides a modified interface to function f
.
returns a function which accepts a single argument, always passing it as the first argument of f
.
useful with (comp) and threading macros.
similar to partial, provides a modified interface to function `f`. returns a function which accepts a single argument, always passing it as the first argument of `f`. useful with (comp) and threading macros.
(success-let binding expr)
(success-let binding expr else-expr)
conditional let form which expects binding expression to return a hashmap with {:success boolean} content.
success-let
supports a single binding pair: binding
.
will evaluate expr
if (:success y#) is truthy.
will evaluate else
if (:success y#) is falsey.
passes binding symbol/value to both expr
and else-expr
expressions.
conditional let form which expects binding expression to return a hashmap with {:success boolean} content. `success-let` supports a single binding pair: `binding`. will evaluate `expr` if (:success y#) is truthy. will evaluate `else` if (:success y#) is falsey. passes binding symbol/value to both `expr` and `else-expr` expressions.
(try-true? expr)
the expression expr
is expected to be a validation form which returns booleanness.
expr
will be executed in a try/catch form and a boolean returned.
caught exceptions will return false.
the expression `expr` is expected to be a validation form which returns booleanness. `expr` will be executed in a try/catch form and a boolean returned. caught exceptions will return false.
(within? coll x)
(within? coll fun x)
is "x" in "coll"?
has signature and semantics of contains?
.
matches elements rather than indices of indexed collections.
coll
collection which is source of comparison.
x
target comparison value.
fun
comparison function (defaults to =
).
within?
has arguably more consistent semantics for collections than contains?
:
(contains? [4 5 6] 4) => falsey
(contains? '(4 5 6) 4) => truthy
(within? [4 5 6] 4) => truthy
(within? '(4 5 6) 4) => truthy
is "x" in "coll"? has signature and semantics of `contains?`. matches elements rather than indices of indexed collections. `coll` collection which is source of comparison. `x` target comparison value. `fun` comparison function (defaults to `=`). `within?` has arguably more consistent semantics for collections than `contains?`: `(contains? [4 5 6] 4) => falsey` `(contains? '(4 5 6) 4) => truthy` `(within? [4 5 6] 4) => truthy` `(within? '(4 5 6) 4) => truthy`
(wrap-within-fn fun)
(wrap-within-fn compare-fn fun)
convenience function which returns a lambda intended for within?
comparisons.
fun
to process all comparison arguments.
compare-fn
function to perform comparison
convenience function which returns a lambda intended for `within?` comparisons. `fun` to process all comparison arguments. `compare-fn` function to perform comparison
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close