| Copyright | (C) 2012-2016 Edward Kmett |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Control.Lens.Internal.Indexed
Description
Internal implementation details for Indexed lens-likes
Synopsis
- newtype Indexed i a b = Indexed {
- runIndexed :: i -> a -> b
- class (Choice p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Strong p, Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), Costrong p, ArrowLoop p, ArrowApply p, ArrowChoice p, Closed p) => Conjoined (p :: Type -> Type -> Type) where
- class Conjoined p => Indexable i (p :: Type -> Type -> Type) where
- indexed :: p a b -> i -> a -> b
- newtype Indexing (f :: Type -> Type) a = Indexing {
- runIndexing :: Int -> (Int, f a)
- indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
- newtype Indexing64 (f :: Type -> Type) a = Indexing64 {
- runIndexing64 :: Int64 -> (Int64, f a)
- indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t
- withIndex :: (Indexable i p, Functor f) => p (i, s) (f (j, t)) -> Indexed i s (f t)
- asIndex :: (Indexable i p, Contravariant f, Functor f) => p i (f i) -> Indexed i s (f s)
An Indexed Profunctor
newtype Indexed i a b Source #
A function with access to a index. This constructor may be useful when you need to store
an Indexable in a container to avoid ImpredicativeTypes.
index :: Indexed i a b -> i -> a -> b
Constructors
| Indexed | |
Fields
| |
Instances
Classes
class (Choice p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Strong p, Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), Costrong p, ArrowLoop p, ArrowApply p, ArrowChoice p, Closed p) => Conjoined (p :: Type -> Type -> Type) where Source #
This is a Profunctor that is both Corepresentable by f and Representable by g such
that f is left adjoint to g. From this you can derive a lot of structure due
to the preservation of limits and colimits.
Minimal complete definition
Nothing
Methods
distrib :: Functor f => p a b -> p (f a) (f b) Source #
Conjoined is strong enough to let us distribute every Conjoined
Profunctor over every Haskell Functor. This is effectively a
generalization of fmap.
conjoined :: (p ~ (->) => q (a -> b) r) -> q (p a b) r -> q (p a b) r Source #
This permits us to make a decision at an outermost point about whether or not we use an index.
Ideally any use of this function should be done in such a way so that you compute the same answer, but this cannot be enforced at the type level.
Instances
| Conjoined ReifiedGetter Source # | |
Defined in Control.Lens.Reified Methods distrib :: Functor f => ReifiedGetter a b -> ReifiedGetter (f a) (f b) Source # conjoined :: (ReifiedGetter ~ (->) => q (a -> b) r) -> q (ReifiedGetter a b) r -> q (ReifiedGetter a b) r Source # | |
| Conjoined (Indexed i) Source # | |
| Conjoined (->) Source # | |
class Conjoined p => Indexable i (p :: Type -> Type -> Type) where Source #
This class permits overloading of function application for things that also admit a notion of a key or index.
Indexing
newtype Indexing (f :: Type -> Type) a Source #
Applicative composition of with a State IntFunctor, used
by indexed.
Constructors
| Indexing | |
Fields
| |
Instances
| Contravariant f => Contravariant (Indexing f) Source # | |
| Applicative f => Applicative (Indexing f) Source # | |
Defined in Control.Lens.Internal.Indexed | |
| Functor f => Functor (Indexing f) Source # | |
| Apply f => Apply (Indexing f) Source # | |
Defined in Control.Lens.Internal.Indexed | |
| Monoid (f a) => Monoid (Indexing f a) Source # |
|
| Semigroup (f a) => Semigroup (Indexing f a) Source # | |
indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t Source #
Transform a Traversal into an IndexedTraversal or
a Fold into an IndexedFold, etc.
indexing::Traversals t a b ->IndexedTraversalInts t a bindexing::Prisms t a b ->IndexedTraversalInts t a bindexing::Lenss t a b ->IndexedLensInts t a bindexing::Isos t a b ->IndexedLensInts t a bindexing::Folds a ->IndexedFoldInts aindexing::Getters a ->IndexedGetterInts a
indexing::IndexableIntp =>LensLike(Indexingf) s t a b ->Overp f s t a b
64-bit Indexing
newtype Indexing64 (f :: Type -> Type) a Source #
Applicative composition of with a State Int64Functor, used
by indexed64.
Constructors
| Indexing64 | |
Fields
| |
Instances
| Contravariant f => Contravariant (Indexing64 f) Source # | |
Defined in Control.Lens.Internal.Indexed Methods contramap :: (a' -> a) -> Indexing64 f a -> Indexing64 f a' # (>$) :: b -> Indexing64 f b -> Indexing64 f a # | |
| Applicative f => Applicative (Indexing64 f) Source # | |
Defined in Control.Lens.Internal.Indexed Methods pure :: a -> Indexing64 f a # (<*>) :: Indexing64 f (a -> b) -> Indexing64 f a -> Indexing64 f b # liftA2 :: (a -> b -> c) -> Indexing64 f a -> Indexing64 f b -> Indexing64 f c # (*>) :: Indexing64 f a -> Indexing64 f b -> Indexing64 f b # (<*) :: Indexing64 f a -> Indexing64 f b -> Indexing64 f a # | |
| Functor f => Functor (Indexing64 f) Source # | |
Defined in Control.Lens.Internal.Indexed Methods fmap :: (a -> b) -> Indexing64 f a -> Indexing64 f b # (<$) :: a -> Indexing64 f b -> Indexing64 f a # | |
| Apply f => Apply (Indexing64 f) Source # | |
Defined in Control.Lens.Internal.Indexed Methods (<.>) :: Indexing64 f (a -> b) -> Indexing64 f a -> Indexing64 f b Source # (.>) :: Indexing64 f a -> Indexing64 f b -> Indexing64 f b Source # (<.) :: Indexing64 f a -> Indexing64 f b -> Indexing64 f a Source # liftF2 :: (a -> b -> c) -> Indexing64 f a -> Indexing64 f b -> Indexing64 f c Source # | |
indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t Source #
Transform a Traversal into an IndexedTraversal or
a Fold into an IndexedFold, etc.
This combinator is like indexing except that it handles large traversals and folds gracefully.
indexing64::Traversals t a b ->IndexedTraversalInt64s t a bindexing64::Prisms t a b ->IndexedTraversalInt64s t a bindexing64::Lenss t a b ->IndexedLensInt64s t a bindexing64::Isos t a b ->IndexedLensInt64s t a bindexing64::Folds a ->IndexedFoldInt64s aindexing64::Getters a ->IndexedGetterInt64s a
indexing64::IndexableInt64p =>LensLike(Indexing64f) s t a b ->Overp f s t a b
Converting to Folds
withIndex :: (Indexable i p, Functor f) => p (i, s) (f (j, t)) -> Indexed i s (f t) Source #
Fold a container with indices returning both the indices and the values.
The result is only valid to compose in a Traversal, if you don't edit the
index as edits to the index have no effect.
>>>[10, 20, 30] ^.. ifolded . withIndex[(0,10),(1,20),(2,30)]
>>>[10, 20, 30] ^.. ifolded . withIndex . alongside negated (re _Show)[(0,"10"),(-1,"20"),(-2,"30")]