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 | Trustworthy |
Language | Haskell2010 |
Control.Lens.Review
Contents
Description
Synopsis
- type Review t b = forall (p :: Type -> Type -> Type) (f :: Type -> Type). (Choice p, Bifunctor p, Settable f) => Optic' p f t b
- type AReview t b = Optic' (Tagged :: Type -> Type -> Type) 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 :: AReview t b -> Getter 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 (forall a. Functor (p a)) => Bifunctor (p :: Type -> Type -> Type) 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 :: Type -> Type -> Type)
- reviewing :: (Bifunctor p, Functor f) => Optic (Tagged :: Type -> Type -> Type) Identity s t a b -> Optic' p f t b
Reviewing
type Review t b = forall (p :: Type -> Type -> Type) (f :: Type -> Type). (Choice p, Bifunctor p, Settable f) => Optic' p f t b Source #
re :: AReview t b -> Getter 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
.
>>>
5 ^.re _Left
Left 5
>>>
6 ^.re (_Left.unto succ)
Left 7
review
≡view
.
re
reviews
≡views
.
re
reuse
≡use
.
re
reuses
≡uses
.
re
re
::Prism
s t a b ->Getter
b tre
::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
>>>
review _Left "mustard"
Left "mustard"
>>>
review (unto succ) 5
6
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 -> sreview
::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 sreview
::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
>>>
reviews _Left isRight "mustard"
False
>>>
reviews (unto succ) (*2) 3
8
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 -> rreviews
::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 rreviews
::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
>>>
evalState (reuse _Left) 5
Left 5
>>>
evalState (reuse (unto succ)) 5
6
reuse
::MonadState
a m =>Prism'
s a -> m sreuse
::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)
>>>
evalState (reuses _Left isLeft) (5 :: Int)
True
reuses
::MonadState
a m =>Prism'
s a -> (s -> r) -> m rreuses
::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
>>>
base 16 # 123
"7b"
(#) ::Iso'
s a -> a -> s (#) ::Prism'
s a -> a -> s (#) ::Review
s a -> a -> s (#) ::Equality'
s a -> a -> s
class (forall a. Functor (p a)) => Bifunctor (p :: Type -> Type -> Type) where #
Minimal complete definition
bimap | first, second
Instances
Bifunctor Arg | |
Defined in Data.Semigroup | |
Bifunctor Either | |
Defined in Data.Bifunctor | |
Bifunctor Either | |
Defined in Data.Strict.Either | |
Bifunctor These | |
Defined in Data.Strict.These | |
Bifunctor Pair | |
Defined in Data.Strict.Tuple | |
Bifunctor These | |
Defined in Data.These | |
Bifunctor (,) | |
Defined in Data.Bifunctor | |
Bifunctor bi => Bifunctor (Biap bi) | |
Defined in Data.Bifunctor.Biap | |
Functor f => Bifunctor (CofreeF f) | |
Defined in Control.Comonad.Trans.Cofree | |
Functor f => Bifunctor (FreeF f) | |
Defined in Control.Monad.Trans.Free | |
Functor f => Bifunctor (FreeF f) | |
Defined in Control.Monad.Trans.Free.Ap | |
Bifunctor (Const :: Type -> Type -> Type) | |
Functor f => Bifunctor (AlongsideLeft f) Source # | |
Defined in Control.Lens.Internal.Getter Methods bimap :: (a -> b) -> (c -> d) -> AlongsideLeft f a c -> AlongsideLeft f b d # first :: (a -> b) -> AlongsideLeft f a c -> AlongsideLeft f b c second :: (b -> c) -> AlongsideLeft f a b -> AlongsideLeft f a c | |
Functor f => Bifunctor (AlongsideRight f) Source # | |
Defined in Control.Lens.Internal.Getter Methods bimap :: (a -> b) -> (c -> d) -> AlongsideRight f a c -> AlongsideRight f b d # first :: (a -> b) -> AlongsideRight f a c -> AlongsideRight f b c second :: (b -> c) -> AlongsideRight f a b -> AlongsideRight f a c | |
Bifunctor (Tagged :: Type -> Type -> Type) | |
Defined in Data.Tagged | |
Bifunctor (Constant :: Type -> Type -> Type) | |
Defined in Data.Functor.Constant | |
Bifunctor ((,,) x1) | |
Defined in Data.Bifunctor | |
Bifunctor (K1 i :: Type -> Type -> Type) | |
Defined in Data.Bifunctor | |
Bifunctor ((,,,) x1 x2) | |
Defined in Data.Bifunctor | |
Functor f => Bifunctor (Clown f :: Type -> Type -> Type) | |
Defined in Data.Bifunctor.Clown | |
Bifunctor p => Bifunctor (Flip p) | |
Defined in Data.Bifunctor.Flip | |
Functor g => Bifunctor (Joker g :: Type -> Type -> Type) | |
Defined in Data.Bifunctor.Joker | |
Bifunctor p => Bifunctor (WrappedBifunctor p) | |
Defined in Data.Bifunctor.Wrapped | |
Bifunctor ((,,,,) x1 x2 x3) | |
Defined in Data.Bifunctor | |
(Bifunctor f, Bifunctor g) => Bifunctor (Product f g) | |
Defined in Data.Bifunctor.Product | |
(Bifunctor p, Bifunctor q) => Bifunctor (Sum p q) | |
Defined in Data.Bifunctor.Sum | |
Bifunctor ((,,,,,) x1 x2 x3 x4) | |
Defined in Data.Bifunctor | |
(Functor f, Bifunctor p) => Bifunctor (Tannen f p) | |
Defined in Data.Bifunctor.Tannen | |
Bifunctor ((,,,,,,) x1 x2 x3 x4 x5) | |
Defined in Data.Bifunctor | |
(Bifunctor p, Functor f, Functor g) => Bifunctor (Biff p f g) | |
Defined in Data.Bifunctor.Biff |
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 :: Type -> Type -> Type) Source #
This class is provided mostly for backwards compatibility with lens 3.8, but it can also shorten type signatures.
Instances
(Profunctor p, Bifunctor p) => Reviewable p Source # | |
Defined in Control.Lens.Internal.Review |