A nicer equivalent form would be:

(cond-> []
  this-error? (conj “It failed with this error”)
  that-error? (conj “It failed with that error”))

However, purely for validation there are a few utilities out there already. 
Checkout the ‘Validation’ section on http://www.clojure-toolbox.com 
<http://www.clojure-toolbox.com/>

Also, in terms of enforcing contracts - Prismatic Schema is highly recommended 
but hard to ‘englishify’ the errors. Failures are considered API failures 
rather than happy-case failures.

> On 12 Nov 2015, at 16:09, Brian Forester <brian.fores...@gmail.com> wrote:
> 
> I'm writing a very small REST application in clojure using compojure and 
> ring.  One problem is that I don't have anyone who can review my work or 
> provide feedback.
> 
> I've written a small function to validate a simple JSON request.  I'm 
> validating the three values that are in the post and collecting the errors 
> for return.
> The core mechanic I've used
>      (swap! errors str "'grepString' must not be null or empty.\n"))
> does not seem to be a very idiomatic clojure way to solve this simple problem.
> 
> https://gist.github.com/BDF/8e61daf8fe8b602a248a
> 
> Any feedback is appreciated.
> BDF.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> <http://groups.google.com/group/clojure?hl=en>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to