Class ValueTracker<T>Abstract

An object to keep track of an item with a certain numeric value based on the given predicate.

Items with a non-finite numeric value (e.g. NEGATIVE_INFINITY,POSITIVE_INFINITY, NaN, null, undefined), determined by the given getValue function, are ignored.

See

Example

export class MinimumTracker<T> extends ValueTracker<T> {
constructor(getValue: (item: T) => number) {
super(getValue, (current, candidate) => candidate < current);
}
}

export function minBy<T>(
iterable: Iterable<T>,
selector: (item: T) => number
): [item: T, value: number] | [] {
const min = new MinimumTracker<T>(selector);
for (const item of iterable) {
min.consider(item);
}
return min.result;
}

Type Parameters

  • T

Hierarchy

Constructors

Properties

Accessors

Methods

Constructors

  • Type Parameters

    Type Parameters

    • T

    Parameters

    • getValue: ((item: T) => undefined | null | number)
        • (item: T): undefined | null | number
        • Parameters

          • item: T

          Returns undefined | null | number

    • predicate: ((current: number, candidate: number) => boolean)
        • (current: number, candidate: number): boolean
        • Parameters

          • current: number
          • candidate: number

          Returns boolean

    Returns ValueTracker<T>

Properties

_result?: [item: T, value: number]
getValue: ((item: T) => undefined | null | number)

Type declaration

    • (item: T): undefined | null | number
    • Parameters

      • item: T

      Returns undefined | null | number

predicate: ((current: number, candidate: number) => boolean)

Type declaration

    • (current: number, candidate: number): boolean
    • Parameters

      • current: number
      • candidate: number

      Returns boolean

Accessors

Methods

Generated using TypeDoc