Copyright | (C) 2012-16 Edward Kmett |
---|---|

License | BSD-style (see the file LICENSE) |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Stability | provisional |

Portability | non-portable |

Safe Haskell | None |

Language | Haskell98 |

- type Review t b = forall p f. (Choice p, Bifunctor p, Settable f) => Optic' p f t b
- type AReview t b = Optic' Tagged Identity t b
- unto :: (Profunctor p, Bifunctor p, Functor f) => (b -> t) -> Optic p f s t a b
- un :: (Profunctor p, Bifunctor p, Functor f) => Getting a s a -> Optic' p f a s
- re :: Contravariant f => AReview t b -> LensLike' f b t
- review :: MonadReader b m => AReview t b -> m t
- reviews :: MonadReader b m => AReview t b -> (t -> r) -> m r
- reuse :: MonadState b m => AReview t b -> m t
- reuses :: MonadState b m => AReview t b -> (t -> r) -> m r
- (#) :: AReview t b -> b -> t
- class Bifunctor p where
- bimap :: (a -> b) -> (c -> d) -> p a c -> p b d

- retagged :: (Profunctor p, Bifunctor p) => p a b -> p s b
- class (Profunctor p, Bifunctor p) => Reviewable p

# Reviewing

re :: Contravariant f => AReview t b -> LensLike' f b t Source

Turn a `Prism`

or `Iso`

around to build a `Getter`

.

If you have an `Iso`

, `from`

is a more powerful version of this function
that will return an `Iso`

instead of a mere `Getter`

.

`>>>`

Left 5`5 ^.re _Left`

`>>>`

Left 7`6 ^.re (_Left.unto succ)`

`review`

≡`view`

`.`

`re`

`reviews`

≡`views`

`.`

`re`

`reuse`

≡`use`

`.`

`re`

`reuses`

≡`uses`

`.`

`re`

`re`

::`Prism`

s t a b ->`Getter`

b t`re`

::`Iso`

s t a b ->`Getter`

b t

review :: MonadReader b m => AReview t b -> m t Source

This can be used to turn an `Iso`

or `Prism`

around and `view`

a value (or the current environment) through it the other way.

`review`

≡`view`

`.`

`re`

`review`

.`unto`

≡`id`

`>>>`

Left "mustard"`review _Left "mustard"`

`>>>`

6`review (unto succ) 5`

Usually `review`

is used in the `(->)`

`Monad`

with a `Prism`

or `Iso`

, in which case it may be useful to think of
it as having one of these more restricted type signatures:

`review`

::`Iso'`

s a -> a -> s`review`

::`Prism'`

s a -> a -> s

However, when working with a `Monad`

transformer stack, it is sometimes useful to be able to `review`

the current environment, in which case
it may be beneficial to think of it as having one of these slightly more liberal type signatures:

`review`

::`MonadReader`

a m =>`Iso'`

s a -> m s`review`

::`MonadReader`

a m =>`Prism'`

s a -> m s

reviews :: MonadReader b m => AReview t b -> (t -> r) -> m r Source

This can be used to turn an `Iso`

or `Prism`

around and `view`

a value (or the current environment) through it the other way,
applying a function.

`reviews`

≡`views`

`.`

`re`

`reviews`

(`unto`

f) g ≡ g`.`

f

`>>>`

False`reviews _Left isRight "mustard"`

`>>>`

8`reviews (unto succ) (*2) 3`

Usually this function is used in the `(->)`

`Monad`

with a `Prism`

or `Iso`

, in which case it may be useful to think of
it as having one of these more restricted type signatures:

`reviews`

::`Iso'`

s a -> (s -> r) -> a -> r`reviews`

::`Prism'`

s a -> (s -> r) -> a -> r

However, when working with a `Monad`

transformer stack, it is sometimes useful to be able to `review`

the current environment, in which case
it may be beneficial to think of it as having one of these slightly more liberal type signatures:

`reviews`

::`MonadReader`

a m =>`Iso'`

s a -> (s -> r) -> m r`reviews`

::`MonadReader`

a m =>`Prism'`

s a -> (s -> r) -> m r

reuse :: MonadState b m => AReview t b -> m t Source

This can be used to turn an `Iso`

or `Prism`

around and `use`

a value (or the current environment) through it the other way.

`reuse`

≡`use`

`.`

`re`

`reuse`

`.`

`unto`

≡`gets`

`>>>`

Left 5`evalState (reuse _Left) 5`

`>>>`

6`evalState (reuse (unto succ)) 5`

`reuse`

::`MonadState`

a m =>`Prism'`

s a -> m s`reuse`

::`MonadState`

a m =>`Iso'`

s a -> m s

reuses :: MonadState b m => AReview t b -> (t -> r) -> m r Source

This can be used to turn an `Iso`

or `Prism`

around and `use`

the current state through it the other way,
applying a function.

`reuses`

≡`uses`

`.`

`re`

`reuses`

(`unto`

f) g ≡`gets`

(g`.`

f)

`>>>`

True`evalState (reuses _Left isLeft) (5 :: Int)`

`reuses`

::`MonadState`

a m =>`Prism'`

s a -> (s -> r) -> m r`reuses`

::`MonadState`

a m =>`Iso'`

s a -> (s -> r) -> m r

(#) :: AReview t b -> b -> t infixr 8 Source

An infix alias for `review`

.

`unto`

f # x ≡ f x l # x ≡ x`^.`

`re`

l

This is commonly used when using a `Prism`

as a smart constructor.

`>>>`

Left 4`_Left # 4`

But it can be used for any `Prism`

`>>>`

"7b"`base 16 # 123`

(#) ::`Iso'`

s a -> a -> s (#) ::`Prism'`

s a -> a -> s (#) ::`Review`

s a -> a -> s (#) ::`Equality'`

s a -> a -> s

class Bifunctor p where

Formally, the class `Bifunctor`

represents a bifunctor
from `Hask`

-> `Hask`

.

Intuitively it is a bifunctor where both the first and second arguments are covariant.

You can define a `Bifunctor`

by either defining `bimap`

or by
defining both `first`

and `second`

.

If you supply `bimap`

, you should ensure that:

`bimap`

`id`

`id`

≡`id`

If you supply `first`

and `second`

, ensure:

`first`

`id`

≡`id`

`second`

`id`

≡`id`

If you supply both, you should also ensure:

`bimap`

f g ≡`first`

f`.`

`second`

g

These ensure by parametricity:

`bimap`

(f`.`

g) (h`.`

i) ≡`bimap`

f h`.`

`bimap`

g i`first`

(f`.`

g) ≡`first`

f`.`

`first`

g`second`

(f`.`

g) ≡`second`

f`.`

`second`

g

*Since: 4.8.0.0*

bimap :: (a -> b) -> (c -> d) -> p a c -> p b d

Bifunctor Either | |

Bifunctor (,) | |

Bifunctor Const | |

Bifunctor Arg | |

Bifunctor ((,,) x1) | |

Functor f => Bifunctor (CofreeF f) | |

Functor f => Bifunctor (FreeF f) | |

Bifunctor (Tagged *) | |

Functor f => Bifunctor (AlongsideRight f) | |

Functor f => Bifunctor (AlongsideLeft f) | |

Bifunctor ((,,,) x1 x2) | |

Bifunctor ((,,,,) x1 x2 x3) | |

Bifunctor p => Bifunctor (WrappedBifunctor * * p) | |

Functor g => Bifunctor (Joker * * g) | |

Bifunctor p => Bifunctor (Flip * * p) | |

Functor f => Bifunctor (Clown * * f) | |

Bifunctor ((,,,,,) x1 x2 x3 x4) | |

(Bifunctor f, Bifunctor g) => Bifunctor (Product * * f g) | |

(Bifunctor p, Bifunctor q) => Bifunctor (Sum * * p q) | |

Bifunctor ((,,,,,,) x1 x2 x3 x4 x5) | |

(Functor f, Bifunctor p) => Bifunctor (Tannen * * * f p) | |

(Bifunctor p, Functor f, Functor g) => Bifunctor (Biff * * * * p f g) | |

retagged :: (Profunctor p, Bifunctor p) => p a b -> p s b Source

This is a profunctor used internally to implement Review

It plays a role similar to that of `Accessor`

or `Const`

do for Control.Lens.Getter

class (Profunctor p, Bifunctor p) => Reviewable p Source

This class is provided mostly for backwards compatibility with lens 3.8, but it can also shorten type signatures.

(Profunctor p, Bifunctor p) => Reviewable p Source | |