collectype

collectype v0.11.0


collectype / factory/numbers/numberRange / numberRangeFactory

Function: numberRangeFactory()

numberRangeFactory<T, C>(ctx, oper): <K>(field, min, max) => C

Defined in: factory/numbers/numberRange.ts:41

Creates a predicate filter for number range using PredicType.number.range.

Type Parameters

T

T

The item type in the collection.

C

C extends Wherable<T, C>

The Wherable context type (must extend Wherable<T, C>).

Parameters

ctx

C

The context (usually a collection) supporting the where method.

oper

NumberRangeOper

The number range operation (e.g., ‘between’, ‘notBetween’, etc.).

Returns

Returns a function that takes a field (of type number on T), a min and max value, and applies the number range predicate to filter the context.

<K>(field, min, max): C

Type Parameters

K

K extends string | number | symbol

Parameters

field

K

min

number

max

number

Returns

C

Example

// Example: Composing a number range filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { numberRangeFactory } from 'collectype';

type Person = { name: string; age: number };

class PersonFunctions extends BaseFunctions<Person> {
  numberBetween = numberRangeFactory<Person, this>(this, 'between');
}

// Usage:
const people: Person[] = [
  { name: 'Alice', age: 30 },
  { name: 'Bob', age: 18 },
  { name: 'Charlie', age: 40 }
];
const fn = new PersonFunctions(people);
const filtered = fn.numberBetween('age', 20, 35);
// filtered contains the items where 'age' is between 20 and 35

Remarks