NAME
Util::Underscore::ListUtils - Interface to List::Util and List::MoreUtils
VERSION
version v1.4.2
FUNCTION REFERENCE
$scalar = _::reduce { BLOCK } @list
-
wrapper for
List::Util::reduce
$bool = _::any { PREDICATE } @list
-
wrapper for
List::Util::any
$bool = _::all { PREDICATE } @list
-
wrapper for
List::Util::all
$bool = _::none { PREDICATE } @list
-
wrapper for
List::Util::none
$scalar = _::first { PREDICATE } @list
-
wrapper for
List::MoreUtils::first_value
$int = _::first_index { PREDICATE } @list
-
wrapper for
List::MoreUtils::first_index
$scalar = _::last { PREDICATE } @list
-
wrapper for
List::MoreUtils::last_value
$int = _::last_index { PREDICATE } @list
-
wrapper for
List::MoreUtils::last_index
$num = _::max @list
$str = _::max_str @list
-
wrappers for
List::Util::max
andList::Util::maxstr
, respectively. $num = _::min @list
$str = _::min_str @list
-
wrappers for
List::Util::min
andList::Util::minstr
, respectively. $scalar = _::max_by { BLOCK } @list
@list = _::max_by { BLOCK } @list
$scalar = _::max_str_by { BLOCK } @list
@list = _::max_str_by { BLOCK } @list
-
Finds the maximum element(s). However, not the elements themselves but the value returned by the code block is used for sorting. This makes it unnecessary to sort with a Schwartzian Transform.
This function is context dependent. In void context, it will return immediately.
The
max_by
variant compares sorting keys numerically, whereasmax_str_by
uses string comparison.{ BLOCK }: the sorting key code block. The current element will be aliased to
$_
inside the code block. The code inside the block should have no side effects, because it's not guaranteed how often the block will be executed.@list: the list from which the maximum element is to be found
returns: In scalar context: returns the first maximum element, or
undef
if no elements are found. In list context: returns the maximum elements, or the empty list of no elements are found. The maximum elements are returned in order. $scalar = _::min_by { BLOCK } @list
@list = _::min_by { BLOCK } @list
$scalar = _::min_str_by { BLOCK } @list
@list = _::min_str_by { BLOCK } @list
-
See
_::max_by
and_::max_str_by
. These functions work equivalently, except that they return the minimum element(s). $num = _::sum 0, @list
-
wrapper for
List::Util::sum
$num = _::product @list
-
wrapper for
List::Util::product
%kvlist = _::pairgrep { PREDICATE } %kvlist
-
wrapper for
List::Util::pairgrep
($k, $v) = _::pairfirst { PREDICATE } %kvlist
-
wrapper for
List::Util::pairfirst
%kvlist = _::pairmap { BLOCK } %kvlist
-
wrapper for
List::Util::pairmap
@list = _::shuffle @list
-
wrapper for
List::Util::shuffle
$iter = _::natatime $size, @list
-
wrapper for
List::MoreUtils::natatime
@list = _::zip \@array1, \@array2, ...
-
wrapper for
List::MoreUtils::zip
Unlike
List::MoreUtils::zip
, this function directly takes array references, and not array variables. It still uses the same implementation. This change makes it easier to work with anonymous arrayrefs, or other data that isn't already inside a named array variable. @list = _::uniq @list
-
wrapper for
List::MoreUtils::uniq
=
@list = _::uniq_by { KEY } @list
Discards duplicate values, using a key function to determine equality. This can e.g. be used to deduplicate a set of objects, using the result of some method call to determine whether they're equivalent.
{ KEY }: The function to produce an equality key. When called, the current element is passed in via the
$_
variable. This function must return a value that can be used as a hash key, i.e. a string.@list: A list of values to deduplicate.
returns: A list containing the first value of each key. In scalar context, returns the number of unique elements in the list.
%hash = _::classify { KEY } @list
-
Categorizes the input items according to the provided key function.
The behavior in void context is undefined.
{ KEY }: A key function returning a category name. The current item is passed in via
$_
. The return value must be usable as a hash key, i.e. be a string.@list: The list of items to classify.
returns: A key-value-list of classified items, where each key is the category name, and each value is an array ref of items. In scalar context, a hashref of arrayrefs is returned instead, which prevents unnecessary copies.
@list = _::part { INDEX_FUNCTION } @list
-
wrapper for
List::MoreUtils::part
$iter = _::each_array \@array1, \@array2, ...
-
wrapper for
List::MoreUtils::each_arrayref
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/latk/p5-Util-Underscore/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
Lukas Atkinson (cpan: AMON) <amon@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Lukas Atkinson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.