lens-4.15.4: Lenses, Folds and Traversals

Copyright(C) 2012-16 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
PortabilityRank2Types
Safe HaskellSafe
LanguageHaskell98

Control.Lens.Getter

Contents

Description

A Getter s a is just any function (s -> a), which we've flipped into continuation passing style, (a -> r) -> s -> r and decorated with Const to obtain:

type Getting r s a = (a -> Const r a) -> s -> Const r s

If we restrict access to knowledge about the type r, we could get:

type Getter s a = forall r. Getting r s a

However, for Getter (but not for Getting) we actually permit any functor f which is an instance of both Functor and Contravariant:

type Getter s a = forall f. (Contravariant f, Functor f) => (a -> f a) -> s -> f s

Everything you can do with a function, you can do with a Getter, but note that because of the continuation passing style (.) composes them in the opposite order.

Since it is only a function, every Getter obviously only retrieves a single value for a given input.

A common question is whether you can combine multiple Getters to retrieve multiple values. Recall that all Getters are Folds and that we have a Monoid m => Applicative (Const m) instance to play with. Knowing this, we can use <> to glue Folds together:

>>> import Data.Monoid
>>> (1, 2, 3, 4, 5) ^.. (_2 <> _3 <> _5)
[2,3,5]
Synopsis

Getters

type Getter s a = forall f. (Contravariant f, Functor f) => (a -> f a) -> s -> f s Source #

A Getter describes how to retrieve a single value in a way that can be composed with other LensLike constructions.

Unlike a Lens a Getter is read-only. Since a Getter cannot be used to write back there are no Lens laws that can be applied to it. In fact, it is isomorphic to an arbitrary function from (s -> a).

Moreover, a Getter can be used directly as a Fold, since it just ignores the Applicative.

type IndexedGetter i s a = forall p f. (Indexable i p, Contravariant f, Functor f) => p a (f a) -> s -> f s Source #

Every IndexedGetter is a valid IndexedFold and can be used for Getting like a Getter.

type Getting r s a = (a -> Const r a) -> s -> Const r s Source #

When you see this in a type signature it indicates that you can pass the function a Lens, Getter, Traversal, Fold, Prism, Iso, or one of the indexed variants, and it will just "do the right thing".

Most Getter combinators are able to be used with both a Getter or a Fold in limited situations, to do so, they need to be monomorphic in what we are going to extract with Const. To be compatible with Lens, Traversal and Iso we also restricted choices of the irrelevant t and b parameters.

If a function accepts a Getting r s a, then when r is a Monoid, then you can pass a Fold (or Traversal), otherwise you can only pass this a Getter or Lens.

type IndexedGetting i m s a = Indexed i a (Const m a) -> s -> Const m s Source #

Used to consume an IndexedFold.

type Accessing p m s a = p a (Const m a) -> s -> Const m s Source #

This is a convenient alias used when consuming (indexed) getters and (indexed) folds in a highly general fashion.

Building Getters

to :: (Profunctor p, Contravariant f) => (s -> a) -> Optic' p f s a Source #

Build an (index-preserving) Getter from an arbitrary Haskell function.

to f . to g ≡ to (g . f)
a ^. to f ≡ f a
>>> a ^.to f
f a
>>> ("hello","world")^.to snd
"world"
>>> 5^.to succ
6
>>> (0, -5)^._2.to abs
5
to :: (s -> a) -> IndexPreservingGetter s a

ito :: (Indexable i p, Contravariant f) => (s -> (i, a)) -> Over' p f s a Source #

ito :: (s -> (i, a)) -> IndexedGetter i s a

like :: (Profunctor p, Contravariant f, Functor f) => a -> Optic' p f s a Source #

Build an constant-valued (index-preserving) Getter from an arbitrary Haskell value.

like a . like b ≡ like b
a ^. like b ≡ b
a ^. like b ≡ a ^. to (const b)

This can be useful as a second case failing a Fold e.g. foo failing like 0

like :: a -> IndexPreservingGetter s a

ilike :: (Indexable i p, Contravariant f, Functor f) => i -> a -> Over' p f s a Source #

ilike :: i -> a -> IndexedGetter i s a

Combinators for Getters and Folds

(^.) :: s -> Getting a s a -> a infixl 8 Source #

View the value pointed to by a Getter or Lens or the result of folding over all the results of a Fold or Traversal that points at a monoidal values.

This is the same operation as view with the arguments flipped.

The fixity and semantics are such that subsequent field accesses can be performed with (.).

>>> (a,b)^._2
b
>>> ("hello","world")^._2
"world"
>>> import Data.Complex
>>> ((0, 1 :+ 2), 3)^._1._2.to magnitude
2.23606797749979
(^.) ::             s -> Getter s a     -> a
(^.) :: Monoid m => s -> Fold s m       -> m
(^.) ::             s -> Iso' s a       -> a
(^.) ::             s -> Lens' s a      -> a
(^.) :: Monoid m => s -> Traversal' s m -> m

view :: MonadReader s m => Getting a s a -> m a Source #

View the value pointed to by a Getter, Iso or Lens or the result of folding over all the results of a Fold or Traversal that points at a monoidal value.

view . toid
>>> view (to f) a
f a
>>> view _2 (1,"hello")
"hello"
>>> view (to succ) 5
6
>>> view (_2._1) ("hello",("world","!!!"))
"world"

As view is commonly used to access the target of a Getter or obtain a monoidal summary of the targets of a Fold, It may be useful to think of it as having one of these more restricted signatures:

