import { set } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { traverse } = set;
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
Example 1
import * as S from "./set.ts";
import * as O from "./option.ts";
import { pipe } from "./fn.ts";
const traverseOption = S.traverse(O.ApplicableOption);
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
Parameters
A: Applicable<V>