Okay, your longer post makes more sense. Then is the seq (1 :a a) guaranteed? How do I know that I won't get (2 :b b), (1 :b c), etc? What if I want a specific combination instead? I've had to actually code this specific problem, and I found that using group-by & some secondary mapping operation was the only thing that gave me the flexibility I needed (manufacturing is fun!).
Sean On Feb 22, 2:19 pm, Michał Marczyk <michal.marc...@gmail.com> wrote: > On 22 February 2010 19:59, Sean Devlin <francoisdev...@gmail.com> wrote: > > > Generally when you have a "*-by" fn, you return the a sequence of > > original values, not the mapped values (e.g. sort-by) > > Which is precisely what both versions of distinct-by are doing. They > return a sequence of values taken from the original collection, > although determining which values those are involves calling a > user-supplied function and performing a bunch of comparisons of the > value thus obtained to values obtained from calls to said function at > previous steps. > > E.g. (I'm repeating an example; this uses the second version of distinct-by): > > (distinct-by class [1 2 3 :a :b :c 'a 'b 'c]) > ; => (1 :a a) > > whereas > > (distinct (map class [1 2 3 :a :b :c 'a 'b 'c]) > ; => (java.lang.Integer clojure.lang.Keyword clojure.lang.Symbol) > > The primes one-liner using the nubBy-like version returns a list of > numbers, whereas the "mapped values" are Booleans. > > Sincerely, > Michał -- 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