On Sun, Apr 3, 2011 at 3:23 AM, Stefan Rohlfing <stefan.rohlf...@gmail.com> wrote: > @ Ken, Andreas > > Thank you for your nice implementations! > > As far as I can see, there are two main methods of comparing adjacent items > of a list: > > 1) Take the first item of a coll. Compare the remaining items with an offset > of 1: > (map f coll (rest coll)) > ;; apply some sort of filter > > 2) Take the first and the second item of a coll. Test if both items exists > and then compare: > (let [x (first coll), y (second coll)] > (and x y (= (f x) (f y)))) > > The first method works for take-by, but not for drop-while (or so I think).
I don't. :) (defn drop-by [f coll] (let [fs (map f coll) ps (map = fs (rest fs)) zs (map list ps (rest coll))] (map second (drop-while first zs)))) user=> (drop-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42]) (2 99 103 42) I especially like the symmetry of using take-while for the one and drop-while for the other, under the hood. -- 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