Liking cljdoc? Tell your friends :D

promenade.core

Success/Failure (known as Either) are the dual of each other with respect to an operation result. Similarly, other duals include Just/Nothing (known as Maybe) and Result/Exception (known as Trial) on related perspectives. This namespace provides unified, standalone and composable mechanism to represent and process such operation outcomes.

Success/Failure (known as Either) are the dual of each other with respect to an operation result. Similarly, other
duals include Just/Nothing (known as Maybe) and Result/Exception (known as Trial) on related perspectives. This
namespace provides unified, standalone and composable mechanism to represent and process such operation outcomes.
raw docstring

!clj/smacro

(! x)
(! catch-class x)

Evaluate given form and return it; on exception return the exception as thrown context.

See: promenade.util/!se-info

Evaluate given form and return it; on exception return the exception as thrown context.

See: [[promenade.util/!se-info]]
sourceraw docstring

!wrapclj/smacro

(!wrap f)
(!wrap catch-class f)

Wrap given function such that on exception it returns the exception as a thrown context.

See: promenade.util/!wrap-se-info

Wrap given function such that on exception it returns the exception as a thrown context.

See: [[promenade.util/!wrap-se-info]]
sourceraw docstring

bind-eitherclj/s

(bind-either mval success-f)
(bind-either mval failure-f success-f)

Given a context mval (success or failure) bind it with a function of respective type, i.e. success-f or failure-f. See: either-> either->> either-as-> bind-maybe bind-trial

Given a context mval (success or failure) bind it with a function of respective type, i.e. success-f or failure-f.
See:
  [[either->]]
  [[either->>]]
  [[either-as->]]
  [[bind-maybe]]
  [[bind-trial]]
sourceraw docstring

bind-maybeclj/s

(bind-maybe mval just-f)
(bind-maybe mval nothing-f just-f)

Given a context mval (just or nothing) bind it with a function of respective type, i.e. just-f or nothing-f. See: maybe-> maybe->> maybe-as-> bind-either bind-trial

Given a context mval (just or nothing) bind it with a function of respective type, i.e. just-f or nothing-f.
See:
  [[maybe->]]
  [[maybe->>]]
  [[maybe-as->]]
  [[bind-either]]
  [[bind-trial]]
sourceraw docstring

bind-trialclj/s

(bind-trial mval result-f)
(bind-trial mval thrown-f result-f)

Given a context mval (value or exception) bind it with a function of respective type, i.e. result-f or thrown-f. See: trial-> trial->> trial-as-> bind-either bind-maybe

Given a context mval (value or exception) bind it with a function of respective type, i.e. result-f or thrown-f.
See:
  [[trial->]]
  [[trial->>]]
  [[trial-as->]]
  [[bind-either]]
  [[bind-maybe]]
sourceraw docstring

branchclj/s

(branch pred f)
(branch fallback pred f)

Given an optional fallback fn (fn [x]) (default: clojure.core/identity), compose it with branch execution as per predicate. You may use this to compose a branching pipeline:

(-> identity
  (branch pred f)
  (branch pred2 f2))
Given an optional fallback fn `(fn [x])` (default: `clojure.core/identity`), compose it with branch execution as per
predicate. You may use this to compose a branching pipeline:

```
(-> identity
  (branch pred f)
  (branch pred2 f2))
```
sourceraw docstring

cond-mletclj/smacro

(cond-mlet & clauses)

Given a set of match-bindings/expression pairs, match each binding vector one by one - upon full match evaluate respective expression in the lexical scope and return the result without proceeding any further. When a binding form is not a vector, evaluate it like an expression and a truthy value triggers evaluating respective expression. When no match is found, return a promenade.type.INothing instance.

Given a set of match-bindings/expression pairs, match each binding vector one by one - upon full match evaluate
respective expression in the lexical scope and return the result without proceeding any further. When a binding
form is not a vector, evaluate it like an expression and a truthy value triggers evaluating respective expression.
When no match is found, return a `promenade.type.INothing` instance.
sourceraw docstring

context?clj/s

(context? x)
source

deref-contextclj/s

(deref-context x)
(deref-context x default)

Deref argument if it is a context, return as it is otherwise.

Deref argument if it is a context, return as it is otherwise.
sourceraw docstring

either->clj/smacro

(either-> x & forms)

Thread-first expansion using bind-either. A vector form of one element [x] is applied only to 'failure' leaving 'success' intact. Use clojure.core/reduced for early termination. Example usage

(either-> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)

See: reduce-> bind-either either->> either-as-> maybe-> trial->

