The Exception monad.
Also known as Try monad, popularized by Scala.
It represents a computation that may either result in an exception or return a successfully computed value. Is very similar to Either monad, but is semantically different.
It consists in two types: Success and Failure. The Success type is a simple wrapper like Right of Either monad. But the Failure type is slightly different from Left, because it is forced to wrap an instance of Throwable (or Error in cljs).
The most common use case of this monad is for wrap third party libraries that uses standard Exception based error handling. In normal circumstances you should use Either instead.
The types defined for Exception monad (Success and Failure) also implementes the clojure IDeref interface which facilitates libraries developing using monadic composition without forcing a user of that library to use or understand monads.
That is because when you will dereference the failure instance, it will reraise the containing exception.
The Exception monad. Also known as Try monad, popularized by Scala. It represents a computation that may either result in an exception or return a successfully computed value. Is very similar to Either monad, but is semantically different. It consists in two types: Success and Failure. The Success type is a simple wrapper like Right of Either monad. But the Failure type is slightly different from Left, because it is forced to wrap an instance of Throwable (or Error in cljs). The most common use case of this monad is for wrap third party libraries that uses standard Exception based error handling. In normal circumstances you should use Either instead. The types defined for Exception monad (Success and Failure) also implementes the clojure IDeref interface which facilitates libraries developing using monadic composition without forcing a user of that library to use or understand monads. That is because when you will dereference the failure instance, it will reraise the containing exception.
(exception? v)
Return true in case of v
is instance
of Exception monad.
Return true in case of `v` is instance of Exception monad.
(extract mv)
(extract mv default)
Return inner value from exception monad.
This is a specialized version of cats.core/extract
for Exception monad types that allows set up
the default value.
If a provided mv
is an instance of Failure type
it will re raise the inner exception. If you need
extract value without raising it, use cats.core/extract
function for it.
Return inner value from exception monad. This is a specialized version of `cats.core/extract` for Exception monad types that allows set up the default value. If a provided `mv` is an instance of Failure type it will re raise the inner exception. If you need extract value without raising it, use `cats.core/extract` function for it.
(failure e)
(failure e message)
A failure type constructor.
If a provided parameter is an exception, it wraps
it in a Failure
instance and return it. But if
a provided parameter is arbitrary data, it tries
create an exception from it using clojure ex-info
function.
Take care that ex-info
function in clojurescript
differs a little bit from clojure.
A failure type constructor. If a provided parameter is an exception, it wraps it in a `Failure` instance and return it. But if a provided parameter is arbitrary data, it tries create an exception from it using clojure `ex-info` function. Take care that `ex-info` function in clojurescript differs a little bit from clojure.
(failure? v)
Return true if v
is an instance of
the Failure type.
Return true if `v` is an instance of the Failure type.
(success v)
A Success type constructor.
It wraps any arbitrary value into success type.
A Success type constructor. It wraps any arbitrary value into success type.
(success? v)
Return true if v
is an instance of
the Success type.
Return true if `v` is an instance of the Success type.
(throw-exception message)
(throwable? e)
Return true if v
is an instance of
the Throwable or js/Error type.
Return true if `v` is an instance of the Throwable or js/Error type.
(try-on expr)
Wraps a computation and return success of failure.
Wraps a computation and return success of failure.
(try-or-else expr defaultvalue)
(try-or-recover expr func)
(wrap func)
Wrap a function in a try monad.
Is a high order function that accept a function as parameter and returns an other that returns success or failure depending of result of the first function.
Wrap a function in a try monad. Is a high order function that accept a function as parameter and returns an other that returns success or failure depending of result of the first function.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close