|Maintainer||Edward Kmett <email@example.com>|
- type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
- type Prism' s a = Prism s s a a
- type APrism s t a b = Market a b a (Mutator b) -> Market a b s (Mutator t)
- type APrism' s a = APrism s s a a
- prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
- prism' :: (a -> s) -> (s -> Maybe a) -> Prism' s a
- clonePrism :: APrism s t a b -> Prism s t a b
- outside :: APrism s t a b -> Lens (t -> r) (s -> r) (b -> r) (a -> 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 (Either s u) (Either t v) (Either a c) (Either b d)
- isn't :: APrism s t a b -> s -> Bool
- _Left :: Prism (Either a c) (Either b c) a b
- _Right :: Prism (Either c a) (Either c b) a b
- _Just :: Prism (Maybe a) (Maybe b) a b
- class Profunctor p => Choice p where
There are two laws that a
Prism should satisfy:
Second, if you can extract a value
a using a
l from a value
s, then the value
s is completely described my
It may help to think of this as a
Iso that can be partial in one direction.
$\ i -> if i
We can update the ones that are:
(-3,4) & both.nat *~ 2(-3,8)
5 ^. re nat -- :: Natural5
Left "hello" & _Left %~ lengthLeft 5
or to construct an
5^.re _LeftLeft 5
such that if you query it with the
Prism, you will get your original input back.
5^.re _Left ^? _LeftJust 5
Note: Composition with a
Prism is index-preserving.
If you see this in a signature for a function, the function is expecting a
Prism to work over part of a structure.
Check to see if this
Prism doesn't match.
isn't _Left (Right 12)True
isn't _Left (Left 12)False
over _Left (+1) (Left 2)Left 3
over _Left (+1) (Right 2)Right 2
Right 42 ^._Left :: String""
Left "hello" ^._Left"hello"
5^.re _LeftLeft 5
over _Right (+1) (Left 2)Left 2
over _Right (+1) (Right 2)Right 3
Right "hello" ^._Right"hello"
Left "hello" ^._Right :: [Double]
5^.re _RightRight 5
|(Profunctor (Kleisli m), Monad m) => Choice (Kleisli m)|
|(Profunctor (Cokleisli w), Comonad w) => Choice (Cokleisli w)|
|(Profunctor (DownStar w), Traversable w) => Choice (DownStar w)|
|(Profunctor (WrappedArrow p), ArrowChoice p) => Choice (WrappedArrow p)|
|Choice (Tagged *)|
|Profunctor (Indexed i) => Choice (Indexed i)|
|Profunctor (Market a b) => Choice (Market a b)|