Liking cljdoc? Tell your friends :D

jepsen.util

Kitchen sink

Kitchen sink
raw docstring

*relative-time-origin*clj


all-jdk-loggersclj

(all-jdk-loggers)

buf-sizeclj


chunk-vecclj

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

collclj

(coll thing-or-things)

Wraps non-coll things into singleton lists, and leaves colls as themselves. Useful when you can take either a single thing or a sequence of things.

Wraps non-coll things into singleton lists, and leaves colls as themselves.
Useful when you can take either a single thing or a sequence of things.
raw docstring

compare<clj

(compare< a b)

Like <, but works on any comparable objects, not just numbers.

Like <, but works on any comparable objects, not just numbers.
raw docstring

concat-files!clj

(concat-files! out fs)

Appends contents of all fs, writing to out. Returns fs.

Appends contents of all fs, writing to out. Returns fs.
raw docstring

drop-common-proper-prefixclj

(drop-common-proper-prefix cs)

Given a collection of sequences, removes the longest common proper prefix from each one.

Given a collection of sequences, removes the longest common proper prefix
from each one.
raw docstring

exception?clj

(exception? x)

Is x an Exception?

Is x an Exception?
raw docstring

fast-lastclj

(fast-last coll)

Like last, but O(1) on counted collections.

Like last, but O(1) on counted collections.
raw docstring

fcatchclj

(fcatch f)

Takes a function and returns a version of it which returns, rather than throws, exceptions.

Takes a function and returns a version of it which returns, rather than
throws, exceptions.
raw docstring

fractionclj

(fraction a b)

a/b, but if b is zero, returns unity.

a/b, but if b is zero, returns unity.
raw docstring

history->latenciesclj

(history->latencies history)

Takes a history--a sequence of operations--and emits the same history but with every invocation containing two new keys:

:latency the time in nanoseconds it took for the operation to complete. :completion the next event for that process

Takes a history--a sequence of operations--and emits the same history but
with every invocation containing two new keys:

:latency    the time in nanoseconds it took for the operation to complete.
:completion the next event for that process
raw docstring

inc*clj

(inc* x)

Like inc, but (inc nil) => 1.

Like inc, but (inc nil) => 1.
raw docstring

integer-interval-set-strclj

(integer-interval-set-str set)

Takes a set of integers and yields a sorted, compact string representation.

Takes a set of integers and yields a sorted, compact string representation.
raw docstring

lazy-atomclj

(lazy-atom f)

An atom with lazy state initialization. Calls (f) on first use to provide the initial value of the atom. Only supports swap/reset/deref. Reset bypasses lazy initialization. If f throws, behavior is undefined (read: proper fucked).

An atom with lazy state initialization. Calls (f) on first use to provide
the initial value of the atom. Only supports swap/reset/deref. Reset bypasses
lazy initialization. If f throws, behavior is undefined (read: proper
fucked).
raw docstring

letrclj/smacro

(letr bindings & body)

Let bindings, plus early return.

You want to do some complicated, multi-stage operation assigning lots of variables--but at different points in the let binding, you need to perform some conditional check to make sure you can proceed to the next step. Ordinarily, you'd intersperse let and if statements, like so:

