Let's play !
First:
Slight variation on Chouser's second version (presuming it should be faster
for the token comparison, which is evil - presuming performance instead of
testing it ! ) :
(let [x (Object.)]
(defn filter-collecting [p c & l]
(remove #(identical? % x)
(apply map #(if (apply p %&) (apply c %&) x) l))))
Second:
Very short, certainly not (?) as efficient:
(defn filter-collecting [p c & l] (apply mapcat #(when (apply p %&) [(apply
c %&)]) l))
2009/8/14 Chouser <[email protected]>
>
> On Fri, Aug 14, 2009 at 3:43 PM, Fogus<[email protected]> wrote:
> >
> > Wanna play golf?
>
> Yes I do!
>
> (defn filter-collecting [p c & l]
> (remove nil? (apply map #(when % (apply c %&)) (apply map p l) l)))
>
> But that gives incorrect results if c ever returns nil, so
> I guess it should be:
>
> (defn filter-collecting [p c & l]
> (let [x `x#]
> (remove #(= % x)
> (apply map #(if % (apply c %&) x)
> (apply map p l)
> l))))
>
> But that's getting pretty ugly, so maybe this is better:
>
> (defn filter-collecting [p c & l]
> (map #(apply c %)
> (filter #(apply p %)
> (apply map vector l))))
>
> Nothing terribly inventive there. I'll have to get my
> satisfaction from being first. I'm sure the best are yet to
> come...
>
> --Chouser
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---