interface List<T>
A random accessible immutable sequence of values of type T. See the List documentation and the List API documentation
Companion namespace: List
Extends: FastIterable<T>
Implemented by: Empty<T>
, List.NonEmpty<T>
Type parameters
Name | Description |
---|---|
T | the value type |
const l1 = List.empty<string>()
const l2 = List.of(1, 3, 2)
Properties
context
The list context that acts as a factory for all related list instances.
context
isEmpty
Returns true if the collection is empty
isEmpty
length
Returns the number of values in the collection
length
Methods
[Symbol.iterator]
Returns a FastIterator
instance used to iterate over the values of this Iterable
.
[Symbol.iterator]
FastIterator
instance used to iterate over the values of this Iterable
.append
Returns the List with the given value
added to the end.
append
value
added to the end.assumeNonEmpty
Returns the same collection typed as non-empty.
assumeNonEmpty
collect
Returns a List containing the values resulting from applying given collectFun
to each value in this List.
collect
collectFun
to each value in this List.concat
Returns the List succeeded by the values from all given StreamSource
instances given in sources
.
concat
StreamSource
instances given in sources
.drop
Returns a List skipping the first given amount
elements of this List.
drop
amount
elements of this List.filter
Returns a List containing only those values within optionally given range
that satisfy given pred
predicate. If reversed
is true, the order of the values is reversed.
filter
range
that satisfy given pred
predicate. If reversed
is true, the order of the values is reversed.first
Returns the first value of the List, or the otherwise
value if the list is empty.
first
otherwise
value if the list is empty.flatMap
Returns a List containing the joined results of applying given flatMapFun
to each value in this List.
flatMap
flatMapFun
to each value in this List.forEach
Performs given function f
for each value of the List.
forEach
f
for each value of the List.get
Returns the value in the List at the given index
.
get
index
.insert
Returns the List with the given values
inserted at the given index
.
insert
values
inserted at the given index
.last
Returns the last value of the List, or the otherwise
value if the list is empty.
last
otherwise
value if the list is empty.map
Returns a List containing the result of applying given mapFun
to each value in this List. If reversed
is true, the order of the values is reversed.
map
mapFun
to each value in this List. If reversed
is true, the order of the values is reversed.mapPure
Returns a List containing the result of applying given mapFun
to each value in this List. If reversed
is true, the order of the values is reversed.
mapPure
mapFun
to each value in this List. If reversed
is true, the order of the values is reversed. nonEmpty
Returns true if there is at least one value in the collection, and instructs the compiler to treat the collection as a .NonEmpty type.
nonEmpty
padTo
Returns the List where, if given length
is larger than the List length, the given fill
value is added to the start and/or end of the List according to the positionPercentage
such that the result length is equal to length
.
padTo
length
is larger than the List length, the given fill
value is added to the start and/or end of the List according to the positionPercentage
such that the result length is equal to length
.prepend
Returns the List with the given value
added to the start.
prepend
value
added to the start.remove
Returns the List with the given amount
of values removed at the given index
.
remove
amount
of values removed at the given index
.repeat
Returns a List that contains this List the given amount
of times.
repeat
amount
of times.reversed
Returns the List in reversed order.
reversed
rotate
Returns the List where the elements are shifted to right by shiftRoundAmount
position, and the elements at the end are placed at the beginning.
rotate
shiftRoundAmount
position, and the elements at the end are placed at the beginning.slice
Returns the List containing the values within the given index range
, potentially reversed in order if reversed
is true.
slice
range
, potentially reversed in order if reversed
is true.sort
Returns the values sorted according to the given, optional Comp.
Performance warning: this method is not designed for frequent calls; should you need to keep in order a collection with potentially duplicate values, please consider SortedMultiSet
instead.
sort
SortedMultiSet
instead.splice
Returns the List, where at the given index
the remove
amount of values are replaced by the values from the optionally given insert
StreamSource
.
splice
index
the remove
amount of values are replaced by the values from the optionally given insert
StreamSource
.stream
Returns a Stream containing the values in order of the List, or in reverse order if reversed
is true.
stream
reversed
is true.streamRange
Returns a Stream containing the values contained in the given index range
, in order of the List, or in reverse order if reversed
is true.
streamRange
range
, in order of the List, or in reverse order if reversed
is true.take
Returns a List containing the first (or last) given amount
values of this List.
take
amount
values of this List.toArray
Returns an array containing the values within given range
(default: all) in this collection. If reversed
is true, reverses the order of the values.
toArray
range
(default: all) in this collection. If reversed
is true, reverses the order of the values.toBuilder
Returns a builder object containing the values of this collection.
toBuilder
toJSON
Returns a JSON representation of this collection.
toJSON
toString
Returns a string representation of this collection.
toString
updateAt
Returns the List where at the given index
the value is replaced or updated by the given update
.
updateAt
index
the value is replaced or updated by the given update
.