ReadOnlyArray
is an abstract over an ordinary Array
which only exposes
APIs that don't modify the instance, hence "read-only".
Note that this doesn't necessarily mean that the instance is immutable.
Other code holding a reference to the underlying Array
can still modify it,
and the reference can be obtained with a cast
.
Methods
indexOf(x:T, ?fromIndex:Int):Int
Returns position of the first occurrence of x
in this
Array, searching front to back.
If x
is found by checking standard equality, the function returns its index.
If x
is not found, the function returns -1.
If fromIndex
is specified, it will be used as the starting index to search from,
otherwise search starts with zero index. If it is negative, it will be taken as the
offset from the end of this
Array to compute the starting index. If given or computed
starting index is less than 0, the whole array will be searched, if it is greater than
or equal to the length of this
Array, the function returns -1.
join(sep:String):String
Returns a string representation of this
Array, with sep
separating
each element.
The result of this operation is equal to Std.string(this[0]) + sep +
Std.string(this[1]) + sep + ... + sep + Std.string(this[this.length-1])
If this
is the empty Array []
, the result is the empty String ""
.
If this
has exactly one element, the result is equal to a call to
Std.string(this[0])
.
If sep
is null, the result is unspecified.
slice(pos:Int, ?end:Int):Array<T>
Creates a shallow copy of the range of this
Array, starting at and
including pos
, up to but not including end
.
This operation does not modify this
Array.
The elements are not copied and retain their identity.
If end
is omitted or exceeds this.length
, it defaults to the end of
this
Array.
If pos
or end
are negative, their offsets are calculated from the
end of this
Array by this.length + pos
and this.length + end
respectively. If this yields a negative value, 0 is used instead.
If pos
exceeds this.length
or if end
is less than or equals
pos
, the result is []
.
toString():String
Returns a string representation of this
Array.
The result will include the individual elements' String representations
separated by comma. The enclosing [ ] may be missing on some platforms,
use Std.string()
to get a String representation that is consistent
across platforms.