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