Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Collection<T, TCollection>

A collection of values.

Type parameters

  • T

  • TCollection: Collection<T, TCollection>

Hierarchy

  • Collection

Index

Constructors

constructor

  • Returns Collection

Properties

Private __values

__values: Array<T>
internal

Private __valuesLock

__valuesLock: Object
internal

Methods

add

  • add(value: T): boolean
  • Adds a value.

    Parameters

    • value: T

      The value.

    Returns boolean

addMany

  • addMany(values: T[]): boolean
  • Adds some values.

    Parameters

    • values: T[]

      The values.

    Returns boolean

Protected addSuccess

  • addSuccess(value: T): void
  • Invoked when an element is added to the collection.

    Parameters

    • value: T

      The value.

    Returns void

any

  • any(predicate: IFunction1<T, boolean>): boolean
  • any(): boolean
  • Determined whether the collection contains at least one value that matches the specified predicate.

    Parameters

    • predicate: IFunction1<T, boolean>

      The predicate.

    Returns boolean

  • Determined whether the collection contains at least one value.

    Returns boolean

Protected Abstract arrayFromList

  • arrayFromList(list: Array<T>): T[]
  • Creates an array from a list.

    Parameters

    • list: Array<T>

      The list.

    Returns T[]

contains

  • contains(value: T): boolean
  • Determines whether the collection contains a value.

    Parameters

    • value: T

      The value.

    Returns boolean

Protected Abstract createCollection

  • createCollection(): TCollection
  • Creates a collection.

    Returns TCollection

first

  • first(predicate: IFunction1<T, boolean>): T
  • first(): T
  • Gets the first value that matches the specified predicate. Throws an exception if there are no such values in the collection.

    Parameters

    • predicate: IFunction1<T, boolean>

      The predicate.

    Returns T

  • Gets the first value. Throws an exception if there are no values in the collection.

    Returns T

firstOrDefault

  • firstOrDefault(): T
  • firstOrDefault(predicate: IFunction1<T, boolean>): T
  • Gets the first value. Returns a default value if there are no values in the collection.

    Returns T

  • Gets the first value that matches the specified predicate. Returns a default value if there are no such values in the collection.

    Parameters

    • predicate: IFunction1<T, boolean>

      The predicate.

    Returns T

forEach

  • forEach(callback: IAction2<T, number>): void
  • Executes a callback function once per value.

    Parameters

    • callback: IAction2<T, number>

      The callback to execute.

    Returns void

getCount

  • getCount(): number
  • Gets the count.

    Returns number

getTypeString

  • getTypeString(): string
  • Returns string

getValue

  • getValue(): T
  • Gets the value.

    Returns T

getValues

  • getValues(): T[]
  • Gets the values.

    Returns T[]

last

  • last(predicate: IFunction1<T, boolean>): T
  • last(): T
  • Gets the last value that matches the specified predicate. Throws an exception if there are no such values in the collection.

    Parameters

    • predicate: IFunction1<T, boolean>

      The predicate.

    Returns T

  • Gets the last value. Throws an exception if there are no values in the collection.

    Returns T

lastOrDefault

  • lastOrDefault(predicate: IFunction1<T, boolean>): T
  • lastOrDefault(): T
  • Gets the last value that matches the specified predicate. Returns a default value if there are no such values in the collection.

    Parameters

    • predicate: IFunction1<T, boolean>

      The predicate.

    Returns T

  • Gets the last value. Returns a default value if there are no values in the collection.

    Returns T

remove

  • remove(value: T): boolean
  • Removes a value.

    Parameters

    • value: T

      The value.

    Returns boolean

removeAll

  • removeAll(): void
  • Removes all values.

    Returns void

removeFirst

  • removeFirst(condition: IFunction1<T, boolean>): T
  • removeFirst(): T
  • Removes the first value that matches a given condition.

    Parameters

    • condition: IFunction1<T, boolean>

    Returns T

  • Removes the first value.

    Returns T

removeLast

  • removeLast(): T
  • removeLast(condition: IFunction1<T, boolean>): T
  • Removes the last value.

    Returns T

  • Removes the last value that matches a given condition.

    Parameters

    • condition: IFunction1<T, boolean>

    Returns T

removeMany

  • removeMany(values: T[]): boolean
  • Removes some values.

    Parameters

    • values: T[]

      The values.

    Returns boolean

Protected removeSuccess

  • removeSuccess(value: T): void
  • Invoked when an element is removed from the collection.

    Parameters

    • value: T

      The value.

    Returns void

replace

  • replace(values: T[]): void
  • Replaces the collection with a new set of values.

    Parameters

    • values: T[]

      The values.

    Returns void

setValue

  • setValue(value: T): void
  • Sets the value.

    Parameters

    • value: T

    Returns void

setValues

  • setValues(value: T[]): void
  • Sets the values.

    Parameters

    • value: T[]

    Returns void

single

  • single(predicate: IFunction1<T, boolean>): T
  • single(): T
  • Gets the only value that matches the specified predicate. Throws an exception if there are no values or more than one value in the collection.

    Parameters

    • predicate: IFunction1<T, boolean>

    Returns T

  • Gets the only value. Throws an exception if there are no values or more than one value in the collection.

    Returns T

singleOrDefault

  • singleOrDefault(): T
  • singleOrDefault(predicate: IFunction1<T, boolean>): T
  • Gets the only value. Returns a default value if there are no values or more than one value in the collection.

    Returns T

  • Gets the only value that matches the specified predicate. Returns a default value if there are no values or more than one value in the collection.

    Parameters

    • predicate: IFunction1<T, boolean>

    Returns T

valueAt

  • valueAt(index: number): T
  • Gets the value at the specified index. Throws an exception if a value does not exist at that index.

    Parameters

    • index: number

      The index.

    Returns T

valueAtOrDefault

  • valueAtOrDefault(index: number): T
  • Gets the value at the specified index. Returns a default value if a value does not exist at that index.

    Parameters

    • index: number

      The index.

    Returns T

where

  • where(predicate: IFunction2<T, number, boolean>): TCollection
  • Creates a new collection with values that match the specified predicate.

    Parameters

    • predicate: IFunction2<T, number, boolean>

      The predicate.

    Returns TCollection