filter()
filter<
Input,Output>(predicate):OperatorFunction<Input,Input>
Defined in: src/Filter.ts:23
Creates an operator that keeps only the items for which predicate
returns true.
The predicate must be synchronous and must be a type predicate
(value is Output), so the chain method filter can narrow the item type.
Type Parameters
Input
Input
Output
Output
Parameters
predicate
(value) => value is Output
a synchronous type predicate
Returns
OperatorFunction<Input, Input>
an operator function
Example
const mixed: (number | string)[] = [1, "a", 2, "b"];
const numbers = await chain(mixed)
.filter((v): v is number => typeof v === "number")
.toArray();
// => [1, 2]