A Lens is a functional concept which solves a very common problem: how to easily update a complex immutable structure, for this purpose Lens acts as a zoom into a record.
addressStreetNameLens : Lens Address String
addressStreetNameLens =
let
get a = a.streetName
set sn a = { a | streetName = sn }
in
Lens get set
placeAddressLens : Lens Place Address
placeAddressLens =
let
get p = p.address
set a p = { p | address = a }
in
Lens get set
placeStreetName: Lens Place String
placeStreetName = placeAddressLens `compose` addressStreetNameLensComposes Lens a b with Lens b c and returns Lens a c
Modifies given function (b -> b) to be (a -> a) using Lens a b
addressStreetNameLens = Lens Address String
fx streetName = String.reverse streeName
fx2 = Lens.modify addressStreetNameLens fx
fx2 {streetName="abcdef"} == {streetName="fedcba"}Zips Lens a c with Lens b d to form Lens ( a, b ) ( c, d )
Casts Iso a b to Lens a b
In order to create Lens we need to suply 2 functions: set and get