Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Fold0 s a = forall p. (Choice p, Representable p, Applicative (Rep p), forall x. Contravariant (p x)) => Optic' p s a
- fold0 :: (s -> Maybe a) -> Fold0 s a
- ixfold0 :: (s -> Maybe (i, a)) -> Ixfold0 i s a
- failing :: AFold0 a s a -> AFold0 a s a -> Fold0 s a
- toFold0 :: View s (Maybe a) -> Fold0 s a
- fromFold0 :: AFold0 a s a -> View s (Maybe a)
- folded0 :: Fold0 (Maybe a) a
- withFold0 :: Optic (Fold0Rep r) s t a b -> (a -> Maybe r) -> s -> Maybe r
- withIxfold0 :: AIxfold0 r i s a -> (i -> a -> Maybe r) -> i -> s -> Maybe r
- (^?) :: s -> AFold0 a s a -> Maybe a
- preview :: MonadReader s m => AFold0 a s a -> m (Maybe a)
- preuse :: MonadState s m => AFold0 a s a -> m (Maybe a)
- ixpreview :: Monoid i => AIxfold0 (i, a) i s a -> s -> Maybe (i, a)
- ixpreviews :: Monoid i => AIxfold0 r i s a -> (i -> a -> r) -> s -> Maybe r
- tries :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m (Either e a)
- tries_ :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m (Maybe a)
- catches :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> (e -> m a) -> m a
- catches_ :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m a -> m a
- handles :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> (e -> m a) -> m a -> m a
- handles_ :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m a -> m a
- newtype Fold0Rep r a b = Fold0Rep {
- runFold0Rep :: a -> Maybe r
- type AFold0 r s a = Optic' (Fold0Rep r) s a
- type AIxfold0 r i s a = IndexedOptic' (Fold0Rep r) i s a
- newtype Pre a b = Pre {}
- class Profunctor p => Strong (p :: Type -> Type -> Type) where
- class Profunctor p => Choice (p :: Type -> Type -> Type) where
Fold0 & Ixfold0
type Fold0 s a = forall p. (Choice p, Representable p, Applicative (Rep p), forall x. Contravariant (p x)) => Optic' p s a Source #
A Fold0
combines at most one element, with no interactions.
failing :: AFold0 a s a -> AFold0 a s a -> Fold0 s a infixl 3 Source #
Try the first Fold0
. If it returns no entry, try the second one.
Optics
folded0 :: Fold0 (Maybe a) a Source #
Obtain a Fold0
from a partial function.
>>>
[Just 1, Nothing] ^.. folded . folded0
[1]
Primitive operators
Operators
(^?) :: s -> AFold0 a s a -> Maybe a infixl 8 Source #
An infix variant of preview'
.
(^?
) ≡flip
preview'
Perform a safe head
of a Fold
or Traversal
or retrieve Just
the result from a View
or Lens
.
When using a Traversal
as a partial Lens
, or a Fold
as a partial
View
this can be a convenient way to extract the optional value.
>>>
Left 4 ^? left
Just 4
>>>
Right 4 ^? left
Nothing
Indexed operators
MonadUnliftIO
tries :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m (Either e a) Source #
Test for synchronous exceptions that match a given optic.
In the style of 'safe-exceptions' this function rethrows async exceptions synchronously in order to preserve async behavior,
tries
::MonadUnliftIO
m =>AFold0
eSomeException
e -> m a -> m (Either
e a)tries
exception
::MonadUnliftIO
m =>Exception
e => m a -> m (Either
e a)
tries_ :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m (Maybe a) Source #
A variant of tries
that returns synchronous exceptions.
catches :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> (e -> m a) -> m a Source #
Catch synchronous exceptions that match a given optic.
Rethrows async exceptions synchronously in order to preserve async behavior.
catches
::MonadUnliftIO
m =>AFold0
eSomeException
e -> m a -> (e -> m a) -> m acatches
exception
::MonadUnliftIO
m => Exception e => m a -> (e -> m a) -> m a
>>>
catches (only Overflow) (throwIO Overflow) (\_ -> return "caught")
"caught"
catches_ :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m a -> m a Source #
Catch synchronous exceptions that match a given optic, discarding the match.
>>>
catches_ (only Overflow) (throwIO Overflow) (return "caught")
"caught"
handles :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> (e -> m a) -> m a -> m a Source #
Flipped variant of catches
.
>>>
handles (only Overflow) (\_ -> return "caught") $ throwIO Overflow
"caught"
handles_ :: MonadUnliftIO m => Exception ex => AFold0 e ex e -> m a -> m a -> m a Source #
Flipped variant of catches_
.
>>>
handles_ (only Overflow) (return "caught") $ throwIO Overflow
"caught"
Carriers
newtype Fold0Rep r a b Source #
Fold0Rep | |
|
Instances
Representable (Fold0Rep r) Source # | |
Choice (Fold0Rep r) Source # | |
Cochoice (Fold0Rep r) Source # | |
Strong (Fold0Rep r) Source # | |
Profunctor (Fold0Rep r) Source # | |
Defined in Data.Profunctor.Optic.Fold0 dimap :: (a -> b) -> (c -> d) -> Fold0Rep r b c -> Fold0Rep r a d # lmap :: (a -> b) -> Fold0Rep r b c -> Fold0Rep r a c # rmap :: (b -> c) -> Fold0Rep r a b -> Fold0Rep r a c # (#.) :: Coercible c b => q b c -> Fold0Rep r a b -> Fold0Rep r a c # (.#) :: Coercible b a => Fold0Rep r b c -> q a b -> Fold0Rep r a c # | |
Sieve (Fold0Rep r) (Pre r) Source # | |
Defined in Data.Profunctor.Optic.Fold0 | |
Functor (Fold0Rep r a) Source # | |
Contravariant (Fold0Rep r a) Source # | |
type Rep (Fold0Rep r) Source # | |
Defined in Data.Profunctor.Optic.Fold0 |
type AIxfold0 r i s a = IndexedOptic' (Fold0Rep r) i s a Source #
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.
http://www-kb.is.s.u-tokyo.ac.jp/~asada/papers/arrStrMnd.pdf
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)