Skip to main content
Module

x/itertools/more-itertools.ts>partition

🦕 A TypeScript port of Python's itertools and more-itertools for Deno
Latest
function partition
import { partition } from "https://deno.land/x/itertools@v1.1.2/more-itertools.ts";

Returns a 2-tuple of arrays. Splits the elements in the input iterable into either of the two arrays. Will fully exhaust the input iterable. The first array contains all items that match the predicate, the second the rest:

>>> const isOdd = x => x % 2 !== 0;
>>> const iterable = range(10);
>>> const [odds, evens] = partition(iterable, isOdd);
>>> odds
[1, 3, 5, 7, 9]
>>> evens
[0, 2, 4, 6, 8]

Parameters

iterable: Iterable<T>
predicate: Predicate<T>

Returns

[Array<T>, Array<T>]