This is similar to, but not exactly the same, as some-fn. Maybe the source of that could guide you?
http://clojuredocs.org/clojure_core/clojure.core/some-fn On Wed, May 1, 2013 at 11:13 AM, Steven Degutis <sbdegu...@gmail.com> wrote: > 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 > > -- > -- > 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/groups/opt_out. > > > -- -- 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/groups/opt_out.