import { Comparator } from "./arrays.js"; export declare function findLast(array: readonly T[], predicate: (item: T, index: number) => item is R, fromIndex?: number): R | undefined; export declare function findLast(array: readonly T[], predicate: (item: T, index: number) => unknown, fromIndex?: number): T | undefined; export declare function findLastIdx(array: readonly T[], predicate: (item: T, index: number) => unknown, fromIndex?: number): number; export declare function findFirst(array: readonly T[], predicate: (item: T, index: number) => item is R, fromIndex?: number): R | undefined; export declare function findFirst(array: readonly T[], predicate: (item: T, index: number) => unknown, fromIndex?: number): T | undefined; export declare function findFirstIdx(array: readonly T[], predicate: (item: T, index: number) => unknown, fromIndex?: number): number; /** * Finds the last item where predicate is true using binary search. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[true, ..., true, false, ..., false]`! * * @returns `undefined` if no item matches, otherwise the last item that matches the predicate. */ export declare function findLastMonotonous(array: readonly T[], predicate: (item: T) => boolean): T | undefined; /** * Finds the last item where predicate is true using binary search. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[true, ..., true, false, ..., false]`! * * @returns `startIdx - 1` if predicate is false for all items, otherwise the index of the last item that matches the predicate. */ export declare function findLastIdxMonotonous(array: readonly T[], predicate: (item: T) => boolean, startIdx?: number, endIdxEx?: number): number; /** * Finds the first item where predicate is true using binary search. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[false, ..., false, true, ..., true]`! * * @returns `undefined` if no item matches, otherwise the first item that matches the predicate. */ export declare function findFirstMonotonous(array: readonly T[], predicate: (item: T) => boolean): T | undefined; /** * Finds the first item where predicate is true using binary search. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[false, ..., false, true, ..., true]`! * * @returns `endIdxEx` if predicate is false for all items, otherwise the index of the first item that matches the predicate. */ export declare function findFirstIdxMonotonousOrArrLen(array: readonly T[], predicate: (item: T) => boolean, startIdx?: number, endIdxEx?: number): number; export declare function findFirstIdxMonotonous(array: readonly T[], predicate: (item: T) => boolean, startIdx?: number, endIdxEx?: number): number; /** * Use this when * * You have a sorted array * * You query this array with a monotonous predicate to find the last item that has a certain property. * * You query this array multiple times with monotonous predicates that get weaker and weaker. */ export declare class MonotonousArray { private readonly _array; static assertInvariants: boolean; private _findLastMonotonousLastIdx; private _prevFindLastPredicate; constructor(_array: readonly T[]); /** * The predicate must be monotonous, i.e. `arr.map(predicate)` must be like `[true, ..., true, false, ..., false]`! * For subsequent calls, current predicate must be weaker than (or equal to) the previous predicate, i.e. more entries must be `true`. */ findLastMonotonous(predicate: (item: T) => boolean): T | undefined; } /** * Returns the first item that is equal to or greater than every other item. */ export declare function findFirstMax(array: readonly T[], comparator: Comparator): T | undefined; /** * Returns the last item that is equal to or greater than every other item. */ export declare function findLastMax(array: readonly T[], comparator: Comparator): T | undefined; /** * Returns the first item that is equal to or less than every other item. */ export declare function findFirstMin(array: readonly T[], comparator: Comparator): T | undefined; export declare function findMaxIdx(array: readonly T[], comparator: Comparator): number; /** * Returns the first mapped value of the array which is not undefined. */ export declare function mapFindFirst(items: Iterable, mapFn: (value: T) => R | undefined): R | undefined;