import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { atMap } = optic;
Construct a composable combinator from an instance of Comparable and a key of a map. The combinator can then be composed with an existing optic to access or remove the value in the map.
Examples
Example 1
Example 1
import * as O from "./optic.ts";
import * as M from "./map.ts";
import { ComparableString, toLowerCase } from "./string.ts";
import { premap } from "./comparable.ts";
import { constNone } from "./option.ts";
import { pipe } from "./fn.ts";
type Words = ReadonlyMap<string, number>;
const insensitive = pipe(ComparableString, premap(toLowerCase));
const fun = pipe(O.id<Words>(), O.atMap(insensitive)("fun"));
const remove = pipe(fun, O.replace(constNone()));
const result1 = pipe(fun, O.view(new Map([["FUN", 100]]))); // Some(100)
const result2 = pipe(fun, O.view(M.init())); // None
const result3 = remove(new Map([["FUN", 100], ["not", 10]]));
// Map("not": 10);
Parameters
eq: Comparable<B>