collectype

collectype v0.11.0


collectype / factory/numbers/numberState / numberStateFactory

Function: 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.

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

NumberStateOper

The number state operation (e.g., ‘isInteger’, ‘isPositive’, etc.).

Returns

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

Type Parameters

K

K extends string | number | symbol

Parameters

field

K

Returns

C

Example

// 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

Remarks