Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Created May 1, 2015 15:59
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 kindlychung/c05aa1c9ba9ac2b481f0 to your computer and use it in GitHub Desktop.
Save kindlychung/c05aa1c9ba9ac2b481f0 to your computer and use it in GitHub Desktop.
(def sarah (atom {:name "Sarah" :age 25}))
(set-validator! sarah #(when-not (:age %) (throw (IllegalStateException. ":age required"))))
@kindlychung
Copy link
Author

CompilerException java.lang.IllegalStateException: Invalid reference state, compiling:(/Users/kaiyin/personal_config_bin_files/workspace/cina/src/cina/ref_types.clj:1:24)

@xonev
Copy link

xonev commented May 1, 2015

You need to return true (or a non-false val) if the state is acceptable. You could do this:

(set-validator! sarah #(if (:age %) true (throw (IllegalStateException. ":age required"))))

or this:

(set-validator! sarah #(:age %))

@kindlychung
Copy link
Author

I see. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment