Listicles
A collection of helper methods to make working with Arrays a little easier.
method drop
method drop(
Int $count,
Bool :$all_or_nothing = Bool::False
) returns Array:DReturns a new list without the first or last $count elements of the array depending on if count is positive or negative.
method includes
method includes(
$x,
Bool :$ducktyped = Bool::False
) returns BoolTests if the array includes the item passed in. Set ducktyped to True for ducktyped matches. For example "4" will match 4 with ducktyped matches.
method is-empty
method is-empty() returns BoolTests if the array is empty
method split-by
method split-by(
Int $size,
Bool :$only_perfect_splits = Bool::False
) returns ArraySplits a Array into an array of arrays of the specified length (or smaller). If the array is not evenly divisble then the last array will contain the remainder. If only_perfect_splits is set to True it will throw an exception if the Array is not evenly divisible by $size.
method take
method take(
Int $count,
Bool :$all_or_nothing = Bool::False
) returns Array:DTake returns count is positive or negative. If there are fewer elements than $count it will return whatever is available. Set all_or_nothing to True and it will throw an exception if there are insufficient elements.
method to-hash
method to-hash(
:$one_based = Bool::False
) returns Hash:Dcreates a hash with the stringified index of each element as its key. Set one_based to True to have it start the keys at 1 instead of 0. Example: ["foo", "bar"] -> {"0"=>"foo", "1"=>"bar"}