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