Constructor
new PersistentArray(n)
Creates an uninitialized persistent array of size n.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
n |
Integer
|
The initial array size. |
Members
length
- Source:
Methods
(static) from(arrayLike) → {PersistentArray}
Create and return a persistent array from an array-like.
Mutation to the elements of the original array-like WILL affect the
persistent array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arrayLike |
ArrayLike
|
Array-like object to be copied. |
Returns:
- Type:
-
PersistentArray
A persistent array with the same elements as
the given array-like object.
(static) of(…elements)
Create and return a persistent array with the given elements.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
elements |
any
|
<repeatable> |
Desired elements. |
at(index) → {any}
Returns the element at the given index.
Mutation on the returned element WILL affect the persistent array. If
mutation is absolutely needed (hint: usually it's not), make sure you
clone the returned object beforehand and then update the array.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
index |
Integer
|
Array index. |
Throws:
-
Index must be positive and bounded by array size.
- Type
-
RangeError
Returns:
- Type:
-
any
The object stored at the given position.
toArray() → {Array.<any>}
Reroots the context tree and returns the cache for this array.
- Source:
Returns:
- Type:
-
Array.<any>
Cache for the array.
toString() → {String}
Returns a string representation of the array and its elements.
- Source:
Returns:
- Type:
-
String
The array as a string.
update(index, value) → {PersistentArray}
Returns a new version of the array updated with the given value at the
given index.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
index |
Integer
|
Array index at which to update. |
value |
any
|
The value to be put into the array. |
Throws:
-
Index must be positive and bounded by array size.
- Type
-
RangeError
Returns:
- Type:
-
PersistentArray
A persistent array with the same elements as
the original, except that it has an updated value at the given index.