Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Last active August 29, 2015 14:21
Show Gist options
  • Save pesterhazy/fc8930c8eaa4f2eadc02 to your computer and use it in GitHub Desktop.
Save pesterhazy/fc8930c8eaa4f2eadc02 to your computer and use it in GitHub Desktop.
guard-nil: ensure non-nil argument, raise descriptive exception otherwise
(defmacro guard-nil
"Returns `x` unless it is nil, in which case a descriptive exception is raised"
[x]
`(if-some [v# ~x]
v#
(throw (AssertionError. (str "Form should not be nil: " (pr-str '~x))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment