Add sorting (targeting dev)

Retargeting #351 to `dev` branch.

The unresolved question is whether `sortBy` should take an `a -> comparable` or `a -> a -> Order`.