API reference / @evolu/common / Types / PredicateWithIndex

Type Alias: PredicateWithIndex()<T>

type PredicateWithIndex<T> = (value, index) => boolean;

Defined in: packages/common/src/Types.ts:40

Checks a condition on a value at a given index and returns a boolean.

Useful for callbacks that need both the element and its position.

Example

const isEvenIndex: PredicateWithIndex<string> = (value, index) =>
  index % 2 === 0;

const items = ["a", "b", "c", "d"];
const evenIndexItems = items.filter(isEvenIndex); // ["a", "c"]

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT
indexnumber

Returns

boolean

Was this page helpful?