(find-cycle input update-fn)
(find-cycle input update-fn hash-fn)
Apply update-fn
to input
iteratively until a cycle is found.
Return [start
end
] of the cycle, so applying start
times is the
same as end
times. An optional hash-fn
may be provided - in this
case when two results have the same hash the cycle is reported.
Apply `update-fn` to `input` iteratively until a cycle is found. Return [`start` `end`] of the cycle, so applying `start` times is the same as `end` times. An optional `hash-fn` may be provided - in this case when two results have the same hash the cycle is reported.
(find-cyclic input n update-fn)
(find-cyclic input n update-fn hash-fn)
See also find-cycle
. Finds the result of applying update-fn
to input
n
times by first detecting a cycle in the iteration using find-cyclic-equivalent
and then computing based on that. Note that there is an inherent inefficiency
because we compute first to find the cycle and then again to find the answer.
This is necessary to support non-identity hash-fn
.
See also `find-cycle`. Finds the result of applying `update-fn` to `input` `n` times by first detecting a cycle in the iteration using `find-cyclic-equivalent` and then computing based on that. Note that there is an inherent inefficiency because we compute first to find the cycle and then again to find the answer. This is necessary to support non-identity `hash-fn`.
(find-cyclic-equivalent input n update-fn)
(find-cyclic-equivalent input n update-fn hash-fn)
See also find-cycle
. Assuming applying update-fn
repeatedly to input
produces a cycle
(or repeats a hash if the optional hash-fn
is provided), finds an equivalent number of
applications of update-fn
to the provided n
but less than the number needed to reach the
end of the first cycle.
See also `find-cycle`. Assuming applying `update-fn` repeatedly to `input` produces a cycle (or repeats a hash if the optional `hash-fn` is provided), finds an equivalent number of applications of `update-fn` to the provided `n` but less than the number needed to reach the end of the first cycle.
(fixed-point-n f x)
(fixed-point-n f x max-iterations)
(fixed-point-n f x max-iterations test-fn)
Iterate one argument function f
on starting value x
unil a fixed point is reached, returning [fixed-point n]
where n
is the number of iterations needed to reach the fixed point.
If max-iterations
is provided then will return nil after applying
f
that many times instead of running forever.
If test-fn
is provided then compares test-fn
applied to the iterates
to determine when to stop.
Note that if you want to use a test-fn
you need to supply max-iterations
,
though it can be nil
to have unlimited.
Iterate one argument function `f` on starting value `x` unil a fixed point is reached, returning `[fixed-point n]` where `n` is the number of iterations needed to reach the fixed point. If `max-iterations` is provided then will return nil after applying `f` that many times instead of running forever. If `test-fn` is provided then compares `test-fn` applied to the iterates to determine when to stop. Note that if you want to use a `test-fn` you need to supply `max-iterations`, though it can be `nil` to have unlimited.
(flip-args f)
Given a function f
that takes at least two arguments
returns a new function that reverses the order of
the first two arguments
Given a function `f` that takes at least two arguments returns a new function that reverses the order of the first two arguments
(iterate-until f x pred)
Iterate one argument function f
on starting value x
and return the first iterate that makes pred
true.
Iterate one argument function `f` on starting value `x` and return the first iterate that makes `pred` true.
(iterates-while f x pred)
Iterate one argument function f
on starting value x
and return the sequence until the predicate pred
returns false.
Just (take-while pred (iterate f x)).
Iterate one argument function `f` on starting value `x` and return the sequence until the predicate `pred` returns false. Just (take-while pred (iterate f x)).
(reverse-args f)
Given a function f
returns a new function that takes its
arguments in the reverse order.
Given a function `f` returns a new function that takes its arguments in the reverse order.
(update-vec-state f initial-v)
Take the initial vector initial-v
and the function
f
of vec and index, and successively update state by
applying f
to the current state and indexes.
Basically a reduce over the state where you can use the
index.
Take the initial vector `initial-v` and the function `f` of vec and index, and successively update state by applying `f` to the current state and indexes. Basically a reduce over the state where you can use the index.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close