dimap
import { dimap } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/fn.ts";A combination of premap and map, dimap applies fld to the input of a function and fai to the output.
@example
import type { NonEmptyArray } from "./array.ts";
import { dimap, pipe } from "./fn.ts";
import { plural, split } from "./string.ts";
const are = plural("is", "are");
const words = plural("word", "words");
const describe = (n: number) => `There ${are(n)} ${n} ${words(n)}`;
const toWords = split(/\s+/g); // string => string[]
const count = (ws: NonEmptyArray<string>) => ws.length;
const fromString = pipe(
count,
dimap(toWords, describe),
);
const result1 = fromString("Hello World"); // "There are 2 words"
const result2 = fromString("Hi"); // "There is 1 word"
const result3 = fromString("This is a test"); // "There are 4 words"