Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Prism s t a b = forall p. Choice p => Optic p s t a b
- type Prism' s a = Prism s s a a
- type Cxprism k s t a b = forall p. Choice p => CoindexedOptic p k s t a b
- type Cxprism' k s a = Cxprism k s s a a
- type APrism s t a b = Optic (PrismRep a b) s t a b
- type APrism' s a = APrism s s a a
- prism :: (s -> t + a) -> (b -> t) -> Prism s t a b
- prism' :: (s -> Maybe a) -> (a -> s) -> Prism' s a
- cxprism :: (s -> (k -> t) + a) -> (b -> t) -> Cxprism k s t a b
- handling :: (s -> c + a) -> ((c + b) -> t) -> Prism s t a b
- clonePrism :: APrism s t a b -> Prism s t a b
- type Coprism s t a b = forall p. Cochoice p => Optic p s t a b
- type Coprism' t b = Coprism t t b b
- type Ixprism i s t a b = forall p. Cochoice p => IndexedOptic p i s t a b
- type Ixprism' i s a = Coprism s s a a
- type ACoprism s t a b = Optic (CoprismRep a b) s t a b
- type ACoprism' s a = ACoprism s s a a
- coprism :: (s -> a) -> (b -> a + t) -> Coprism s t a b
- coprism' :: (s -> a) -> (a -> Maybe s) -> Coprism' s a
- rehandling :: ((c + s) -> a) -> (b -> c + t) -> Coprism s t a b
- cloneCoprism :: ACoprism s t a b -> Coprism s t a b
- l1 :: Prism ((a :+: c) t) ((b :+: c) t) (a t) (b t)
- r1 :: Prism ((c :+: a) t) ((c :+: b) t) (a t) (b t)
- left :: Prism (a + c) (b + c) a b
- right :: Prism (c + a) (c + b) a b
- cxright :: (e -> k -> e + b) -> Cxprism k (e + a) (e + b) a b
- just :: Prism (Maybe a) (Maybe b) a b
- nothing :: Prism (Maybe a) (Maybe b) () ()
- cxjust :: (k -> Maybe b) -> Cxprism k (Maybe a) (Maybe b) a b
- keyed :: Eq a => a -> Prism' (a, b) b
- filtered :: (a -> Bool) -> Prism' a a
- compared :: Eq a => Prd a => a -> Prism' a Ordering
- prefixed :: Eq a => [a] -> Prism' [a] [a]
- only :: Eq a => a -> Prism' a ()
- nearly :: a -> (a -> Bool) -> Prism' a ()
- nthbit :: Bits s => Int -> Prism' s ()
- sync :: Exception e => Prism' e e
- async :: Exception e => Prism' e e
- exception :: Exception e => Prism' SomeException e
- asyncException :: Exception e => Prism' SomeException e
- withPrism :: APrism s t a b -> ((s -> t + a) -> (b -> t) -> r) -> r
- withCoprism :: ACoprism s t a b -> ((s -> a) -> (b -> a + t) -> r) -> r
- aside :: APrism s t a b -> Prism (e, s) (e, t) (e, a) (e, b)
- without :: APrism s t a b -> APrism u v c d -> Prism (s + u) (t + v) (a + c) (b + d)
- below :: Traversable f => APrism' s a -> Prism' (f s) (f a)
- toPastroSum :: APrism s t a b -> p a b -> PastroSum p s t
- toTambaraSum :: Choice p => APrism s t a b -> p a b -> TambaraSum p s t
- data PrismRep a b s t = PrismRep (s -> t + a) (b -> t)
- data CoprismRep a b s t = CoprismRep (s -> a) (b -> a + t)
- class Profunctor p => Choice (p :: Type -> Type -> Type) where
- class Profunctor p => Cochoice (p :: Type -> Type -> Type) where
Prism & Cxprism
type Prism s t a b = forall p. Choice p => Optic p s t a b Source #
Prisms access one piece of a sum.
\( \mathsf{Prism}\;S\;A = \exists D, S \cong D + A \)
type Cxprism k s t a b = forall p. Choice p => CoindexedOptic p k s t a b Source #
prism :: (s -> t + a) -> (b -> t) -> Prism s t a b Source #
Obtain a Prism
from a constructor and a matcher function.
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions satisfy the following properties:
sta (bt b) ≡ Right b
(id ||| bt) (sta s) ≡ s
left sta (sta s) ≡ left Left (sta s)
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
.
cxprism :: (s -> (k -> t) + a) -> (b -> t) -> Cxprism k s t a b Source #
Obtain a Cxprism'
from a reviewer and a matcher function that returns either a match or a failure handler.
handling :: (s -> c + a) -> ((c + b) -> t) -> Prism s t a b Source #
Obtain a Prism
from its free tensor representation.
Useful for constructing prisms from try and handle functions.
clonePrism :: APrism s t a b -> Prism s t a b Source #
TODO: Document
Coprism & Ixprism
type Ixprism i s t a b = forall p. Cochoice p => IndexedOptic p i s t a b Source #
type ACoprism s t a b = Optic (CoprismRep a b) s t a b Source #
coprism :: (s -> a) -> (b -> a + t) -> Coprism s t a b Source #
Obtain a Cochoice
optic from a constructor and a matcher function.
coprism f g ≡ f g -> re (prism f g)
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions satisfy the following properties:
bat (bt b) ≡ Right b
(id ||| bt) (bat b) ≡ b
left bat (bat b) ≡ left Left (bat b)
A Coprism
is a View
, so you can specialise types to obtain:
view :: Coprism'
s a -> s -> a
rehandling :: ((c + s) -> a) -> (b -> c + t) -> Coprism s t a b Source #
Obtain a Coprism
from its free tensor representation.
cloneCoprism :: ACoprism s t a b -> Coprism s t a b Source #
TODO: Document
Optics
filtered :: (a -> Bool) -> Prism' a a Source #
Filter another optic.
>>>
[1..10] ^.. folded . filtered even
[2,4,6,8,10]
compared :: Eq a => Prd a => a -> Prism' a Ordering Source #
Focus on comparability to a given element of a partial order.
prefixed :: Eq a => [a] -> Prism' [a] [a] Source #
Prism
into the remainder of a list with a given prefix.
only :: Eq a => a -> Prism' a () Source #
Focus not just on a case, but a specific value of that case.
nthbit :: Bits s => Int -> Prism' s () Source #
Focus on the truth value of the nth bit in a bit array.
asyncException :: Exception e => Prism' SomeException e Source #
TODO: Document
Primitive operators
withPrism :: APrism s t a b -> ((s -> t + a) -> (b -> t) -> r) -> r Source #
Extract the two functions that characterize a Prism
.
withCoprism :: ACoprism s t a b -> ((s -> a) -> (b -> a + t) -> r) -> r Source #
Extract the two functions that characterize a Coprism
.
Operators
aside :: APrism s t a b -> Prism (e, s) (e, t) (e, a) (e, b) Source #
Use a Prism
to lift part of a structure.
without :: APrism s t a b -> APrism u v c d -> Prism (s + u) (t + v) (a + c) (b + d) Source #
Given a pair of prisms, project sums.
below :: Traversable f => APrism' s a -> Prism' (f s) (f a) Source #
Lift a Prism
through a Traversable
functor.
Returns a Prism
that matches only if each element matches the original Prism
.
>>>
[Left 1, Right "foo", Left 4, Right "woot"] ^.. below right
[]
>>>
[Right "hail hydra!", Right "foo", Right "blah", Right "woot"] ^.. below right
[["hail hydra!","foo","blah","woot"]]
toPastroSum :: APrism s t a b -> p a b -> PastroSum p s t Source #
toTambaraSum :: Choice p => APrism s t a b -> p a b -> TambaraSum p s t Source #
Use a Prism
to construct a TambaraSum
.
Carriers
data PrismRep a b s t Source #
Instances
Choice (PrismRep a b) Source # | |
Profunctor (PrismRep a b) Source # | |
Defined in Data.Profunctor.Optic.Prism dimap :: (a0 -> b0) -> (c -> d) -> PrismRep a b b0 c -> PrismRep a b a0 d # lmap :: (a0 -> b0) -> PrismRep a b b0 c -> PrismRep a b a0 c # rmap :: (b0 -> c) -> PrismRep a b a0 b0 -> PrismRep a b a0 c # (#.) :: Coercible c b0 => q b0 c -> PrismRep a b a0 b0 -> PrismRep a b a0 c # (.#) :: Coercible b0 a0 => PrismRep a b b0 c -> q a0 b0 -> PrismRep a b a0 c # | |
Functor (PrismRep a b s) Source # | |
data CoprismRep a b s t Source #
CoprismRep (s -> a) (b -> a + t) |
Instances
Cochoice (CoprismRep a b) Source # | |
Defined in Data.Profunctor.Optic.Prism unleft :: CoprismRep a b (Either a0 d) (Either b0 d) -> CoprismRep a b a0 b0 # unright :: CoprismRep a b (Either d a0) (Either d b0) -> CoprismRep a b a0 b0 # | |
Profunctor (CoprismRep a b) Source # | |
Defined in Data.Profunctor.Optic.Prism dimap :: (a0 -> b0) -> (c -> d) -> CoprismRep a b b0 c -> CoprismRep a b a0 d # lmap :: (a0 -> b0) -> CoprismRep a b b0 c -> CoprismRep a b a0 c # rmap :: (b0 -> c) -> CoprismRep a b a0 b0 -> CoprismRep a b a0 c # (#.) :: Coercible c b0 => q b0 c -> CoprismRep a b a0 b0 -> CoprismRep a b a0 c # (.#) :: Coercible b0 a0 => CoprismRep a b b0 c -> q a0 b0 -> CoprismRep a b a0 c # | |
Functor (CoprismRep a b s) Source # | |
Defined in Data.Profunctor.Optic.Prism fmap :: (a0 -> b0) -> CoprismRep a b s a0 -> CoprismRep a b s b0 # (<$) :: a0 -> CoprismRep a b s b0 -> CoprismRep a b s a0 # |
Classes
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 => Cochoice (p :: Type -> Type -> Type) where #
unleft :: p (Either a d) (Either b d) -> p a b #
Laws:
unleft
≡unright
.
dimap
swapE swapE where swapE ::Either
a b ->Either
b a swapE =either
Right
Left
rmap
(either
id
absurd
) ≡unleft
.
lmap
(either
id
absurd
)unfirst
.
rmap
(second
f) ≡unfirst
.
lmap
(second
f)unleft
.
unleft
≡unleft
.
dimap
assocE unassocE 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)
unright :: p (Either d a) (Either d b) -> p a b #
Laws:
unright
≡unleft
.
dimap
swapE swapE where swapE ::Either
a b ->Either
b a swapE =either
Right
Left
rmap
(either
absurd
id
) ≡unright
.
lmap
(either
absurd
id
)unsecond
.
rmap
(first
f) ≡unsecond
.
lmap
(first
f)unright
.
unright
≡unright
.
dimap
unassocE assocE 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)