The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Hydrogen::Topic::ArrayRef - functions from Hydrogen::ArrayRef applied to $_

VERSION

This documentation is for Hydrogen::Topic::ArrayRef 0.016, which is based on Sub::HandlesVia::HandlerLibrary::Array 0.037.

FUNCTIONS

Each function implicitly operates on $_, expecting it to be a reference to an array.

accessor( $index, $value? )

Operates on $_, which must be a reference to an array.

Arguments: Int, Optional[Any].

Acts like get if given one argument, or set if given two arguments.

all()

Operates on $_, which must be a reference to an array.

All elements in the array, in list context.

all_true( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::all().

any( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::any().

apply( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Executes the coderef (which should modify $_) against each element of the array; returns the resulting array in list context.

clear()

Operates on $_, which must be a reference to an array.

Empties the array.

count()

Operates on $_, which must be a reference to an array.

The number of elements in the referenced array.

delete( $index )

Operates on $_, which must be a reference to an array.

Arguments: Int.

Removes the indexed element from the array and returns it. Elements after it will be "moved up".

elements()

Operates on $_, which must be a reference to an array.

All elements in the array, in list context. (Essentially the same as all.)

first( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::first().

first_index( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::MoreUtils::first_index().

flatten()

Operates on $_, which must be a reference to an array.

All elements in the array, in list context. (Essentially the same as all.)

flatten_deep( $depth? )

Operates on $_, which must be a reference to an array.

Arguments: Optional[Int].

Flattens the arrayref into a list, including any nested arrayrefs. (Has the potential to loop infinitely.)

for_each( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Function which executes the coderef on each element of the array. The coderef will be passed two values: the element and its index.

for_each_pair( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Function which executes the coderef on each pair of elements in the array. The coderef will be passed the two elements.

get( $index )

Operates on $_, which must be a reference to an array.

Arguments: Int.

Returns a single element from the array by index.

grep( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like grep from perlfunc.

head( $count )

Operates on $_, which must be a reference to an array.

Arguments: Int.

Returns the first $count elements of the array in list context.

insert( $index, $value )

Operates on $_, which must be a reference to an array.

Arguments: Int, Any.

Inserts a value into the array with the given index. Elements after it will be "moved down".

is_empty()

Operates on $_, which must be a reference to an array.

Boolean indicating if the referenced array is empty.

join( $with? )

Operates on $_, which must be a reference to an array.

Arguments: Optional[Str].

Returns a string joining all the elements in the array; if $with is omitted, defaults to a comma.

map( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like map from perlfunc.

max()

Operates on $_, which must be a reference to an array.

Like List::Util::max().

maxstr()

Operates on $_, which must be a reference to an array.

Like List::Util::maxstr().

min()

Operates on $_, which must be a reference to an array.

Like List::Util::min().

minstr()

Operates on $_, which must be a reference to an array.

Like List::Util::minstr().

natatime( $n, $callback? )

Operates on $_, which must be a reference to an array.

Arguments: Int, Optional[CodeRef].

Given just a number, returns an iterator which reads that many elements from the array at a time. If also given a callback, calls the callback repeatedly with those values.

not_all_true( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::notall().

pairfirst( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::pairfirst().

pairgrep( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::pairgrep().

pairkeys()

Operates on $_, which must be a reference to an array.

Like List::Util::pairkeys().

pairmap( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::pairmap().

pairs()

Operates on $_, which must be a reference to an array.

Like List::Util::pairs().

pairvalues()

Operates on $_, which must be a reference to an array.

Like List::Util::pairvalues().

pick_random( $count )

Operates on $_, which must be a reference to an array.

Arguments: Optional[Int].

If no $count is given, returns one element of the array at random. If $count is given, creates a new array with that many random elements from the original array (or fewer if the original array is not long enough) and returns that as an arrayref or list depending on context

pop()

Operates on $_, which must be a reference to an array.

Removes the last element from the array and returns it.

print( $fh?, $with? )

Operates on $_, which must be a reference to an array.

Arguments: Optional[FileHandle], Optional[Str].

Prints a string joining all the elements in the array; if $fh is omitted, defaults to STDOUT; if $with is omitted, defaults to a comma.

product()

Operates on $_, which must be a reference to an array.

Like List::Util::product().

push( @values )

Operates on $_, which must be a reference to an array.

Adds elements to the end of the array.

reduce( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::reduce().

reductions( $coderef )

Operates on $_, which must be a reference to an array.

Arguments: CodeRef.

Like List::Util::reductions().

reset()

Operates on $_, which must be a reference to an array.

Resets the original value to its default value, or an empty arrayref if it has no default.

reverse()

Operates on $_, which must be a reference to an array.

Returns the reversed array in list context.

sample( $count )

Operates on $_, which must be a reference to an array.

Arguments: Int.

Like List::Util::sample().

set( $index, $value )

Operates on $_, which must be a reference to an array.

Arguments: Int, Any.

Sets the element with the given index to the supplied value.

shallow_clone()

Operates on $_, which must be a reference to an array.

Creates a new arrayref with the same elements as the original.

shift()

Operates on $_, which must be a reference to an array.

Removes an element from the start of the array and returns it.

shuffle()

Operates on $_, which must be a reference to an array.

Returns the array in a random order; can be called in list context or scalar context and will return an arrayref in the latter case.

shuffle_in_place()

Operates on $_, which must be a reference to an array.

Rearranges the array in a random order, and changes the original value to point to the new order.

sort( $coderef? )

Operates on $_, which must be a reference to an array.

Arguments: Optional[CodeRef].

Like sort from perlfunc.

sort_in_place( $coderef? )

Operates on $_, which must be a reference to an array.

Arguments: Optional[CodeRef].

Like sort from perlfunc, but changes the original value to point to the newly sorted array.

splice( $index, $length, @values )

Operates on $_, which must be a reference to an array.

Like splice from perlfunc.

sum()

Operates on $_, which must be a reference to an array.

Like List::Util::sum0().

tail( $count )

Operates on $_, which must be a reference to an array.

Arguments: Int.

Returns the last $count elements of the array in list context.

uniq()

Operates on $_, which must be a reference to an array.

Returns the array filtered to remove duplicates; can be called in list context or scalar context and will return an arrayref in the latter case.

uniq_in_place()

Operates on $_, which must be a reference to an array.

Filters the array to remove duplicates, and changes the original value to point to the filtered array.

uniqnum()

Operates on $_, which must be a reference to an array.

Returns the array filtered to remove duplicates numerically; can be called in list context or scalar context and will return an arrayref in the latter case.

uniqnum_in_place()

Operates on $_, which must be a reference to an array.

Filters the array to remove duplicates numerically, and changes the original value to point to the filtered array.

uniqstr()

Operates on $_, which must be a reference to an array.

Returns the array filtered to remove duplicates stringwise; can be called in list context or scalar context and will return an arrayref in the latter case.

uniqstr_in_place()

Operates on $_, which must be a reference to an array.

Filters the array to remove duplicates stringwise, and changes the original value to point to the filtered array.

unshift( @values )

Operates on $_, which must be a reference to an array.

Adds an element to the start of the array.

EXPORT

No functions are exported by this module by default. To import them all (this is usually a bad idea), use:

    use Hydrogen::Topic::ArrayRef -all;

To import a particular function, use:

    use Hydrogen::Topic::ArrayRef 'all_true';

To rename functions:

    use Hydrogen::Topic::ArrayRef 'all_true' => { -as => 'myfunc' };

On Perl 5.37.2+, you can import lexically:

    use Hydrogen::Topic::ArrayRef -lexical, 'all_true';

See Exporter::Tiny::Manual::Importing for more hints on importing.

BUGS

Please report any bugs to http://github.com/tobyink/p5-hydrogen/issues.

SEE ALSO

Hydrogen, Hydrogen::ArrayRef, Hydrogen::Array, Hydrogen::Curry::ArrayRef, Sub::HandlesVia::HandlerLibrary::Array, List::Util, List::MoreUtils.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2022 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.