Liking cljdoc? Tell your friends :D

bract.core.util

Standalone utility functions.

Standalone utility functions.
raw docstring

aftercljmacro

(after & body)

Create a function (fn [arg]) -> arg that returns the supplied argument after evaluating body of code.

Create a function `(fn [arg]) -> arg` that returns the supplied argument after evaluating body of code.
sourceraw docstring

alive-millisclj

(alive-millis)
(alive-millis n)

Return a function (fn []) that when invoked, records the current time as when was the application last alive. You may deref the same function as (deref f) to find out the time the application was last alive. Optimized for concurrent updates; eventually consistent.

Return a function `(fn [])` that when invoked, records the current time as when was the application last alive. You
may deref the same function as `(deref f)` to find out the time the application was last alive. Optimized for
concurrent updates; eventually consistent.
sourceraw docstring

as-strclj

(as-str x)

Turn anything into string.

Turn anything into string.
sourceraw docstring

as-vecclj

(as-vec x)

Turn argument into a vector if it is a collection, else wrap the argument into a single-item vector.

Turn argument into a vector if it is a collection, else wrap the argument into a single-item vector.
sourceraw docstring

clean-uuidclj

(clean-uuid)
(clean-uuid uuid)

Generate or convert UUID into a sanitized, lower-case form.

Generate or convert UUID into a sanitized, lower-case form.
sourceraw docstring

doaftercljmacro

(doafter expr & body)

Evaluate supplied expression and return it after evaluating body of code.

Evaluate supplied expression and return it after evaluating body of code.
sourceraw docstring

err-print-bannerclj

(err-print-banner x & more)

Print a banner to *err*.

Print a banner to `*err*`.
sourceraw docstring

err-printlnclj

(err-println x & more)

Same as clojure.core/println for *err*.

Same as `clojure.core/println` for `*err*`.
sourceraw docstring

exec-once!cljmacro

(exec-once! a-var & body)

Given a redefinable var e.g. (defonce a-var nil) having logical false value, set it to true and evaluate the body.

Given a redefinable var e.g. `(defonce a-var nil)` having logical false value, set it to `true` and evaluate the
body.
sourceraw docstring

expectedclj

(expected expectation found)
(expected pred expectation found)

Throw illegal input exception citing expectation and what was found did not match. Optionally accept a predicate fn to test found before throwing the exception.

Throw illegal input exception citing _expectation_ and what was _found_ did not match. Optionally accept a predicate
fn to test _found_ before throwing the exception.
sourceraw docstring

health-statusclj

(health-status components)

Given a collection of health status maps (with keys :status and :impact) of zero or more components, derive overall health status and return status map {:status status :components components} based on the following rules:

  1. Health status :critical > :degraded > :healthy (high to low)

  2. Higher old-status always overrides lower new-status.

  3. Same old-status and new-status are considered unchanged.

  4. A higher new-status is interpreted as follows:

    Old statusNew statusImpact :directImpact :indirectImpact :noimpact
    degradedcriticalcriticaldegradeddegraded
    healthycriticalcriticaldegradedhealthy
    healthydegradeddegradeddegradedhealthy

Example of returned status:

{:status :degraded  ; derived from components - :critical, :degraded, :healthy (default), :unknown
 :components [{:id     :mysql
               :status :degraded
               :impact :hard    ; impact on overall health - :hard (default), :soft, :none/nil/false
               :breaker :half-open
               :retry-in "14000ms"}
              {:id     :cache
               :status :critical
               :impact :soft}
              {:id     :disk
               :status :healthy
               :impact :none
               :free-gb 39.42}]}
Given a collection of health status maps (with keys `:status` and `:impact`) of zero or more components, derive
overall health status and return status map `{:status status :components components}` based on the following rules:

