import { optics } from "https://deno.land/x/fun@v.2.0.0-alpha.11/mod.ts";
const { atMap } = optics;
Construct a composable combinator from an instance of Eq 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 "./optics.ts";
import * as M from "./map.ts";
import { EqString, toLowerCase } from "./string.ts";
import { contramap } from "./eq.ts";
import { constNone } from "./option.ts";
import { pipe } from "./fn.ts";
type Words = ReadonlyMap<string, number>;
const insensitive = pipe(EqString, contramap(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.empty())); // None
const result3 = remove(new Map([["FUN", 100], ["not", 10]]));
// Map("not": 10);
Parameters
eq: Eq<B>