flâneur

Overview · ekmett/lens Wiki

github.com · 571 words · saved by 2 readers

Lenses, Folds, and Traversals - Join us on web.libera.chat #haskell-lens - ekmett/lens

What are Lenses? Lenses are composable functional references. They allow you to access and modify data potentially very deep within a structure! Ignoring the implementation for the moment, lenses provide us with two operations: view :: Lens' a b -> a -> b set :: Lens' a b -> b -> a -> a So we can view a lens as a pair of a getter and a setter that are in some sense compatible. We'll use the following lenses to start off: _1 :: Lens' (a,b) a _2 :: Lens' (a,b) b to both read from >>> view _2 ("hello","world") ("world") and write to parts of a whole: >>> set _2 42 ("hello",0)…

saved by

related reading