Mastodon

hjertnes.blog

Clojure functions pre and post

24.09.2018 10:00

Sometimes when I read in the Clojure docs on my phone, because I don’t have anything better to do, I find something really interesting. Like a few days ago when I found out that you can set lists of pre and post conditions for a clojure function. That means that you can add a list of predicates (boolean assertments) to run either before or after the function runs. If it runs before it checks the parameters, and if it runs after it checks the result.

The way it works is that you get a Exception if any of them are anything but true.

I think this is a really cool idea.