Thread-first expansion using [[bind-either]]. A vector form of one element `[x]` is applied only to 'failure' leaving
'success' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(either-> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)
```
See:
  [[reduce->]]
  [[bind-either]]
  [[either->>]]
  [[either-as->]]
  [[maybe->]]
  [[trial->]]
sourceraw docstring

either->>clj/smacro

(either->> x & forms)

Thread-last expansion using bind-either. A vector form of one element [x] is applied only to 'failure' leaving 'success' intact. Use clojure.core/reduced for early termination. Example usage

(either->> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)

See: reduce->> bind-either either-> either-as-> maybe->> trial->>

Thread-last expansion using [[bind-either]]. A vector form of one element `[x]` is applied only to 'failure' leaving
'success' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(either->> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)
```
See:
  [[reduce->>]]
  [[bind-either]]
  [[either->]]
  [[either-as->]]
  [[maybe->>]]
  [[trial->>]]
sourceraw docstring

either-as->clj/smacro

(either-as-> expr name & forms)

Thread-anywhere expansion using bind-either. A vector form of one element [x] is applied only to 'failure' leaving 'success' intact. Use clojure.core/reduced for early termination. Example usage

(either-as-> (place-order) $
  (check-inventory $ :foo)
  [(cancel-order :bar $) process-order]
  (fulfil-order $))

See: reduce-as-> bind-either either-> either->> maybe-as-> trial-as->

Thread-anywhere expansion using [[bind-either]]. A vector form of one element `[x]` is applied only to 'failure'
leaving 'success' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(either-as-> (place-order) $
  (check-inventory $ :foo)
  [(cancel-order :bar $) process-order]
  (fulfil-order $))
```
See:
  [[reduce-as->]]
  [[bind-either]]
  [[either->]]
  [[either->>]]
  [[maybe-as->]]
  [[trial-as->]]
sourceraw docstring

ex-failclj/smacro

(ex-fail expr)

Catch ExceptionInfo and turn its ex-data into 'failure'.

Catch ExceptionInfo and turn its ex-data into 'failure'.
sourceraw docstring

failclj/s

(fail)
(fail x)

Turn given argument into 'failure' unless it is already a context.

See: promenade.util/defailure

Turn given argument into 'failure' unless it is already a context.

See: [[promenade.util/defailure]]
sourceraw docstring

failureclj/s

source

failure?clj/s

(failure? x)
source

free?clj/s

(free? x)
source

if-mletclj/smacro

(if-mlet bindings then)
(if-mlet bindings then else)

Bind symbols in the binding forms to their respective matching context and evaluate then form in the lexical scope. If a non-matching context is encountered, evaluate the else form independent of the binding context, or return a promenade.type.INothing instance when else is unspecified. See: mfailure mnothing mthrown mlet when-mlet cond-mlet

Bind symbols in the binding forms to their respective matching context and evaluate `then` form in the lexical
scope. If a non-matching context is encountered, evaluate the `else` form independent of the binding context, or
return a promenade.type.INothing instance when `else` is unspecified.
See:
  [[mfailure]]
  [[mnothing]]
  [[mthrown]]
  [[mlet]]
  [[when-mlet]]
  [[cond-mlet]]
sourceraw docstring

maybe->clj/smacro

(maybe-> x & forms)

Thread-first expansion using bind-maybe. A vector form of one element [x] is applied only to 'nothing' leaving 'just' intact. Use clojure.core/reduced for early termination. Example usage

(maybe-> (find-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)

See: reduce-> bind-maybe maybe->> maybe-as-> either-> trial->

Thread-first expansion using [[bind-maybe]]. A vector form of one element `[x]` is applied only to 'nothing' leaving
'just' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(maybe-> (find-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)
```
See:
  [[reduce->]]
  [[bind-maybe]]
  [[maybe->>]]
  [[maybe-as->]]
  [[either->]]
  [[trial->]]
sourceraw docstring

maybe->>clj/smacro

(maybe->> x & forms)

Thread-last expansion using bind-maybe. A vector form of one element [x] is applied only to 'nothing' leaving 'just' intact. Use clojure.core/reduced for early termination. Example usage

