Liking cljdoc? Tell your friends :D

clj-helpers.responses

Helper functions for returning unified responses.

Helper functions for returning unified responses.
raw docstring

as-errorclj/s

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

as-successclj/s

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

error?clj/s

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

get-errorclj/s

(get-error v)

Returns unified error result.

Returns unified `error` result.
sourceraw docstring

get-error-dataclj/s

(get-error-data v)

Returns data of unified error result.

Returns `data` of unified `error` result.
sourceraw docstring

get-error-metadataclj/s

(get-error-metadata v)

Returns metadata of unified error result.

Returns `metadata` of unified `error` result.
sourceraw docstring

get-error-typeclj/s

(get-error-type v)

Returns type of unified error result.

Returns `type` of unified `error` result.
sourceraw docstring

get-successclj/s

(get-success v)

Returns unified success result.

Returns unified `success` result.
sourceraw docstring

get-success-dataclj/s

(get-success-data v)

Returns data of unified success result.

Returns `data` of unified `success` result.
sourceraw docstring

get-success-metadataclj/s

(get-success-metadata v)

Returns metadata of unified success result.

Returns `metadata` of unified `success` result.
sourceraw docstring

get-success-typeclj/s

(get-success-type v)

Returns type of unified success result.

Returns `type` of unified `success` result.
sourceraw docstring

if-errorcljmacro

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

if-successcljmacro

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

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

success?clj/s

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

when-errorcljmacro

(when-error bindings & then)

Works the same as if-error, but without else branch.

Works the same as `if-error`, but without `else` branch.
sourceraw docstring

when-successcljmacro

(when-success bindings & then)

Works the same as if-success, but without else branch.

Works the same as `if-success`, but without `else` branch.
sourceraw docstring

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

× close