export interface Lens < A , B > { get ( root ) : B ; set ( root , newValue ) : A ; } export function isLens ( x ) { return ( typeof x === "object" && typeof x . get === "function" && typeof x . set === "function" ) ; } export function prop < A , K extends keyof A > ( key ) { return { get : ( root ) => ( root as any ) [ key ] , set : ( root , newValue ) => ( { ... root , [ key ] : newValue } ) , } ; } export function item < I > ( index ) { return { get : ( root ) => ( root as any ) [ index ] , set : ( nums , newValue ) => newValue === undefined ? [ ... nums . slice ( 0 , index ) , ... nums . slice ( index + 1 ) ] : [ ... nums . slice ( 0 , index ) , newValue , ... nums . slice ( index + 1 ) ] , } ; }