forked from clojure/clojurescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Comparators
relevance edited this page Jul 14, 2011
·
1 revision
- comparison fn: boolean valued fn
- comparator: -/0/+ valued fn
- comp: either of the above
(These terms are not good, but I wanted one-word ways to talk about each idea below.)
- different underlying platform API
- Java expects comparators (instances of Comparator)
- goog expects comparison fns
- users care about composability, not abstractions
- Clojure fns can be either comparators or comparison fns
- implementation via wrapper in AFn's Comparable implementation
- newly created fns just work
- protocols not helpful for implementation
- if fns were some kind of IComparable, would just have to convert back to plain fns for goog to use them
- don't see any obvious performance win
- protocols not helpful for consumers
- making comp writers implement a protocol is just introducing a Javaism
- usage
- no Comparable protocol
- just use fns
- implementation
- do AFn's wrapping work in a helper fn that wraps user fns inside sort
I am pretty confident about the usage. Less confident about implementation, but this can be improved later.