(maybe->> (find-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)

See: reduce->> bind-maybe either-> either-as-> maybe->> trial->>

Thread-last expansion using [[bind-maybe]]. A vector form of one element `[x]` is applied only to 'nothing' leaving
'just' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(maybe->> (find-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)
```
See:
  [[reduce->>]]
  [[bind-maybe]]
  [[either->]]
  [[either-as->]]
  [[maybe->>]]
  [[trial->>]]
sourceraw docstring

maybe-as->clj/smacro

(maybe-as-> expr name & forms)

Thread-anywhere expansion using bind-maybe. A vector form of one element [x] is applied only to 'nothing' leaving 'just' intact. Use clojure.core/reduced for early termination. Example usage

(maybe-as-> (find-order) $
  (check-inventory $ :foo)
  [(cancel-order :bar) process-order]
  (fulfil-order $))

See: reduce-as-> bind-maybe maybe-> maybe->> either-as-> trial-as->

Thread-anywhere expansion using [[bind-maybe]]. A vector form of one element `[x]` is applied only to 'nothing'
leaving 'just' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(maybe-as-> (find-order) $
  (check-inventory $ :foo)
  [(cancel-order :bar) process-order]
  (fulfil-order $))
```
See:
  [[reduce-as->]]
  [[bind-maybe]]
  [[maybe->]]
  [[maybe->>]]
  [[either-as->]]
  [[trial-as->]]
sourceraw docstring

mdoclj/smacro

(mdo & body)

Evaluate body of code such that any context is returned as soon as it is encountered unexpectedly. However, context matches are ignored. Return nil for empty body.

Evaluate body of code such that any context is returned as soon as it is encountered unexpectedly. However, context
matches are ignored. Return `nil` for empty body.
sourceraw docstring

mfailureclj/s

(mfailure x)
(mfailure x default)

Match argument as Failure, returning a match-result. See: mnothing mthrown mlet if-mlet when-mlet cond-mlet

Match argument as Failure, returning a match-result.
See:
  [[mnothing]]
  [[mthrown]]
  [[mlet]]
  [[if-mlet]]
  [[when-mlet]]
  [[cond-mlet]]
sourceraw docstring

mletclj/smacro

(mlet bindings & body)

Bind symbols in the binding forms to their respective matching context and evaluate body of code in the lexical scope. If a non-matching context is encountered, return it without proceeding any further. See: mfailure mnothing mthrown if-mlet when-mlet cond-mlet

Bind symbols in the binding forms to their respective matching context and evaluate body of code in the lexical
scope. If a non-matching context is encountered, return it without proceeding any further.
See:
  [[mfailure]]
  [[mnothing]]
  [[mthrown]]
  [[if-mlet]]
  [[when-mlet]]
  [[cond-mlet]]
sourceraw docstring

mnothingclj/s

(mnothing x value)

Match argument as Nothing, returning a match-result. See: mfailure mthrown mlet if-mlet when-mlet cond-mlet

Match argument as Nothing, returning a match-result.
See:
  [[mfailure]]
  [[mthrown]]
  [[mlet]]
  [[if-mlet]]
  [[when-mlet]]
  [[cond-mlet]]
sourceraw docstring

mthrownclj/s

(mthrown x)
(mthrown x default)

Match argument as Thrown, returning a match-result. See: mfailure mnothing mlet if-mlet when-mlet cond-mlet

Match argument as Thrown, returning a match-result.
See:
  [[mfailure]]
  [[mnothing]]
  [[mlet]]
  [[if-mlet]]
  [[when-mlet]]
  [[cond-mlet]]
sourceraw docstring

nil->failureclj/s

source

nil->nothingclj/s

source

nothingclj/s

source

nothing?clj/s

(nothing? x)
source

reduce->clj/smacro

(reduce-> bind expr & forms)

Given a bind function (fn [mval alt-fn val-fn]) -> mval and one or more expressions in thread-first form, reduce over the expressions returning the final result. Use clojure.core/reduced for early termination.

Given a bind function `(fn [mval alt-fn val-fn]) -> mval` and one or more expressions in thread-first form,
reduce over the expressions returning the final result. Use `clojure.core/reduced` for early termination.
sourceraw docstring

reduce->>clj/smacro

(reduce->> bind expr & forms)

Given a bind function (fn [mval alt-fn val-fn]) -> mval and one or more expressions in thread-last form, reduce over the expressions returning the final result. Use clojure.core/reduced for early termination.

Given a bind function `(fn [mval alt-fn val-fn]) -> mval` and one or more expressions in thread-last form,
reduce over the expressions returning the final result. Use `clojure.core/reduced` for early termination.
sourceraw docstring

reduce-as->clj/smacro

(reduce-as-> bind expr name & forms)

Given a bind function (fn [mval alt-fn val-fn]) -> mval, a name to bind and one or more expressions in thread-as form, reduce over the expressions returning the final result. Use clojure.core/reduced for early termination.

Given a bind function `(fn [mval alt-fn val-fn]) -> mval`, a name to bind and one or more expressions in thread-as
form, reduce over the expressions returning the final result. Use `clojure.core/reduced` for early termination.
sourceraw docstring

refnclj/smacro

(refn argvec expr)
(refn context-pred argvec expr)

Given 'accumulator' and 'each' arguments placeholder and an S-expression to evaluate, return a reducing function (fn [accumulator each]) that bails out on encountering a context. Example:

(reduce (refn [vs x] (if (odd? x)
                       (conj vs (* x 2))
                       vs))
        []
        coll)
Given 'accumulator' and 'each' arguments placeholder and an S-expression to evaluate, return a reducing function
`(fn [accumulator each])` that bails out on encountering a context.
Example:
```
(reduce (refn [vs x] (if (odd? x)
                       (conj vs (* x 2))
                       vs))
        []
        coll)
```
sourceraw docstring

rewrapclj/s

(rewrap f)
(rewrap context-pred f)

Given a reducing function (fn [val each]) wrap it such that it bails out on encountering a context. Example: (reduce (rewrap f) init coll)

Given a reducing function `(fn [val each])` wrap it such that it bails out on encountering a context.
Example: `(reduce (rewrap f) init coll)`
sourceraw docstring

thrownclj/s

(thrown x)

Turn given argument into a 'thrown' unless it is already a context.

Turn given argument into a 'thrown' unless it is already a context.
sourceraw docstring

thrown?clj/s

(thrown? x)
source

trial->clj/smacro

(trial-> x & forms)

Thread-first expansion using bind-trial. A vector form of one element [x] is applied only to 'thrown' leaving 'result' intact. Use clojure.core/reduced for early termination. Example usage

(trial-> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)

See: reduce-> bind-trial trial->> trial-as-> either-> maybe->

Thread-first expansion using [[bind-trial]]. A vector form of one element `[x]` is applied only to 'thrown' leaving
'result' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(trial-> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)
```
See:
  [[reduce->]]
  [[bind-trial]]
  [[trial->>]]
  [[trial-as->]]
  [[either->]]
  [[maybe->]]
sourceraw docstring

trial->>clj/smacro

(trial->> x & forms)

Thread-last expansion using bind-trial. A vector form of one element [x] is applied only to 'thrown' leaving 'result' intact. Use clojure.core/reduced for early termination. Example usage

(either->> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)

See: reduce->> bind-trial trial-> trial-as-> either->> maybe->>

Thread-last expansion using [[bind-trial]]. A vector form of one element `[x]` is applied only to 'thrown' leaving
'result' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(either->> (place-order)
  (check-inventory :foo)
  [(cancel-order :bar) process-order]
  fulfil-order)
```
See:
  [[reduce->>]]
  [[bind-trial]]
  [[trial->]]
  [[trial-as->]]
  [[either->>]]
  [[maybe->>]]
sourceraw docstring

trial-as->clj/smacro

(trial-as-> expr name & forms)

Thread-anywhere expansion using bind-trial. A vector form of one element [x] is applied only to 'thrown' leaving 'result' intact. Use clojure.core/reduced for early termination. Example usage

(either-as-> (place-order) $
  (check-inventory $ :foo)
  [(cancel-order :bar $) process-order]
  (fulfil-order $))

See: reduce-as-> bind-trial trial-> trial->> either-as-> maybe-as->

Thread-anywhere expansion using [[bind-trial]]. A vector form of one element `[x]` is applied only to 'thrown'
leaving 'result' intact. Use `clojure.core/reduced` for early termination.
Example usage
```
(either-as-> (place-order) $
  (check-inventory $ :foo)
  [(cancel-order :bar $) process-order]
  (fulfil-order $))
```
See:
  [[reduce-as->]]
  [[bind-trial]]
  [[trial->]]
  [[trial->>]]
  [[either-as->]]
  [[maybe-as->]]
sourceraw docstring

voidclj/s

(void)
(void x)

Turn given argument into 'nothing' unless it is already a context.

Turn given argument into 'nothing' unless it is already a context.
sourceraw docstring

when-mletclj/smacro

(when-mlet bindings & body)

Bind symbols in the binding forms to their respective matching context and evaluate th body of code in the lexical scope. If a non-matching context is encountered, return nil. See: mfailure mnothing mthrown mlet if-mlet cond-mlet

Bind symbols in the binding forms to their respective matching context and evaluate th body of code in the lexical
scope. If a non-matching context is encountered, return `nil`.
See:
  [[mfailure]]
  [[mnothing]]
  [[mthrown]]
  [[mlet]]
  [[if-mlet]]
  [[cond-mlet]]
sourceraw docstring

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

× close