tesser.utils

Toolbox.

->UnsafePair

(->UnsafePair a b)

Positional factory function for class tesser.utils.UnsafePair.

append

(append coll element)

Appends a single value to the end of a sequence. O(1); uses conj for vectors, concat for other seqs.

bytes?

(bytes? x__6523__auto__)

chunk-array

(chunk-array chunk-size ary)

Partitions an array into reducibles of size chunk-size (like chunk), but faster.

chunk-vec

(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.

complete-triangular-matrix

(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.

cumulative-sums

(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)

def-type-predicate

macro

(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.

differences

(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)

doubles?

(doubles? x__6523__auto__)

first-non-nil-reducer

(first-non-nil-reducer _ x)

A reducing function that simply returns the first non-nil element in the collection.

floats?

(floats? x__6523__auto__)

index-by

(index-by f xs)

Given an indexing function f and a collection of xs, return a map of (f x) -> x.

ints?

(ints? x__6523__auto__)

longs?

(longs? x__6523__auto__)

map-vals

(map-vals f m)

Maps over a key-value map, returning a new map by transforming each value with (f v).

maybe-unary

(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.

objects?

(objects? x__6523__auto__)

Pair

protocol

members

a

(a pair)

Returns the first element in the Pair.

b

(b pair)

Returns the second element in the Pair.

set-a!

(set-a! pair a')

Set the first element in the Pair.

set-b!

(set-b! pair b')

Set the second element in the Pair.

set-both!

(set-both! pair a' b')

Set both the first and second element in the pair.

path-fn

(path-fn path)

Takes a path for get-in and converts it to a function that operates on associative structures.

prepend

(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.

reduce-first

(reduce-first reducible)

clojure.core/first, but for for reducibles.

reducible-chunk

(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])

reducible-slice

macro

(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 ith 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.

reducible-slice-bytes

(reducible-slice-bytes ary chunk-size offset)

reducible-slice-doubles

(reducible-slice-doubles ary chunk-size offset)

reducible-slice-floats

(reducible-slice-floats ary chunk-size offset)

reducible-slice-ints

(reducible-slice-ints ary chunk-size offset)

reducible-slice-longs

(reducible-slice-longs ary chunk-size offset)

reducible-slice-objects

(reducible-slice-objects ary chunk-size offset)

reducible-slice-shorts

(reducible-slice-shorts ary chunk-size offset)

scred

macro

(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.

shorts?

(shorts? x__6523__auto__)

successive-pairs

(successive-pairs coll)(successive-pairs prev coll)

A much faster version of (partition 2 1 coll) which generates vectors, not lazy seqs.

unsafe-pair

(unsafe-pair)(unsafe-pair a b)

Constructs a new unsynchronized mutable pair object, suitable for single-threaded mutation.

var->sym

(var->sym v)

Converts a var to fully qualified symbol.