view ::             Getter s a     -> s -> a
view :: Monoid m => Fold s m       -> s -> m
view ::             Iso' s a       -> s -> a
view ::             Lens' s a      -> s -> a
view :: Monoid m => Traversal' s m -> s -> m

In a more general setting, such as when working with a Monad transformer stack you can use:

view :: MonadReader s m             => Getter s a     -> m a
view :: (MonadReader s m, Monoid a) => Fold s a       -> m a
view :: MonadReader s m             => Iso' s a       -> m a
view :: MonadReader s m             => Lens' s a      -> m a
view :: (MonadReader s m, Monoid a) => Traversal' s a -> m a

views :: MonadReader s m => LensLike' (Const r) s a -> (a -> r) -> m r Source #

View a function of the value pointed to by a Getter or Lens or the result of folding over the result of mapping the targets of a Fold or Traversal.

views l f ≡ view (l . to f)
>>> views (to f) g a
g (f a)
>>> views _2 length (1,"hello")
5

As views is commonly used to access the target of a Getter or obtain a monoidal summary of the targets of a Fold, It may be useful to think of it as having one of these more restricted signatures:

views ::             Getter s a     -> (a -> r) -> s -> r
views :: Monoid m => Fold s a       -> (a -> m) -> s -> m
views ::             Iso' s a       -> (a -> r) -> s -> r
views ::             Lens' s a      -> (a -> r) -> s -> r
views :: Monoid m => Traversal' s a -> (a -> m) -> s -> m

In a more general setting, such as when working with a Monad transformer stack you can use:

views :: MonadReader s m             => Getter s a     -> (a -> r) -> m r
views :: (MonadReader s m, Monoid r) => Fold s a       -> (a -> r) -> m r
views :: MonadReader s m             => Iso' s a       -> (a -> r) -> m r
views :: MonadReader s m             => Lens' s a      -> (a -> r) -> m r
views :: (MonadReader s m, Monoid r) => Traversal' s a -> (a -> r) -> m r
views :: MonadReader s m => Getting r s a -> (a -> r) -> m r

use :: MonadState s m => Getting a s a -> m a Source #

Use the target of a Lens, Iso, or Getter in the current state, or use a summary of a Fold or Traversal that points to a monoidal value.

>>> evalState (use _1) (a,b)
a
>>> evalState (use _1) ("hello","world")
"hello"
use :: MonadState s m             => Getter s a     -> m a
use :: (MonadState s m, Monoid r) => Fold s r       -> m r
use :: MonadState s m             => Iso' s a       -> m a
use :: MonadState s m             => Lens' s a      -> m a
use :: (MonadState s m, Monoid r) => Traversal' s r -> m r

uses :: MonadState s m => LensLike' (Const r) s a -> (a -> r) -> m r Source #

Use the target of a Lens, Iso or Getter in the current state, or use a summary of a Fold or Traversal that points to a monoidal value.

>>> evalState (uses _1 length) ("hello","world")
5
uses :: MonadState s m             => Getter s a     -> (a -> r) -> m r
uses :: (MonadState s m, Monoid r) => Fold s a       -> (a -> r) -> m r
uses :: MonadState s m             => Lens' s a      -> (a -> r) -> m r
uses :: MonadState s m             => Iso' s a       -> (a -> r) -> m r
uses :: (MonadState s m, Monoid r) => Traversal' s a -> (a -> r) -> m r
uses :: MonadState s m => Getting r s t a b -> (a -> r) -> m r

listening :: MonadWriter w m => Getting u w u -> m a -> m (a, u) Source #

This is a generalized form of listen that only extracts the portion of the log that is focused on by a Getter. If given a Fold or a Traversal then a monoidal summary of the parts of the log that are visited will be returned.

listening :: MonadWriter w m             => Getter w u     -> m a -> m (a, u)
listening :: MonadWriter w m             => Lens' w u      -> m a -> m (a, u)
listening :: MonadWriter w m             => Iso' w u       -> m a -> m (a, u)
listening :: (MonadWriter w m, Monoid u) => Fold w u       -> m a -> m (a, u)
listening :: (MonadWriter w m, Monoid u) => Traversal' w u -> m a -> m (a, u)
listening :: (MonadWriter w m, Monoid u) => Prism' w u     -> m a -> m (a, u)

listenings :: MonadWriter w m => Getting v w u -> (u -> v) -> m a -> m (a, v) Source #

This is a generalized form of listen that only extracts the portion of the log that is focused on by a Getter. If given a Fold or a Traversal then a monoidal summary of the parts of the log that are visited will be returned.

listenings :: MonadWriter w m             => Getter w u     -> (u -> v) -> m a -> m (a, v)
listenings :: MonadWriter w m             => Lens' w u      -> (u -> v) -> m a -> m (a, v)
listenings :: MonadWriter w m             => Iso' w u       -> (u -> v) -> m a -> m (a, v)
listenings :: (MonadWriter w m, Monoid v) => Fold w u       -> (u -> v) -> m a -> m (a, v)
listenings :: (MonadWriter w m, Monoid v) => Traversal' w u -> (u -> v) -> m a -> m (a, v)
listenings :: (MonadWriter w m, Monoid v) => Prism' w u     -> (u -> v) -> m a -> m (a, v)

Indexed Getters

Indexed Getter Combinators

(^@.) :: s -> IndexedGetting i (i, a) s a -> (i, a) infixl 8 Source #

