Liking cljdoc? Tell your friends :D

ribelo.fatum


->clj/smacro

(-> expr & more)

like clojure.core/-> but expr is wrapped in attempt, and the following functions in then

like `clojure.core/->` but `expr` is wrapped in [[attempt]], and the following functions in [[then]]
sourceraw docstring

->>clj/smacro

(->> expr & more)

like clojure.core/->> but expr is wrapped in attempt, and the following functions in then

like `clojure.core/->>` but `expr` is wrapped in [[attempt]], and the following
functions in [[then]]
sourceraw docstring

-if-cljclj/smacro

(-if-clj then & [else])
source

-match-map?clj/s

(-match-map? x m)

chech if x has every kv from m

chech if `x` has every `kv` from `m`
sourceraw docstring

andclj/smacro

(and)
(and x)
(and x & next)
source

attemptclj/smacro

(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

```clojure
(attempt (/ 1 1))
=> 1
```

```clojure
(attempt (/ 1 0))
=>
#error {
:cause "Divide by zero"
:data {}
:via
[{:type ribelo.fatum.Fail
 :message "Divide by zero"
 :data {}}]
:trace
[]}
```
sourceraw docstring

callclj/s

(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`

```clojure
(call 1 inc)
=> 2
```

```clojure
(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
[]}
````
sourceraw docstring

catchclj/s

(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?]]

```clojure
(-> {: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
```
sourceraw docstring

catch-errorsclj/smacro

(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`

```clojure
(catch-errors (/ 1 1)) => [1 nil]
```
```clojure
(catch-errors (/ 1 0)) => [nil java.lang.ArithmeticException]
```
sourceraw docstring

catch-ifclj/s

(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

```clojure
(-> {: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
```
sourceraw docstring

catchingclj/smacro

(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

```clojure
(catching (/ 1 0) => nil
```
```clojure
(catching (/ 1 0) e e) => java.lang.ArithmeticException
```
sourceraw docstring

ensure-failclj/s

(ensure-fail x)

ensure that Exception err is Fail

ensure that `Exception` `err` is [[Fail]]
sourceraw docstring

every?clj/s

(every? pred xs)
source

exception-info?clj/s

(exception-info? x)

check if x is ExceptionInfo

check if `x` is `ExceptionInfo`
sourceraw docstring

Failcljs

(Fail msg data)
source

failclj/s

(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 
sourceraw docstring

fail!clj/s

(fail!)
(fail! msg)
(fail! msg data)
(fail! msg k v & kvs)

throw Fail

see fail

throw [[Fail]]

see [[fail]]
sourceraw docstring

fail-ifclj/s

(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

```clojure
(-> {: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
[]}
```
sourceraw docstring

fail?clj/s

(fail? x)
(fail? x & more)

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
sourceraw docstring

fail?!clj/s

(fail?! x)
(fail?! x & more)

throw x if x meets fail? else returns x

`throw` `x` if `x` meets [[fail?]] else returns x
sourceraw docstring

finallyclj/s

(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`.
sourceraw docstring

if-okclj/smacro

(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?`

```clojure
(if-ok (/ 1 1) :ok :err)
=> :ok
```

```clojure
(if-ok (/ 1 1) :ok :err)
=> :err
```

```clojure
(if-ok nil :ok :err)
=> :ok
```
sourceraw docstring

isa?clj/s

(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`

```clojure
(isa? 1 number?) => true
```
```clojure
(isa? java.lang.ArithmeticException (catching (/ 1 0))) => true
```
```clojure
(isa? {:a 1 :b 2} {:a 1}) => true
```
```clojure
(isa? {:a 1 :b 2} {:c 3}) => false
```
sourceraw docstring

ok?clj/s

(ok? x)
(ok? x & more)

check if x is not Fail

check if `x` is not [[Fail]]
sourceraw docstring

ok?!clj/s

(ok?! x)
(ok?! x & more)

throw x if x meets fail? else returns x

`throw` `x` if `x` meets [[fail?]] else returns x
sourceraw docstring

orclj/smacro

(or)
(or x)
(or x & next)
source

someclj/s

(some pred xs)
source

thenclj/s

(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`

```clojure
(-> {:name "Ivan" :age 17}
    (then #(update % :age inc)))
=> {:name "Ivan", :age 18}
```
sourceraw docstring

then-ifclj/s

(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

```clojure
(-> {: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}
```
sourceraw docstring

throw-ifclj/s

(throw-if x pred)
(throw-if x pred msg-or-fn)
(throw-if x pred msg data)

throw fail! with optional msg and data if x is ok? and meets isa? condition

see fail-if

throw [[fail!]] with optional `msg` and `data` if `x` is [[ok?]] and
meets [[isa?]] condition

see [[fail-if]]
sourceraw docstring

thruclj/s

(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
sourceraw docstring

thru-ifclj/s

(thru-if x pred f)

attempt to call function f on unreduced value of x if unreduced x meets isa? condition. return x unchanged. used for side effects

[[attempt]] to call function `f` on `unreduced` value of `x` if `unreduced` `x`
meets [[isa?]] condition. return `x` unchanged. used for side effects
sourceraw docstring

when-okclj/smacro

(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
=> :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

```clojure
(when-ok (/ 1 1) :ok)
=> :ok
```

```clojure(when-ok nil :ok)
=> :ok
```

```clojure
(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
[]}
```

```clojure
(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
[]}
```
sourceraw docstring

when-ok!clj/smacro

(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 throw Fail with attached var & failing expresions

(when-ok (/ 1 1) :ok)
=> :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 throw [[Fail]] with attached var & failing
expresions

```clojure
(when-ok (/ 1 1) :ok)
=> :ok
```

```clojure(when-ok nil :ok)
=> :ok
```

```clojure
(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
[]}
```

```clojure
(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
[]}
```
sourceraw docstring

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

× close