Skip to content

Commit

Permalink
Added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrannell1 committed Jun 30, 2023
1 parent f787f9d commit 0a3763d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/prisms.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { AbstractPrism, Prism } from "./types.ts";

/**
* Static methods for prisms
*
*/
export class Prisms {

/**
* Construct a prism that unions a series of prisms.
*
* - view: returns the first non-null view of the prism series
* - set: sets the value of the first prism that has a non-null view
*
*/
static union<Whole, Part>(...prisms: Prism<Whole, Part>[]) {
return new class extends AbstractPrism<Whole, Part> {
view(whole: Whole): Part | null {
Expand Down
12 changes: 12 additions & 0 deletions src/traversals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { AbstractTraversal, Traversal } from "./types.ts";

/**
* Static methods for traversals
*
*/
export class Traversals {

/**
* Construct a traversal that joins the views of multiple traversals.
*
* - view: returns the concatenation of the views of each traversal
* - modify: applies the modifier to the view of each traversal
*
*/
static union<Whole, Part>(...traversals: Traversal<Whole, Part>[]) {
return new class extends AbstractTraversal<Whole, Part> {
view(whole: Whole): Part[] {
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export interface Prism<Whole, Part> {
): Prism<Whole, SubPart>;
}

/*
* Partial implementation of the prism interface, leaving view and set abstract
*
*/
export abstract class AbstractPrism<Whole, Part> implements Prism<Whole, Part> {
abstract view(whole: Whole): Part | null;
abstract set(newPart: Part, whole: Whole): Whole;
Expand Down Expand Up @@ -78,6 +82,10 @@ export interface Traversal<Whole, Part> {
composePrism<SubPart>(prism: Prism<Part, SubPart>): Traversal<Whole, SubPart>;
}

/*
* Partial implementation of the traversal interface, leaving view and modify abstract
*
*/
export abstract class AbstractTraversal<Whole, Part>
implements Traversal<Whole, Part> {
abstract view(whole: Whole): Part[];
Expand Down

0 comments on commit 0a3763d

Please sign in to comment.