import { filter } from "https://deno.land/x/iter@v3.2.3/lib/transformers.ts";
Returns the items of an iterable that meet the condition specified in a callback function.
Examples
Example 1
Example 1
import * as iter from "https://deno.land/x/iter/mod.ts";
const naturals = iter.create.increments(1);
const odds = iter.filter(naturals, (n) => n % 2 === 1);
const iterator = odds[Symbol.iterator]();
console.log(iterator.next().value); // -> 1
console.log(iterator.next().value); // -> 3
console.log(iterator.next().value); // -> 5
console.log(iterator.next().value); // -> 7
console.log(iterator.next().value); // -> 9
console.log(iterator.next().value); // -> 11
Parameters
it: Iterable<T>
- The iterable being filtered
predicate: IterablePredicateCallback<T>
- A function that accepts up to three arguments. The filter function calls the predicate function one time for each item in the iterable.
Returns
A new iterable