lens-4.9: Lenses, Folds and Traversals

Copyright(C) 2012-15 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell98

Control.Lens

Description

Usage:

You can derive lenses automatically for many data types:

import Control.Lens

data FooBar a
  = Foo { _x :: [Int], _y :: a }
  | Bar { _x :: [Int] }
makeLenses ''FooBar

This defines the following lenses:

x :: Lens' (FooBar a) [Int]
y :: Traversal (FooBar a) (FooBar b) a b

You can then access the value of _x with (^.), the value of _y – with (^?) or (^?!) (since it can fail), set the values with (.~), modify them with (%~), and use almost any other combinator that is re-exported here on those fields.

The combinators here have unusually specific type signatures, so for particularly tricky ones, the simpler type signatures you might want to pretend the combinators have are specified as well.

More information on how to use lenses is available on the lens wiki:

http://github.com/ekmett/lens/wiki

Documentation