NAME
FP::Array_sort - 'sensible' sorting setup
SYNOPSIS
use FP::Array_sort; # for `array_sort` and `on`
use FP::Ops 'real_cmp'; use FP::Array ':all'; use FP::Equal 'is_equal';
is_equal array_sort([[10, 'a'], [15, 'b'], [-3, 'c']],
on *array_first, \&real_cmp),
[[-3, 'c'], [10, 'a'], [15, 'b']];
DESCRIPTION
Perl's sort is rather verbose and uses repetition of the accessor code:
sort { &$foo ($a) <=> &$foo ($b) } @$ary
Abstracting the repetition of the accessor as a function (`on`) and wrapping sort as a higher-order function makes it more straight-forward:
array_sort $ary, on ($foo, \&real_cmp)
In method interfaces the need becomes more obvious: if $ary is one of the FP sequences (FP::PureArray, FP::List, FP::StrictList, FP::Stream) that supports `sort` (TODO) then:
$s->sort (on $foo, \&real_cmp)
or if the comparison function already exists:
$numbers->sort (\&real_cmp)
SEE ALSO
NOTE
This is alpha software! Read the status section in the package README or on the website.