import { decoder } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { compose } = decoder;
Compose two Decoders where the input to second aligns with the output of first.
Examples
Example 1
Example 1
import * as D from "./decoder.ts";
import * as S from "./string.ts";
import { pipe } from "./fn.ts";
const prefixed = <T extends string>(prefix: T) =>
D.fromPredicate(S.startsWith(prefix), `prefixed with "${prefix}"`);
const eventMethod = pipe(
D.string,
D.compose(prefixed("on")),
);
const result1 = eventMethod(null); // Left(DecodeError)
const result2 = eventMethod("hello"); // Left(DecodeError)
const result3 = eventMethod("onClick"); // Right("onClick");