Skip to main content
Module

x/fun/mod.ts>optics.map

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 optics.map
import { optics } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { map } = optics;

Map over the Viewer portion of an optic. This effectively uses the map from the Flatmappable associated with the tag of the optic.

Examples

Example 1

import * as O from "./optics.ts";
import { pipe } from "./fn.ts";

const mapped = pipe(
  O.id<ReadonlyArray<string>>(),
  O.index(1),
  O.map(str => str.length),
);

const result1 = mapped.view(["Hello", "World"]); // Some(5)
const result2 = mapped.view([]); // None

Parameters

fai: (a: A) => I

Returns

<T extends Tag, S>(first: Viewer<T, S, A>) => Viewer<T, S, I>