import { decoder } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { refine } = decoder;
Apply a refinement or predicate to the output of an existing Decoder. This is useful for building complicated Decoders.
Examples
Example 1
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
B extends A
Parameters
refinement: Predicate<A>