2009/10/14 Meikel Brandmeyer <m...@kotka.de> > > Hi, > > On Oct 14, 8:06 am, Mark Tomko <mjt0...@gmail.com> wrote: > > > (defn matching-elements2 [coll1 coll2] > > (map first (filter #(let [[e1 e2] %] (= e1 e2)) (partition 2 > > (interleave coll1 coll2))))) > > > > Can anyone suggest an improved implementation of either > > implementation? > > I'm not sure it is improved, but it sure is another way: > > (defn matching-elements3 > [s1 s2] > (mapcat #(when (= %1 %2) [%1]) s1 s2)) >
Or, just to generalize a little bit more to any number of compared seqs: (def matching-elements4 (partial mapcat #(when (apply = %&) [%1]))) :-p --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---