Returns all elements in the given collection until the first element that does not match the given predicate.
Note: If you want to process any iterable, use the new version of takeWhile from @std/collections/unstable-take-while.
takeWhile
@std/collections/unstable-take-while
The type of the array elements.
The array to take elements from.
The predicate function to determine if an element should be included.
A new array containing all elements until the first element that does not match the predicate.
import { takeWhile } from "@std/collections/take-while";import { assertEquals } from "@std/assert";const numbers = [1, 2, 3, 4, 5, 6];const result = takeWhile(numbers, (number) => number < 4);assertEquals(result, [1, 2, 3]); Copy
import { takeWhile } from "@std/collections/take-while";import { assertEquals } from "@std/assert";const numbers = [1, 2, 3, 4, 5, 6];const result = takeWhile(numbers, (number) => number < 4);assertEquals(result, [1, 2, 3]);
Returns all elements in the given collection until the first element that does not match the given predicate.
Note: If you want to process any iterable, use the new version of
takeWhilefrom@std/collections/unstable-take-while.