compare-lists
Version:
Super efficiently compares two sorted lists (arrays, strings, anything that is iterable actually).
28 lines (27 loc) • 1.26 kB
TypeScript
export interface BaseCompareOptions<TLeft, TRight> {
compare: (left: TLeft, right: TRight) => number;
onMissingInLeft?: (right: TRight) => void;
onMissingInRight?: (left: TLeft) => void;
onMatch?: (left: TLeft, right: TRight) => void;
}
export interface CompareListsOptions<TLeft, TRight> extends BaseCompareOptions<TLeft, TRight> {
left: Iterable<TLeft>;
right: Iterable<TRight>;
}
export interface CompareListsReport<TLeft, TRight> {
missingInLeft: TRight[];
missingInRight: TLeft[];
matches: [TLeft, TRight][];
}
export declare function compareLists<TLeft, TRight>(options: CompareListsOptions<TLeft, TRight>): void;
export declare function compareLists<TLeft, TRight>(options: CompareListsOptions<TLeft, TRight> & {
returnReport: true;
}): CompareListsReport<TLeft, TRight>;
export interface CompareIteratorsOptions<TLeft, TRight> extends BaseCompareOptions<TLeft, TRight> {
left: Iterator<TLeft>;
right: Iterator<TRight>;
}
export declare function compareIterators<TLeft, TRight>(options: CompareIteratorsOptions<TLeft, TRight>): void;
export declare function compareIterators<TLeft, TRight>(options: CompareIteratorsOptions<TLeft, TRight> & {
returnReport: true;
}): CompareListsReport<TLeft, TRight>;