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

x/fun/record.ts>partitionMap

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

Given a function that takes an A and a key and returns an Either<J, K> return a function that simultaneously partitions and maps over the values in a ReadonlyRecord. This is the equivalent of first partitioning a ReadonlyRecord, and then using Pair's Bimap over both values in a Pair.

Examples

Example 1

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

const result = pipe(
  { one: 1, two: 2, three: 3 },
  R.partitionMap(
    n => n > 1
      ? E.right(`${n} is big enough`)
      : E.left(`${n} is small enough`)
  ),
);
// [
//   { two: "2 is big enough", three: "3 is big enough" },
//   { one: "1 is small enough" }
// ]

Parameters

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