Skip to content

Instantly share code, notes, and snippets.

@LukasRychtecky
Last active August 13, 2018 07:51
Show Gist options
  • Save LukasRychtecky/7475838e339b6bd6546c3b676afc4ecd to your computer and use it in GitHub Desktop.
Save LukasRychtecky/7475838e339b6bd6546c3b676afc4ecd to your computer and use it in GitHub Desktop.
;; VERSION 0
(defn- validate-request=
[input]
(if (valid? ...)
(rop/succeed input)
(rop/fail {:status 400})))
(defn- create-user!
[{:keys [conf request] :as input}]
(assoc input :user (db/create-user conf request)))
(defn- send-email!
[{:keys [conf]}]
(send! conf))
(defn create-user!
[conf request]
{:conf conf
:request request}
validate-request=
(rop/switch create-user!) ;; <-- wrapped into `switch`
(rop/dead send-email!)) ;; <-- wrapped into `dead`
;; VERSION 1
(defn- =validate-request=
[input]
(if (valid? ...)
(rop/succeed input)
(rop/fail {:status 400})))
(defn- =create-user! ;; <-- ending `=` is missing as a sign, that it needs to be wrapped into switch
[{:keys [conf request]}]
(assoc input :user (db/create-user conf request))) ;; <-- function doesn't return a monad, because it's always truthy
(defn- =send-email! ;; <-- ending `=` is missing as a sign, that it needs to be wrapped into dead
[{:keys [conf]}]
(send! conf)) ;; <-- function doesn't return a monad, because it's always truthy
(defn create-user!
[conf request]
{:conf conf
:request request}
=validate-request=
(rop/switch =create-user!) ;; <-- wrapped into `switch`
(rop/dead =send-email!)) ;; <-- wrapped into `dead`
;; VERSION 2
(defn- =validate-request=
[input]
(if (valid? ...)
(rop/succeed input)
(rop/fail {:status 400})))
(defn- =create-user!= ;; <-- ending `=` is placed
[{:keys [conf request]}]
(assoc input :user (db/create-user conf request))) ;; <-- function doesn't return a monad, because it's always truthy
(defn- =send-email!= ;; <-- ending `=` is placed
[{:keys [conf]}]
(send! conf)) ;; <-- function doesn't return a monad, because it's always truthy
(defn create-user!
[conf request]
{:conf conf
:request request}
=validate-request=
(rop/switch =create-user!=) ;; <-- wrapped into `switch`
(rop/switch =send-email!=)) ;; <-- wrapped into `dead`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment