Name

SPVM::Immutable::FloatList - Immutable float Array

Description

The Immutable::FloatList class has methods to manipulate an immutable float array.

Usage

use Immutable::FloatList;

# Create a float list
my $list = Immutable::FloatList->new;
my $list = Immutable::FloatList->new([(float)1, 2, 3]);

# Create a float list with array length
my $list = Immutable::FloatList->new_len(10);

# Get list length
my $length = $list->length;

# Get value.
my $element = $list->get(2);

# Convert list to array.
my $array = $list->to_array;

Fields

length

has length : ro int;

Gets the length field.

This field is the length of the elements of the list.

Class Methods

new

static method new : Immutable::FloatList ($array : float[] = undef);

Create a new Immutable::FloatList 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 elements of the array are copied to the values of the the created array.

Examples:

my $list = Immutable::FloatList->new;
my $list = Immutable::FloatList->new([(float)1, 2, 3]);

new_len

static method new_len : Immutable::FloatList ($length : int);

Creates a new Immutable::FloatList object with the $length.

The $length must be greater than or equal to 0. Otherwize an exception is thrown.

Instance Methods

get

method get : float ($index : int);

Gets the element of the position of the $index.

Exceptions:

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.

to_array

method to_array : float[] ();

Converts the list to an array.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License