fileability/mutton — Issue #6: Sorting
Author: fileability
Created: 2012-03-10 01:23:45+00:00
State: open
Labels: enhancement

Quite a large hole in mutton's functionality.

* The default sort should be stable. Most of the time, unstable sorting algorithms are a premature optimization, and not worth the debugging difficulties they entail.

Sorting should be *comparator focused*. i.e. we provide tools for building comparators, everything follows from that.

NSArray* sort(Iter it);
NSArray* sortBy(Iter it, NSComparator cmp);

Operations on comparators:

* **Composition**. For a comparator `f` and a comparator `g`, the composition of `f` and `g` gives a comparator that first tries `f`, then tries `g` (note that this is the reverse of usual function composition).
* **By a selector**. Return a comparator that captures performing a given selector on an object. For example, `compareBySel(@selector(compare:))` would be the default comparator.
* **Through a block**. First apply a `Mapping`, and use that for the comparator. For instance `compareThrough(byKey(@"name"))` would sort an list of dictionaries by their *name* key.
* **Through a selector**. Same as `compareThrough(bySel(sel))`