Skip to main content
Module

x/fun/mod.ts>option.partitionMap

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

Map and partition over the inner value of an Option at the same time. If the option passed is None then the result is [None, None], otherwise Right will result in [Some, None], and Left will result in [None, Some].

Examples

Example 1

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

const partitioner = (n: number) => n > 0 ? E.right(n) : E.left(n * -1);
const partitionMap = O.partitionMap(partitioner);

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

Parameters

fai: (a: A) => Either<J, I>

Returns

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