filterArray()function

filterArray(input: ImmutableArray<T>, match: Match<[T, ...A]>, ...args: A): ImmutableArray<T>
ParamType
inputImmutableArray<T>
Array of items to filter. required
matchMatch<[T, ...A]>
Matcher called with each item (plus any extra args); items it returns true for are kept. required
argsA
Extra arguments passed to match after each item. required
Return
ImmutableArray<T>
A filtered array, or the same input instance if nothing was removed.

Filter an array (immutably) using a matcher.

  • Returns the exact same array instance if no items were removed (for referential stability).

Examples

filterArray([1, 2, 3], n => n > 1) // [2, 3]