Procedures that act on Clojure's function and multimethod types, along with extensions of the SICMUtils generic operations to functions.
See the Function
cljdocs
for a discussion of generic function arithmetic.
Procedures that act on Clojure's function and multimethod types, along with extensions of the SICMUtils generic operations to functions. See [the `Function` cljdocs](https://cljdoc.org/d/sicmutils/sicmutils/CURRENT/doc/data-types/function) for a discussion of generic function arithmetic.
If true, attempting to pass two functions of incompatible arity
into any binary function, or into combine-arities
, will throw. False by
default.
If true, attempting to pass two functions of incompatible arity into any binary function, or into [[combine-arities]], will throw. False by default.
(arg-scale f & factors)
Takes a function f
and a sequence of factors
, and returns a new function
that multiplies each factor by the corresponding argument of f
. Too many or
two few factors are ignored.
((arg-scale square 3) 4) ==> 144
((arg-scale square 3 2 1) 4) ==> 144
Takes a function `f` and a sequence of `factors`, and returns a new function that multiplies each factor by the corresponding argument of `f`. Too many or two few factors are ignored. ```clojure ((arg-scale square 3) 4) ==> 144 ((arg-scale square 3 2 1) 4) ==> 144 ```
(arg-shift f & shifts)
Takes a function f
and a sequence of shifts
, and returns a new function
that adds each shift to the corresponding argument of f
. Too many or two few
shifts are ignored.
((arg-shift square 3) 4) ==> 49
((arg-shift square 3 2 1) 4) ==> 49
Takes a function `f` and a sequence of `shifts`, and returns a new function that adds each shift to the corresponding argument of `f`. Too many or two few shifts are ignored. ```clojure ((arg-shift square 3) 4) ==> 49 ((arg-shift square 3 2 1) 4) ==> 49 ```
(coerce-to-fn x arity)
Given a [[value/numerical?]] input x
, returns a function of arity arity
that always returns x
no matter what input it receives.
For non-numerical x
, returns x
.
Given a [[value/numerical?]] input `x`, returns a function of arity `arity` that always returns `x` no matter what input it receives. For non-numerical `x`, returns `x`.
(combine-arities)
(combine-arities a)
(combine-arities a b)
Returns the joint arity of arities a
and b
.
The joint arity is the loosest possible arity specification compatible with
both a
and b
. Throws if a
and b
are incompatible.
Returns the joint arity of arities `a` and `b`. The joint arity is the loosest possible arity specification compatible with both `a` and `b`. Throws if `a` and `b` are incompatible.
(compose & fns)
Arity-preserving version of clojure.core/comp
.
The arity of a composition is the arity of the rightmost (that is, first to be
applied) function term in fns
.
Arity-preserving version of `clojure.core/comp`. The arity of a composition is the arity of the rightmost (that is, first to be applied) function term in `fns`.
(function? f)
Returns true if f
is of [[v/kind]] ::v/function
, false otherwise.
Returns true if `f` is of [[v/kind]] `::v/function`, false otherwise.
(get f k)
(get f k not-found)
For non-functions, acts like [[clojure.core/get]]. For function
arguments (anything that responds true to function?
), returns
(comp #(clojure.core/get % k) f)
If not-found
is supplied it's passed through to the
composed [[clojure.core/get]].
For non-functions, acts like [[clojure.core/get]]. For function arguments (anything that responds true to [[function?]]), returns ```clojure (comp #(clojure.core/get % k) f) ``` If `not-found` is supplied it's passed through to the composed [[clojure.core/get]].
(get-in f ks)
(get-in f ks not-found)
For non-functions, acts like [[clojure.core/get-in]]. For function
arguments (anything that responds true to function?
), returns
(comp #(clojure.core/get-in % ks) f)
If not-found
is supplied it's passed through to the
composed [[clojure.core/get-in]].
For non-functions, acts like [[clojure.core/get-in]]. For function arguments (anything that responds true to [[function?]]), returns ```clojure (comp #(clojure.core/get-in % ks) f) ``` If `not-found` is supplied it's passed through to the composed [[clojure.core/get-in]].
Identity function. Returns its argument.
Identity function. Returns its argument.
(arity f)
Return the cached or obvious arity of f
if we know it. Otherwise
delegates to heavy duty reflection.
Return the cached or obvious arity of `f` if we know it. Otherwise delegates to heavy duty reflection.
(joint-arity arities)
Find the most relaxed possible statement of the joint arity of the given sequence of arities
.
If they are incompatible, an exception is thrown.
Find the most relaxed possible statement of the joint arity of the given sequence of `arities`. If they are incompatible, an exception is thrown.
(memoize f)
meta-preserving version of clojure.core/memoize
.
The returned function will have a new :arity
entry in its metadata with the
arity
of the original f
; this is because the process used to figure out a
function's arity will not work across the memoization boundary.
meta-preserving version of `clojure.core/memoize`. The returned function will have a new `:arity` entry in its metadata with the `arity` of the original `f`; this is because the process used to figure out a function's arity will not work across the memoization boundary.
(seq-arity xs)
Returns the most general arity compatible with the aritiies of all entries in
the supplied sequence xs
of values.
Returns the most general arity compatible with the aritiies of all entries in the supplied sequence `xs` of values.
(with-arity f arity)
(with-arity f arity m)
Appends the supplied arity
to the metadata of f
, knocking out any
pre-existing arity notation.
Optionally accepts a third parameter m
of metadata to attach to the return
function, in addition to the new :arity
key.
Appends the supplied `arity` to the metadata of `f`, knocking out any pre-existing arity notation. Optionally accepts a third parameter `m` of metadata to attach to the return function, in addition to the new `:arity` key.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close