Try Api Documentation

Version: 0.3.0

try.core

->Try

(->Try tag value)

Positional factory function for class try.core.Try.

apply

(apply ftry & try)

Apply value in ftry if it’s a success to the values in all the try if all of them are also a success. If ftry is a failure it is returned, otherwise the first failed try is returned.

Examples: (apply (succeed +) (succeed 1) (succeed 2) (succeed 3)) => #try.core.Try{:tag :try.core/success, :value 6}

(apply (succeed +) (succeed 1) (fail 2) (fail 3)) => #try.core.Try{:tag :try.core/failure, :value 2}

bimap

(bimap f g try)

Apply function f to try’s value if it’s a success, otherwise apply function g to try’s value if it’s a failure.

bind

(bind try & fs)

Apply f to try’s value if is successful and return its result, otherwise return try. Examples: (bind (succeed 1) #(succeed (+ 2 %))) => #try.core.Try{:tag :try.core/success, :value 3}

(bind (fail 1) #(succeed (+ 2 %))) => #try.core.Try{:tag :try.core/failure, :value 1}

(bind (succeed 1) #(fail (str “err” %)) #(succeed (+ 1 %))) => #try.core.Try{:tag :try.core/failure, :value “err1”}

fail

(fail value)

Wrap value as a failed Try.

failure?

(failure? try)

Check if try is a failed Try.

into

(into to coll)

If all items in coll are successful Try, return a successful Try which value is the to collection filled with the value of each Try in coll. Otherwise return a failed Try which value is the to collection filled with the value of each Try in coll. Examples: (into [] (list (succeed 1) (succeed 2) (succeed 3))) => #try.core.Try{:tag :try.core/success, :value [1 2 3]}

(into [] [(succeed 1) (fail 2) (fail 3)]) => #try.core.Try{:tag :try.core/failure, :value [2 3]}

map

(map f try)

Apply function f to try’s value if is a successful Try.

map->Try

(map->Try m__6522__auto__)

Factory function for class try.core.Try, taking a map of keywords to field values.

map-failure

(map-failure f try)

Apply function f to try’s value if is a failed Try.

sequence

(sequence coll)

Transform a collection coll of try items in a try where the value is a collection of each try value. If given an empty collection, returns a successful try with the empty vector as value.

succeed

(succeed value)

Wrap value as a successful Try.

success?

(success? try)

Check if try is a successful Try.

try-let

macro

(try-let bindings & body)

Wrap a let with bindings and body in a tryc.

try>

macro

(try> & body)

Wrap body in a try/catch that returns a successful Try if no exception is raised, or a failed Try if an exception is raised.

val

(val try)

Retrieve the value of try no matter if it’s a success or a failure.

val-or

macro

(val-or try default)

Retrieve the value of try if it’s a success or evaluate and return default if it’s a failure.

val-throw

(val-throw try)

Retrieve the value of try, but throw an exception if it’s a failed Try. This is the same as dereferencing try with deref or @.