Skip to main content
Module

x/fun/record.ts>partition

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function partition
import { partition } from "https://deno.land/x/fun@v.2.0.0-alpha.11/record.ts";

Given a refinement or predicate, return a function that splits a ReadonlyRecord into a Pair of ReadonlyRecords, with the first record containing the values for which the predicate/refinement returned true and the second record containing the values for which the predicate/refinement returned false.

Examples

Example 1

import * as R from "./record.ts";
import { pipe } from "./fn.ts";

const result = pipe(
  { one: 1, two: 2, three: 3 },
  R.partition(n => n > 1),
); // [{ two: 2, three: 3 }, { one: 1 }]

Type Parameters

A
I extends A

Parameters

refinement: (a: A, key: string) => a is I

Parameters

predicate: (a: A, key: string) => boolean