import { Maybe , fromJust , isNothing } from '@typed/maybe' ; import { Lens } from '../types' ; import { curry2 } from '@typed/functions' ; name export const lens = curry2 ( __lens ) ; function __lens < A , B > ( getter , setter ) { function updateAt ( f , a ) { const value = f ( view ( a ) ) ; if ( isNothing ( value ) ) return a ; return setter ( fromJust ( value ) , a ) ; } function view ( a ) { return Maybe . of ( getter ( a ) ) ; } return { view , updateAt : curry2 ( updateAt ) } ; } export type LensFn = { < A , B > ( getter , setter ) : Lens < A , B > ; < A , B > ( getter ) : ( setter : ( value : B , a : A ) => A ) => Lens < A , B > ; } ;