This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Lens<S, A> = (f: (y: A) => A, x: S) => S; | |
export const view = <S, A>(lens: Lens<S, A>) => (x: S) => { | |
let value: unknown = null; | |
lens(x => (value = x), x); | |
// Because of lack of functor we can't create beautiful composition of .map.map... etc., | |
// so Const functor here is just plain variable without initializer | |
return value as A; | |
}; |