Sort a
NonEmpty on a user-supplied projection of its elements.
See
sortOn for more detailed information.
Examples
>>> sortOn fst $ (2, "world") :| [(4, "!"), (1, "Hello")]
(1,"Hello") :| [(2,"world"),(4,"!")]
>>> sortOn length $ "jim" :| ["creed", "pam", "michael", "dwight", "kevin"]
"jim" :| ["pam","creed","kevin","dwight","michael"]
Performance notes
This function minimises the projections performed, by materialising
the projections in an intermediate list.
For trivial projections, you should prefer using
sortBy with
comparing, for example:
>>> sortBy (comparing fst) $ (3, 1) :| [(2, 2), (1, 3)]
(1,3) :| [(2,2),(3,1)]
Or, for the exact same API as
sortOn, you can use `sortBy .
comparing`:
>>> (sortBy . comparing) fst $ (3, 1) :| [(2, 2), (1, 3)]
(1,3) :| [(2,2),(3,1)]
sortWith is an alias for `sortBy . comparing`.
Since: 4.20.0.0