@bodil/monkey-business
    Preparing search index...

    Interface Array<T>

    Added methods on Arrays.

    interface Array<T> {
        equals<U = unknown>(
            other: unknown,
            equalsFn?: (a: T, b: U) => boolean,
        ): other is T[];
        get(index: number): Option<T>;
        insert(value: T, index: number): T[];
        insertOrdered(value: T, cmp: OrderFn<T>, duplicates?: "low" | "high"): T[];
        nonNullable(): NonNullable<T>[];
        present(): Present<T>[];
        remove(value: T): Option<T>;
        removeFn(
            predicate: (value: T, index: number, obj: T[]) => boolean,
        ): Option<T>;
        removeIndex(index: number): Option<T>;
        [n: number]: T;
    }

    Type Parameters

    • T

    Indexable

    • [n: number]: T

    Methods

    • Test whether a value is an array with the same contents as this one.

      Type Parameters

      • U = unknown

      Parameters

      • other: unknown
      • OptionalequalsFn: (a: T, b: U) => boolean

      Returns other is T[]

    • Checked index operator. Returns None if an index isn't present, even for sparse arrays. Returns a Some if the index is present, even if the value is undefined.

      Parameters

      • index: number

      Returns Option<T>

    • Insert value at index in the array.

      Parameters

      • value: T
      • index: number

      Returns T[]

    • Insert value into the array at the correct position according to the ordering function cmp. The array must already be ordered accordingly.

      If duplicates is "low", the correct position in case of duplicates is considered to be the index of the first occurrence of a duplicate. If it is "high", which is the default, the correct position is considered to be the index after the last occurrence of a duplicate.

      Parameters

      • value: T
      • cmp: OrderFn<T>
      • Optionalduplicates: "low" | "high"

      Returns T[]

    • Return a copy of the array with any undefined values removed.

      Returns Present<T>[]

    • Remove the first occurrence of a given value from an array.

      Returns an Option containing the removed value, or None if no matches were found.

      Parameters

      • value: T

      Returns Option<T>

    • Remove the first value for which the provided predicate function returns true from the array.

      Returns an Option containing the removed value, or None if no matches were found.

      Parameters

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

      Returns Option<T>

    • Remove the value at the given index from the array.

      Returns an Option containing the removed value, or None if the index was out of bounds.

      Parameters

      • index: number

      Returns Option<T>