import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { atKey } = optic;
A composible combinator that focuses on a key in a readonly record. The difference between atKey and key is that the key can be removed from the record by the modify function if the modify function returns None.
Examples
Example 1
Example 1
import * as O from "./optic.ts";
import { constNone } from "./option.ts";
import { pipe } from "./fn.ts";
const atOne = pipe(
O.id<Readonly<Record<string, string>>>(),
O.atKey("one"),
);
const removeAtOne = pipe(atOne, O.replace(constNone()));
const result1 = pipe(atOne, O.view({})); // None
const result2 = pipe(atOne, O.view({ one: "one" })); // Some("one")
const result3 = removeAtOne({}); // {}
const result4 = removeAtOne({ one: "one" }); // {}
const result5 = removeAtOne({ one: "one", two: "two" }); // { two: "two" }