UNPKG

tamda

Version:

Practical functional programming library for TypeScript

35 lines (34 loc) 1.48 kB
/** * Filters items that are both in `arrayA` and `arrayB`. * @note From set theory, given sets A and B, denoted A ∩ B, * returns the set of intersection members of both A and B. * @param arrayA Array to filter. * @param arrayB Array to check item existance. * @param keyFn Optional function to extract a key for comparison between array items. Default: `identity()`. * @example * intersection([1, 2, 3], [2, 3, 4]); * // [2, 3] */ export declare function intersection<T>(arrayA: T[], arrayB: T[], keyFn?: KeyFn<T>): T[]; /** * Returns a function that * filters items that are both in `arrayA` and `arrayB`. * @note From set theory, given sets A and B, denoted A ∩ B, * returns the set of intersection members of both A and B. * @param arrayB Array to check item existance. * @param keyFn Optional function to extract a key for comparison between array items. Default: `identity()`. * @example * const inBoth = intersection([2, 3, 4]); * inBoth([1, 2, 3]); * // [2, 3] */ export declare function intersection<T>(arrayB: T[], keyFn?: KeyFn<T>): typeof deferred; /** * Filters items that are both in `arrayA` and previously specified `arrayB`. * @note From set theory, given sets A and B, denoted A ∩ B, * returns the set of intersection members of both A and B. * @param arrayA Array to filter. */ declare function deferred<T>(arrayA: T[]): T[]; declare type KeyFn<T> = (item: T, index: number) => any; export {};