Class List

An ordered iterable collection. It optionally enforces the type of elements that may be added to the List.

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(type: new(...args: any[]) => Object): List

This creates a List that checks the type of the values to be instances of a particular kind of Object.

Parameters

  • type: new(...args: any[]) => Object

    this must be a class function/constructor.

Returns

List

constructor(type?: string): List

This creates a List that may check the types of the values.

Parameters

  • type?: string optional

    if supplied, this must be one of: 'number', 'string', 'boolean', or 'function' for the value type.

Returns

List

Properties

public count: number

Gets the length of the List.

public iterator: Iterator

Gets an object that you can use for iterating over the List.

public iteratorBackwards: Iterator

Gets an object that you can use for iterating over the List in backwards order.

public length: number

Gets the length of the List, a synonym for the #count property.

Methods

public add(val: any): any

Adds a given value to the end of the List.

Parameters

  • val: any

Returns

any

public addAll(coll: any): List

Adds all of the values of a collection (either an Iterable or an Array) to the end of this List.

Parameters

  • coll: any

Returns

List

public clear(): any

Clears the List.

Returns

any

public contains(val: any): boolean

Returns whether the given value is in this List.

Parameters

  • val: any

Returns

boolean

public copy(): List

Makes a shallow copy of this List.

Returns

List

public elt(i: number): any

Returns the element at the given index.

Parameters

  • i: number

Returns

any

public first(): any

Returns the first item in the collection, or null if there is none.

Returns

any

public indexOf(val: any): number

Returns the index of the given value if it is in this List.

Parameters

  • val: any

Returns

number

public insertAt(i: number, val: any): any

Insert a value before the index i.

Parameters

  • i: number
  • val: any

Returns

any

public remove(val: any): boolean

Removes a given value (if found) from the List.

Parameters

  • val: any

Returns

boolean

public removeAt(i: number): any

Removes a value at a given index from the List.

Parameters

  • i: number

Returns

any

public removeRange(to: number, from: number): any

Removes a range of values from the List.

Parameters

  • to: number
  • from: number

Returns

any

public reverse(): List

Reverse the order of items in this List.

Returns

List

public setElt(i: number, val: any): any

Set the element at the given index to a given value.

Parameters

  • i: number
  • val: any

Returns

any

public sort(sortfunc: (a: any, b: any) => number): List

Sort the List according to a comparison function.

Parameters

  • sortfunc: (a: any, b: any) => number

    the same kind of function as passed to Array.sort

Returns

List

public toArray(): Array<any>

Produces a JavaScript Array from the contents of this List.

Returns

Array<any>

public toSet(): Set

Converts the List to a Set.

Returns

Set