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