View the index and value of an IndexedGetter or IndexedLens.

This is the same operation as iview with the arguments flipped.

The fixity and semantics are such that subsequent field accesses can be performed with (.).

(^@.) :: s -> IndexedGetter i s a -> (i, a)
(^@.) :: s -> IndexedLens' i s a  -> (i, a)

The result probably doesn't have much meaning when applied to an IndexedFold.

iview :: MonadReader s m => IndexedGetting i (i, a) s a -> m (i, a) Source #

View the index and value of an IndexedGetter into the current environment as a pair.

When applied to an IndexedFold the result will most likely be a nonsensical monoidal summary of the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted.

iviews :: MonadReader s m => IndexedGetting i r s a -> (i -> a -> r) -> m r Source #

View a function of the index and value of an IndexedGetter into the current environment.

When applied to an IndexedFold the result will be a monoidal summary instead of a single answer.

iviewsifoldMapOf

iuse :: MonadState s m => IndexedGetting i (i, a) s a -> m (i, a) Source #

Use the index and value of an IndexedGetter into the current state as a pair.

When applied to an IndexedFold the result will most likely be a nonsensical monoidal summary of the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted.

iuses :: MonadState s m => IndexedGetting i r s a -> (i -> a -> r) -> m r Source #

Use a function of the index and value of an IndexedGetter into the current state.

When applied to an IndexedFold the result will be a monoidal summary instead of a single answer.

ilistening :: MonadWriter w m => IndexedGetting i (i, u) w u -> m a -> m (a, (i, u)) Source #

This is a generalized form of listen that only extracts the portion of the log that is focused on by a Getter. If given a Fold or a Traversal then a monoidal summary of the parts of the log that are visited will be returned.

ilistening :: MonadWriter w m             => IndexedGetter i w u     -> m a -> m (a, (i, u))
ilistening :: MonadWriter w m             => IndexedLens' i w u      -> m a -> m (a, (i, u))
ilistening :: (MonadWriter w m, Monoid u) => IndexedFold i w u       -> m a -> m (a, (i, u))
ilistening :: (MonadWriter w m, Monoid u) => IndexedTraversal' i w u -> m a -> m (a, (i, u))

ilistenings :: MonadWriter w m => IndexedGetting i v w u -> (i -> u -> v) -> m a -> m (a, v) Source #

This is a generalized form of listen that only extracts the portion of the log that is focused on by a Getter. If given a Fold or a Traversal then a monoidal summary of the parts of the log that are visited will be returned.

ilistenings :: MonadWriter w m             => IndexedGetter w u     -> (i -> u -> v) -> m a -> m (a, v)
ilistenings :: MonadWriter w m             => IndexedLens' w u      -> (i -> u -> v) -> m a -> m (a, v)
ilistenings :: (MonadWriter w m, Monoid v) => IndexedFold w u       -> (i -> u -> v) -> m a -> m (a, v)
ilistenings :: (MonadWriter w m, Monoid v) => IndexedTraversal' w u -> (i -> u -> v) -> m a -> m (a, v)

Implementation Details

class Contravariant (f :: * -> *) where #

Any instance should be subject to the following laws:

contramap id = id
contramap f . contramap g = contramap (g . f)

Note, that the second law follows from the free theorem of the type of contramap and the first law, so you need only check that the former condition holds.

Minimal complete definition

contramap

Methods

contramap :: (a -> b) -> f b -> f a #

(>$) :: b -> f b -> f a infixl 4 #

Replace all locations in the output with the same value. The default definition is contramap . const, but this may be overridden with a more efficient version.

Instances
Contravariant SettableStateVar 
Instance details
Contravariant Predicate

A Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate.

Instance details

Methods

contramap :: (a -> b) -> Predicate b -> Predicate a #

(>$) :: b -> Predicate b -> Predicate a #

Contravariant Comparison

A Comparison is a Contravariant Functor, because contramap can apply its function argument to each input of the comparison function.

Instance details

Methods

contramap :: (a -> b) -> Comparison b -> Comparison a #

(>$) :: b -> Comparison b -> Comparison a #

Contravariant Equivalence

Equivalence relations are Contravariant, because you can apply the contramapped function to each input to the equivalence relation.

Instance details

Methods

contramap :: (a -> b) -> Equivalence b -> Equivalence a #

(>$) :: b -> Equivalence b -> Equivalence a #

Contravariant (V1 *) 
Instance details

Methods

contramap :: (a -> b) -> V1 * b -> V1 * a #

(>$) :: b -> V1 * b -> V1 * a #

Contravariant (U1 *) 
Instance details

Methods

contramap :: (a -> b) -> U1 * b -> U1 * a #

(>$) :: b -> U1 * b -> U1 * a #

Contravariant (Op a) 
Instance details

Methods

contramap :: (a0 -> b) -> Op a b -> Op a a0 #

(>$) :: b -> Op a b -> Op a a0 #

Contravariant (Proxy *) 
Instance details

Methods

contramap :: (a -> b) -> Proxy * b -> Proxy * a #

(>$) :: b -> Proxy * b -> Proxy * a #

Contravariant m => Contravariant (ListT m) 
Instance details

Methods

contramap :: (a -> b) -> ListT m b -> ListT m a #

(>$) :: b -> ListT m b -> ListT m a #

Contravariant m => Contravariant (MaybeT m) 
Instance details

Methods

contramap :: (a -> b) -> MaybeT m b -> MaybeT m a #

