import { apply } from "https://deno.land/x/fun@v2.0.0-alpha.12/optics.ts";
Apply the value returned by a Viewer to a function returned by a Viewer.
Examples
Example 1
Example 1
import * as O from "./optics.ts";
import { pipe } from "./fn.ts";
type Person = { name: string, age: number };
type State = { people: readonly Person[], format: (p: Person) => string };
const fmt = pipe(O.id<State>(), O.prop("format"));
const adults = pipe(
O.id<State>(),
O.prop("people"),
O.array,
O.filter(p => p.age > 18)
);
const formatted = pipe(fmt, O.apply(adults));
const result = formatted.view({
people: [
{ name: "Brandon", age: 37 },
{ name: "Rufus", age: 1 },
],
format: p => `${p.name} is ${p.age}`,
}); // [ "Brandon is 37" ]