List::MoreUtils::XS#
The compiled implementation of List::MoreUtils: the list functions List::Util does not have - junctions (any, all, none, notall, one and their _u variants that answer undef for an empty list), index and value searches from either end (firstidx, lastval, onlyres, …), slicing by a predicate (after, before_incl), iterators (each_array, natatime, slideatatime), merging (mesh, zip6, pairwise, arrayify), counting (uniq, singleton, duplicates, frequency, occurrences, mode), binary searches over sorted lists (bsearch, lower_bound, equal_range, binsert, bremove) and an in-place qsort.
This is a native implementation of List::MoreUtils::XS 0.430’s XS.xs; its List/MoreUtils/XS.pm is used unchanged, and List::MoreUtils, which picks it as its backend, comes from CPAN.
Synopsis#
use List::MoreUtils qw(firstidx pairwise natatime uniq);
my $i = firstidx { $_ eq 'b' } qw(a b c); # 1
my @s = pairwise { $a + $b } @x, @y;
my $it = natatime 3, 1 .. 10;
while (my @chunk = $it->()) { print "@chunk\n" }
my $n = uniq 1, 1, 2, undef, undef; # 3
Differences from upstream#
A block that is a compiled sub (
any \&Scalar::Util::blessed, ...) is called; perl jumps into it as if it were Perl code and crashes.minmaxover objects that overload only other operators, withfallback => 1, compares their numeric values as<=>would; perl crashes. An overloaded<=>that returns a string or a fraction is read as a number; perl reads an unrelated field and answers wrongly (the maximum of 3, 1, 2 comes out as 2).reduce_u,reduce_0andreduce_1leave the caller’s$_alone; perl overwrites it with the last index, which changes the current element of an enclosingfor (@array)and dies insidefor (1)with “Modification of a read-only value attempted”.frequencyno longer leaks a scalar per call when the list holds undef.An object that overloads
@{}over a hash or a scalar is read through its overloading byarrayify,mesh,zip6,listcmp,each_array,insert_afterandinsert_after_string; perl reads the hash as an array and crashes.An array with holes (
$a[5] = 1on an empty array) is read with undef in the holes byarrayify,each_array,insert_afterandinsert_after_string; perl crashes.Calling the iterator bodies
List::MoreUtils::XS::_array_iteratorand_slideatatime_iteratordirectly returns an empty list; perl crashes.