Skip to content

Instantly share code, notes, and snippets.

@paomian
Created January 20, 2016 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paomian/0a9bf63530b9fe740351 to your computer and use it in GitHub Desktop.
Save paomian/0a9bf63530b9fe740351 to your computer and use it in GitHub Desktop.
(defrecord Merror [wrap])
(defmonad error-m
[m-bind (fn m-bind-error
[x f]
(if (contains? (:wrap x) :error)
x
(f x)))
m-result (fn m-result-error
[x]
x)])
(defmacro m->
[x & form]
`(-> ~x
~@(map (fn [xx] (if (seq? xx)
`((monad/m-lift 1 (fn [y#] (~(first xx) y# ~@(next xx)))))
`((monad/m-lift 1 ~xx))))
form)))
#_(monad/domonad error-m
[x (Merror. {:success ""})]
(m-> x
(println "1" "2")
((fn [x] (println "0" x) (Merror. {:error 1})))
(#(println "2" %))))
#_(defendpoint request-sms
[req app_id]
{:pre [(not (adb/allow-verify-sms-code-api? (:flags (:app req))))
kPFErrorOperationForbidden
(boolean-env
(keyword (format "%s.sms.blacklist" (-> req :app :app_id))))
"Your app is in blacklist, please contact us."]
:validators [(when-let [st (-> req :json-params :smsType)]
(require-sms-type st))
(require-mobile-phone-number
(-> req :json-params :mobilePhoneNumber))]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment