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.
(! x)
(! catch-class x)
Evaluate given form and return it; on exception return the exception as thrown context.
Evaluate given form and return it; on exception return the exception as thrown context. See: [[promenade.util/!se-info]]
(!wrap f)
(!wrap catch-class f)
Wrap given function such that on exception it returns the exception as a thrown context.
Wrap given function such that on exception it returns the exception as a thrown context. See: [[promenade.util/!wrap-se-info]]
(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]]
(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]]
(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]]
(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)) ```
(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.
(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.
(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->]]
(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->>]]
(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->]]
(ex-fail expr)
Catch ExceptionInfo and turn its ex-data into 'failure'.
Catch ExceptionInfo and turn its ex-data into 'failure'.
(fail)
(fail x)
Turn given argument into 'failure' unless it is already a context.
Turn given argument into 'failure' unless it is already a context. See: [[promenade.util/defailure]]
(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]]
(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->]]
(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->>]]
(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->]]
(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.
(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]]
(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.
(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.
(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.
(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) ```
(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)`
(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.
(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->]]
(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->>]]
(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->]]
(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.
(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]]
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close