NAME

FP::Array_sort - 'sensible' sorting setup

SYNOPSIS

    use FP::Array_sort; # for `array_sort`, `on`, and `cmp_complement`

    use FP::Ops 'number_cmp'; use FP::Array ':all'; use FP::Equal 'is_equal';
    is_equal array_sort([[10, 'a'], [15, 'b'], [-3, 'c']],
                        on *array_first, *number_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, \&number_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, \&number_cmp)

or if the comparison function already exists:

    $numbers->sort (\&number_cmp)

SEE ALSO

FP::Ops, FP::Combinators

NOTE

This is alpha software! Read the status section in the package README or on the website.