(>$) :: b -> MaybeT m b -> MaybeT m a #

Contravariant f => Contravariant (Indexing64 f) # 
Instance details

Methods

contramap :: (a -> b) -> Indexing64 f b -> Indexing64 f a #

(>$) :: b -> Indexing64 f b -> Indexing64 f a #

Contravariant f => Contravariant (Indexing f) # 
Instance details

Methods

contramap :: (a -> b) -> Indexing f b -> Indexing f a #

(>$) :: b -> Indexing f b -> Indexing f a #

Contravariant f => Contravariant (Rec1 * f) 
Instance details

Methods

contramap :: (a -> b) -> Rec1 * f b -> Rec1 * f a #

(>$) :: b -> Rec1 * f b -> Rec1 * f a #

Contravariant (Const * a) 
Instance details

Methods

contramap :: (a0 -> b) -> Const * a b -> Const * a a0 #

(>$) :: b -> Const * a b -> Const * a a0 #

Contravariant f => Contravariant (Alt * f) 
Instance details

Methods

contramap :: (a -> b) -> Alt * f b -> Alt * f a #

(>$) :: b -> Alt * f b -> Alt * f a #

Contravariant f => Contravariant (IdentityT * f) 
Instance details

Methods

contramap :: (a -> b) -> IdentityT * f b -> IdentityT * f a #

(>$) :: b -> IdentityT * f b -> IdentityT * f a #

(Functor f, Contravariant g) => Contravariant (ComposeFC f g) 
Instance details

Methods

contramap :: (a -> b) -> ComposeFC f g b -> ComposeFC f g a #

(>$) :: b -> ComposeFC f g b -> ComposeFC f g a #

(Contravariant f, Functor g) => Contravariant (ComposeCF f g) 
Instance details

Methods

contramap :: (a -> b) -> ComposeCF f g b -> ComposeCF f g a #

(>$) :: b -> ComposeCF f g b -> ComposeCF f g a #

Contravariant m => Contravariant (ErrorT e m) 
Instance details

Methods

contramap :: (a -> b) -> ErrorT e m b -> ErrorT e m a #

(>$) :: b -> ErrorT e m b -> ErrorT e m a #

Contravariant m => Contravariant (ExceptT e m) 
Instance details

Methods

contramap :: (a -> b) -> ExceptT e m b -> ExceptT e m a #

(>$) :: b -> ExceptT e m b -> ExceptT e m a #

Contravariant m => Contravariant (StateT s m) 
Instance details

Methods

contramap :: (a -> b) -> StateT s m b -> StateT s m a #

(>$) :: b -> StateT s m b -> StateT s m a #

Contravariant m => Contravariant (StateT s m) 
Instance details

Methods

contramap :: (a -> b) -> StateT s m b -> StateT s m a #

(>$) :: b -> StateT s m b -> StateT s m a #

Contravariant m => Contravariant (WriterT w m) 
Instance details

Methods

contramap :: (a -> b) -> WriterT w m b -> WriterT w m a #

(>$) :: b -> WriterT w m b -> WriterT w m a #

Contravariant m => Contravariant (WriterT w m) 
Instance details

Methods

contramap :: (a -> b) -> WriterT w m b -> WriterT w m a #

(>$) :: b -> WriterT w m b -> WriterT w m a #

Contravariant f => Contravariant (Reverse * f) 
Instance details

Methods

contramap :: (a -> b) -> Reverse * f b -> Reverse * f a #

(>$) :: b -> Reverse * f b -> Reverse * f a #

Contravariant (Constant * a) 
Instance details

Methods

contramap :: (a0 -> b) -> Constant * a b -> Constant * a a0 #

(>$) :: b -> Constant * a b -> Constant * a a0 #

Contravariant f => Contravariant (Backwards * f) 
Instance details

Methods

contramap :: (a -> b) -> Backwards * f b -> Backwards * f a #

(>$) :: b -> Backwards * f b -> Backwards * f a #

Contravariant f => Contravariant (AlongsideRight f a) # 
Instance details

Methods

contramap :: (a0 -> b) -> AlongsideRight f a b -> AlongsideRight f a a0 #

(>$) :: b -> AlongsideRight f a b -> AlongsideRight f a a0 #

Contravariant f => Contravariant (AlongsideLeft f b) # 
Instance details

Methods

contramap :: (a -> b0) -> AlongsideLeft f b b0 -> AlongsideLeft f b a #

(>$) :: b0 -> AlongsideLeft f b b0 -> AlongsideLeft f b a #

Contravariant (Effect m r) # 
Instance details

Methods

contramap :: (a -> b) -> Effect m r b -> Effect m r a #

(>$) :: b -> Effect m r b -> Effect m r a #

Contravariant (K1 * i c) 
Instance details

Methods

contramap :: (a -> b) -> K1 * i c b -> K1 * i c a #

(>$) :: b -> K1 * i c b -> K1 * i c a #

(Contravariant f, Contravariant g) => Contravariant ((:+:) * f g) 
Instance details

Methods

contramap :: (a -> b) -> (* :+: f) g b -> (* :+: f) g a #

(>$) :: b -> (* :+: f) g b -> (* :+: f) g a #

(Contravariant f, Contravariant g) => Contravariant ((:*:) * f g) 
Instance details

Methods

contramap :: (a -> b) -> (* :*: f) g b -> (* :*: f) g a #

(>$) :: b -> (* :*: f) g b -> (* :*: f) g a #

