// @flow import type { PLens } from './PLens' import type { PPrism } from './PPrism' import type { Either } from './Either' import * as either from './Either' export interface PIso { get(s: S): A, reverseGet(b: B): T } export type Iso = PIso; export function modify(iso: PIso, f: (a: A) => B, s: S): T { return iso.reverseGet(f(iso.get(s))) } export function composeIso(abcd: PIso, stab: PIso): PIso { return { get(s: S): C { return abcd.get(stab.get(s)) }, reverseGet(d: D): T { return stab.reverseGet(abcd.reverseGet(d)) } } } export function asLens(iso: PIso): PLens { return { get: iso.get, set: iso.reverseGet } } export function asPrism(iso: PIso): PPrism { return { getOrModify(s: S): Either { return either.right(iso.get(s)) }, reverseGet: iso.reverseGet } }