Helper functions for returning unified responses.
Helper functions for returning unified responses.
(as-error data)
(as-error type data)
(as-error type data metadata)
Returns wrapped unified error
result with the given value.
Returns wrapped unified `error` result with the given value.
(as-success data)
(as-success type data)
(as-success type data metadata)
Returns wrapped unified success
result with the given value.
Returns wrapped unified `success` result with the given value.
(error? v)
Returns true
when the given value is unified error
result. Otherwise false
.
Returns `true` when the given value is unified `error` result. Otherwise `false`.
(get-error v)
Returns unified error
result.
Returns unified `error` result.
(get-error-data v)
Returns data
of unified error
result.
Returns `data` of unified `error` result.
(get-error-metadata v)
Returns metadata
of unified error
result.
Returns `metadata` of unified `error` result.
(get-error-type v)
Returns type
of unified error
result.
Returns `type` of unified `error` result.
(get-success v)
Returns unified success
result.
Returns unified `success` result.
(get-success-data v)
Returns data
of unified success
result.
Returns `data` of unified `success` result.
(get-success-metadata v)
Returns metadata
of unified success
result.
Returns `metadata` of unified `success` result.
(get-success-type v)
Returns type
of unified success
result.
Returns `type` of unified `success` result.
(if-error bindings then)
(if-error bindings then else & oldform)
Works the same as if-success
, but with inverted logic.
Works the same as `if-success`, but with inverted logic.
(if-success bindings then)
(if-success bindings then else & oldform)
Works the same as if-some
or if-let
, but checks for unified success
result.
And returns result as [:type :data :metadata]. Where:
:type
- keyword:data
- any value:metadata
- mapExamples: (defn get-user-by-email [email] (if (= "john@doe.com" email) (as-success :ok {:user/id 1, :user/email email}) (as-error :not-found {:user/email email} {:i18n/key :user/not-exists}])))
(if-success [[type data metadata] (get-user-by-email "john@doe.com")] [type data metadata] [type data metadata]) => [:ok {:user/id 1, :user/email "john@doe.com"} {}]
(if-success [[type data metadata] (get-user-by-email "jane@doe.com")] [type data metadata] [type data metadata]) => [:not-found {:user/email "jane@doe.com"} {:i18n/key :user/not-exists}]
Works the same as `if-some` or `if-let`, but checks for unified `success` result. And returns result as [:type :data :metadata]. Where: * `:type` - keyword * `:data` - any value * `:metadata` - map Examples: (defn get-user-by-email [email] (if (= "john@doe.com" email) (as-success :ok {:user/id 1, :user/email email}) (as-error :not-found {:user/email email} {:i18n/key :user/not-exists}]))) (if-success [[type data metadata] (get-user-by-email "john@doe.com")] [type data metadata] [type data metadata]) => [:ok {:user/id 1, :user/email "john@doe.com"} {}] (if-success [[type data metadata] (get-user-by-email "jane@doe.com")] [type data metadata] [type data metadata]) => [:not-found {:user/email "jane@doe.com"} {:i18n/key :user/not-exists}]
(success? v)
Returns true
when the given value is unified success
result. Otherwise false
.
Returns `true` when the given value is unified `success` result. Otherwise `false`.
(when-error bindings & then)
Works the same as if-error
, but without else
branch.
Works the same as `if-error`, but without `else` branch.
(when-success bindings & then)
Works the same as if-success
, but without else
branch.
Works the same as `if-success`, but without `else` branch.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close