(Contravariant f, Contravariant g) => Contravariant (Product * f g) 
Instance details

Methods

contramap :: (a -> b) -> Product * f g b -> Product * f g a #

(>$) :: b -> Product * f g b -> Product * f g a #

(Contravariant f, Contravariant g) => Contravariant (Sum * f g) 
Instance details

Methods

contramap :: (a -> b) -> Sum * f g b -> Sum * f g a #

(>$) :: b -> Sum * f g b -> Sum * f g a #

Contravariant m => Contravariant (ReaderT * r m) 
Instance details

Methods

contramap :: (a -> b) -> ReaderT * r m b -> ReaderT * r m a #

(>$) :: b -> ReaderT * r m b -> ReaderT * r m a #

Contravariant f => Contravariant (M1 * i c f) 
Instance details

Methods

contramap :: (a -> b) -> M1 * i c f b -> M1 * i c f a #

(>$) :: b -> M1 * i c f b -> M1 * i c f a #

(Functor f, Contravariant g) => Contravariant ((:.:) * * f g) 
Instance details

Methods

contramap :: (a -> b) -> (* :.: *) f g b -> (* :.: *) f g a #

(>$) :: b -> (* :.: *) f g b -> (* :.: *) f g a #

(Functor f, Contravariant g) => Contravariant (Compose * * f g) 
Instance details

Methods

contramap :: (a -> b) -> Compose * * f g b -> Compose * * f g a #

(>$) :: b -> Compose * * f g b -> Compose * * f g a #

Contravariant m => Contravariant (RWST r w s m) 
Instance details

Methods

contramap :: (a -> b) -> RWST r w s m b -> RWST r w s m a #

(>$) :: b -> RWST r w s m b -> RWST r w s m a #

Contravariant m => Contravariant (RWST r w s m) 
Instance details

Methods

contramap :: (a -> b) -> RWST r w s m b -> RWST r w s m a #

(>$) :: b -> RWST r w s m b -> RWST r w s m a #

(Profunctor p, Contravariant g) => Contravariant (PretextT p g a b) # 
Instance details

Methods

contramap :: (a0 -> b0) -> PretextT p g a b b0 -> PretextT p g a b a0 #

(>$) :: b0 -> PretextT p g a b b0 -> PretextT p g a b a0 #

(Profunctor p, Contravariant g) => Contravariant (BazaarT1 p g a b) # 
Instance details

Methods

contramap :: (a0 -> b0) -> BazaarT1 p g a b b0 -> BazaarT1 p g a b a0 #

(>$) :: b0 -> BazaarT1 p g a b b0 -> BazaarT1 p g a b a0 #

(Profunctor p, Contravariant g) => Contravariant (BazaarT p g a b) # 
Instance details

Methods

contramap :: (a0 -> b0) -> BazaarT p g a b b0 -> BazaarT p g a b a0 #

(>$) :: b0 -> BazaarT p g a b b0 -> BazaarT p g a b a0 #

Contravariant f => Contravariant (TakingWhile p f a b) # 
Instance details

Methods

contramap :: (a0 -> b0) -> TakingWhile p f a b b0 -> TakingWhile p f a b a0 #

(>$) :: b0 -> TakingWhile p f a b b0 -> TakingWhile p f a b a0 #

Contravariant (EffectRWS w st m s) # 
Instance details

Methods

contramap :: (a -> b) -> EffectRWS w st m s b -> EffectRWS w st m s a #

(>$) :: b -> EffectRWS w st m s b -> EffectRWS w st m s a #

getting :: (Profunctor p, Profunctor q, Functor f, Contravariant f) => Optical p q f s t a b -> Optical' p q f s a Source #

Coerce a Getter-compatible Optical to an Optical'. This is useful when using a Traversal that is not simple as a Getter or a Fold.

getting :: Traversal s t a b          -> Fold s a
getting :: Lens s t a b               -> Getter s a
getting :: IndexedTraversal i s t a b -> IndexedFold i s a
getting :: IndexedLens i s t a b      -> IndexedGetter i s a

newtype Const k a (b :: k) :: forall k. * -> k -> * #

The Const functor.

Constructors

Const 

Fields

Instances
Generic1 k (Const k a) 
Instance details

Associated Types

type Rep1 (Const k a) (f :: Const k a -> *) :: k -> * #

Methods

from1 :: f a0 -> Rep1 (Const k a) f a0 #

to1 :: Rep1 (Const k a) f a0 -> f a0 #

Bitraversable (Const *)

Since: 4.10.0.0

Instance details

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Const * a b -> f (Const * c d) #

Bifoldable (Const *)

Since: 4.10.0.0

Instance details

Methods

bifold :: Monoid m => Const * m m -> m #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> Const * a b -> m #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> Const * a b -> c #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> Const * a b -> c #

Bifunctor (Const *)

Since: 4.8.0.0

Instance details

Methods

bimap :: (a -> b) -> (c -> d) -> Const * a c -> Const * b d #

first :: (a -> b) -> Const * a c -> Const * b c #

second :: (b -> c) -> Const * a b -> Const * a c #

Eq2 (Const *)

Since: 4.9.0.0

Instance details

Methods

liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> Const * a c -> Const * b d -> Bool #

Ord2 (Const *)

Since: 4.9.0.0

Instance details

Methods

liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Const * a c -> Const * b d -> Ordering #

Read2 (Const *)

Since: 4.9.0.0

Instance details

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Const * a b) #

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Const * a b] #

liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Const * a b) #

liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Const * a b] #

Show2 (Const *)

Since: 4.9.0.0

Instance details

Methods

liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Const * a b -> ShowS #

liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Const * a b] -> ShowS #

Biapplicative (Const *) 
Instance details

Methods

bipure :: a -> b -> Const * a b #

(<<*>>) :: Const * (a -> b) (c -> d) -> Const * a c -> Const * b d #

(*>>) :: Const * a b -> Const * c d -> Const * c d #

(<<*) :: Const * a b -> Const * c d -> Const * a b #

Hashable2 (Const *) 
Instance details

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> Const * a b -> Int #

Bitraversable1 (Const *) 
Instance details

Methods

bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> Const * a c -> f (Const * b d) #

bisequence1 :: Apply f => Const * (f a) (f b) -> f (Const * a b) #

Bifoldable1 (Const *) 
Instance details

Methods

bifold1 :: Semigroup m => Const * m m -> m #

bifoldMap1 :: Semigroup m => (a -> m) -> (b -> m) -> Const * a b -> m #

Biapply (Const *) 
Instance details

Methods

(<<.>>) :: Const * (a -> b) (c -> d) -> Const * a c -> Const * b d #

(.>>) :: Const * a b -> Const * c d -> Const * c d #

(<<.) :: Const * a b -> Const * c d -> Const * a b #

Semigroupoid * (Const *) 
Instance details

Methods

o :: c j k1 -> c i j -> c i k1 #

Sieve (Forget r) (Const * r) 
Instance details

Methods

sieve :: Forget r a b -> a -> Const * r b #

Functor (Const * m)

Since: 2.1

Instance details

Methods

fmap :: (a -> b) -> Const * m a -> Const * m b #

(<$) :: a -> Const * m b -> Const * m a #

Monoid m => Applicative (Const * m)

Since: 2.0.1

Instance details

Methods

pure :: a -> Const * m a #

(<*>) :: Const * m (a -> b) -> Const * m a -> Const * m b #

liftA2 :: (a -> b -> c) -> Const * m a -> Const * m b -> Const * m c #

(*>) :: Const * m a -> Const * m b -> Const * m b #

(<*) :: Const * m a -> Const * m b -> Const * m a #

Foldable (Const * m)

Since: 4.7.0.0

Instance details

Methods

fold :: Monoid m0 => Const * m m0 -> m0 #

foldMap :: Monoid m0 => (a -> m0) -> Const * m a -> m0 #

foldr :: (a -> b -> b) -> b -> Const * m a -> b #

foldr' :: (a -> b -> b) -> b -> Const * m a -> b #

foldl :: (b -> a -> b) -> b -> Const * m a -> b #

foldl' :: (b -> a -> b) -> b -> Const * m a -> b #

foldr1 :: (a -> a -> a) -> Const * m a -> a #

foldl1 :: (a -> a -> a) -> Const * m a -> a #

toList :: Const * m a -> [a] #

null :: Const * m a -> Bool #

length :: Const * m a -> Int #

elem :: Eq a => a -> Const * m a -> Bool #

maximum :: Ord a => Const * m a -> a #

minimum :: Ord a => Const * m a -> a #

sum :: Num a => Const * m a -> a #

product :: Num a => Const * m a -> a #

Traversable (Const * m)

Since: 4.7.0.0

Instance details

Methods

traverse :: Applicative f => (a -> f b) -> Const * m a -> f (Const * m b) #

sequenceA :: Applicative f => Const * m (f a) -> f (Const * m a) #

mapM :: Monad m0 => (a -> m0 b) -> Const * m a -> m0 (Const * m b) #

sequence :: Monad m0 => Const * m (m0 a) -> m0 (Const * m a) #

Contravariant (Const * a) 
Instance details

Methods

contramap :: (a0 -> b) -> Const * a b -> Const * a a0 #

(>$) :: b -> Const * a b -> Const * a a0 #

Eq a => Eq1 (Const * a)

Since: 4.9.0.0

Instance details

Methods

liftEq :: (a0 -> b -> Bool) -> Const * a a0 -> Const * a b -> Bool #

Ord a => Ord1 (Const * a)

Since: 4.9.0.0

Instance details

Methods

liftCompare :: (a0 -> b -> Ordering) -> Const * a a0 -> Const * a b -> Ordering #

Read a => Read1 (Const * a)

Since: 4.9.0.0

Instance details

Methods

liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Const * a a0) #

liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Const * a a0] #

liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Const * a a0) #

liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Const * a a0] #

Show a => Show1 (Const * a)

Since: 4.9.0.0

Instance details

Methods

liftShowsPrec :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> Int -> Const * a a0 -> ShowS #

liftShowList :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> [Const * a a0] -> ShowS #

Hashable a => Hashable1 (Const * a) 
Instance details

Methods

liftHashWithSalt :: (Int -> a0 -> Int) -> Int -> Const * a a0 -> Int #

Semigroup m => Apply (Const * m) 
Instance details

Methods

(<.>) :: Const * m (a -> b) -> Const * m a -> Const * m b #

(.>) :: Const * m a -> Const * m b -> Const * m b #

(<.) :: Const * m a -> Const * m b -> Const * m a #

Bounded a => Bounded (Const k a b) 
Instance details

Methods

minBound :: Const k a b #

maxBound :: Const k a b #

Enum a => Enum (Const k a b) 
Instance details

Methods

