import { takeWhile } from "https://deno.land/x/iter@v3.2.3/mod.ts";
Returns a new iterable which yields while f
returns true.
Examples
Example 1
Example 1
import * as iter from "https://deno.land/x/iter/mod.ts";
const naturals = iter.create.increments(1);
const numbers = iter.takeWhile(naturals, (n) => n <= 5);
for (const num of numbers) {
console.log(num);
}
// -> 1
// -> 2
// -> 3
// -> 4
// -> 5
Parameters
it: Iterable<T>
- The iterable being cut.
- A function that accepts up to three
arguments. The
takeWhile
function callsf
one time for each item in the iterable. included.
Returns
A new iterables of it
which terminates