Take a look at sort/sort-by in core.  That would be starting point for
fn style.

On Feb 23, 12:44 pm, Michał Marczyk <michal.marc...@gmail.com> wrote:
> On 23 February 2010 00:17, Eugen Dück <eu...@dueck.org> wrote:
>
> > Rather than having a separate fn 'distinct-by' in addition to the
> > existing 'distinct', which, apart from the hard-coded keyfn would be
> > EXACTLY the same, shouldn't we just generalize distinct to default to
> > hard-coded if no keyfn is specified? (Btw I'm not considering my other
> > suggestion to allow the set to be passed in here, which I personally
> > like, but also understand can be seen as unorthogonal)
>
> > And this is not only true for distinct-by, it's true for some of the
> > other * / *-by pairs. It just seems this should be generalized in
> > order not to duplicate code for these cases. If we copy-and-paste
> > code, what's the justification? I'd say orthogonality is an argument
> > against copy-and-paste. Do we copy and paste rather than generalize in
> > order to have distinct a little bit faster due to it being hard-coded?
>
> That seems like a very good point to me! Especially if
> clojure.core/identity could be inlined by the compiler (which I
> thought it is, although now that I look the inlining-related entries
> are missing from (meta #'identity)), both distinct and sort could be
> arity overloaded to accept an optional keyfn or not (sort would
> basically have to be replaced with sort-by + an added unary variant
> with defaults for both keyfn and comparator).
>
> Then perhaps we could reuse the *-by names for Haskell-style binary
> predicate-based versions. Haskell's sortBy, groupBy, nubBy all take
> binary functions to decide ordering / equality of pairs of elements
> from the input sequence... That's enables some neat code sometimes,
> cf. the primes on liner. How about that?
>
> 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

Reply via email to