succ :: Const k a b -> Const k a b #

pred :: Const k a b -> Const k a b #

toEnum :: Int -> Const k a b #

fromEnum :: Const k a b -> Int #

enumFrom :: Const k a b -> [Const k a b] #

enumFromThen :: Const k a b -> Const k a b -> [Const k a b] #

enumFromTo :: Const k a b -> Const k a b -> [Const k a b] #

enumFromThenTo :: Const k a b -> Const k a b -> Const k a b -> [Const k a b] #

Eq a => Eq (Const k a b) 
Instance details

Methods

(==) :: Const k a b -> Const k a b -> Bool #

(/=) :: Const k a b -> Const k a b -> Bool #

Floating a => Floating (Const k a b) 
Instance details

Methods

pi :: Const k a b #

exp :: Const k a b -> Const k a b #

log :: Const k a b -> Const k a b #

sqrt :: Const k a b -> Const k a b #

(**) :: Const k a b -> Const k a b -> Const k a b #

logBase :: Const k a b -> Const k a b -> Const k a b #

sin :: Const k a b -> Const k a b #

cos :: Const k a b -> Const k a b #

tan :: Const k a b -> Const k a b #

asin :: Const k a b -> Const k a b #

acos :: Const k a b -> Const k a b #

atan :: Const k a b -> Const k a b #

sinh :: Const k a b -> Const k a b #

cosh :: Const k a b -> Const k a b #

tanh :: Const k a b -> Const k a b #

asinh :: Const k a b -> Const k a b #

acosh :: Const k a b -> Const k a b #

atanh :: Const k a b -> Const k a b #

log1p :: Const k a b -> Const k a b #

expm1 :: Const k a b -> Const k a b #

log1pexp :: Const k a b -> Const k a b #

log1mexp :: Const k a b -> Const k a b #

Fractional a => Fractional (Const k a b) 
Instance details

Methods

(/) :: Const k a b -> Const k a b -> Const k a b #

recip :: Const k a b -> Const k a b #

fromRational :: Rational -> Const k a b #

Integral a => Integral (Const k a b) 
Instance details

Methods

quot :: Const k a b -> Const k a b -> Const k a b #

rem :: Const k a b -> Const k a b -> Const k a b #

div :: Const k a b -> Const k a b -> Const k a b #

mod :: Const k a b -> Const k a b -> Const k a b #

quotRem :: Const k a b -> Const k a b -> (Const k a b, Const k a b) #

divMod :: Const k a b -> Const k a b -> (Const k a b, Const k a b) #

toInteger :: Const k a b -> Integer #

(Typeable * k3, Data a, Typeable k3 b) => Data (Const k3 a b)

Since: 4.10.0.0

Instance details

Methods

gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Const k3 a b -> c (Const k3 a b) #

gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Const k3 a b) #

toConstr :: Const k3 a b -> Constr #

dataTypeOf :: Const k3 a b -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Const k3 a b)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Const k3 a b)) #

gmapT :: (forall b0. Data b0 => b0 -> b0) -> Const k3 a b -> Const k3 a b #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const k3 a b -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const k3 a b -> r #

gmapQ :: (forall d. Data d => d -> u) -> Const k3 a b -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Const k3 a b -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Const k3 a b -> m (Const k3 a b) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Const k3 a b -> m (Const k3 a b) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Const k3 a b -> m (Const k3 a b) #

Num a => Num (Const k a b) 
Instance details

Methods

(+) :: Const k a b -> Const k a b -> Const k a b #

(-) :: Const k a b -> Const k a b -> Const k a b #

(*) :: Const k a b -> Const k a b -> Const k a b #

negate :: Const k a b -> Const k a b #

abs :: Const k a b -> Const k a b #

signum :: Const k a b -> Const k a b #

fromInteger :: Integer -> Const k a b #

Ord a => Ord (Const k a b) 
Instance details

Methods

compare :: Const k a b -> Const k a b -> Ordering #

(<) :: Const k a b -> Const k a b -> Bool #

(<=) :: Const k a b -> Const k a b -> Bool #

(>) :: Const k a b -> Const k a b -> Bool #

(>=) :: Const k a b -> Const k a b -> Bool #

max :: Const k a b -> Const k a b -> Const k a b #

min :: Const k a b -> Const k a b -> Const k a b #

Read a => Read (Const k a b)

This instance would be equivalent to the derived instances of the Const newtype if the runConst field were removed

Since: 4.8.0.0

Instance details

Methods

readsPrec :: Int -> ReadS (Const k a b) #

readList :: ReadS [Const k a b] #

readPrec :: ReadPrec (Const k a b) #

readListPrec :: ReadPrec [Const k a b] #

Real a => Real (Const k a b) 
Instance details

Methods

toRational :: Const k a b -> Rational #

RealFloat a => RealFloat (Const k a b) 
Instance details

Methods

floatRadix :: Const k a b -> Integer #

floatDigits :: Const k a b -> Int #

floatRange :: Const k a b -> (Int, Int) #

decodeFloat :: Const k a b -> (Integer, Int) #

encodeFloat :: Integer -> Int -> Const k a b #

exponent :: Const k a b -> Int #

significand :: Const k a b -> Const k a b #

scaleFloat :: Int -> Const k a b -> Const k a b #

isNaN :: Const k a b -> Bool #

isInfinite :: Const k a b -> Bool #

isDenormalized :: Const k a b -> Bool #

isNegativeZero :: Const k a b -> Bool #

