Toolbox.
Toolbox.
(append coll element)
Appends a single value to the end of a sequence. O(1); uses conj for vectors, concat for other seqs.
Appends a single value to the end of a sequence. O(1); uses conj for vectors, concat for other seqs.
(chunk-array chunk-size ary)
Partitions an array into reducibles of size chunk-size
(like
chunk), but faster.
Partitions an array into reducibles of size `chunk-size` (like chunk), but faster.
(chunk-vec n v)
Partitions a vector into reducibles of size n (somewhat like partition-all) but uses subvec for speed.
(chunk-vec 2 [1]) ; => ([1])
(chunk-vec 2 [1 2 3]) ; => ([1 2] [3])
Useful for supplying vectors to tesser.core/tesser.
Partitions a vector into reducibles of size n (somewhat like partition-all) but uses subvec for speed. (chunk-vec 2 [1]) ; => ([1]) (chunk-vec 2 [1 2 3]) ; => ([1 2] [3]) Useful for supplying vectors to tesser.core/tesser.
(complete-triangular-matrix m)
Given a map of [x y]
keys to values, returns a map where both [x y]
and [y x]
point to identical values. Useful for pairwise comparisons which
compute triangular matrices but want to return a full matrix.
Given a map of `[x y]` keys to values, returns a map where *both* `[x y]` and `[y x]` point to identical values. Useful for pairwise comparisons which compute triangular matrices but want to return a full matrix.
(cumulative-sums coll)
(cumulative-sums init coll)
A seq of the cumulative sums of all elements in coll
, starting at init
or the first element of coll
if init
is not provided. If differences
provides differentials, cumulative-sums
provides integrals.
(cumulative-sums 1 [1 2 1 -3])
; (1 2 4 5 2)
A seq of the cumulative sums of all elements in `coll`, starting at `init` or the first element of `coll` if `init` is not provided. If `differences` provides differentials, `cumulative-sums` provides integrals. (cumulative-sums 1 [1 2 1 -3]) ; (1 2 4 5 2)
(def-type-predicate name exemplar)
Takes an instance of an object and defines a function that tests an object to see if its class is an instance of the exemplar's.
Takes an instance of an object and defines a function that tests an object to see if its class is an instance of the exemplar's.
(differences coll)
A seq of the differences between successive elements in a collection. For example,
(differences [1 2 4 5 2])
; (1 2 1 -3)
A seq of the differences between successive elements in a collection. For example, (differences [1 2 4 5 2]) ; (1 2 1 -3)
(first-non-nil-reducer _ x)
A reducing function that simply returns the first non-nil element in the collection.
A reducing function that simply returns the first non-nil element in the collection.
(index-by f xs)
Given an indexing function f and a collection of xs, return a map of (f x) -> x.
Given an indexing function f and a collection of xs, return a map of (f x) -> x.
(map-vals f m)
Maps over a key-value map, returning a new map by transforming each value with (f v).
Maps over a key-value map, returning a new map by transforming each value with (f v).
(maybe-unary f)
Not all functions used in tesser/fold
and tesser/reduce
have a
single-arity form. This takes a function f
and returns a fn g
such that
(g x)
is (f x)
unless (f x)
throws ArityException, in which case (g x)
returns just x
.
Not all functions used in `tesser/fold` and `tesser/reduce` have a single-arity form. This takes a function `f` and returns a fn `g` such that `(g x)` is `(f x)` unless `(f x)` throws ArityException, in which case `(g x)` returns just `x`.
(a pair)
Returns the first element in the Pair.
Returns the first element in the Pair.
(b pair)
Returns the second element in the Pair.
Returns the second element in the Pair.
(set-a! pair a')
Set the first element in the Pair.
Set the first element in the Pair.
(set-b! pair b')
Set the second element in the Pair.
Set the second element in the Pair.
(set-both! pair a' b')
Set both the first and second element in the pair.
Set both the first and second element in the pair.
(path-fn path)
Takes a path for get-in and converts it to a function that operates on associative structures.
Takes a path for get-in and converts it to a function that operates on associative structures.
(prepend coll element)
Prepends a single value to the beginning of a sequence. O(1) for sequences using cons, O(n) for vectors. Returns a singleton vector when coll is nil.
Prepends a single value to the beginning of a sequence. O(1) for sequences using cons, O(n) for vectors. Returns a singleton vector when coll is nil.
(reduce-first reducible)
clojure.core/first, but for for reducibles.
clojure.core/first, but for for reducibles.
(reducible-chunk n coll)
Like partition-all, but only emits reducibles. Faster for vectors and arrays. May return chunks of any reducible type. Useful for supplying colls to tesser.
(->> [1 2 3 4 5 6 7 8]
(chunk 2)
(map (partial into [])))
; => ([1 2] [3 4] [5 6] [7 8])
Like partition-all, but only emits reducibles. Faster for vectors and arrays. May return chunks of any reducible type. Useful for supplying colls to tesser. (->> [1 2 3 4 5 6 7 8] (chunk 2) (map (partial into []))) ; => ([1 2] [3 4] [5 6] [7 8])
(reducible-slice getter coll length offset)
A reducible slice of an indexed collection. Expands into a reified
CollReduce which uses (getter coll ... i)
to return the i
th element.
Defined as a macro so we can do primitive agets, which are waaaay faster for
arrays. Slice will have maximum length n, and starts at index i0.
A reducible slice of an indexed collection. Expands into a reified CollReduce which uses `(getter coll ... i)` to return the `i`th element. Defined as a macro so we can do primitive agets, which are waaaay faster for arrays. Slice will have maximum length n, and starts at index i0.
(scred rfn-name expr)
Helper for short-circuiting nested reduction functions which can emit reduced values. Given the name of a function that could emit a reduced value, and an expression:
(scred rfn [1 (rfn x y)])
Expands to code that converts the expression to a reduced value whenever the underlying function emits a reduced value:
(let [acc (rfn x y)]
(if (reduced? acc)
(let [acc @acc] (reduced [1 acc]))
[1 acc]))
scred does not interpret lexical scope, so don't rebind rfn in expr. Uses prewalk, so the outermost fn is where scred will cut out an expr. Keep this as simple as possible, haha.
Helper for short-circuiting nested reduction functions which can emit reduced values. Given the name of a function that could emit a reduced value, and an expression: (scred rfn [1 (rfn x y)]) Expands to code that converts the expression to a reduced value whenever the underlying function emits a reduced value: (let [acc (rfn x y)] (if (reduced? acc) (let [acc @acc] (reduced [1 acc])) [1 acc])) scred does not interpret lexical scope, so don't rebind rfn in expr. Uses prewalk, so the outermost fn is where scred will cut out an expr. Keep this as simple as possible, haha.
(successive-pairs coll)
(successive-pairs prev coll)
A much faster version of (partition 2 1 coll) which generates vectors, not lazy seqs.
A much faster version of (partition 2 1 coll) which generates vectors, not lazy seqs.
(unsafe-pair)
(unsafe-pair a b)
Constructs a new unsynchronized mutable pair object, suitable for single-threaded mutation.
Constructs a new unsynchronized mutable pair object, suitable for single-threaded mutation.
(var->sym v)
Converts a var to fully qualified symbol.
Converts a var to fully qualified symbol.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close