optics-core-0.4.1.1: Optics as an abstract interface: core definitions

Safe Haskell | None
Language | Haskell2010

Optics.Re

Description

Some optics can be reversed with `re`. This is mainly useful to invert `Iso`s:

    >>> let _Identity = iso runIdentity Identity
    >>> view (_1 % re _Identity) ('x', "yz")
    Identity 'x'

Yet we can use a `Lens` as a `Review` too:

    >>> review (re _1) ('x', "yz")
    'x'

In the following diagram, red arrows illustrate how `re` transforms optics. The `ReversedLens` and `ReversedPrism` optic kinds are backwards versions of `Lens` and `Prism` respectively, and are present so that ``re` . `re`` does not change the optic kind.

Synopsis

- class ReversibleOptic k where
  - type ReversedOptic k = (r :: Type) | r -> k
  - re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic k is s t a b -> Optic (ReversedOptic k) is b a t s

# Documentation

class ReversibleOptic k where Source #

Class for optics that can be `re`versed.

Associated Types

type ReversedOptic k = (r :: Type) | r -> k Source #

Injective type family that maps an optic kind to the optic kind produced by `re`versing it.

    ReversedOptic An_Iso            = An_Iso
    ReversedOptic A_Prism           = A_ReversedPrism
    ReversedOptic A_ReversedPrism   = A_Prism
    ReversedOptic A_Lens            = A_ReversedLens
    ReversedOptic A_ReversedLens    = A_Lens
    ReversedOptic A_Getter          = A_Review
    ReversedOptic A_Review          = A_Getter

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic k is s t a b -> Optic (ReversedOptic k) is b a t s Source #

Reverses optics, turning around `Iso` into `Iso`, `Prism` into `ReversedPrism` (and back), `Lens` into `ReversedLens` (and back) and `Getter` into `Review` (and back).

#### Instances

Instances details

ReversibleOptic A_Getter Source # |

Instance details

Defined in Optics.Re

Associated Types

type ReversedOptic A_Getter |
Instance details Defined in Optics.Re type ReversedOptic A_Getter = A_Review

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic A_Getter is s t a b -> Optic (ReversedOptic A_Getter) is b a t s Source #

ReversibleOptic A_Lens Source # |

Instance details

Defined in Optics.Re

Associated Types

type ReversedOptic A_Lens |
Instance details Defined in Optics.Re type ReversedOptic A_Lens = A_ReversedLens

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic A_Lens is s t a b -> Optic (ReversedOptic A_Lens) is b a t s Source #

ReversibleOptic A_Prism Source # |

Instance details

Defined in Optics.Re

Associated Types

type ReversedOptic A_Prism |
Instance details Defined in Optics.Re type ReversedOptic A_Prism = A_ReversedPrism

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic A_Prism is s t a b -> Optic (ReversedOptic A_Prism) is b a t s Source #

ReversibleOptic A_ReversedLens Source # |

Instance details

Defined in Optics.Re

Associated Types

type ReversedOptic A_ReversedLens |
Instance details Defined in Optics.Re type ReversedOptic A_ReversedLens = A_Lens

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic A_ReversedLens is s t a b -> Optic (ReversedOptic A_ReversedLens) is b a t s Source #

ReversibleOptic A_ReversedPrism Source # |

Instance details

Defined in Optics.Re

Associated Types

type ReversedOptic A_ReversedPrism |
Instance details Defined in Optics.Re type ReversedOptic A_ReversedPrism = A_Prism

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic A_ReversedPrism is s t a b -> Optic (ReversedOptic A_ReversedPrism) is b a t s Source #

ReversibleOptic A_Review Source # |

Instance details

Defined in Optics.Re

Associated Types

type ReversedOptic A_Review |
Instance details Defined in Optics.Re type ReversedOptic A_Review = A_Getter

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic A_Review is s t a b -> Optic (ReversedOptic A_Review) is b a t s Source #

ReversibleOptic An_Iso Source # |

Instance details

Defined in Optics.Re

Associated Types

type ReversedOptic An_Iso |
Instance details Defined in Optics.Re type ReversedOptic An_Iso = An_Iso

Methods

re :: forall (is :: IxList) s t a b. AcceptsEmptyIndices "re" is => Optic An_Iso is s t a b -> Optic (ReversedOptic An_Iso) is b a t s Source #