Skip to main content
Module

x/fun/pair.ts>traverse

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

Traverse a pair using another algebraic structure's Applicable.

Examples

Example 1

import { traverse, pair } from "./pair.ts";
import { some, ApplicableOption, fromPredicate } from "./option.ts";
import { pipe } from "./fn.ts";

const traverseOption = traverse(ApplicableOption);
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" }