(-match-map? x m)
chech if x
has every kv
from m
chech if `x` has every `kv` from `m`
(attempt & body)
like catching
, but takes body
as argument
(attempt (/ 1 1)) => 1
(attempt (/ 1 0)) => #error { :cause "Divide by zero" :data {} :via [{:type ribelo.fatum.Fail :message "Divide by zero" :data {}}] :trace []}
like [[catching]], but takes `body` as argument `(attempt (/ 1 1)) => 1` `(attempt (/ 1 0)) => #error { :cause "Divide by zero" :data {} :via [{:type ribelo.fatum.Fail :message "Divide by zero" :data {}}] :trace []} `
(call x f)
attempt
to call function f
on value x
(call 1 inc) => 2
(call "1" inc) => #error { :cause "class java.lang.String cannot be cast to class java.lang.Number ..." :data {} :via [{:type ribelo.fatum.Fail :message "class java.lang.String cannot be cast to class java.lang.Number ... " :data {}}] :trace []}
[[attempt]] to call function `f` on value `x` `(call 1 inc) => 2` `(call "1" inc) => #error { :cause "class java.lang.String cannot be cast to class java.lang.Number ..." :data {} :via [{:type ribelo.fatum.Fail :message "class java.lang.String cannot be cast to class java.lang.Number ... " :data {}}] :trace []}`
(catch x f)
attempt
to call function f
on value x
if x
is fail?
(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false)) (fail-if (complement (comp :adult)) "user is underage" #(find % :age)) (catch-if (constantly :err))) => :err
[[attempt]] to call function `f` on value `x` if `x` is [[fail?]] `(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false)) (fail-if (complement (comp :adult)) "user is underage" #(find % :age)) (catch-if (constantly :err))) => :err`
(catch-errors & body)
like catching
, but returns a vector where the first element is the result of
executing the body
and the second is an Exception
(catch-errors (/ 1 1)) => [1 nil]
`(catch-errors (/ 1 0)) => [nil java.lang.ArithmeticException]
like [[catching]], but returns a vector where the first element is the result of executing the `body` and the second is an `Exception` `(catch-errors (/ 1 1)) => [1 nil]` `(catch-errors (/ 1 0)) => [nil java.lang.ArithmeticException]
(catch-if x pred f)
attempt
to call function f
on value x
if x
is fail?
, not
reduced
and meets isa?
condition
(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false)) (fail-if (complement (comp :adult)) "user is underage" #(find % :age)) (catch-if (comp (partial > 18) :age) (constantly :err))) => :err
[[attempt]] to call function `f` on value `x` if `x` is [[fail?]], not `reduced` and meets [[isa?]] condition `(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false)) (fail-if (complement (comp :adult)) "user is underage" #(find % :age)) (catch-if (comp (partial > 18) :age) (constantly :err))) => :err`
(catching expr)
(catching expr err catch)
(catching expr err catch finally)
try
to execute expr
, if catch
an error returns it itself
(catching (/ 1 0) => nil
(catching (/ 1 0) e e) => java.lang.ArithmeticException
`try` to execute `expr`, if `catch` an error returns it itself `(catching (/ 1 0) => nil` `(catching (/ 1 0) e e) => java.lang.ArithmeticException`
(ensure-fail x)
ensure that Exception
err
is Fail
ensure that `Exception` `err` is [[Fail]]
(exception-info? x)
check if x
is ExceptionInfo
check if `x` is `ExceptionInfo`
(fail)
(fail msg)
(fail msg data)
(fail msg k v & kvs)
returns Fail
for flexibility, the data
can be either a map, an explicit kv collection or
a variadic kv collection
returns [[Fail]] for flexibility, the `data` can be either a map, an explicit kv collection or a variadic kv collection
(fail-if x pred)
(fail-if x pred msg)
(fail-if x pred msg data-or-fn)
return fail
with optional msg
and data
if x
is ok?
and
meets isa?
condition
(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false)) (fail-if (complement (comp :adult)) "user is underage" (juxt (constantly :user) identity))) => #error { :cause "user is underage" :data {:user {:name "Ivan", :age 17, :adult false}} :via [{:type ribelo.fatum.Fail :message "user is underage" :data {:user {:name "Ivan", :age 17, :adult false}}}] :trace []}
return [[fail]] with optional `msg` and `data` if `x` is [[ok?]] and meets [[isa?]] condition `(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false)) (fail-if (complement (comp :adult)) "user is underage" (juxt (constantly :user) identity))) => #error { :cause "user is underage" :data {:user {:name "Ivan", :age 17, :adult false}} :via [{:type ribelo.fatum.Fail :message "user is underage" :data {:user {:name "Ivan", :age 17, :adult false}}}] :trace []} `
(fail? x)
check if x
is instance of Exception
in clj or js/Error
in cljs
check if `x` is instance of `Exception` in clj or `js/Error` in cljs
(finally x f)
attempt
to call function f
on unreduced
value of x
. return x
unchanged and unreduced
.
[[attempt]] to call function `f` on `unreduced` value of `x`. return `x` unchanged and `unreduced`.
(if-ok test-or-bindings then)
(if-ok test-or-bindings then else)
Like core/if-let
but can bind multiple values. execute then
if all tests
are ok?
(if-ok (/ 1 1) :ok :err) => :ok
(if-ok (/ 1 1) :ok :err) => :err
(if-ok nil :ok :err) => :ok
Like `core/if-let` but can bind multiple values. execute `then` if all tests are `ok?` `(if-ok (/ 1 1) :ok :err) => :ok` `(if-ok (/ 1 1) :ok :err) => :err` `(if-ok nil :ok :err) => :ok`
(isa? x pred)
check if x
meets pred
, or whether Exception
has in ex-data
under the
key k
the value v
(isa? 1 number?) => true
(isa? java.lang.ArithmeticException (catching (/ 1 0))) => true
(isa? {:a 1 :b 2} {:a 1}) => true
(isa? {:a 1 :b 2} {:c 3}) => false
check if `x` meets `pred`, or whether `Exception` has in `ex-data` under the key `k` the value `v` `(isa? 1 number?) => true` `(isa? java.lang.ArithmeticException (catching (/ 1 0))) => true` `(isa? {:a 1 :b 2} {:a 1}) => true` `(isa? {:a 1 :b 2} {:c 3}) => false`
(maybe-throw x)
throw
x
if x
meets fail?
`throw` `x` if `x` meets [[fail?]]
(then x f)
attempt
to call function f
on value x
if x
is ok?
and is not
reduced
(-> {:name "Ivan" :age 17} (then #(update % :age inc))) => {:name "Ivan", :age 18}
[[attempt]] to call function `f` on value `x` if `x` is [[ok?]] and is not `reduced` `(-> {:name "Ivan" :age 17} (then #(update % :age inc))) => {:name "Ivan", :age 18}`
(then-if x pred f)
attempt
to call function f
on value x
if x
is ok?
, not reduced
and meets isa?
condition
(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false))) => {:name "Ivan", :age 17, :adult false}
[[attempt]] to call function `f` on value `x` if `x` is [[ok?]], not `reduced` and meets [[isa?]] condition `(-> {:name "Ivan" :age 17} (then-if (comp (partial <= 18) :age) #(assoc % :adult true)) (then-if (comp (partial > 18) :age) #(assoc % :adult false))) => {:name "Ivan", :age 17, :adult false} `
(throw-if x pred)
(throw-if x pred msg-or-fn)
(throw-if x pred msg data)
(thru x f)
attempt
to call function f
on unreduced
value of x
. return x
unchanged. used for side effects
[[attempt]] to call function `f` on `unreduced` value of `x`. return `x` unchanged. used for side effects
(when-ok test-or-bindings & body)
Like clojure.core/when
however if first arg is binding vector behave like
clojure.core/when-let
, but can bind multiple values. check if all
tests/bindings are ok?
, else return fail
with attached var & failing
expresions
(when-ok (/ 1 1) :ok) => :ok
(when-ok nil :ok) => :ok
(when-ok (/ 1 0) :ok => #error { :cause "Divide by zero" :data {:binding test, :expr (/ 1 0)} :via [{:type ribelo.fatum.Fail :message "Divide by zero" :data {:binding test, :expr (/ 1 0)}}] :trace []}
(when-ok [x (/ 1 0)] :ok) => #error { :cause "Divide by zero" :data {:binding x, :expr (/ 1 0)} :via [{:type ribelo.fatum.Fail :message "Divide by zero" :data {:binding x, :expr (/ 1 0)}}] :trace []}
Like `clojure.core/when` however if first arg is binding vector behave like `clojure.core/when-let`, but can bind multiple values. check if all tests/bindings are [[ok?]], else return `fail` with attached var & failing expresions `(when-ok (/ 1 1) :ok) => :ok` `(when-ok nil :ok) => :ok` `(when-ok (/ 1 0) :ok => #error { :cause "Divide by zero" :data {:binding test, :expr (/ 1 0)} :via [{:type ribelo.fatum.Fail :message "Divide by zero" :data {:binding test, :expr (/ 1 0)}}] :trace []}` `(when-ok [x (/ 1 0)] :ok) => #error { :cause "Divide by zero" :data {:binding x, :expr (/ 1 0)} :via [{:type ribelo.fatum.Fail :message "Divide by zero" :data {:binding x, :expr (/ 1 0)}}] :trace []}`
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close