interface Array<T> {
    $filterMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): U[];
    $first(predicate?: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<T>;
    $firstIndex(predicate: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<number>;
    $firstMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): Option<U>;
    $last(predicate?: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<T>;
    $lastIndex(predicate: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<number>;
    $lastMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): Option<U>;
    $mapWhile<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): U[];
    $reduceWhile<U>(fn: ((previousValue: U, currentValue: T, currentIndex: number, array: T[]) => Option<U>), initialValue: U, thisArg?: any): U;
}

Type Parameters

  • T

Methods

  • From tsur.

    filterMap filers and maps an iterable at the same time.

    It makes chains of filter and map more concise, as it shortens map().filter().map() to a single call.

    Type Parameters

    • U

    Parameters

    • fn: ((value: T, index: number, array: T[]) => Option<U>)

      A function that produces an Option.

        • (value, index, array): Option<U>
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns Option<U>

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns U[]

    An array of filtered and mapped values.

  • From tsur.

    first finds the first item that matches a predicate. Returns the first item of array if no predicate is provided.

    Parameters

    • Optionalpredicate: ((value: T, index: number, array: T[]) => boolean)

      A predicate function.

        • (value, index, array): boolean
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns boolean

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns Option<T>

    The first item that matches the predicate, or None if no item matches.

  • From tsur.

    Returns the index of the first element in the array that satisfies the provided testing function. Otherwise None is returned.

    Parameters

    • predicate: ((value: T, index: number, array: T[]) => boolean)

      A predicate function.

        • (value, index, array): boolean
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns boolean

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns Option<number>

    The index of the first item that matches the predicate, or None if no item matches.

  • From tsur.

    Applies function to the elements of iterator and returns the first non-none result.

    firstMap(fn) is the lighter version of filterMap(fn).first().

    Type Parameters

    • U

    Parameters

    • fn: ((value: T, index: number, array: T[]) => Option<U>)

      A function that produces an Option.

        • (value, index, array): Option<U>
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns Option<U>

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns Option<U>

    The first non-none result.

  • From tsur.

    last finds the last item that matches a predicate. Returns the last item of array if no predicate is provided.

    Parameters

    • Optionalpredicate: ((value: T, index: number, array: T[]) => boolean)

      A predicate function.

        • (value, index, array): boolean
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns boolean

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns Option<T>

    The last item that matches the predicate, or None if no item matches.

  • From tsur.

    Returns the index of the last element in the array where predicate is true, and None otherwise.

    Parameters

    • predicate: ((value: T, index: number, array: T[]) => boolean)

      lastIndex calls predicate once for each element of the array, in backward order, until it finds one where predicate returns true.

        • (value, index, array): boolean
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns boolean

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns Option<number>

    The index of the last item that matches the predicate, or None if no item matches.

  • From tsur.

    lastMap(fn) is the lighter version of filterMap(fn).last().

    Type Parameters

    • U

    Parameters

    • fn: ((value: T, index: number, array: T[]) => Option<U>)

      A function that produces an Option.

        • (value, index, array): Option<U>
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns Option<U>

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns Option<U>

    The last non-none result.

  • From tsur.

    mapWhile maps an iterable until the first None is encountered.

    Type Parameters

    • U

    Parameters

    • fn: ((value: T, index: number, array: T[]) => Option<U>)

      A function that produces an Option.

        • (value, index, array): Option<U>
        • Parameters

          • value: T
          • index: number
          • array: T[]

          Returns Option<U>

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns U[]

    An array of mapped values.

  • From tsur.

    reduceWhile reduces an iterable until the first None is encountered.

    Type Parameters

    • U = T

    Parameters

    • fn: ((previousValue: U, currentValue: T, currentIndex: number, array: T[]) => Option<U>)

      A function that produces an Option.

        • (previousValue, currentValue, currentIndex, array): Option<U>
        • Parameters

          • previousValue: U
          • currentValue: T
          • currentIndex: number
          • array: T[]

          Returns Option<U>

    • initialValue: U

      The initial value.

    • OptionalthisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns U

    The reduced value.