Modulelens-5.3.5Haskell2010
Control.Lens.Review
A Review is a type-restricted form of a Prism that can only be used for writing back via re, review, reuse.
- 2 types
- 2 classes
- 10 values
- Packagelens-5.3.5
- Exports14
- LanguageHaskell2010
- LicenceBSD-2-Clause
- SourceReview.hs
Reviewing
14 declarationsTurn 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 _LeftLeft 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 t
re :: Iso s t a b -> Getter b t
This can be used to turn an Control.Lens.Iso.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) 56
Usually review is used in the (->) Monad with a Prism or Control.Lens.Iso.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
This can be used to turn an Control.Lens.Iso.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) 38
Usually this function is used in the (->) Monad with a Prism or Control.Lens.Iso.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
This can be used to turn an Control.Lens.Iso.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) 5Left 5
evalState (reuse (unto succ)) 56
reuse :: MonadState a m => Prism' s a -> m s
reuse :: MonadState a m => Iso' s a -> m s
This can be used to turn an Control.Lens.Iso.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 r
reuses :: MonadState a m => Iso' s a -> (s -> r) -> m r
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 # 4Left 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
A bifunctor is a type constructor that takes two type arguments and is a functor in both arguments. That is, unlike with Functor, a type constructor such as Either does not need to be partially applied for a Bifunctor instance, and the methods in this class permit mapping functions over the Left value or the Right value, or both at the same time.
Formally, the class Bifunctor represents a bifunctor
from Hask -> Hask.
Intuitively it is a bifunctor where both the first and second arguments are covariant.
The class definition of a Bifunctor p uses the
QuantifiedConstraints
language extension to quantify over the first type
argument a in its context. The context requires that p a
must be a Functor for all a. In other words a partially
applied Bifunctor must be a Functor. This makes Functor a
superclass of Bifunctor such that a function with a
Bifunctor constraint may use fmap in its implementation.
Functor has been a quantified superclass of
Bifunctor since base-4.18.0.0.
You can define a Bifunctor by either defining bimap or by defining both first and second. The second method must agree with fmap:
second ≡ fmapFrom this it follows that:
second id ≡ idIf you supply bimap, you should ensure that:
bimap id id ≡ idIf 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 gThese 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
Instances30Bifunctor, …
Bifunctor ArgDefined in base-4.20.2.0 · Data.SemigroupBifunctor EitherDefined in base-4.20.2.0 · Data.BifunctorBifunctor Tuple2Defined in base-4.20.2.0 · Data.BifunctorBifunctor EitherDefined in strict-0.5.1 · Data.Strict.EitherBifunctor TheseDefined in strict-0.5.1 · Data.Strict.TheseBifunctor PairDefined in strict-0.5.1 · Data.Strict.TupleBifunctor TheseDefined in these-1.2.1 · Data.TheseBifunctor ConstDefined in base-4.20.2.0 · Data.BifunctorBifunctor TaggedDefined in tagged-0.8.9 · Data.TaggedBifunctor ConstantDefined in transformers-0.6.1.1 · Data.Functor.ConstantBifunctor (Tuple3 x1)Defined in base-4.20.2.0 · Data.BifunctorBifunctor bi => Bifunctor (Biap bi)Defined in bifunctors-5.6.2 · Data.Bifunctor.BiapFunctor f => Bifunctor (CofreeF f)Defined in free-5.2 · Control.Comonad.Trans.CofreeFunctor f => Bifunctor (FreeF f)Defined in free-5.2 · Control.Monad.Trans.FreeFunctor f => Bifunctor (FreeF f)Defined in free-5.2 · Control.Monad.Trans.Free.ApFunctor f => Bifunctor (AlongsideLeft f)Defined in lens-5.3.5 · Control.Lens.Internal.GetterFunctor f => Bifunctor (AlongsideRight f)Defined in lens-5.3.5 · Control.Lens.Internal.GetterBifunctor (K1 i)Defined in base-4.20.2.0 · Data.BifunctorBifunctor (Tuple4 x1 x2)Defined in base-4.20.2.0 · Data.BifunctorBifunctor (Tuple5 x1 x2 x3)Defined in base-4.20.2.0 · Data.BifunctorBifunctor p => Bifunctor (Flip p)Defined in bifunctors-5.6.2 · Data.Bifunctor.FlipBifunctor p => Bifunctor (WrappedBifunctor p)Defined in bifunctors-5.6.2 · Data.Bifunctor.WrappedFunctor f => Bifunctor (Clown f)Defined in bifunctors-5.6.2 · Data.Bifunctor.ClownFunctor g => Bifunctor (Joker g)Defined in bifunctors-5.6.2 · Data.Bifunctor.JokerBifunctor (Tuple6 x1 x2 x3 x4)Defined in base-4.20.2.0 · Data.Bifunctor(Bifunctor f, Bifunctor g) => Bifunctor (Product f g)Defined in bifunctors-5.6.2 · Data.Bifunctor.Product(Bifunctor p, Bifunctor q) => Bifunctor (Sum p q)Defined in bifunctors-5.6.2 · Data.Bifunctor.SumBifunctor (Tuple7 x1 x2 x3 x4 x5)Defined in base-4.20.2.0 · Data.Bifunctor(Functor f, Bifunctor p) => Bifunctor (Tannen f p)Defined in bifunctors-5.6.2 · Data.Bifunctor.Tannen(Bifunctor p, Functor f, Functor g) => Bifunctor (Biff p f g)Defined in bifunctors-5.6.2 · Data.Bifunctor.Biff
This is a profunctor used internally to implement Review
It plays a role similar to that of Control.Lens.Internal.Getter.Accessor
or Const do for Control.Lens.Getter
This class is provided mostly for backwards compatibility with lens 3.8, but it can also shorten type signatures.
Instances1Reviewable
(Profunctor p, Bifunctor p) => Reviewable pDefined in lens-5.3.5 · Control.Lens.Internal.Review