Skip to main content
Module

x/fun/mod.ts>optic.props

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function optic.props
import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { props } = optic;

A composible combinator that focuses on a list of properties of a struct.

Examples

Example 1

import * as O from "./optic.ts";
import { pipe } from "./fn.ts";

type Book = {
  title: string,
  description: string,
  authors: readonly string[],
  published: Date,
};

const short = pipe(O.id<Book>(), O.props("title", "description"));

const suttree: Book = {
  title: "Suttree",
  description: "Cormac on Cormac",
  authors: ["Cormac McCarthy"],
  published: new Date("May 01 1979"),
};

const result1 = pipe(short, O.view(suttree));
// { title: "Suttree", description: "Cormac on Cormac" }

Type Parameters

A extends ReadonlyRecord<unknown>
P extends keyof A

Parameters

...props: [P, P, ...Array<P>]

Returns

<U extends Tag, S>(first: Optic<U, S, A>) => Optic<Align<U, LensTag>, S, [K in P]: A[K]>