collectype / factory/arrays/arrayIntersection / arrayIntersectionFactory
arrayIntersectionFactory<
T,C>(ctx,oper): <K>(field,target) =>C
Defined in: factory/arrays/arrayIntersection.ts:40
Creates a predicate filter for array intersection using PredicType.array.intersection.
T
The item type in the collection.
C extends Wherable<T, C>
The Wherable context type (must extend Wherable<T, C>).
C
The context (usually a collection) supporting the where method.
ArrayIntersectionOper
The array intersection operation (e.g., ‘intersects’, ‘disjoint’, etc.).
Returns a function that takes a field (of type array on T) and a target value, and applies the array intersection predicate to filter the context.
<
K>(field,target):C
K extends string | number | symbol
K
unknown[]
C
// Example: Composing an array intersection filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { arrayIntersectionFactory } from 'collectype';
type Person = { name: string; tags: string[] };
class PersonFunctions extends BaseFunctions<Person> {
arrayIntersects = arrayIntersectionFactory<Person, this>(this, 'intersects');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', tags: ['a', 'b', 'c'] },
{ name: 'Bob', tags: ['c', 'd'] }
];
const fn = new PersonFunctions(people);
const filtered = fn.arrayIntersects('tags', ['c']);
// filtered contains the items where 'tags' intersects ['c']