How to use the monocle-ts.Prism.fromPredicate function in monocle-ts

To help you get started, we’ve selected a few monocle-ts examples, based on popular ways it is used in public projects.

github gcanti / fp-ts-codegen / examples / These.ts View on Github external
export function _right<A, B>(): Prism<These<A, B>, These<A, B>> { return Prism.fromPredicate(s => s.type === "Right"); }
github gcanti / fp-ts-codegen / examples / FooBar.ts View on Github external
export const bar: FooBar = { type: "Bar" };

export function fold<R>(fa: FooBar, onFoo: R, onBar: R): R { switch (fa.type) {
    case "Foo": return onFoo;
    case "Bar": return onBar;
} }

export function foldL<R>(fa: FooBar, onFoo: () => R, onBar: () => R): R { switch (fa.type) {
    case "Foo": return onFoo();
    case "Bar": return onBar();
} }

import { Prism } from "monocle-ts";

export const _Foo: Prism<FooBar, FooBar> = Prism.fromPredicate(s => s.type === "Foo");

export const _Bar: Prism<FooBar, FooBar> = Prism.fromPredicate(s => s.type === "Bar");
github gcanti / fp-ts-codegen / examples / Either.ts View on Github external
export function _right<E, R>(): Prism<Either<E, R>, Either<E, R>> { return Prism.fromPredicate(s => s.type === "Right"); }
github gcanti / fp-ts-codegen / examples / Maybe.ts View on Github external
export function _just<A>(): Prism<Maybe<A>, Maybe<A>> { return Prism.fromPredicate(s => s.type === "Just"); }
github gcanti / fp-ts-codegen / examples / Constrained.ts View on Github external
export function _fetching<A extends string>(): Prism<Constrained<A>, Constrained<A>> { return Prism.fromPredicate(s => s.type === "Fetching"); }
github gcanti / io-ts-types / src / monocle-ts / createRangePrism.ts View on Github external
export const createRangePrism = (from: number, to: number): Prism<number, number> => {
  return Prism.fromPredicate<number>(n => n >= from && n <= to)
}
github gcanti / fp-ts-codegen / examples / Maybe.ts View on Github external
export function _nothing<A>(): Prism<Maybe<A>, Maybe<A>> { return Prism.fromPredicate(s => s.type === "Nothing"); }
github gcanti / fp-ts-codegen / examples / Either.ts View on Github external
export function _left<E, R>(): Prism<Either<E, R>, Either<E, R>> { return Prism.fromPredicate(s => s.type === "Left"); }
github gcanti / fp-ts-codegen / examples / Tree.ts View on Github external
export function _leaf<A>(): Prism<Tree<A>, Tree<A>> { return Prism.fromPredicate(s => s.type === "Leaf"); }
github gcanti / fp-ts-codegen / examples / Option.ts View on Github external
export function _none<A>(): Prism<Option<A>, Option<A>> { return Prism.fromPredicate(s => s.type === "None"); }

monocle-ts

A porting of scala monocle library to TypeScript

MIT
Latest version published 6 months ago

Package Health Score

72 / 100
Full package analysis

Similar packages