Skip to main content
Module

x/fun/set.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.10/set.ts";

Traverse a ReadonlySet value by value, applying a function A -> V, then collecting all of the I values into ReadonlySet and returning V<ReadonlySet>. In concrete terms this can take ReadonlySet<Option> and turn it into Option<ReadonlySet> and other ADT inversions.

Examples

Example 1

import * as S from "./set.ts";
import * as O from "./option.ts";
import { pipe } from "./fn.ts";

const traverseOption = S.traverse(O.ApplicativeOption);
const invert = traverseOption((o: O.Option<number>) => o);

const result1 = pipe(
  S.set(O.some(1), O.some(2), O.some(3)),
  invert,
); // Some(Set(1, 2, 3))
const result2 = pipe(
  S.set(O.some(1), O.some(2), O.none),
  invert,
); // None