import { optics } from "https://deno.land/x/fun@v.2.0.0-alpha.11/mod.ts";
const { traverse } = optics;
Construct a composable optic from a Traversable instance for a Kind T. This will reduce the values wrapped in the Kind T into a single Array when viewed.
Examples
Example 1
Example 1
import * as O from "./optics.ts";
import * as T from "./tree.ts";
import { pipe } from "./fn.ts";
type Data = { tree: T.Tree<number> };
const numbers = pipe(
O.id<Data>(),
O.prop("tree"),
O.traverse(T.TraversableTree),
);
const tree1: Data = { tree: T.tree(1, [T.tree(2), T.tree(3)]) };
const tree2: Data = { tree: T.tree(0) };
const result1 = pipe(numbers, O.view(tree1)); // [1, 2, 3]
const result2 = pipe(numbers, O.view(tree2)); // [0]
const result3 = pipe(tree1, numbers.modify(n => n + 1));
// Tree(2, [Tree(3), Tree(4)])
Parameters
T: Traversable<T>