isIEEE :: Const k a b -> Bool #

atan2 :: Const k a b -> Const k a b -> Const k a b #

RealFrac a => RealFrac (Const k a b) 
Instance details

Methods

properFraction :: Integral b0 => Const k a b -> (b0, Const k a b) #

truncate :: Integral b0 => Const k a b -> b0 #

round :: Integral b0 => Const k a b -> b0 #

ceiling :: Integral b0 => Const k a b -> b0 #

floor :: Integral b0 => Const k a b -> b0 #

Show a => Show (Const k a b)

This instance would be equivalent to the derived instances of the Const newtype if the runConst field were removed

Since: 4.8.0.0

Instance details

Methods

showsPrec :: Int -> Const k a b -> ShowS #

show :: Const k a b -> String #

showList :: [Const k a b] -> ShowS #

Ix a => Ix (Const k a b) 
Instance details

Methods

range :: (Const k a b, Const k a b) -> [Const k a b] #

index :: (Const k a b, Const k a b) -> Const k a b -> Int #

unsafeIndex :: (Const k a b, Const k a b) -> Const k a b -> Int

inRange :: (Const k a b, Const k a b) -> Const k a b -> Bool #

rangeSize :: (Const k a b, Const k a b) -> Int #

unsafeRangeSize :: (Const k a b, Const k a b) -> Int

Generic (Const k a b) 
Instance details

Associated Types

type Rep (Const k a b) :: * -> * #

Methods

from :: Const k a b -> Rep (Const k a b) x #

to :: Rep (Const k a b) x -> Const k a b #

Semigroup a => Semigroup (Const k a b)

Since: 4.9.0.0

Instance details

Methods

(<>) :: Const k a b -> Const k a b -> Const k a b #

sconcat :: NonEmpty (Const k a b) -> Const k a b #

stimes :: Integral b0 => b0 -> Const k a b -> Const k a b #

Monoid a => Monoid (Const k a b) 
Instance details

Methods

mempty :: Const k a b #

mappend :: Const k a b -> Const k a b -> Const k a b #

mconcat :: [Const k a b] -> Const k a b #

Storable a => Storable (Const k a b) 
Instance details

Methods

sizeOf :: Const k a b -> Int #

alignment :: Const k a b -> Int #

peekElemOff :: Ptr (Const k a b) -> Int -> IO (Const k a b) #

pokeElemOff :: Ptr (Const k a b) -> Int -> Const k a b -> IO () #

peekByteOff :: Ptr b0 -> Int -> IO (Const k a b) #

pokeByteOff :: Ptr b0 -> Int -> Const k a b -> IO () #

peek :: Ptr (Const k a b) -> IO (Const k a b) #

poke :: Ptr (Const k a b) -> Const k a b -> IO () #

Bits a => Bits (Const k a b) 
Instance details

Methods

(.&.) :: Const k a b -> Const k a b -> Const k a b #

(.|.) :: Const k a b -> Const k a b -> Const k a b #

xor :: Const k a b -> Const k a b -> Const k a b #

complement :: Const k a b -> Const k a b #

shift :: Const k a b -> Int -> Const k a b #

rotate :: Const k a b -> Int -> Const k a b #

zeroBits :: Const k a b #

bit :: Int -> Const k a b #

setBit :: Const k a b -> Int -> Const k a b #

clearBit :: Const k a b -> Int -> Const k a b #

complementBit :: Const k a b -> Int -> Const k a b #

testBit :: Const k a b -> Int -> Bool #

bitSizeMaybe :: Const k a b -> Maybe Int #

bitSize :: Const k a b -> Int #

isSigned :: Const k a b -> Bool #

shiftL :: Const k a b -> Int -> Const k a b #

unsafeShiftL :: Const k a b -> Int -> Const k a b #

shiftR :: Const k a b -> Int -> Const k a b #

unsafeShiftR :: Const k a b -> Int -> Const k a b #

rotateL :: Const k a b -> Int -> Const k a b #

rotateR :: Const k a b -> Int -> Const k a b #

popCount :: Const k a b -> Int #

FiniteBits a => FiniteBits (Const k a b) 
Instance details

Methods

finiteBitSize :: Const k a b -> Int #

countLeadingZeros :: Const k a b -> Int #

countTrailingZeros :: Const k a b -> Int #

Hashable a => Hashable (Const k a b) 
Instance details

Methods

hashWithSalt :: Int -> Const k a b -> Int #

hash :: Const k a b -> Int #

Wrapped (Const k a x) Source # 
Instance details

Associated Types

type Unwrapped (Const k a x) :: * Source #

Methods

_Wrapped' :: Iso' (Const k a x) (Unwrapped (Const k a x)) Source #

(~) * t (Const k2 a' x') => Rewrapped (Const k1 a x) t Source # 
Instance details
type Rep1 k (Const k a) 
Instance details
type Rep1 k (Const k a) = D1 k (MetaData "Const" "Data.Functor.Const" "base" True) (C1 k (MetaCons "Const" PrefixI True) (S1 k (MetaSel (Just Symbol "getConst") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 k a)))
type Rep (Const k a b) 
Instance details
type Rep (Const k a b) = D1 * (MetaData "Const" "Data.Functor.Const" "base" True) (C1 * (MetaCons "Const" PrefixI True) (S1 * (MetaSel (Just Symbol "getConst") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * a)))
type Unwrapped (Const k a x) Source # 
Instance details
type Unwrapped (Const k a x) = a