Nutrient Web SDK

Interface List

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.

Interface

Type Parameters

T

Properties

size

Readonly
number

The number of values in the list.

Methods

  • Iterates the values in order.

    Returns

    IterableIterator<T>

    An iterator of each value.

  • Returns the list followed by the values and collections given. A string, or a value that is not iterable, is added as one value.

    Type Parameters

    C

    Parameters

    ...valuesOrCollections(C | Iterable<C, any, any>)[]

    The values to add, or collections whose values to add.

    Returns

    A new list, or this one when nothing is added.

  • An alias of includes.

    Parameters

    valueT

    The value to look for.

    Returns

    boolean

    true when an equal value is present.

  • Counts the values.

    Returns

    number

    The number of values.

  • Counts the values the predicate accepts.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    number

    The number of values it returns truthy for.

  • Iterates the [index, value] pairs in order.

    Returns

    IterableIterator<[number, T]>

    An iterator of each pair.

  • Reports whether other is an ordered, indexed collection, such as a list, holding equal values in the same order, comparing as is() does.

    Parameters

    otherunknown

    The value to compare against.

    Returns

    boolean

    true when other is an ordered, indexed collection with equal values.

  • Reports whether the predicate accepts every value, narrowing the collection to the type predicate guards.

    Type Parameters

    F

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => value is F

    Called with each value and its index until it returns falsy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    true when every value is accepted, or the list is empty.

  • Reports whether the predicate accepts every value.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value and its index until it returns falsy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    boolean

    true when every value is accepted, or the list is empty.

  • Returns the first value the predicate accepts, narrowed to the type predicate guards.

    Type Parameters

    F

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => value is F

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    F | undefined

    The first matching value, or undefined.

  • Returns the first value the predicate accepts.

    Type Parameters

    N

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown

    The this value for predicate.

    notSetValueN

    Returned when no value matches.

    Returns

    T | N

    The first matching value, or notSetValue.

  • Returns the first value the predicate accepts.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    notSetValueT
    Optional

    Returned when no value matches.

    Returns

    T | undefined

    The first matching value, or notSetValue.

  • Returns the index of the first value the predicate accepts.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    number

    The index, or -1 when no value matches.

  • Returns the last value the predicate accepts, searching from the end, narrowed to the type predicate guards.

    Type Parameters

    F

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => value is F

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    F | undefined

    The last matching value, or undefined.

  • Returns the last value the predicate accepts, searching from the end.

    Type Parameters

    N

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown

    The this value for predicate.

    notSetValueN

    Returned when no value matches.

    Returns

    T | N

    The last matching value, or notSetValue.

  • Returns the last value the predicate accepts, searching from the end.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    notSetValueT
    Optional

    Returned when no value matches.

    Returns

    T | undefined

    The last matching value, or notSetValue.

  • Returns the index and value of the last value the predicate accepts.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    notSetValue[number, T]
    Optional

    Returned when no value matches.

    Returns

    [number, T] | undefined

    An [index, value] pair, or notSetValue.

  • Returns the index of the last value the predicate accepts, searching from the end.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    number

    The index, or -1 when no value matches.

  • Returns the index of the last value the predicate accepts.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value, its index and the list until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    number | undefined

    The index, or undefined when no value matches.

  • Returns the first value.

    Returns

    T | undefined

    The first value, or undefined for an empty list.

  • Returns the first value.

    Type Parameters

    N

    Parameters

    notSetValueN

    Returned when the list is empty.

    Returns

    T | N

    The first value, or notSetValue for an empty list.

  • Calls sideEffect for each value in order.

    Parameters

    sideEffect(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => unknown

    Called with each value and its index; returning false stops the loop.

    contextunknown
    Optional

    The this value for sideEffect.

    Returns

    number

    The number of values visited, including the one that stopped the loop.

  • Returns the value at index. A negative index counts from the end.

    Parameters

    indexnumber

    The position to read.

    Returns

    T | undefined

    The value, or undefined when index is out of range.

  • Returns the value at index. A negative index counts from the end.

    Type Parameters

    N

    Parameters

    indexnumber

    The position to read.

    notSetValueN

    Returned when index is out of range.

    Returns

    T | N

    The value, or notSetValue when index is 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.

    notSetValueunknown
    Optional

    Returned when the path breaks.

    Returns

    unknown

    The value at the path, or notSetValue.

  • Reports whether index is within the list. A negative index counts from the end.

    Parameters

    indexnumber

    The position to look for.

    Returns

    boolean

    true when the list has a value at index, even if that value is undefined.

  • 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

    number

    An integer hash.

  • Reports whether searchKeyPath resolves to a value.

    Parameters

    searchKeyPathIterable<unknown>

    The keys to follow, outermost first.

    Returns

    boolean

    true when every key on the path exists.

  • Reports whether the list holds a value equal to value, comparing as is() does.

    Parameters

    valueT

    The value to look for.

    Returns

    boolean

    true when an equal value is present.

  • Returns the index of the first value equal to searchValue.

    Parameters

    searchValueT

    The value to look for.

    Returns

    number

    The index, or -1 when no value is equal.

  • Reports whether the list has no values.

    Returns

    boolean

    true for an empty list.

  • Reports whether every value is included in iter.

    Parameters

    iterIterable<T>

    The collection to check against.

    Returns

    boolean

    true when each value of this list is in iter.

  • Reports whether every value of iter is included in this list.

    Parameters

    iterIterable<T>

    The collection to check.

    Returns

    boolean

    true when each value of iter is in this list.

  • Joins the values into a string, printing null and undefined as nothing.

    Parameters

    separatorstring
    Optional

    Placed between values; defaults to ,.

    Returns

    string

    The joined string.

  • Returns the index of the first value equal to searchValue.

    Parameters

    searchValueT

    The value to look for.

    Returns

    number | undefined

    The index, or undefined when no value is equal.

  • Iterates the indices.

    Returns

    IterableIterator<number>

    An iterator of each index.

  • Returns the last value.

    Returns

    T | undefined

    The last value, or undefined for an empty list.

  • Returns the last value.

    Type Parameters

    N

    Parameters

    notSetValueN

    Returned when the list is empty.

    Returns

    T | N

    The last value, or notSetValue for an empty list.

  • Returns the index of the last value equal to searchValue.

    Parameters

    searchValueT

    The value to look for.

    Returns

    number

    The index, or -1 when no value is equal.

  • Returns the index of the last value equal to searchValue.

    Parameters

    searchValueT

    The value to look for.

    Returns

    number | undefined

    The index, or undefined when no value is equal.

  • Returns the largest value.

    Parameters

    comparator(a: T, b: T) => number
    Optional

    Orders two values; defaults to < and >.

    Returns

    T | undefined

    The largest value, or undefined for an empty list.

  • Returns the value with the largest mapped key.

    Type Parameters

    C

    Parameters

    comparatorValueMapper(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => C

    Maps each value to the key to compare.

    comparator(a: C, b: C) => number
    Optional

    Orders two keys; defaults to < and >.

    Returns

    T | undefined

    The value, or undefined for an empty list.

  • A combination of updateIn and mergeDeep, 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: mergeDeepIn can be used in withMutations.

    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 updateIn and merge, 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: mergeIn can be used in withMutations.

    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.

  • Returns the smallest value.

    Parameters

    comparator(a: T, b: T) => number
    Optional

    Orders two values; defaults to < and >.

    Returns

    T | undefined

    The smallest value, or undefined for an empty list.

  • Returns the value with the smallest mapped key.

    Type Parameters

    C

    Parameters

    comparatorValueMapper(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => C

    Maps each value to the key to compare.

    comparator(a: C, b: C) => number
    Optional

    Orders two keys; defaults to < and >.

    Returns

    T | undefined

    The value, or undefined for an empty list.

  • Folds the values into one, from the first to the last, starting from the first value.

    Parameters

    reducer(
    reduction: T,
    value: T,
    index: number,
    list: NutrientViewer.Immutable.List<T>
    ) => T

    Called with the reduction so far, a value and its index.

    Returns

    The final reduction.

  • Folds the values into one, from the first to the last.

    Type Parameters

    R

    Parameters

    reducer(
    reduction: R,
    value: T,
    index: number,
    list: NutrientViewer.Immutable.List<T>
    ) => R

    Called with the reduction so far, a value and its index.

    initialReductionR

    The starting reduction.

    contextunknown
    Optional

    The this value for reducer.

    Returns

    The final reduction.

  • Folds the values into one, from the first to the last, starting from the first value.

    Type Parameters

    R

    Parameters

    reducer(
    reduction: T | R,
    value: T,
    index: number,
    list: NutrientViewer.Immutable.List<T>
    ) => R

    Called with the reduction so far, a value and its index.

    Returns

    The final reduction.

  • Folds the values into one, from the last to the first, starting from the last value.

    Parameters

    reducer(
    reduction: T,
    value: T,
    index: number,
    list: NutrientViewer.Immutable.List<T>
    ) => T

    Called with the reduction so far, a value and its index.

    Returns

    The final reduction.

  • Folds the values into one, from the last to the first.

    Type Parameters

    R

    Parameters

    reducer(
    reduction: R,
    value: T,
    index: number,
    list: NutrientViewer.Immutable.List<T>
    ) => R

    Called with the reduction so far, a value and its index.

    initialReductionR

    The starting reduction.

    contextunknown
    Optional

    The this value for reducer.

    Returns

    The final reduction.

  • Folds the values into one, from the last to the first, starting from the last value.

    Type Parameters

    R

    Parameters

    reducer(
    reduction: T | R,
    value: T,
    index: number,
    list: NutrientViewer.Immutable.List<T>
    ) => R

    Called with the reduction so far, a value and its index.

    Returns

    The final reduction.

  • Returns a list with the value at index replaced. An index past the end pads with undefined; a negative index before the start prepends undefined values.

    Parameters

    indexnumber

    The position to write. A negative index counts from the end.

    valueT

    The value to store.

    Returns

    A new list, or this one when the value is unchanged or index is not valid.

  • Returns the values from begin up to, but not including, end.

    Parameters

    beginnumber
    Optional

    Where to start; negative counts from the end. Defaults to the start.

    endnumber
    Optional

    Where to stop; negative counts from the end. Defaults to the end.

    Returns

    A new list, or this one when the range covers it all.

  • Reports whether the predicate accepts any value.

    Parameters

    predicate(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => boolean

    Called with each value and its index until it returns truthy.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    boolean

    true when some value is accepted.

  • Returns the values sorted by a mapped key. The sort is stable.

    Type Parameters

    C

    Parameters

    comparatorValueMapper(value: T, index: number, list: NutrientViewer.Immutable.List<T>) => C

    Maps each value to the key to sort by.

    comparator(a: C, b: C) => number
    Optional

    Orders two keys; defaults to < and >, with undefined last.

    Returns

  • Returns a list with removeNum values removed at index and values inserted there.

    Parameters

    indexnumber

    Where to start. A negative index counts from the end.

    removeNumnumber

    How many values to remove.

    ...valuesT[]

    The values to insert.

    Returns

    A new list, or this one when nothing is removed or inserted.

  • 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.

  • 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.

  • Prints the list, for example List [ 1, "a" ].

    Returns

    string

    The printed list.

  • Returns a list with the value at index replaced by the result of updater.

    Parameters

    indexnumber

    The position to update.

    notSetValueT

    The value passed to the updater when index is missing.

    updater(value: T) => T

    Returns the new value.

    Returns

    A new list, or this one when the value is unchanged.

  • Returns a list with the value at index replaced by the result of updater.

    Parameters

    indexnumber

    The position to update.

    updater(value: T | undefined) => T | undefined

    Returns the new value.

    Returns

    A new list, or this one when the value is unchanged.

  • Returns the result of calling updater with this list.

    Type Parameters

    R

    Parameters

    updater(value: NutrientViewer.Immutable.List<T>) => R

    Receives the list.

    Returns

    The updater's result.

  • Returns a list with the value at the end of keyPath replaced by the result of updater.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    notSetValueunknown

    The value passed to the updater when the path is missing.

    updater(value: unknown) => unknown

    Returns the new value.

    Returns

    A new list, or this one when the value is unchanged.

  • Returns a list with the value at the end of keyPath replaced by the result of updater.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, outermost first.

    updater(value: unknown) => unknown

    Returns 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.