Type Parameters
Properties
Methods
Iterates the values in order.
Returns
IterableIterator<T>An iterator of each value.
Returns the list without its last value.
Returns
A new list.
Returns an empty list.
Returns
A new empty list, or this one when it is already empty.
An alias of
includes.Parameters
valueTThe value to look for.
Returns
booleantruewhen an equal value is present.
Counts the values.
Returns
numberThe number of values.
- count(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): numberCounts the values the predicate accepts.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value, its index and the list.
contextunknownOptionalThe
thisvalue forpredicate.Returns
numberThe number of values it returns truthy for.
- countBy<G>(
grouper: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => G,
context?: unknown,
): NutrientViewer.Immutable.Map<G, number>Counts the values per key.
Type Parameters
GParameters
Returns
NutrientViewer.Immutable.Map<G, number>A map from each key to how many values produced it.
Returns a list without the value at
index.Parameters
indexnumberThe position to remove. A negative index counts from the end.
Returns
A new list, or this one when
indexis out of range.
Returns a list with the value at the end of
keyPathremoved.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
A new list, or this one when nothing was removed.
Iterates the
[index, value]pairs in order.Returns
IterableIterator<[number, T]>An iterator of each pair.
Reports whether
otheris an ordered, indexed collection, such as a list, holding equal values in the same order, comparing asis()does.Parameters
otherunknownThe value to compare against.
Returns
booleantruewhenotheris an ordered, indexed collection with equal values.
- every<F>(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => value is F,
context?: unknown,
): this is NutrientViewer.Immutable.List<F>Reports whether the predicate accepts every value, narrowing the collection to the type
predicateguards.Type Parameters
FParameters
Returns
this is NutrientViewer.Immutable.List<F>truewhen every value is accepted, or the list is empty. - every(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): booleanReports whether the predicate accepts every value.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value and its index until it returns falsy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
booleantruewhen every value is accepted, or the list is empty.
- filter<F>(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => value is F,
context?: unknown,
): NutrientViewer.Immutable.List<F>Returns the values the predicate accepts.
Type Parameters
FParameters
Returns
A new list.
- filter(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => unknown,
context?: unknown,
): NutrientViewer.Immutable.List<T>Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => unknowncontextunknownOptionalReturns
- filterNot(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): NutrientViewer.Immutable.List<T>Returns the values the predicate rejects.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value and its index.
contextunknownOptionalThe
thisvalue forpredicate.Returns
A new list.
- find<F>(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => value is F,
context?: unknown,
): F | undefinedReturns the first value the predicate accepts, narrowed to the type
predicateguards. - find<N>(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context: unknown,
notSetValue: N,
): T | NReturns the first value the predicate accepts.
Type Parameters
NParameters
- find(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
notSetValue?: T,
): T | undefinedReturns the first value the predicate accepts.
Parameters
Returns
T | undefinedThe first matching value, or
notSetValue.
- findIndex(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): numberReturns the index of the first value the predicate accepts.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value, its index and the list until it returns truthy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
numberThe index, or
-1when no value matches.
- findLast<F>(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => value is F,
context?: unknown,
): F | undefinedReturns the last value the predicate accepts, searching from the end, narrowed to the type
predicateguards. - findLast<N>(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context: unknown,
notSetValue: N,
): T | NReturns the last value the predicate accepts, searching from the end.
Type Parameters
NParameters
- findLast(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
notSetValue?: T,
): T | undefinedReturns the last value the predicate accepts, searching from the end.
Parameters
Returns
T | undefinedThe last matching value, or
notSetValue.
- findLastEntry(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
notSetValue?: [number, T],
): [number, T] | undefinedReturns the index and value of the last value the predicate accepts.
Parameters
Returns
[number, T] | undefinedAn
[index, value]pair, ornotSetValue.
- findLastIndex(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): numberReturns the index of the last value the predicate accepts, searching from the end.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value, its index and the list until it returns truthy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
numberThe index, or
-1when no value matches.
- findLastKey(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): number | undefinedReturns the index of the last value the predicate accepts.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value, its index and the list until it returns truthy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
number | undefinedThe index, or
undefinedwhen no value matches.
Returns the first value.
Returns
T | undefinedThe first value, or
undefinedfor an empty list.
Flattens nested collections. Plain arrays are not flattened.
Parameters
depthnumberOptionalHow many levels to flatten; omitted for all.
Returns
NutrientViewer.Immutable.List<unknown>A new list.
Flattens nested collections. Plain arrays are not flattened.
Parameters
shallowbooleanOptionaltrueto flatten one level; omitted orfalsefor all.Returns
NutrientViewer.Immutable.List<unknown>A new list.
- forEach(
sideEffect: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => unknown,
context?: unknown,
): numberCalls
sideEffectfor each value in order.Parameters
sideEffect(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => unknownCalled with each value and its index; returning
falsestops the loop.contextunknownOptionalThe
thisvalue forsideEffect.Returns
numberThe number of values visited, including the one that stopped the loop.
Returns the value at
index. A negative index counts from the end.Parameters
indexnumberThe position to read.
Returns
T | undefinedThe value, or
undefinedwhenindexis out of range.
Reads the value at the end of
searchKeyPath, walking lists, maps, records and plain objects and arrays.Parameters
searchKeyPathIterable<unknown>The keys to follow, outermost first.
notSetValueunknownOptionalReturned when the path breaks.
Returns
unknownThe value at the path, or
notSetValue.
- groupBy<G>(
grouper: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => G,
context?: unknown,
): NutrientViewer.Immutable.Map<G, NutrientViewer.Immutable.List<T>>Groups the values by key, keeping list order within each group.
Type Parameters
GParameters
Returns
A map, keyed in order of first appearance, from each key to the list of values that produced it.
Reports whether
indexis within the list. A negative index counts from the end.Parameters
indexnumberThe position to look for.
Returns
booleantruewhen the list has a value atindex, even if that value isundefined.
Computes a hash of this list from its contents, the same way Immutable.js does. Equal lists have equal hashes; lists with equal hashes are not necessarily equal. Plain objects, functions and symbols hash by identity, so a hash is only meaningful within the page that computed it.
Returns
numberAn integer hash.
Reports whether
searchKeyPathresolves to a value.Parameters
searchKeyPathIterable<unknown>The keys to follow, outermost first.
Returns
booleantruewhen every key on the path exists.
Reports whether the list holds a value equal to
value, comparing asis()does.Parameters
valueTThe value to look for.
Returns
booleantruewhen an equal value is present.
Returns the index of the first value equal to
searchValue.Parameters
searchValueTThe value to look for.
Returns
numberThe index, or
-1when no value is equal.
Returns a list with
valueinserted atindex.Parameters
indexnumberThe position to insert at. A negative index counts from the end.
valueTThe value to insert.
Returns
A new list.
Returns the list with
separatorbetween each pair of values.Parameters
separatorTThe value to place between values.
Returns
A new list.
Reports whether the list has no values.
Returns
booleantruefor an empty list.
Joins the values into a string, printing
nullandundefinedas nothing.Parameters
separatorstringOptionalPlaced between values; defaults to
,.Returns
stringThe joined string.
Returns the index of the first value equal to
searchValue.Parameters
searchValueTThe value to look for.
Returns
number | undefinedThe index, or
undefinedwhen no value is equal.
Iterates the indices.
Returns
IterableIterator<number>An iterator of each index.
Returns the last value.
Returns
T | undefinedThe last value, or
undefinedfor an empty list.
Returns the index of the last value equal to
searchValue.Parameters
searchValueTThe value to look for.
Returns
numberThe index, or
-1when no value is equal.
Returns the index of the last value equal to
searchValue.Parameters
searchValueTThe value to look for.
Returns
number | undefinedThe index, or
undefinedwhen no value is equal.
- mergeDeepIn(
keyPath: Iterable<unknown>,
...collections: unknown[],
): NutrientViewer.Immutable.List<T>A combination of
updateInandmergeDeep, returning a new List, but performing the deep merge at a point arrived at by following the keyPath. In other words, these two lines are equivalent:list.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y))
list.mergeDeepIn(['a', 'b', 'c'], y)Note:
mergeDeepIncan be used inwithMutations.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
...collectionsunknown[]Collections or plain objects to merge into the value there.
Returns
A new list, or this one when the value is unchanged.
A combination of
updateInandmerge, returning a new List, but performing the merge at a point arrived at by following the keyPath. In other words, these two lines are equivalent:list.updateIn(['a', 'b', 'c'], abc => abc.merge(y))
list.mergeIn(['a', 'b', 'c'], y)Note:
mergeIncan be used inwithMutations.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
...collectionsunknown[]Collections or plain objects to merge into the value there.
Returns
A new list, or this one when the value is unchanged.
- partition<F, C>(
predicate: (
this: C,
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => value is F,
context?: C,
): [NutrientViewer.Immutable.List<T>, NutrientViewer.Immutable.List<F>]Splits the values into those the predicate rejects and those it accepts.
Type Parameters
FCParameters
Returns
A pair of lists: the rejected values, then the accepted values.
- partition<C>(
predicate: (
this: C,
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => unknown,
context?: C,
): [NutrientViewer.Immutable.List<T>, NutrientViewer.Immutable.List<T>]Type Parameters
CParameters
Returns
Returns a list without the last value.
Returns
A new list, or this one when it is empty.
Returns a list with
valuesadded to the end.Parameters
...valuesT[]The values to add, in order.
Returns
A new list, or this one when no values are given.
An alias of
delete.Parameters
indexnumberThe position to remove. A negative index counts from the end.
Returns
A new list, or this one when
indexis out of range.
An alias of
deleteIn.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
A new list, or this one when nothing was removed.
Returns the list without its first value.
Returns
A new list.
Returns the values in reverse order.
Returns
A new list.
Returns a list with the value at
indexreplaced. An index past the end pads withundefined; a negative index before the start prependsundefinedvalues.Parameters
indexnumberThe position to write. A negative index counts from the end.
valueTThe value to store.
Returns
A new list, or this one when the value is unchanged or
indexis not valid.
Returns a list with the value at the end of
keyPathreplaced.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
valueunknownThe value to store.
Returns
A new list, or this one when the value is unchanged.
Returns a list without the first value.
Returns
A new list, or this one when it is empty.
Returns the values in a random order.
Parameters
random() => numberOptionalReturns a number in
[0, 1); defaults toMath.random.Returns
A new list, or this one when no value moved.
Returns the list without its first
amountvalues.Parameters
amountnumberHow many values to drop.
Returns
A new list, or this one when
amountis not positive.
Returns the list without its last
amountvalues.Parameters
amountnumberHow many values to drop.
Returns
A new list, or this one when
amountis not positive.
- skipUntil(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): NutrientViewer.Immutable.List<T>Returns the list without the leading values the predicate rejects.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value and its index until it returns truthy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
A new list.
- skipWhile(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): NutrientViewer.Immutable.List<T>Returns the list without the leading values the predicate accepts.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value and its index until it returns falsy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
A new list.
Returns the values from
beginup to, but not including,end.Parameters
beginnumberOptionalWhere to start; negative counts from the end. Defaults to the start.
endnumberOptionalWhere to stop; negative counts from the end. Defaults to the end.
Returns
A new list, or this one when the range covers it all.
- some(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): booleanReports whether the predicate accepts any value.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value and its index until it returns truthy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
booleantruewhen some value is accepted.
Returns a list with
removeNumvalues removed atindexandvaluesinserted there.Parameters
indexnumberWhere to start. A negative index counts from the end.
removeNumnumberHow many values to remove.
...valuesT[]The values to insert.
Returns
A new list, or this one when nothing is removed or inserted.
Returns the first
amountvalues.Parameters
amountnumberHow many values to keep.
Returns
A new list, or this one when
amountcovers it all.
Returns the last
amountvalues.Parameters
amountnumberHow many values to keep.
Returns
A new list, or this one when
amountcovers it all.
- takeUntil(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): NutrientViewer.Immutable.List<T>Returns the leading values the predicate rejects.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value and its index until it returns truthy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
A new list.
- takeWhile(
predicate: (
value: T,
index: number,
list: NutrientViewer.Immutable.List<T>,
) => boolean,
context?: unknown,
): NutrientViewer.Immutable.List<T>Returns the leading values the predicate accepts.
Parameters
predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => booleanCalled with each value and its index until it returns falsy.
contextunknownOptionalThe
thisvalue forpredicate.Returns
A new list.
Converts the list to an array of its values, leaving nested collections as they are.
Returns
T[]A new array.
Converts the list to plain values all the way down: nested collections, records, arrays and plain objects become plain arrays and objects.
Returns
CollectionPlainValue<T>[]A new array of plain values.
Converts the list to an array of its values, leaving nested collections as they are, for
JSON.stringify.Returns
T[]A new array.
Returns this list.
Returns
This list.
Converts the list to a map from each index to its value.
Returns
NutrientViewer.Immutable.Map<number, T>A new map.
Converts the list to an object keyed by index.
Returns
{ [key: string]: T }A new object.
Converts the list to an ordered map from each index to its value.
Returns
OrderedMap<number, T>A new ordered map.
Converts the list to an ordered set of its values, dropping duplicates.
Returns
OrderedSet<T>A new ordered set.
Converts the list to a set of its values, dropping duplicates.
Returns
A new set.
Prints the list, for example
List [ 1, "a" ].Returns
stringThe printed list.
Returns a list with
valuesadded to the start.Parameters
...valuesT[]The values to add; they end up in argument order.
Returns
A new list, or this one when no values are given.
- updateIn(
keyPath: Iterable<unknown>,
notSetValue: unknown,
updater: (value: unknown) => unknown,
): NutrientViewer.Immutable.List<T>Returns a list with the value at the end of
keyPathreplaced by the result ofupdater.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
notSetValueunknownThe value passed to the updater when the path is missing.
updater(value: unknown) => unknownReturns the new value.
Returns
A new list, or this one when the value is unchanged.
- updateIn(
keyPath: Iterable<unknown>,
updater: (value: unknown) => unknown,
): NutrientViewer.Immutable.List<T>Returns a list with the value at the end of
keyPathreplaced by the result ofupdater.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
updater(value: unknown) => unknownReturns the new value.
Returns
A new list, or this one when the value is unchanged.
Iterates the values in order.
Returns
IterableIterator<T>An iterator of each value.
- withMutations(
mutator: (mutable: NutrientViewer.Immutable.List<T>) => unknown,
): NutrientViewer.Immutable.List<T>Applies several changes in one batch. The mutator receives a draft list whose changing methods modify it in place and return it.
Parameters
mutator(mutable: NutrientViewer.Immutable.List<T>) => unknownCalled once with the draft.
Returns
A new list holding the changes, or this one when the mutator changed nothing.
An immutable, ordered list of values. Every change returns a new list and leaves the original untouched; a change that would not alter the list returns the same list.