Skip to main content
Module

x/fun/decoder.ts>dimap

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 dimap
import { dimap } from "https://deno.land/x/fun@v.2.0.0-alpha.11/decoder.ts";

Map over the input and output of a Decoder. This is effectively a combination of map and contramap in a single operator.

Examples

Example 1

import * as D from "./decoder.ts";
import { pipe } from "./fn.ts";

const fromStr = pipe(
  D.tuple(D.string, D.string),
  D.dimap(
    (s) => [s, s],
    ([s]) => [s, s.length] as const,
  ),
);

const result1 = fromStr("hello"); // Right(["hello", 5])
const result2 = fromStr(null); // Left(DecodeError)

Parameters

fld: (l: L) => D
fai: (a: A) => I

Returns

(ua: Decoder<D, A>) => Decoder<L, I>