Skip to main content
Module

x/fun/optic.ts>imap

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

An invariant map over an Optic. If a type can be represented isomorphically by another type, one can imap to go back and forth.

Examples

Example 1

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

const plussed = pipe(
  O.id<number>(),
  O.imap(n => n + 100, n => n - 100),
);

const result1 = plussed.view(1); // 101
const result2 = plussed.modify(n => n + 1)(1); // 2

Parameters

fai: (a: A) => I
fia: (i: I) => A

Returns

<U extends Tag, S>(first: Optic<U, S, A>) => Optic<Align<U, LensTag>, S, I>