Liking cljdoc? Tell your friends :D

grimoire.either

Quick and dirty implementation of something like Haskell's Either[Success, Failure] for Clojure. Not the nicest thing in the world, but it'll do the job. Used to indicate success and failure throughout the lib-grimoire API.

Quick and dirty implementation of something like Haskell's Either[Success,
Failure] for Clojure. Not the nicest thing in the world, but it'll do the
job. Used to indicate success and failure throughout the lib-grimoire API.
raw docstring

either?clj

(either? x)

λ [t] → Bool

Type predicate, matching either succeed or failure structures. Intended as a postcondition for maybe functions.

λ [t] → Bool

Type predicate, matching either succeed or failure structures. Intended as a
postcondition for maybe functions.
raw docstring

failclj


fail?clj


Failure?clj

(Failure? x__5843__auto__)

Generated predicate for the Failure type.

Generated predicate for the Failure type.
raw docstring

messageclj

(message x)

λ [Failure[t]] → t

Value extractor. For a failure value, unboxes the result of the failure. Otherwise encounters an assertion failure (type error).

λ [Failure[t]] → t

Value extractor. For a failure value, unboxes the result of the
failure. Otherwise encounters an assertion failure (type error).
raw docstring

resultclj

(result x)

λ [Succeed[t]] → t

Value extractor. For a succeed value, unboxes the result of the succeed. Otherwise encounters an assertion failure (type error).

λ [Succeed[t]] → t

Value extractor. For a succeed value, unboxes the result of the
succeed. Otherwise encounters an assertion failure (type error).
raw docstring

succeedclj


succeed?clj


Succeess?clj

(Succeess? x__5843__auto__)

Generated predicate for the Succeess type.

Generated predicate for the Succeess type.
raw docstring

with-resultcljmacro

(with-result [binding form] left)
(with-result [binding form] left right)

This macro is a helper designed to emulate the Haskell pattern matching which Clojure lacks by default.

Usage: (with-result [x (could-fail-form)] (use-x x))

In the two-arity case, the value expression is evaluated and if a failure is generated it is passed back up the stack implicitly as this is assumed to be the common case. If the possibly failing expression succeeds, then the result is extracted and let-bound to the binding form. The binding form may contain destructuring. Exceptions occuring inside the left form will be caught and bound into Failure values.

Usage: (with-result [x (could-fail-form)] (use-x x) ; x is the Result (failure-case x)) ; x is the Message

In the three-arity case, the expression value is evaluated, and unaltered value of the possibly failing form is bound to the given symbol. If the result value is a success structure, then the "left" form is evaluated, otherwise the "right" form is evaluated. No implicit result or error destructuring is provided in this case. Exceptions occuring inside either form will be caught and bound into Failure values.

This macro is a helper designed to emulate the Haskell pattern matching which
Clojure lacks by default.

Usage:
(with-result [x (could-fail-form)]
  (use-x x))

In the two-arity case, the value expression is evaluated and if a failure is
generated it is passed back up the stack implicitly as this is assumed to be
the common case. If the possibly failing expression succeeds, then the result
is extracted and let-bound to the binding form. The binding form may contain
destructuring. Exceptions occuring inside the left form will be caught and
bound into Failure values.

Usage:
(with-result [x (could-fail-form)]
  (use-x x)         ; x is the Result
  (failure-case x)) ; x is the Message

In the three-arity case, the expression value is evaluated, and unaltered
value of the possibly failing form is bound to the given symbol. If the result
value is a success structure, then the "left" form is evaluated, otherwise
the "right" form is evaluated. No implicit result or error destructuring is
provided in this case. Exceptions occuring inside either form will be caught
and bound into Failure values.
raw docstring

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

× close