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