API
Modules
Types and constants
Functions and macros
FunctionChains.:∘̂FunctionChains.applyfFunctionChains.asfunctionFunctionChains.fbcastFunctionChains.fchainFunctionChains.fchainfsFunctionChains.fcompFunctionChains.fcprodFunctionChains.fcprodfsFunctionChains.ffanoutFunctionChains.ffanoutfsFunctionChains.ffchainFunctionChains.ffcompFunctionChains.frepeatFunctionChains.typed_callableFunctionChains.with_intermediate_results
Documentation
FunctionChains.FunctionChains — Module
module FunctionChainsImplements chained functions (composed functions) beyond Base.ComposedFunction.
FunctionChains.AsFunction — Type
struct FunctionChains.AsFunction{F} <: FunctionWraps a callable object to make it a Function.
User code should typically not instantiate AsFunction objects directly, but use asfunction(f) instead.
FunctionChains.FCartProd — Type
struct FCartProd{FS}<:FunctionRepresents a Cartesian product of functions.
A FCartProd has a single field _fs which may be a Tuple, NamedTuple, an array or a generator/iterator of functions.
Use fcprod to construct products of functions instead of using the constructor FCartProd(fs) directly.
FunctionChains.FFanout — Type
struct FFanout{FS}<:FunctionRepresents a function fanout.
A FFanout has a single field _fs which may be a Tuple, NamedTuple, an array or a generator/iterator of functions.
Use ffanout to construct a function fanout instead of using the constructor FFanout(fs) directly.
FunctionChains.FunctionChain — Type
struct FunctionChain{FS}<:FunctionRepresents a chain of composed functions.
(fc::FunctionChain)(x) applies the functions in the chain in order of iteration over fc._fs.
Use fchain to construct function chains instead of using the constructor FunctionChain(fs) directly.
Use fchainfs(fc) to retrieve the components of a FunctionChain in order of function execution.
FunctionChains.:∘̂ — Method
∘̂(f, n::Integer)
f∘̂ nCreate a chain of function f repeated n times, with support for n <= 0.
The type of the returned function depends on n:
n == 0: returnidentityn == 1: returnfn > 1: returnfrepeat(f, n)n == -1: returnInverseFunctions.inverse(f)n < -1: returnfrepeat(InverseFunctions.inverse(f), -n)
FunctionChains.applyf — Function
applyf(f, xs...) = f(xs...)Function application: Apply a function f to one or multiple arguments.
Primarily useful to broadcast collections of function over collections of arguments, e.g. applyf(fs, as, bs, ...) or to calculate derivatives in respect to function parameters (closure contents), e.g. Zygote.gradient(applyf, f_withargs, xs...).
FunctionChains.asfunction — Function
asfunction(f)::Function
asfunction(f::Function) === fWraps a callable f to make it a Function.
If f isa Function, simply returns f. If f is a type (constructor), returns a properly typed function object.
FunctionChains.fbcast — Function
fbcast(f)Return a broadcasted version of the function f, so that fbcast(f)(A, ...) is semantically equivalent to f.(A, ...).
fbcast(f)(A) is also semantically equivalent to fcprod( Fill(f, size(A)) )(A).
Typically returns a Broadcast.BroadcastFunction, but may be specialized to return broadcasted implementations depending on the type of f. For example, fbcast(identity) === identity.
The resulting broadcasted function supports InverseFunctions.inverse and/or ChangesOfVariables.with_logabsdet_jacobian if f does so.
FunctionChains.fchain — Function
fchain()
fchain(fs)
fchain(fs...)Construct a function chain of functions fs.
Typically returns a FunctionChain, but may be specialized to return other function chain types for specific types of functions.
fs must be iterable, it may be a tuple, vector, generator, etc. fchain(fs)(x) will apply the functions in fs in order of iteration. A chain of zero functions acts as the identity function.
The resulting function chain supports with_intermediate_results, and also supports InverseFunctions.inverse and/or ChangesOfVariables.with_logabsdet_jacobian if all functions in the chain do so.
Use fchainfs(fc) to retrieve fs.
FunctionChains.fchainfs — Function
fchainfs(fc)Get the component functions of a function chain or composed function fc, in order of function execution.
See fchain for details.
FunctionChains.fcomp — Function
fcomp()
fcomp(fs)
fcomp(fs...)Construct a composition of the functions fs that is semantically equivalent to fs[1] ∘ fs[2] ∘ ... and fchain(reverse(fs)).
The resulting function composition supports with_intermediate_results, but note that the intermediate results are in order of function evaluation, not in the order of the functions in fs.
The composition also supports InverseFunctions.inverse and/or ChangesOfVariables.with_logabsdet_jacobian if all functions in the composition do so.
FunctionChains.fcprod — Function
fcprod()
fcprod(fs)
fcprod(fs...)Construct the Cartesian product of functions over the functions fs.
Typically returns a FCartProd, but may be specialized to return other product function types for specific types of element functions.
fs must be iterable, it may be a Tuple, NamedTuple, an array or a generator/iterator of functions.
fcprod behaves like
fcprod((f_a, f_b, ...))((x_a, x_b, ...)) = (f_a(x_a), f_b(x_b), ...)
fcprod((a = f_a, b = f_b, ...))((a = x_a, b = x_b, ...)) = (a = f_a(x_a), b = f_b(x_b), ...)
fcprod([f_a, f_b, ...])([x_a, x_b, ...]) = [f_a(x_a), f_b(x_b), ...]This is similar, semantically, to Haskell's *** for arrows.
For fp = fcprod(fs), use fcprodfs(fp) to retrieve fs.
The resulting product of functions supports InverseFunctions.inverse and/or ChangesOfVariables.with_logabsdet_jacobian if all functions in the product do so.
FunctionChains.fcprodfs — Function
FunctionChains.ffanout — Function
ffanout()
ffanout(fs)
ffanout(fs...)Construct a function fanout with the functions fs.
This is similar, semantically, to Haskell's &&& for arrows.
Typically returns a FFanout, but may be specialized to return other function fanout types for specific types of element functions.
fs must be iterable, it may be a Tuple, NamedTuple, an array or a generator/iterator of functions.
The resulting function fanout behaves like
ffanout((f_a, f_b, ...))(x) = (f_a(x), f_b(x), ...)
ffanout((a = f_a, b = f_b, ...))(x) = (a = f_a(x), b = f_b(x), ...)
ffanout([f_a, f_b, ...])(x) = [f_a(x), f_b(x), ...]For ff = ffanout(fs), use ffanoutfs(ff) to retrieve fs.
FunctionChains.ffanoutfs — Function
FunctionChains.ffchain — Function
ffchain(f, g, hs...)
ffchain() = identity
ffchain(f) = f
ffchain(::Type{F}) where F = FunctionChains.AsFunction{Type{F}}(F)Similar to fchain((f, g, hs...)), but flattens arguments of type ComposedFunction and merges FunctionChain arguments.
Tries to remove superfluous identity functions and to return a simple function instead of a FunctionChain if possible.
Behaves like ffcomp(hs..., g, f) (see ffcomp).
FunctionChains.ffcomp — Function
ffcomp(f, g, hs...)
ffcomp() = identity
ffcomp(f) = f
ffcomp(::Type{F}) where F = FunctionChains.AsFunction{Type{F}}(F)Similar to fcomp((f, g, hs...)), but flattens arguments of type ComposedFunction and merges FunctionChain arguments.
Tries to remove superfluous identity functions and to return a simple function instead of a FunctionChain if possible.
Behaves like ffchain(hs..., g, f) (see ffchain).
FunctionChains.frepeat — Function
frepeat(f, n::Integer)Create a chain of function f repeated n times.
See also ∘̂(f, n) for a version that supports n <= 0.
The resulting function chain supports InverseFunctions.inverse and/or ChangesOfVariables.with_logabsdet_jacobian if f does so.
FunctionChains.typed_callable — Function
typed_callable(f)Wraps a callable f in a typed function object if necessary, e.g. if f is a type (constructor).
FunctionChains.with_intermediate_results — Function
with_intermediate_results(f, x)Apply multi-step function f to x and return a collection that contains the intermediate results and the final result.