import { pair } from "https://deno.land/x/fun@v2.0.0-alpha.6/mod.ts";
const { traverse } = pair;
Traverse a pair using another algebraic structure's Applicative.
Examples
Example 1
Example 1
import { traverse, pair } from "./pair.ts";
import { some, ApplicativeOption, fromPredicate } from "./option.ts";
import { pipe } from "./fn.ts";
const traverseOption = traverse(ApplicativeOption);
const startsWithB = fromPredicate(
(name: string) => name.startsWith("B")
);
const result1 = pipe(
pair("Brandon", 37),
traverseOption(startsWithB),
); // { tag: "Some", value: ["Brandon", 37] }
const result2 = pipe(
pair("Alice", 37),
traverseOption(startsWithB),
); // { tag: "None" }
Parameters
A: Applicative<V>