operator: sort-by
description:
sort-by[op] sp
natural sort the given superposition with respect to the given operator
chomps any ',' chars, so you can sort by to-comma-numbers.
examples:
load pretty-print-table-of-australian-cities.sw
-- sort by area:
table[city, area, population, annual-rainfall] sort-by[area] "" |city list>
+-----------+------+------------+-----------------+
| city | area | population | annual-rainfall |
+-----------+------+------------+-----------------+
| Darwin | 112 | 120900 | 1714.7 |
| Adelaide | 1295 | 1158259 | 600.5 |
| Hobart | 1357 | 205556 | 619.5 |
| Melbourne | 1566 | 3806092 | 646.9 |
| Sydney | 2058 | 4336374 | 1214.8 |
| Perth | 5386 | 1554769 | 869.4 |
| Brisbane | 5905 | 1857594 | 1146.4 |
+-----------+------+------------+-----------------+
-- reverse sort by population:
table[city, area, population, annual-rainfall] reverse sort-by[population] "" |city list>
+-----------+------+------------+-----------------+
| city | area | population | annual-rainfall |
+-----------+------+------------+-----------------+
| Sydney | 2058 | 4336374 | 1214.8 |
| Melbourne | 1566 | 3806092 | 646.9 |
| Brisbane | 5905 | 1857594 | 1146.4 |
| Perth | 5386 | 1554769 | 869.4 |
| Adelaide | 1295 | 1158259 | 600.5 |
| Hobart | 1357 | 205556 | 619.5 |
| Darwin | 112 | 120900 | 1714.7 |
+-----------+------+------------+-----------------+
see also:
reverse, table
Home