| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Optic.Fold0
Contents
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'.
(^?) ≡flippreview'
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 ^? leftJust 4
>>>Right 4 ^? leftNothing
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::MonadUnliftIOm =>AFold0eSomeExceptione -> m a -> m (Eithere a)triesexception::MonadUnliftIOm =>Exceptione => m a -> m (Eithere 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::MonadUnliftIOm =>AFold0eSomeExceptione -> m a -> (e -> m a) -> m acatchesexception::MonadUnliftIOm => 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 #
Constructors
| Fold0Rep | |
Fields
| |
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 Methods 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
Methods
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.
Methods
left' :: p a b -> p (Either a c) (Either b c) #
Laws:
left'≡dimapswapE swapE.right'where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmapLeft≡lmapLeft.left'lmap(rightf).left'≡rmap(rightf).left'left'.left'≡dimapassocE unassocE.left'where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb) =Left(Rightb) unassocE (Right(Rightc)) =Rightc)
right' :: p a b -> p (Either c a) (Either c b) #
Laws:
right'≡dimapswapE swapE.left'where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmapRight≡lmapRight.right'lmap(leftf).right'≡rmap(leftf).right'right'.right'≡dimapunassocE assocE.right'where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb) =Left(Rightb) unassocE (Right(Rightc)) =Rightc)