NAME
    "List::UtilsBy" - higher-order list utility functions

SYNOPSIS
     use List::UtilsBy qw( nsortby minby );

     use File::stat qw( stat );
     my @files_by_age = nsortby { stat($_)->mtime } @files;

     my $shortest_name = minby { length } @names;

DESCRIPTION
    This module provides a number of list utility functions, all of which
    take an initial code block to control their behaviour. They are
    variations on similar core perl or "List::Util" functions of similar
    names, but which use the block to control their behaviour. For example,
    the core Perl function "sort" takes a list of values and returns them,
    sorted into order by their string value. The "sortby" function sorts
    them according to the string value returned by the extra function, when
    given each value.

     my @names_sorted = sort @names;

     my @people_sorted = sortby { $_->name } @people;

FUNCTIONS
  @vals = sortby { KEYFUNC } @vals
    Returns the list of values sorted according to the string values
    returned by the "KEYFUNC" block or function. A typical use of this may
    be to sort objects according to the string value of some accessor, such
    as

     sortby { $_->name } @people

    The key function is called in scalar context, being passed each value in
    turn as both $_ and the only argument in the parameters, @_. The values
    are then sorted according to string comparisons on the values returned.

    This is equivalent to

     sort { $a->name cmp $b->name } @people

    except that it guarantees the "name" accessor will be executed only once
    per value.

  @vals = nsortby { KEYFUNC } @vals
    Equivalent to "sortby" but compares its key values numerically.

  $optimal = maxby { CMPFUNC } @vals
    Returns the (first) value from @vals that gives the numerically largest
    result from the comparison function.

     my $tallest = maxby { $_->height } @people

     use File::stat qw( stat );
     my $newest = maxby { stat($_)->mtime } @files;

    In the case of a tie, the first value to give the largest result is
    returned. To obtain the last, reverse the input list.

     my $longest = maxby { length $_ } reverse @strings;

    If called on an empty list, "undef" is returned.

  $optimal = minby { CMPFUNC } @vals
    Equivalent to "maxby" but returns the first value which gives the
    numerically smallest result from the comparison function.

  @vals = uniqby { KEYFUNC } @vals
    Returns a list of the subset of values for which the key function block
    returns unique values. The first value yielding a particular key is
    chosen, subsequent values are rejected.

     my @some_fruit = uniqby { $_->colour } @fruit;

    To select instead the last value per key, reverse the input list. If the
    order of the results is significant, don't forget to reverse the result
    as well:

     my @some_fruit = reverse uniqby { $_->colour } reverse @fruit;

TODO
    *   XS implementations

        These functions are currently all written in pure perl. Some at
        least, may benefit from having XS implementations to speed up their
        logic.

    *   List-context "maxby" and "minby"

        Consider whether "maxby" and "minby" ought to return a list of all
        the optimal values, in the case of a tie.

    *   Merge into List::Util or List::MoreUtils

        This module shouldn't really exist. The functions should instead be
        part of one of the existing modules that already contain many list
        utility functions. Having Yet Another List Utilty Module just
        worsens the problem.

        I have attempted to contact the authors of both of the above
        modules, to no avail; therefore I decided it best to write and
        release this code here anyway so that it is at least on CPAN. Once
        there, we can then see how best to merge it into an existing module.

AUTHOR
    Paul Evans <leonerd@leonerd.org.uk>

