protobuf.util

Documentation forthcoming

as-fn

(as-fn x)

Turn an object into a fn if it is not already, by wrapping it in constantly.

catbytes

(catbytes & args)

Documentation forthcoming

combine

(combine a b)

Merge two data structures by combining the contents. For maps, merge recursively by adjoining values with the same key. For collections, combine the right and left using into or conj. If the left value is a set and the right value is a map, the right value is assumed to be an existence map where the value determines whether the key is in the merged set. This makes sets unique from other collections because items can be deleted from them.

Combiner

protocol

members

combine-onto

(combine-onto left right)

Merge two data structures by combining the contents. For maps, merge recursively by adjoining values with the same key. For collections, combine the right and left using into or conj. If the left value is a set and the right value is a map, the right value is assumed to be an existence map where the value determines whether the key is in the merged set. This makes sets unique from other collections because items can be deleted from them.

dissoc-fields

(dissoc-fields schema & fields)

Traverse the given schema, removing the given fields at any level.

fix

(fix x & clauses)

Walk through clauses, a series of predicate/transform pairs. The first predicate that x satisfies has its transformation clause called on x. Predicates or transforms may be values (eg true or nil) rather than functions; these will be treated as functions that return that value. The last “pair” may be only a transform with no pred: in that case it is unconditionally used to transform x, if nothing previously matched. If no predicate matches, then x is returned unchanged.

given

macro

(given x & clauses)

A macro combining the features of fix and fixing, by using parentheses to group the additional arguments to each clause: (-> x (given string? read-string map? (dissoc :x :y :z) even? (/ 2)))

into-set

(into-set set map)

Update the given set using an existence map.

map-entry

macro

(map-entry a b)

Create a clojure.lang.MapEntry from a and b. Equivalent to a cons cell. flatland.useful.experimental.unicode contains a shortcut to this, named ·.

map-vals

(map-vals m f & args)

Create a new map from m by calling function f on each value to get a new value.

postwalk

(postwalk f schema)

Perform a depth-first, post-order traversal of all types within the given schema, replacing each and type with the result of calling f on it.

prewalk

(prewalk f schema)

Like postwalk, but do a pre-order traversal.

to-fix

(to-fix & clauses)

A “curried” version of fix, which sets the clauses once, yielding a function that calls fix with the specified first argument.

update

(update m key f & args)

Update a value for the given key in a map where f is a function that takes the previous value and the supplied args and returns the new value. Like update-in*, unchanged values are not re-assoc’d.

update-in*

(update-in* m keys f & args)

Updates a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created. This implementation was adapted from clojure.core, but the behavior is more correct if keys is empty and unchanged values are not re-assoc’d.

walk

(walk inner outer schema)

Traverse all child types of the given schema, calling inner on each, then call outer on the result.