January 2019
Beginner
210 pages
4h 47m
English
Prisms are almost identical to lenses. We can think about a prism as a kind of lens that allows us to get and set an optional property in an object. The most significant difference between lenses and prisms is that prisms can work with optional types.
The following code snippet declares the Prism interface. As we can see, the Prism interface is very similar to the Lens interface. However, the get method returns an optional type, Maybe<T>:
type Maybe<T> = T | null;interface Prism<T1, T2> { get(o: T1): Maybe<T2>, set(a: T2, o: T1): T1;}
Just like lenses, prisms can be composed. The following code snippet declares a higher-order function that allows us to compose two prisms:
function composePrism<A, B, C>(ab: Prism<A, B>, bc: Prism<B, ...
Read now
Unlock full access