I've found myself writing a validator function.
It has a list of internal validator functions, and should return the first one that evaluates to non-nil, without evaluating the rest.
Here's the code I've come up with:
(defn validate-something [data-1 data-2 data-3]
(some #(%)
[#(validate-data-1 data-1)
#(validate-data-2 data-2)
#(validate-data-3 data-3)]))
But this code just feels ugly and I feel like it could be more idiomatic.
For one thing, it shares something in common with cond, since it should return the first one that returns non-nil. But each cond clause takes two params, the test and the result, whereas this is just one and the same. So I don't know how I would use cond with it.
Alternatively, that property could be implemented by the lazy-evaluation of map. My first impulse was to do (find-first (map apply [f1 f2 f3])) but first of all I'd have to write find-first (or use something in contrib), and second of all apply seems to expect args and gave me an error. But maybe that last part was just me being overtired.
Does anyone here have a more idiomatic or elegant solution than the (some) one above?
-Steven