collectype / factory/arrays/arrayMembership / arrayMembershipFactory
arrayMembershipFactory<
T,C>(ctx,oper): <K>(field,target) =>C
Defined in: factory/arrays/arrayMembership.ts:40
Creates a predicate filter for array membership using PredicType.array.membership.
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.
ArrayMembershipOper
The array membership operation (e.g., ‘in’, ‘notIn’, etc.).
Returns a function that takes a field (of type array on T) and a target value, and applies the array membership predicate to filter the context.
<
K>(field,target):C
K extends string | number | symbol
K
unknown
C
// Example: Composing an array membership filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { arrayMembershipFactory } from 'collectype';
type Person = { name: string; groups: string[] };
class PersonFunctions extends BaseFunctions<Person> {
arrayIn = arrayMembershipFactory<Person, this>(this, 'in');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', groups: ['admin', 'user'] },
{ name: 'Bob', groups: ['user'] }
];
const fn = new PersonFunctions(people);
const filtered = fn.arrayIn('groups', 'admin');
// filtered contains the items where 'groups' contains 'admin'