Wanna play golf? (defn filter-collecting [predicate collector & lists] (lazy-seq (loop [lists lists out []] (if (empty? (first lists)) (reverse out) (let [heads (map first lists)] (if (apply predicate heads) (recur (map rest lists) (cons (apply collector heads) out)) (recur (map rest lists) out)))))))
;; usage: ;; (filter-collecting ;; (fn [x y] (< x y)) ;; (fn [x y] (+ x y)) ;; '(1 7 3 9) ;; '(5 5 5 5)) ;; ==> (6 8) More detail at: http://blog.fogus.me/2009/08/14/clojure-golf-episode-1/ -m --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---