Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Traversal0 s t a b = forall p. Affine p => Optic p s t a b
- type Traversal0' s a = Traversal0 s s a a
- traversal0 :: (s -> t + a) -> (s -> b -> t) -> Traversal0 s t a b
- traversal0' :: (s -> Maybe a) -> (s -> a -> s) -> Traversal0' s a
- traversal0Vl :: (forall f. Functor f => (forall c. c -> f c) -> (a -> f b) -> s -> f t) -> Traversal0 s t a b
- type Traversal s t a b = forall p. (Affine p, Traversing p) => Optic p s t a b
- type Traversal' s a = Traversal s s a a
- type Cotraversal s t a b = forall p. (Coaffine p, Cotraversing p) => Optic p s t a b
- type Cotraversal' t b = Cotraversal t t b b
- traversing :: Traversable f => (s -> a) -> (s -> b -> t) -> Traversal (f s) (f t) a b
- traversalVl :: (forall f. Applicative f => (a -> f b) -> s -> f t) -> Traversal s t a b
- cotraversing :: Distributive g => (((s -> a) -> b) -> t) -> Cotraversal (g s) (g t) a b
- retraversing :: Distributive g => (b -> t) -> (b -> s -> a) -> Cotraversal (g s) (g t) a b
- cotraversalVl :: (forall f. Coapplicative f => (f a -> b) -> f s -> t) -> Cotraversal s t a b
- type Traversal1 s t a b = forall p. (Strong p, Traversing1 p) => Optic p s t a b
- type Traversal1' s a = Traversal1 s s a a
- type Cotraversal1 s t a b = forall p. (Closed p, Cotraversing1 p) => Optic p s t a b
- type Cotraversal1' t b = Cotraversal1 t t b b
- traversing1 :: Traversable1 f => (s -> a) -> (s -> b -> t) -> Traversal1 (f s) (f t) a b
- traversal1Vl :: (forall f. Apply f => (a -> f b) -> s -> f t) -> Traversal1 s t a b
- pappend :: Traversing1 p => p a b -> p a b -> p a b
- (<<*>>) :: Traversing1 p => p a (b -> c) -> p a b -> p a c
- (****) :: Traversing1 p => p a1 b1 -> p a2 b2 -> p (a1, a2) (b1, b2)
- (&&&&) :: Traversing1 p => p a b1 -> p a b2 -> p a (b1, b2)
- divide :: Traversing1 p => (a -> (a1, a2)) -> p a1 b -> p a2 b -> p a b
- divide' :: Traversing1 p => p a1 b -> p a2 b -> p (a1, a2) b
- cochoose :: Traversing1 p => ((b1, b2) -> b) -> p a b1 -> p a b2 -> p a b
- cochoose' :: Traversing1 p => p a b1 -> p a b2 -> p a (b1, b2)
- cotraversing1 :: Distributive1 g => (((s -> a) -> b) -> t) -> Cotraversal1 (g s) (g t) a b
- retraversing1 :: Distributive1 g => (b -> t) -> (b -> s -> a) -> Cotraversal1 (g s) (g t) a b
- cotraversal1Vl :: (forall f. Coapply f => (f a -> b) -> f s -> t) -> Cotraversal1 s t a b
- (++++) :: Cotraversing1 p => p a1 b1 -> p a2 b2 -> p (a1 + a2) (b1 + b2)
- (||||) :: Cotraversing1 p => p a1 b -> p a2 b -> p (a1 + a2) b
- codivide :: Cotraversing1 p => ((b1 + b2) -> b) -> p a b1 -> p a b2 -> p a b
- codivide' :: Cotraversing1 p => p a b1 -> p a b2 -> p a (b1 + b2)
- choose :: Cotraversing1 p => (a -> a1 + a2) -> p a1 b -> p a2 b -> p a b
- choose' :: Cotraversing1 p => p a1 b -> p a2 b -> p (a1 + a2) b
- nulled :: Traversal0' s a
- selected :: (a -> Bool) -> Traversal0' (a, b) b
- traversed :: Traversable f => Traversal (f a) (f b) a b
- cotraversed :: Distributive f => Cotraversal (f a) (f b) a b
- traversed1 :: Traversable1 t => Traversal1 (t a) (t b) a b
- cotraversed1 :: Distributive1 f => Cotraversal1 (f a) (f b) a b
- both :: Traversal (a, a) (b, b) a b
- coboth :: Cotraversal (a + a) (b + b) a b
- both1 :: Traversal1 (a, a) (b, b) a b
- coboth1 :: Cotraversal1 (a + a) (b + b) a b
- duplicated :: Traversal a b a b
- beside :: Bitraversable r => Traversal s1 t1 a b -> Traversal s2 t2 a b -> Traversal (r s1 s2) (r t1 t2) a b
- bitraversed :: Bitraversable f => Traversal (f a a) (f b b) a b
- bitraversed1 :: Bitraversable1 r => Traversal1 (r a a) (r b b) a b
- repeated :: Traversal1' a a
- iterated :: (a -> a) -> Traversal1' a a
- cycled :: Apply f => ATraversal1' f s a -> ATraversal1' f s a
- matches :: ATraversal0 s t a b -> s -> t + a
- traverses :: Applicative f => ATraversal f s t a b -> (a -> f b) -> s -> f t
- cotraverses :: Coapplicative f => ACotraversal f s t a b -> (f a -> b) -> f s -> t
- cotraverses1 :: Coapply f => ACotraversal1 f s t a b -> (f a -> b) -> f s -> t
- traverses1 :: Apply f => ATraversal1 f s t a b -> (a -> f b) -> s -> f t
- sequences :: Applicative f => ATraversal f s t (f a) a -> s -> f t
- collects :: Coapplicative f => ACotraversal f s t a (f a) -> f s -> t
- sequences1 :: Apply f => ATraversal1 f s t (f a) a -> s -> f t
- collects1 :: Coapply f => ACotraversal1 f s t a (f a) -> f s -> t
- class Profunctor p => Strong (p :: Type -> Type -> Type) where
- class Profunctor p => Choice (p :: Type -> Type -> Type) where
- class Profunctor p => Closed (p :: Type -> Type -> Type) where
- closed :: p a b -> p (x -> a) (x -> b)
- 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
Traversal0
type Traversal0 s t a b = forall p. Affine p => Optic p s t a b Source #
\( \mathsf{Traversal0}\;S\;A = \exists C, D, S \cong D + C \times A \)
type Traversal0' s a = Traversal0 s s a a Source #
traversal0 :: (s -> t + a) -> (s -> b -> t) -> Traversal0 s t a b Source #
Create a Traversal0
from match and constructor functions.
Caution: In order for the Traversal0
to be well-defined,
you must ensure that the input functions satisfy the following
properties:
sta (sbt a s) ≡ either (Left . const a) Right (sta s)
either id (sbt s) (sta s) ≡ s
sbt (sbt s a1) a2 ≡ sbt s a2
More generally, a profunctor optic must be monoidal as a natural transformation:
o id ≡ id
o (
Procompose
p q) ≡Procompose
(o p) (o q)
See Property
.
traversal0' :: (s -> Maybe a) -> (s -> a -> s) -> Traversal0' s a Source #
Obtain a Traversal0'
from match and constructor functions.
traversal0Vl :: (forall f. Functor f => (forall c. c -> f c) -> (a -> f b) -> s -> f t) -> Traversal0 s t a b Source #
Transform a Van Laarhoven Traversal0
into a profunctor Traversal0
.
Traversal
type Traversal s t a b = forall p. (Affine p, Traversing p) => Optic p s t a b Source #
\( \mathsf{Traversal}\;S\;A = \exists F : \mathsf{Traversable}, S \equiv F\,A \)
type Traversal' s a = Traversal s s a a Source #
type Cotraversal s t a b = forall p. (Coaffine p, Cotraversing p) => Optic p s t a b Source #
\( \mathsf{Cotraversal}\;S\;A = \exists F : \mathsf{Distributive}, S \equiv F\,A \)
type Cotraversal' t b = Cotraversal t t b b 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"
traversalVl :: (forall f. Applicative f => (a -> f b) -> s -> f t) -> Traversal s t a b Source #
Obtain a profunctor Traversal
from a Van Laarhoven Traversal
.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
abst pure ≡ pure
fmap (abst f) . abst g ≡ getCompose . abst (Compose . fmap f . g)
The traversal laws can be stated in terms of withStar
:
withStar t (pure . f) ≡ pure (fmap f)
Compose . fmap (withStar t f) . withStar t g ≡ withStar t (Compose . fmap f . g)
See Property
.
cotraversing :: Distributive g => (((s -> a) -> b) -> t) -> Cotraversal (g s) (g t) a b Source #
Obtain a Cotraversal
by embedding a continuation into a Distributive
functor.
withGrate
ocotraversing
≡cotraversed
. o
Caution: In order for the generated optic to be well-defined, you must ensure that the input function satisfies the following properties:
sabt ($ s) ≡ s
sabt (k -> f (k . sabt)) ≡ sabt (k -> f ($ k))
retraversing :: Distributive g => (b -> t) -> (b -> s -> a) -> Cotraversal (g s) (g t) a b Source #
Obtain a Cotraversal
by embedding a reversed lens getter and setter into a Distributive
functor.
withLens
(re
o)cotraversing
≡cotraversed
. o
cotraversalVl :: (forall f. Coapplicative f => (f a -> b) -> f s -> t) -> Cotraversal s t a b Source #
Obtain a profunctor Cotraversal
from a Van Laarhoven Cotraversal
.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
abst copure ≡ copure
abst f . fmap (abst g) ≡ abst (f . fmap g . getCompose) . Compose
The cotraversal laws can be restated in terms of withCostar
:
withCostar o (f . copure) ≡ fmap f . copure
withCostar o f . fmap (withCostar o g) == withCostar o (f . fmap g . getCompose) . Compose
See Property
.
Traversal1
type Traversal1 s t a b = forall p. (Strong p, Traversing1 p) => Optic p s t a b Source #
\( \mathsf{Traversal1}\;S\;A = \exists F : \mathsf{Traversable1}, S \equiv F\,A \)
type Traversal1' s a = Traversal1 s s a a Source #
type Cotraversal1 s t a b = forall p. (Closed p, Cotraversing1 p) => Optic p s t a b Source #
\( \mathsf{Cotraversal1}\;S\;A = \exists F : \mathsf{Distributive1}, S \equiv F\,A \)
type Cotraversal1' t b = Cotraversal1 t t b b Source #
traversing1 :: Traversable1 f => (s -> a) -> (s -> b -> t) -> Traversal1 (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
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"
Compare folding
.
traversal1Vl :: (forall f. Apply f => (a -> f b) -> s -> f t) -> Traversal1 s t a b Source #
Obtain a profunctor Traversal1
from a Van Laarhoven Traversal1
.
Caution: In order for the generated family to be well-defined, you must ensure that the traversal1 law holds for the input function:
fmap (abst f) . abst g ≡ getCompose . abst (Compose . fmap f . g)
See Property
.
pappend :: Traversing1 p => p a b -> p a b -> p a b Source #
(<<*>>) :: Traversing1 p => p a (b -> c) -> p a b -> p a c infixl 4 Source #
Profunctor version of <*>
.
(****) :: Traversing1 p => p a1 b1 -> p a2 b2 -> p (a1, a2) (b1, b2) infixr 3 Source #
Profunctor version of ***
.
(&&&&) :: Traversing1 p => p a b1 -> p a b2 -> p a (b1, b2) infixr 3 Source #
Profunctor version of &&&
.
divide :: Traversing1 p => (a -> (a1, a2)) -> p a1 b -> p a2 b -> p a b Source #
Profunctor version of divide.
divide' :: Traversing1 p => p a1 b -> p a2 b -> p (a1, a2) b Source #
cochoose :: Traversing1 p => ((b1, b2) -> b) -> p a b1 -> p a b2 -> p a b Source #
cochoose' :: Traversing1 p => p a b1 -> p a b2 -> p a (b1, b2) Source #
cotraversing1 :: Distributive1 g => (((s -> a) -> b) -> t) -> Cotraversal1 (g s) (g t) a b Source #
Obtain a Cotraversal1
by embedding a continuation into a Distributive1
functor.
withGrate
ocotraversing1
≡cotraversed1
. o
Caution: In order for the generated optic to be well-defined, you must ensure that the input function satisfies the following properties:
sabt ($ s) ≡ s
sabt (k -> f (k . sabt)) ≡ sabt (k -> f ($ k))
retraversing1 :: Distributive1 g => (b -> t) -> (b -> s -> a) -> Cotraversal1 (g s) (g t) a b Source #
Obtain a Cotraversal1
by embedding a reversed lens getter and setter into a Distributive1
functor.
withLens
(re
o)cotraversing
≡cotraversed
. o
cotraversal1Vl :: (forall f. Coapply f => (f a -> b) -> f s -> t) -> Cotraversal1 s t a b Source #
Obtain a profunctor Cotraversal1
from a Van Laarhoven Cotraversal1
.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
abst runIdentity ≡ runIdentity
abst f . fmap (abst g) ≡ abst (f . fmap g . getCompose) . Compose
The cotraversal1 laws can be restated in terms of withCostar
:
withCostar o (f . runIdentity) ≡ fmap f . runIdentity
withCostar o f . fmap (withCostar o g) == withCostar o (f . fmap g . getCompose) . Compose
See Property
.
(++++) :: Cotraversing1 p => p a1 b1 -> p a2 b2 -> p (a1 + a2) (b1 + b2) infixr 2 Source #
Profunctor version of +++
.
(||||) :: Cotraversing1 p => p a1 b -> p a2 b -> p (a1 + a2) b infixr 2 Source #
Profunctor version of |||
.
codivide :: Cotraversing1 p => ((b1 + b2) -> b) -> p a b1 -> p a b2 -> p a b Source #
codivide' :: Cotraversing1 p => p a b1 -> p a b2 -> p a (b1 + b2) Source #
choose :: Cotraversing1 p => (a -> a1 + a2) -> p a1 b -> p a2 b -> p a b Source #
Profunctor version of choose.
choose' :: Cotraversing1 p => p a1 b -> p a2 b -> p (a1 + a2) b Source #
Optics
nulled :: Traversal0' s a Source #
TODO: Document
selected :: (a -> Bool) -> Traversal0' (a, b) b Source #
TODO: Document
traversed :: Traversable f => Traversal (f a) (f b) a b Source #
TODO: Document
cotraversed :: Distributive f => Cotraversal (f a) (f b) a b Source #
TODO: Document
traversed1 :: Traversable1 t => Traversal1 (t a) (t b) a b Source #
Obtain a Traversal1
from a Traversable1
functor.
cotraversed1 :: Distributive1 f => Cotraversal1 (f a) (f b) a b Source #
TODO: Document
both :: Traversal (a, a) (b, b) a b Source #
TODO: Document
>>>
traverses both (pure . length) ("hello","world")
(5,5)
both1 :: Traversal1 (a, a) (b, b) a b Source #
TODO: Document
>>>
traverses both1 (pure . NE.length) ('h' :| "ello", 'w' :| "orld")
(5,5)
coboth1 :: Cotraversal1 (a + a) (b + b) a b Source #
TODO: Document
>>>
cotraverses1 coboth1 (foldMap id) $ Left "foo" :| [Right "bar"]
Left "foo">>>
cotraverses1 coboth1 (foldMap id) $ Right "foo" :| [Right "bar"]
Right "foobar"
duplicated :: Traversal a b a b Source #
Duplicate the results of a Traversal
.
>>>
lists (both . duplicated) ("hello","world")
["hello","hello","world","world"]
beside :: Bitraversable r => Traversal s1 t1 a b -> Traversal s2 t2 a b -> Traversal (r s1 s2) (r t1 t2) a b Source #
TODO: Document
bitraversed :: Bitraversable f => Traversal (f a a) (f b b) a b Source #
Traverse both parts of a Bitraversable
container with matching types.
>>>
traverses bitraversed (pure . length) (Right "hello")
Right 5>>>
traverses 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
bitraversed1 :: Bitraversable1 r => Traversal1 (r a a) (r b b) a b Source #
Traverse both parts of a Bitraversable1
container with matching types.
>>>
traverses bitraversed1 (pure . NE.length) ('h' :| "ello", 'w' :| "orld")
(5,5)
repeated :: Traversal1' a a Source #
Obtain a Traversal1'
by repeating the input forever.
repeat
≡lists
repeated
>>>
take 5 $ 5 ^.. repeated
[5,5,5,5,5]
repeated :: Fold1 a a
iterated :: (a -> a) -> Traversal1' a a Source #
x
returns an infinite ^.
iterated
fTraversal1'
of repeated applications of f
to x
.
lists
(iterated
f) a ≡iterate
f a
>>>
take 3 $ (1 :: Int) ^.. iterated (+1)
[1,2,3]
iterated :: (a -> a) -> Fold1
a a
cycled :: Apply f => ATraversal1' f s a -> ATraversal1' f s a Source #
Transform a Traversal1'
into a Traversal1'
that loops over its elements repeatedly.
>>>
take 7 $ (1 :| [2,3]) ^.. cycled traversed1
[1,2,3,1,2,3,1]
cycled ::Fold1
s a ->Fold1
s a
Operators
matches :: ATraversal0 s t a b -> s -> t + a Source #
Test whether the optic matches or not.
>>>
matches just (Just 2)
Right 2>>>
matches just (Nothing :: Maybe Int) :: Either (Maybe Bool) Int
Left Nothing
traverses :: Applicative f => ATraversal f s t a b -> (a -> f b) -> s -> f t Source #
TODO: Document
cotraverses :: Coapplicative f => ACotraversal f s t a b -> (f a -> b) -> f s -> t Source #
TODO: Document
cotraverses1 :: Coapply f => ACotraversal1 f s t a b -> (f a -> b) -> f s -> t Source #
TODO: Document
traverses1 :: Apply f => ATraversal1 f s t a b -> (a -> f b) -> s -> f t Source #
TODO: Document
sequences :: Applicative f => ATraversal f s t (f a) a -> s -> f t Source #
TODO: Document
collects :: Coapplicative f => ACotraversal f s t a (f a) -> f s -> t Source #
TODO: Document
>>>
collects left' (1, Left "foo") :: Either (Int8, String) String
Left (1,"foo")>>>
collects left' (1, Right "foo")
Right "foo"
sequences1 :: Apply f => ATraversal1 f s t (f a) a -> s -> f t Source #
TODO: Document
collects1 :: Coapply f => ACotraversal1 f s t a (f a) -> f s -> t Source #
TODO: Document
>>>
collects1 cotraversed1 ["xxx","ooo"] :: [String]
["xo","xo","xo"]
Classes
class Profunctor p => Strong (p :: Type -> Type -> Type) where #
Generalizing Star
of a strong Functor
Note: Every Functor
in Haskell is strong with respect to (,)
.
This describes profunctor strength with respect to the product structure of Hask.
Instances
class Profunctor p => Choice (p :: Type -> Type -> Type) where #
The generalization of Costar
of Functor
that is strong with respect
to Either
.
Note: This is also a notion of strength, except with regards to another monoidal structure that we can choose to equip Hask with: the cocartesian coproduct.
left' :: p a b -> p (Either a c) (Either b c) #
Laws:
left'
≡dimap
swapE swapE.
right'
where swapE ::Either
a b ->Either
b a swapE =either
Right
Left
rmap
Left
≡lmap
Left
.
left'
lmap
(right
f).
left'
≡rmap
(right
f).
left'
left'
.
left'
≡dimap
assocE unassocE.
left'
where assocE ::Either
(Either
a b) c ->Either
a (Either
b c) assocE (Left
(Left
a)) =Left
a assocE (Left
(Right
b)) =Right
(Left
b) assocE (Right
c) =Right
(Right
c) unassocE ::Either
a (Either
b c) ->Either
(Either
a b) c unassocE (Left
a) =Left
(Left
a) unassocE (Right
(Left
b)) =Left
(Right
b) unassocE (Right
(Right
c)) =Right
c
right' :: p a b -> p (Either c a) (Either c b) #
Laws:
right'
≡dimap
swapE swapE.
left'
where swapE ::Either
a b ->Either
b a swapE =either
Right
Left
rmap
Right
≡lmap
Right
.
right'
lmap
(left
f).
right'
≡rmap
(left
f).
right'
right'
.
right'
≡dimap
unassocE assocE.
right'
where assocE ::Either
(Either
a b) c ->Either
a (Either
b c) assocE (Left
(Left
a)) =Left
a assocE (Left
(Right
b)) =Right
(Left
b) assocE (Right
c) =Right
(Right
c) unassocE ::Either
a (Either
b c) ->Either
(Either
a b) c unassocE (Left
a) =Left
(Left
a) unassocE (Right
(Left
b)) =Left
(Right
b) unassocE (Right
(Right
c)) =Right
c
Instances
class Profunctor p => Closed (p :: Type -> Type -> Type) where #
A strong profunctor allows the monoidal structure to pass through.
A closed profunctor allows the closed structure to pass through.
Instances
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 (Lin a) | |
Representable (Conjoin j) Source # | |
Representable (Fold0Rep r) Source # | |
Representable ((->) :: Type -> Type -> Type) | |
Representable (Traversal0Rep a b) Source # | |
Defined in Data.Profunctor.Optic.Carrier type Rep (Traversal0Rep a b) :: Type -> Type # tabulate :: (d -> Rep (Traversal0Rep a b) c) -> Traversal0Rep a b d c # | |
Representable (LensRep a b) Source # | |
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 (Conjoin j) Source # | |
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 # | |