lens-3.9.0.2: Lenses, Folds and Traversals

Portability | GHC
Stability | experimental
Maintainer | Edward Kmett <ekmett@gmail.com>
Safe Haskell | None

Generics.Deriving.Lens

Contents

- Isomorphisms for `GHC.Generics`
- Generic Traversal

Description

Note: `Generics.Deriving` exports a number of names that collide with `Control.Lens`.

You can use hiding or imports to mitigate this to an extent, and the following imports, represent a fair compromise for user code:

     import Control.Lens hiding (Rep)
     import Generics.Deriving hiding (from, to)

You can use `generic` to replace `from` and `to` from `Generics.Deriving`, and probably won't be explicitly referencing `Rep` from `Control.Lens` in code that uses generics.

Synopsis

- generic :: Generic a => Iso' a (Rep a b)
- generic1 :: Generic1 f => Iso' (f a) (Rep1 f a)
- tinplate :: (Generic a, GTraversal (Rep a), Typeable b) => Traversal' a b
- class GTraversal f

# Isomorphisms for `GHC.Generics`

generic :: Generic a => Iso' a (Rep a b)

Convert from the data type to its representation (or back)

    >>> "hello"^.generic.from generic :: String
    "hello"

generic1 :: Generic1 f => Iso' (f a) (Rep1 f a)

Convert from the data type to its representation (or back)

# Generic Traversal

tinplate :: (Generic a, GTraversal (Rep a), Typeable b) => Traversal' a b

A `Generic` `Traversal` that visits every occurrence of something `Typeable` anywhere in a container.

    >>> allOf tinplate (=="Hello") (1::Int,2::Double,(),"Hello",["Hello"])
    True

    >>> mapMOf_ tinplate putStrLn ("hello",[(2 :: Int, "world!")])
    hello
    world!

class GTraversal f

Used to traverse `Generic` data by `uniplate`.

Instances

GTraversal U1 |
(Generic a, GTraversal (Rep a), Typeable a) => GTraversal (K1 i a) |
(GTraversal f, GTraversal g) => GTraversal (:+: f g) |
(GTraversal f, GTraversal g) => GTraversal (:*: f g) |
(Traversable f, GTraversal g) => GTraversal (:.: f g) |
GTraversal a => GTraversal (M1 i c a) |