0. Health status `:critical` > `:degraded` > `:healthy` (high to low)
1. Higher old-status always overrides lower new-status.
2. Same old-status and new-status are considered unchanged.
3. A higher new-status is interpreted as follows:

   |Old status|New status|Impact :direct|Impact :indirect|Impact :noimpact|
   |----------|----------|--------------|----------------|----------------|
   | degraded | critical |   critical   |    degraded    |    degraded    |
   | healthy  | critical |   critical   |    degraded    |    healthy     |
   | healthy  | degraded |   degraded   |    degraded    |    healthy     |

Example of returned status:

```edn
{:status :degraded  ; derived from components - :critical, :degraded, :healthy (default), :unknown
 :components [{:id     :mysql
               :status :degraded
               :impact :hard    ; impact on overall health - :hard (default), :soft, :none/nil/false
               :breaker :half-open
               :retry-in "14000ms"}
              {:id     :cache
               :status :critical
               :impact :soft}
              {:id     :disk
               :status :healthy
               :impact :none
               :free-gb 39.42}]}
```
sourceraw docstring

invokeclj

(invoke f & args)

Invoke first argument as a function on the remaining arguments.

Invoke first argument as a function on the remaining arguments.
sourceraw docstring

let-varcljmacro

(let-var bindings & body)

Given a binding vector where right-hand side is fully-qualified var name symbol and body of code, resolve the vars and evaluate the body of code in the binding context.

Given a binding vector where right-hand side is fully-qualified var name symbol and body of code, resolve the vars
and evaluate the body of code in the binding context.
sourceraw docstring

millis->strclj

(millis->str millis)

Convert milliseconds to human readable string.

Convert milliseconds to human readable string.
sourceraw docstring

nbytes->strclj

(nbytes->str n)

Convert bytes-count to human readable string.

Convert bytes-count to human readable string.
sourceraw docstring

nopclj

(nop & args)

Do nothing, return nil.

Do nothing, return `nil`.
sourceraw docstring

now-millisclj

(now-millis)
(now-millis start-millis)

Return current epochal time in milliseconds.

Return current epochal time in milliseconds.
sourceraw docstring

pst-when-uncaught-handlerclj

(pst-when-uncaught-handler e)
(pst-when-uncaught-handler e out)

When uncaught exception handler is configured, print the stack trace.

When uncaught exception handler is configured, print the stack trace.
sourceraw docstring

set-default-uncaught-exception-handlerclj

(set-default-uncaught-exception-handler f)

Set specified function (fn [thread throwable]) as default uncaught exception handler.

Set specified function `(fn [thread throwable])` as default uncaught exception handler.
sourceraw docstring

shorten-nameclj

(shorten-name any-name)
(shorten-name split-regex any-name)

Shorten a stringable name, e.g. foo.bar.baz.qux/fred to f.b.baz.qux/fred, leaving only the last two tokens intact.

Shorten a stringable name, e.g. `foo.bar.baz.qux/fred` to `f.b.baz.qux/fred`, leaving only the last two tokens
intact.
sourceraw docstring

sleep-millisclj

(sleep-millis millis)

Sleep for specified number of milliseconds.

Sleep for specified number of milliseconds.
sourceraw docstring

stack-trace-strclj

(stack-trace-str e)

Given a throwable (generally an exception) return the stack trace string as it would be printed on a console.

Given a throwable (generally an exception) return the stack trace string as it would be printed on a console.
sourceraw docstring

thrown->valcljmacro

(thrown->val [klass value & more] & body)

Execute body of code in a try block, returning value when an exception of type klass is caught. There may be one of more klass/value pairs, laid out as catch expressions in the same order as specified. The caught exceptions are rethrown using clojure.core/future - to be handled by uncaught-exception handler.

Execute `body` of code in a `try` block, returning `value` when an exception of type `klass` is caught.
There may be one of more klass/value pairs, laid out as `catch` expressions in the same order as specified.
The caught exceptions are rethrown using `clojure.core/future` - to be handled by uncaught-exception handler.
sourceraw docstring

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

× close