Skip to main content
Module

x/fun/mod.ts>option.traverse

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

Traverse over an Option using the supplied Applicable. This allows one to turn an Option into Kind<V, Option>.

Examples

Example 1

import * as O from "./option.ts";
import * as A from "./array.ts";
import { pipe } from "./fn.ts";

const toRange = (n: number) => A.range(n);
const traverse = pipe(toRange, O.traverse(A.ApplicableArray));

const result1 = traverse(O.some(3)); // [Some(0), Some(1), Some(2)];
const result2 = traverse(O.none); // [None]

Type Parameters

V extends Kind

Parameters

A: Applicable<V>

Returns

<A, I, J, K, L, M>(favi: (a: A) => $<V, [I, J, K], [L], [M]>) => (ta: Option<A>) => $<V, [Option<I>, J, K], [L], [M]>