Skip to main content
Module

x/fun/decoder.ts>refine

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

Apply a refinement or predicate to the output of an existing Decoder. This is useful for building complicated Decoders.

Examples

Example 1

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

const nonEmptyString = pipe(
  D.string,
  D.refine(s => s.length > 0, "noninit"),
);

const result1 = nonEmptyString(null); // Left(DecodeError)
const result2 = nonEmptyString(""); // Left(DecodeError)
const result3 = nonEmptyString("Hello"); // Right("Hello")

Type Parameters

A
B extends A

Parameters

refinement: Refinement<A, B>
id: string

Returns

<I>(from: Decoder<I, A>) => Decoder<I, B>

Parameters

refinement: Predicate<A>
id: string

Returns

<I>(from: Decoder<I, A>) => Decoder<I, A>