Skip to main content
Module

x/fun/mod.ts>decoder.map

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

Map over the output of a Decoder.

Examples

Example 1

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

const stringLength = pipe(
  D.string,
  D.map(s => s.length),
);

const result1 = stringLength(null); // Left(DecodeError)
const result2 = stringLength(""); // Right(0)
const result3 = stringLength("Hello"); // Right(5)

Parameters

fai: (a: A) => I

Returns

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