Skip to content

Instantly share code, notes, and snippets.

@XPherior
Created January 18, 2013 03:11
Show Gist options
  • Save XPherior/4562064 to your computer and use it in GitHub Desktop.
Save XPherior/4562064 to your computer and use it in GitHub Desktop.
(ns dire-examples.core
(:require [dire.core :refer [with-precondition! with-postcondition!]]))
(defn save-user [& {:keys [username email password state]}]
"Persist the user to a database here."
:ok ;Or :not-ok
)
(with-precondition! #'save-user
:legal-username-length
(fn [& {:keys [username]}]
(let [length (count username)]
(and (> length 4) (< length 11)))))
(with-precondition! #'save-user
:well-formed-password
(fn [& {:keys [password]}]
(and (> (count password) 6) (re-matches #".*\d.*" password))))
(with-precondition! #'save-user
:well-formed-email
(fn [& {:keys [email]}]
(re-matches #"\w+@\w+\.\w+" "mjd3089@rit.edu")))
(with-precondition! #'save-user
:legal-state-abbreviation
(fn [& {:keys [state]}]
(re-matches #"[A-Z]{2}" state)))
(with-postcondition! #'save-user
:successful-save
(fn [result]
(= result :ok)))
(save-user :username "XPherior" :email "mjd3089@rit.edu" :password "mikemike4" :state "PA")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment