Skip to main content

Function: filter()

Returns an iterable that contains the values of iterable in iteration order excluding the values for which fn returns a falsy value.

Like Array.prototype.filter, but for iterables.

Example

import { filter, pipe, reduce, toArray } from 'lfi'

console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
filter(word => word.startsWith(`s`)),
reduce(toArray()),
),
)
//=> [ 'sloth', 'sleep' ]
Playground

Since

v0.0.1

Call Signature

filter<From, To>(fn): (iterable) => Iterable<To, any, any>

Type Parameters

From

To

Parameters

fn

(value) => value is To

Returns

Function

Parameters

iterable

Iterable<From, any, any>

Returns

Iterable<To, any, any>

Defined in

filters.d.ts:29

Call Signature

filter<From, To>(fn, iterable): Iterable<To, any, any>

Type Parameters

From

To

Parameters

fn

(value) => value is To

iterable

Iterable<From, any, any>

Returns

Iterable<To, any, any>

Defined in

filters.d.ts:32

Call Signature

filter<Value>(fn): (iterable) => Iterable<Value, any, any>

Type Parameters

Value

Parameters

fn

(value) => unknown

Returns

Function

Parameters

iterable

Iterable<Value, any, any>

Returns

Iterable<Value, any, any>

Defined in

filters.d.ts:37

Call Signature

filter<Value>(fn, iterable): Iterable<Value, any, any>

Type Parameters

Value

Parameters

fn

(value) => unknown

iterable

Iterable<Value, any, any>

Returns

Iterable<Value, any, any>

Defined in

filters.d.ts:40