Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Traversal s t a b = forall p. (Choice p, Representable p, Applicative (Rep p)) => Optic p s t a b
- type Traversal' s a = Traversal s s a a
- type Ixtraversal i s t a b = forall p. (Choice p, Representable p, Applicative (Rep p)) => IndexedOptic p i s t a b
- type Ixtraversal' i s a = Ixtraversal i s s a a
- type ATraversal f s t a b = Applicative f => ARepn f s t a b
- type ATraversal' f s a = ATraversal f s s a a
- traversing :: Traversable f => (s -> a) -> (s -> b -> t) -> Traversal (f s) (f t) a b
- ixtraversing :: Monoid i => Traversable f => (s -> (i, a)) -> (s -> b -> t) -> Ixtraversal i (f s) (f t) a b
- traversalVl :: (forall f. Applicative f => (a -> f b) -> s -> f t) -> Traversal s t a b
- ixtraversalVl :: (forall f. Applicative f => (i -> a -> f b) -> s -> f t) -> Ixtraversal i s t a b
- noix :: Monoid i => Traversal s t a b -> Ixtraversal i s t a b
- ix :: Monoid i => Semiring i => Traversal s t a b -> Ixtraversal i s t a b
- withTraversal :: Applicative f => ATraversal f s t a b -> (a -> f b) -> s -> f t
- traversed :: Traversable f => Traversal (f a) (f b) a b
- both :: Traversal (a, a) (b, b) a b
- duplicated :: Traversal a b a b
- bitraversed :: Bitraversable f => Traversal (f a a) (f b b) a b
- sequences :: Applicative f => ATraversal f s t (f a) a -> s -> f t
- newtype Star (f :: Type -> Type) d c = Star {
- runStar :: d -> f c
- newtype Costar (f :: Type -> Type) d c = Costar {
- runCostar :: f d -> c
- class (Sieve p (Rep p), Strong p) => Representable (p :: Type -> Type -> Type) where
- class (Cosieve p (Corep p), Costrong p) => Corepresentable (p :: Type -> Type -> Type) where
Traversal & Ixtraversal
type Traversal s t a b = forall p. (Choice p, Representable p, Applicative (Rep p)) => Optic p s t a b Source #
A Traversal
processes 0 or more parts of the whole, with Applicative
interactions.
\( \mathsf{Traversal}\;S\;A = \exists F : \mathsf{Traversable}, S \equiv F\,A \)
type Traversal' s a = Traversal s s a a Source #
type Ixtraversal i s t a b = forall p. (Choice p, Representable p, Applicative (Rep p)) => IndexedOptic p i s t a b Source #
type Ixtraversal' i s a = Ixtraversal i s s a a Source #
type ATraversal f s t a b = Applicative f => ARepn f s t a b Source #
type ATraversal' f s a = ATraversal f s s a a Source #
traversing :: Traversable f => (s -> a) -> (s -> b -> t) -> Traversal (f s) (f t) a b Source #
Obtain a Traversal
by lifting a lens getter and setter into a Traversable
functor.
withLens
otraversing
≡traversed
. o
Compare folding
.
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions constitute a legal lens:
sa (sbt s a) ≡ a
sbt s (sa s) ≡ s
sbt (sbt s a1) a2 ≡ sbt s a2
See Property
.
The resulting optic can detect copies of the lens stucture inside
any Traversable
container. For example:
>>>
lists (traversing snd $ \(s,_) b -> (s,b)) [(0,'f'),(1,'o'),(2,'o'),(3,'b'),(4,'a'),(5,'r')]
"foobar"
ixtraversing :: Monoid i => Traversable f => (s -> (i, a)) -> (s -> b -> t) -> Ixtraversal i (f s) (f t) a b Source #
Obtain a Ixtraversal
by lifting an indexed lens getter and setter into a Traversable
functor.
withIxlens
oixtraversing
≡ixtraversed
. o
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions constitute a legal indexed lens:
snd . sia (sbt s a) ≡ a
sbt s (snd $ sia s) ≡ s
sbt (sbt s a1) a2 ≡ sbt s a2
See Property
.
traversalVl :: (forall f. Applicative f => (a -> f b) -> s -> f t) -> Traversal s t a b Source #
ixtraversalVl :: (forall f. Applicative f => (i -> a -> f b) -> s -> f t) -> Ixtraversal i s t a b Source #
Lift an indexed VL traversal into an indexed profunctor traversal.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
iabst (const pure) ≡ pure
fmap (iabst $ const f) . (iabst $ const g) ≡ getCompose . iabst (const $ Compose . fmap f . g)
See Property
.
noix :: Monoid i => Traversal s t a b -> Ixtraversal i s t a b Source #
Lift a VL traversal into an indexed profunctor traversal that ignores its input.
Useful as the first optic in a chain when no indexed equivalent is at hand.
>>>
ixlists (noix traversed . ixtraversed) ["foo", "bar"]
[(0,'f'),(1,'o'),(2,'o'),(0,'b'),(1,'a'),(2,'r')]
>>>
ixlists (ixtraversed . noix traversed) ["foo", "bar"]
[(0,'f'),(0,'o'),(0,'o'),(0,'b'),(0,'a'),(0,'r')]
ix :: Monoid i => Semiring i => Traversal s t a b -> Ixtraversal i s t a b Source #
Index a traversal with a Semiring
.
>>>
ixlists (ix traversed . ix traversed) ["foo", "bar"]
[((),'f'),((),'o'),((),'o'),((),'b'),((),'a'),((),'r')]
>>>
ixlists (ix @Int traversed . ix traversed) ["foo", "bar"]
[(0,'f'),(1,'o'),(2,'o'),(0,'b'),(1,'a'),(2,'r')]
>>>
ixlists (ix @[()] traversed . ix traversed) ["foo", "bar"]
[([],'f'),([()],'o'),([(),()],'o'),([],'b'),([()],'a'),([(),()],'r')]
>>>
ixlists (ix @[()] traversed % ix traversed) ["foo", "bar"]
[([],'f'),([()],'o'),([(),()],'o'),([()],'b'),([(),()],'a'),([(),(),()],'r')]
Primitive operators
withTraversal :: Applicative f => ATraversal f s t a b -> (a -> f b) -> s -> f t Source #
The traversal laws can be stated in terms of withTraversal
:
Identity:
withTraversal t (Identity . f) ≡ Identity (fmap f)
Composition:
Compose . fmap (withTraversal t f) . withTraversal t g ≡ withTraversal t (Compose . fmap f . g)
withTraversal :: Functor f => Lens s t a b -> (a -> f b) -> s -> f t withTraversal :: Applicative f => Traversal s t a b -> (a -> f b) -> s -> f t
Optics
traversed :: Traversable f => Traversal (f a) (f b) a b Source #
TODO: Document
both :: Traversal (a, a) (b, b) a b Source #
TODO: Document
>>>
withTraversal both (pure . length) ("hello","world")
(5,5)
duplicated :: Traversal a b a b Source #
Duplicate the results of any Fold
.
>>>
lists (both . duplicated) ("hello","world")
["hello","hello","world","world"]
bitraversed :: Bitraversable f => Traversal (f a a) (f b b) a b Source #
Traverse both parts of a Bitraversable
container with matching types.
>>>
withTraversal bitraversed (pure . length) (Right "hello")
Right 5
>>>
withTraversal bitraversed (pure . length) ("hello","world")
(5,5)
>>>
("hello","world") ^. bitraversed
"helloworld"
bitraversed
::Traversal
(a , a) (b , b) a bbitraversed
::Traversal
(a + a) (b + b) a b
Operators
sequences :: Applicative f => ATraversal f s t (f a) a -> s -> f t Source #
TODO: Document
Carriers
newtype Star (f :: Type -> Type) d c #
Lift a Functor
into a Profunctor
(forwards).
Instances
Functor f => Representable (Star f) | |
Applicative f => Choice (Star f) | |
Traversable f => Cochoice (Star f) | |
Distributive f => Closed (Star f) | |
Defined in Data.Profunctor.Closed | |
Functor m => Strong (Star m) | |
Functor f => Profunctor (Star f) | |
Defined in Data.Profunctor.Types | |
Functor f => Sieve (Star f) f | |
Defined in Data.Profunctor.Sieve | |
Monad f => Category (Star f :: Type -> Type -> Type) | |
Monad f => Monad (Star f a) | |
Functor f => Functor (Star f a) | |
Applicative f => Applicative (Star f a) | |
Contravariant f => Contravariant (Star f a) Source # | |
Alternative f => Alternative (Star f a) | |
MonadPlus f => MonadPlus (Star f a) | |
Distributive f => Distributive (Star f a) | |
Defined in Data.Profunctor.Types | |
Apply f => Apply (Star f a) Source # | |
type Rep (Star f) | |
Defined in Data.Profunctor.Rep |
newtype Costar (f :: Type -> Type) d c #
Lift a Functor
into a Profunctor
(backwards).
Instances
Contravariant f => Bifunctor (Costar f) Source # | |
Functor f => Corepresentable (Costar f) | |
Traversable w => Choice (Costar w) | |
Applicative f => Cochoice (Costar f) | |
Functor f => Closed (Costar f) | |
Defined in Data.Profunctor.Closed | |
Comonad f => Strong (Costar f) Source # | |
Functor f => Costrong (Costar f) | |
Functor f => Profunctor (Costar f) | |
Defined in Data.Profunctor.Types | |
Functor f => Cosieve (Costar f) f | |
Defined in Data.Profunctor.Sieve | |
Monad (Costar f a) | |
Functor (Costar f a) | |
Applicative (Costar f a) | |
Defined in Data.Profunctor.Types | |
Distributive (Costar f d) | |
Defined in Data.Profunctor.Types | |
type Corep (Costar f) | |
Defined in Data.Profunctor.Rep |
Classes
class (Sieve p (Rep p), Strong p) => Representable (p :: Type -> Type -> Type) where #
A Profunctor
p
is Representable
if there exists a Functor
f
such that
p d c
is isomorphic to d -> f c
.
Instances
(Monad m, Functor m) => Representable (Kleisli m) | |
Functor f => Representable (Star f) | |
Representable (Forget r) | |
Representable (Fold0Rep r) Source # | |
Representable ((->) :: Type -> Type -> Type) | |
Representable (LensRep a b) Source # | |
Representable (Traversal0Rep a b) Source # | |
Defined in Data.Profunctor.Optic.Traversal0 type Rep (Traversal0Rep a b) :: Type -> Type # tabulate :: (d -> Rep (Traversal0Rep a b) c) -> Traversal0Rep a b d c # |
class (Cosieve p (Corep p), Costrong p) => Corepresentable (p :: Type -> Type -> Type) where #
A Profunctor
p
is Corepresentable
if there exists a Functor
f
such that
p d c
is isomorphic to f d -> c
.
cotabulate :: (Corep p d -> c) -> p d c #
Laws:
cotabulate
.
cosieve
≡id
cosieve
.
cotabulate
≡id
Instances
Functor f => Corepresentable (Costar f) | |
Corepresentable (Tagged :: Type -> Type -> Type) | |
Corepresentable ((->) :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Rep cotabulate :: (Corep (->) d -> c) -> d -> c # | |
Functor w => Corepresentable (Cokleisli w) | |
Corepresentable (GrateRep a b) Source # | |