SPVM::Immutable::StringList - Immutable string array
use Immutable::StringList; # Create a string list my $list = Immutable::StringList->new; my $list = Immutable::StringList->new(["abc", "def", "ghi"]); # Create a string list my $list = Immutable::StringList->new_len(10); # Get list length my $length = $list->length; # Get string value. my $element = $list->get(2); # Convert Immutable::StringList to string array. my $array = $list->to_array;
The Immutable::StringList class has methods to manipulate an immutable string array.
has length : ro int;
Gets the length field.
length
This field is the length of the elements of the list.
static method new : Immutable::StringList ($array = undef : string[]);
Create a new Immutable::StringList object using "new_len".
The passed length to "new_len" is the length of the array. If the array is undef, the length is 0.
The each string of the array is copied and to each value of the the created array and each string is made read-only.
Examples:
my $list = Immutable::StringList->new; my $list = Immutable::StringList->new(["abc", "def", "ghi"]);
static method new_len : Immutable::StringList ($length : int);
Creates a new Immutable::StringList object with the $length.
Exceptions:
The $length must be greater than or equal to 0. Otherwize an exception is thrown.
method get : string ($index : int);
Gets the element of the position of the $index.
The $index must be greater than or equal to 0. Otherwize an exception is thrown.
The $index must be less than the length of the $list. Otherwize an exception is thrown.
method to_array : string[] ();
Converts the list to an array.
Copyright (c) 2023 Yuki Kimoto
MIT License
To install SPVM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPVM
CPAN shell
perl -MCPAN -e shell install SPVM
For more information on module installation, please visit the detailed CPAN module installation guide.