Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/froebel/list.ts>partition

A strictly typed utility library.
Go to Latest
variable partition
import { partition } from "https://deno.land/x/froebel@v0.18.0/list.ts";

Takes a list and returns a pair of lists containing: the elements that match the predicate and those that don't, respectively.

Think of it as filter, but the elements that don't pass the filter aren't discarded but returned in a separate list instead.

Examples

Example 1

const [strings, numbers] = partition(
  ['a', 'b', 1, 'c', 2, 3],
  (el): el is string => typeof el === 'string'
)
// strings: ["a", "b", "c"]
// numbers: [1, 2, 3]

type

Partition