collectype / factory/sets/setState / setStateFactory
setStateFactory<
T,C>(ctx,oper): <K>(field) =>C
Defined in: factory/sets/setState.ts:40
Creates a predicate filter for set state using PredicType.set.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.
SetStateOper
The set state operation to perform (see PredicType.set.state).
Returns a function that takes a field (of type Set on T) and applies the set state predicate to filter the context.
<
K>(field):C
K extends string | number | symbol
K
C
// Example: Composing a set state filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { setStateFactory } from 'collectype';
type Person = { name: string; tags: Set<string> };
class PersonFunctions extends BaseFunctions<Person> {
setIsEmpty = setStateFactory<Person, this>(this, 'isEmpty');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', tags: new Set(['a', 'b']) },
{ name: 'Bob', tags: new Set() },
{ name: 'Eve', tags: new Set(['b']) }
];
const fn = new PersonFunctions(people);
const filtered = fn.setIsEmpty('tags');
// filtered contains the items where 'tags' is an empty Set
PredicType.set.state for set state checks on set fields.