Util::Underscore::ListUtils - Interface to List::Util and List::MoreUtils
version v1.4.2
$scalar = _::reduce { BLOCK } @list
wrapper for List::Util::reduce
List::Util::reduce
$bool = _::any { PREDICATE } @list
wrapper for List::Util::any
List::Util::any
$bool = _::all { PREDICATE } @list
wrapper for List::Util::all
List::Util::all
$bool = _::none { PREDICATE } @list
wrapper for List::Util::none
List::Util::none
$scalar = _::first { PREDICATE } @list
wrapper for List::MoreUtils::first_value
List::MoreUtils::first_value
$int = _::first_index { PREDICATE } @list
wrapper for List::MoreUtils::first_index
List::MoreUtils::first_index
$scalar = _::last { PREDICATE } @list
wrapper for List::MoreUtils::last_value
List::MoreUtils::last_value
$int = _::last_index { PREDICATE } @list
wrapper for List::MoreUtils::last_index
List::MoreUtils::last_index
$num = _::max @list
$str = _::max_str @list
wrappers for List::Util::max and List::Util::maxstr, respectively.
List::Util::max
List::Util::maxstr
$num = _::min @list
$str = _::min_str @list
wrappers for List::Util::min and List::Util::minstr, respectively.
List::Util::min
List::Util::minstr
$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, whereas max_str_by uses string comparison.
max_by
max_str_by
{ 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.
undef
$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).
_::max_by
_::max_str_by
$num = _::sum 0, @list
wrapper for List::Util::sum
List::Util::sum
$num = _::product @list
wrapper for List::Util::product
List::Util::product
%kvlist = _::pairgrep { PREDICATE } %kvlist
wrapper for List::Util::pairgrep
List::Util::pairgrep
($k, $v) = _::pairfirst { PREDICATE } %kvlist
wrapper for List::Util::pairfirst
List::Util::pairfirst
%kvlist = _::pairmap { BLOCK } %kvlist
wrapper for List::Util::pairmap
List::Util::pairmap
@list = _::shuffle @list
wrapper for List::Util::shuffle
List::Util::shuffle
$iter = _::natatime $size, @list
wrapper for List::MoreUtils::natatime
List::MoreUtils::natatime
@list = _::zip \@array1, \@array2, ...
wrapper for List::MoreUtils::zip
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::MoreUtils::uniq
=@list = _::uniq_by { KEY } @list
@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
List::MoreUtils::part
$iter = _::each_array \@array1, \@array2, ...
wrapper for List::MoreUtils::each_arrayref
List::MoreUtils::each_arrayref
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.
Lukas Atkinson (cpan: AMON) <amon@cpan.org>
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.
To install Util::Underscore, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Util::Underscore
CPAN shell
perl -MCPAN -e shell install Util::Underscore
For more information on module installation, please visit the detailed CPAN module installation guide.