(let [res (network-call)]
  (if-not (:ok? res)
    :failed-network-call

    (let [people (:people (:body res))]
      (if (zero? (count people))
        :no-people

        (let [res2 (network-call-2 people)]
          ...

This is a linear chain of operations, but we're forced to nest deeply because we have no early-return construct. In ruby, we might write

res = network_call
return :failed_network_call if not x.ok?

people = res[:body][:people]
return :no-people if people.empty?

res2 = network_call_2 people
...

which reads the same, but requires no nesting thanks to Ruby's early return. Clojure's single-return is usually a boon to understandability, but deep linear branching usually means something like

  • Deep nesting (readability issues)
  • Function chaining (lots of arguments for bound variables)
  • Throw/catch (awkward exception wrappers)
  • Monadic interpreter (slow, indirect)

This macro lets you write:

(letr [res    (network-call)
       _      (when-not (:ok? res) (return :failed-network-call))
       people (:people (:body res))
       _      (when (zero? (count people)) (return :no-people))
       res2   (network-call-2 people)]
  ...)

letr works like let, but if (return x) is ever returned from a binding, letr returns x, and does not evaluate subsequent expressions.

If something other than (return x) is returned from evaluating a binding, letr binds the corresponding variable as normal. Here, we use _ to indicate that we're not using the results of (when ...), but this is not mandatory. You cannot use a destructuring bind for a return expression.

letr is not a true early return--(return x) must be a terminal expression for it to work--like (recur). For example,

(letr [x (do (return 2) 1)]
  x)

returns 1, not 2, because (return 2) was not the terminal expression.

return only works within letr's bindings, not its body.

Let bindings, plus early return.

You want to do some complicated, multi-stage operation assigning lots of
variables--but at different points in the let binding, you need to perform
some conditional check to make sure you can proceed to the next step.
Ordinarily, you'd intersperse let and if statements, like so:

    (let [res (network-call)]
      (if-not (:ok? res)
        :failed-network-call

        (let [people (:people (:body res))]
          (if (zero? (count people))
            :no-people

            (let [res2 (network-call-2 people)]
              ...

This is a linear chain of operations, but we're forced to nest deeply because
we have no early-return construct. In ruby, we might write

    res = network_call
    return :failed_network_call if not x.ok?

    people = res[:body][:people]
    return :no-people if people.empty?

    res2 = network_call_2 people
    ...

which reads the same, but requires no nesting thanks to Ruby's early return.
Clojure's single-return is *usually* a boon to understandability, but deep
linear branching usually means something like

  - Deep nesting         (readability issues)
  - Function chaining    (lots of arguments for bound variables)
  - Throw/catch          (awkward exception wrappers)
  - Monadic interpreter  (slow, indirect)

This macro lets you write:

    (letr [res    (network-call)
           _      (when-not (:ok? res) (return :failed-network-call))
           people (:people (:body res))
           _      (when (zero? (count people)) (return :no-people))
           res2   (network-call-2 people)]
      ...)

letr works like let, but if (return x) is ever returned from a binding, letr
returns x, and does not evaluate subsequent expressions.

If something other than (return x) is returned from evaluating a binding,
letr binds the corresponding variable as normal. Here, we use _ to indicate
that we're not using the results of (when ...), but this is not mandatory.
You cannot use a destructuring bind for a return expression.

letr is not a *true* early return--(return x) must be a *terminal* expression
for it to work--like (recur). For example,

    (letr [x (do (return 2) 1)]
      x)

returns 1, not 2, because (return 2) was not the terminal expression.

return only works within letr's bindings, not its body.
raw docstring

letr-let-ifclj

(letr-let-if groups body)

Takes a sequence of binding groups and a body expression, and emits a let for the first group, an if statement checking for a return, and recurses; ending with body.

Takes a sequence of binding groups and a body expression, and emits a let
for the first group, an if statement checking for a return, and recurses;
ending with body.
raw docstring

letr-partition-bindingsclj

(letr-partition-bindings bindings)

Takes a vector of bindings [sym expr, sym' expr, ...]. Returns binding-groups: a sequence of vectors of bindgs, where the final binding in each group has an early return. The final group (possibly empty!) contains no early return.

Takes a vector of bindings [sym expr, sym' expr, ...]. Returns
binding-groups: a sequence of vectors of bindgs, where the final binding in
each group has an early return. The final group (possibly empty!) contains no
early return.
raw docstring

letr-rewrite-returnclj

(letr-rewrite-return expr)

Rewrites (return x) to (Return. x) in expr. Returns a pair of [changed? expr], where changed is whether the expression contained a return.

Rewrites (return x) to (Return. x) in expr. Returns a pair of [changed?
expr], where changed is whether the expression contained a return.
raw docstring

linear-time-nanosclj

(linear-time-nanos)

A linear time source in nanoseconds.

A linear time source in nanoseconds.
raw docstring

local-timeclj

(local-time)

Drops millisecond resolution

Drops millisecond resolution
raw docstring

logclj

(log & things)

log-opclj

(log-op op)

Logs an operation and returns it.

Logs an operation and returns it.
raw docstring

log-printclj

(log-print _ & things)

loggerclj


longest-common-prefixclj

(longest-common-prefix cs)

Given a collection of sequences, finds the longest sequence which is a prefix of every sequence given.

Given a collection of sequences, finds the longest sequence which is a
prefix of every sequence given.
raw docstring

majorityclj

(majority n)

Given a number, returns the smallest integer strictly greater than half.

Given a number, returns the smallest integer strictly greater than half.
raw docstring

map-kvclj

(map-kv f m)

Takes a function (f [k v]) which returns [k v], and builds a new map by applying f to every pair.

Takes a function (f [k v]) which returns [k v], and builds a new map by
applying f to every pair.
raw docstring

map-valsclj

(map-vals f m)

Maps values in a map.

Maps values in a map.
raw docstring

max-byclj

(max-by f coll)

Finds the maximum element of a collection based on some (f element), which returns Comparables. If coll is empty, returns nil.

Finds the maximum element of a collection based on some (f element), which
returns Comparables. If `coll` is empty, returns nil.
raw docstring

maybe-numberclj

(maybe-number s)

Tries reading a string as a long, then double, then string. Passes through nil. Useful for getting nice values out of stats APIs that just dump a bunch of heterogenously-typed strings at you.

Tries reading a string as a long, then double, then string. Passes through
nil. Useful for getting nice values out of stats APIs that just dump a bunch
of heterogenously-typed strings at you.
raw docstring

mehclj/smacro

(meh & body)

Returns, rather than throws, exceptions.

Returns, rather than throws, exceptions.
raw docstring

min-byclj

(min-by f coll)

Finds the minimum element of a collection based on some (f element), which returns Comparables. If coll is empty, returns nil.

Finds the minimum element of a collection based on some (f element), which
returns Comparables. If `coll` is empty, returns nil.
raw docstring

ms->nanosclj

(ms->nanos ms)

muteclj/smacro

(mute & body)

mute-jdkclj/smacro

(mute-jdk & body)

name+clj

(name+ x)

Tries name, falls back to pr-str.

Tries name, falls back to pr-str.
raw docstring

nanos->msclj

(nanos->ms nanos)

nanos->secsclj

(nanos->secs nanos)

nemesis-intervalsclj

(nemesis-intervals history)

Given a history where a nemesis goes through :f :start and :f :stop transitions, constructs a sequence of pairs of :start and :stop ops. Since a nemesis usually goes :start :start :stop :stop, we construct pairs of the first and third, then second and fourth events. Where no :stop op is present, we emit a pair like [start nil].

Given a history where a nemesis goes through :f :start and :f :stop
transitions, constructs a sequence of pairs of :start and :stop ops. Since a
nemesis usually goes :start :start :stop :stop, we construct pairs of the
first and third, then second and fourth events. Where no :stop op is present,
we emit a pair like [start nil].
raw docstring

op->strclj

(op->str op)

Format an operation as a string.

Format an operation as a string.
raw docstring

poly-compareclj

(poly-compare a b)

Comparator function for sorting heterogenous collections.

Comparator function for sorting heterogenous collections.
raw docstring

polysortclj

(polysort coll)

Sort, but on heterogenous collections.

Sort, but on heterogenous collections.
raw docstring

pprint-strclj

(pprint-str x)

(print-history history)
(print-history printer history)

Prints a history to the console.

Prints a history to the console.
raw docstring

prn-opclj

(prn-op op)

Prints an operation to the console.

Prints an operation to the console.
raw docstring

processorsclj

(processors)

How many processors on this platform?

How many processors on this platform?
raw docstring

pwrite-history!clj

(pwrite-history! f history)
(pwrite-history! f printer history)

Writes history, taking advantage of more cores.

Writes history, taking advantage of more cores.
raw docstring

rand-nth-emptyclj

(rand-nth-empty coll)

Like rand-nth, but returns nil if the collection is empty.

Like rand-nth, but returns nil if the collection is empty.
raw docstring

random-nonempty-subsetclj

(random-nonempty-subset nodes)

A randomly selected, randomly ordered, non-empty subset of the given collection.

A randomly selected, randomly ordered, non-empty subset of the given
collection.
raw docstring

real-pmapclj

(real-pmap f coll)

Like pmap, but launches futures instead of using a bounded threadpool.

Like pmap, but launches futures instead of using a bounded threadpool.
raw docstring

relative-time-nanosclj

(relative-time-nanos)

Time in nanoseconds since relative-time-origin

Time in nanoseconds since *relative-time-origin*
raw docstring

retryclj/smacro

(retry dt & body)

Evals body repeatedly until it doesn't throw, sleeping dt seconds.

Evals body repeatedly until it doesn't throw, sleeping dt seconds.
raw docstring

secs->nanosclj

(secs->nanos s)

sequentialclj

(sequential thing-or-things)

Wraps non-sequential things into singleton lists, and leaves sequential things or nil as themselves. Useful when you can take either a single thing or a sequence of things.

Wraps non-sequential things into singleton lists, and leaves sequential
things or nil as themselves. Useful when you can take either a single thing
or a sequence of things.
raw docstring

sleepclj

(sleep dt)

High-resolution sleep; takes a (possibly fractional) time in ms.

High-resolution sleep; takes a (possibly fractional) time in ms.
raw docstring

spyclj

(spy x)

time-clj/smacro

(time- & body)

timeoutclj/smacro

(timeout millis timeout-val & body)

Times out body after n millis, returning timeout-val.

Times out body after n millis, returning timeout-val.
raw docstring

with-relative-timeclj/smacro

(with-relative-time & body)

Binds relative-time-origin at the start of body.

Binds *relative-time-origin* at the start of body.
raw docstring

with-retryclj/smacro

(with-retry initial-bindings & body)

It's really fucking inconvenient not being able to recur from within (catch) expressions. This macro wraps its body in a (loop [bindings] (try ...)). Provides a (retry & new bindings) form which is usable within (catch) blocks: when this form is returned by the body, the body will be retried with the new bindings.

It's really fucking inconvenient not being able to recur from within (catch)
expressions. This macro wraps its body in a (loop [bindings] (try ...)).
Provides a (retry & new bindings) form which is usable within (catch) blocks:
when this form is returned by the body, the body will be retried with the new
bindings.
raw docstring

with-thread-nameclj/smacro

(with-thread-name thread-name & body)

Sets the thread name for duration of block.

Sets the thread name for duration of block.
raw docstring

write-history!clj

(write-history! f history)
(write-history! f printer history)

Writes a history to a file.

Writes a history to a file.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close