Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/fun/mod.ts>option.partition

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function option.partition
import { option } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { partition } = option;

Given a refinement or predicate, return a function that splits an Option into a Pair<Option, Option>. Due to the nature of the option type this will always return Pair<Some, None>, Pair<None, None>, or Pair<None, Some>.

Examples

Example 1

import * as O from "./option.ts";

const partition = O.partition((n: number) => n > 0);

const result1 = partition(O.some(1)); // [Some(1), None]
const result2 = partition(O.some(0)); // [None, Some(0)]
const result3 = partition(O.none); // [None, None]

Type Parameters

A
B extends A

Parameters

refinement: Refinement<A, B>

Returns

(ua: Option<A>) => Pair<Option<B>, Option<A>>

Parameters

predicate: Predicate<A>

Returns

(ua: Option<A>) => Pair<Option<A>, Option<A>>