Hey everyone,
I've developed a predicate library to handle stuff like this.

http://github.com/francoisdevlin/devlinsf-clojure-utils/

Check out lib.devlinsf.pred-utils

There are two methods, ever-pred? and any-pred? designed to handle
this.  Here's an example

;;mimics OR
user=> (filter (any-pred? odd? zero?) (range 0 10))
(0 1 3 5 7 9)

;;mimics AND
user=> (filter (every-pred #(zero? (mod % 5)) #(zero? (mod % 3)))
(range 1 61))
(15 30 45 60)

They are based on every? & some, so they are appropriately lazy.  You
can check my docs for more information.

Hope this helps.

On Oct 20, 8:52 am, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi,
>
> On Oct 20, 3:08 am, Dmitry Kakurin <dmitry.kaku...@gmail.com> wrote:
>
> > (defn multi-filter [filters coll]
> >   (reduce
> >     (fn [res e]
> >       (map (fn [f r] (if (f e) (conj r e) r))
> >         filters
> >         res))
> >     (repeat (count filters) [])
> >     coll
> >   )
> > )
>
> I think this basically equivalent to the juxt solution. Besides your
> are using sequence, where juxt uses vectors directly. Maybe that is a
> bit faster? Dunno.
>
> Stylistic: you should not put the closing parens on dedicated lines.
> They are normally collected on the last line. While this is only a
> style issue, you should get used to it, since 99.9% of all code at in
> the wild will use that style...
>
> > Interestingly enough replacing map with eager-map in multi-filter
> > definition gives very insignificant boost in perf (less than 10%), so
> > I've decided to leave it as is.
> > May be there are improvements possible to my emap definition?
>
> > (defn emap [f c1 c2]
> >   (loop [s1 (seq c1) s2 (seq c2) res [] ]
> >     (if (and s1 s2)
> >       (recur (seq (rest s1)) (seq (rest s2)) (conj res (f (first s1)
> > (first s2))))
> >       res)))
>
> Use next instead of the seq-rest combination.
>
> Sincerely
> Meikel
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to