collectype / factory/numbers/numberState / numberStateFactory
numberStateFactory<
T,C>(ctx,oper): <K>(field) =>C
Defined in: factory/numbers/numberState.ts:41
Creates a predicate filter for number state using PredicType.number.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.
NumberStateOper
The number state operation (e.g., ‘isInteger’, ‘isPositive’, etc.).
Returns a function that takes a field (of type number on T) and applies the number state predicate to filter the context.
<
K>(field):C
K extends string | number | symbol
K
C
// Example: Composing a number state filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { numberStateFactory } from 'collectype';
type Person = { name: string; age: number };
class PersonFunctions extends BaseFunctions<Person> {
numberIsInteger = numberStateFactory<Person, this>(this, 'isInteger');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 18.5 },
{ name: 'Charlie', age: 40 }
];
const fn = new PersonFunctions(people);
const filtered = fn.numberIsInteger('age');
// filtered contains the items where 'age' is an integer