paf31 / purescript-derive-lenses

A little utility to derive lenses and prisms for data types in PureScript
MIT License
41 stars 3 forks source link

Lenses for newtype #8

Open user471 opened 8 years ago

user471 commented 8 years ago
newtype Bar = {bar :: Int}
newtype Foo = {foo :: Bar}

Lenses like this

bar = lens (\(Bar x) -> x.bar) (\(Bar x) v -> Bar x { bar = v })

instead of

bar = lens _."bar" (_ { "bar" = _ })

looks better

x # foo <<< bar .~ 10

than

x # _Foo <<< foo <<< _Bar <<< bar .~ 10