profunctor-optics-0.0.0.2: An optics library compatible with the typeclasses in 'profunctors'.

Safe HaskellNone
LanguageHaskell2010

Data.Profunctor.Optic.Fold0

Contents

Synopsis

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.

fold0 :: (s -> Maybe a) -> Fold0 s a Source #

Obtain a Fold0 directly.

fold0 . preview ≡ id
fold0 (view o) ≡ o . just
>>> preview (fold0 . preview $ selected even) (2, "yes")
Just "yes"
>>> preview (fold0 . preview $ selected even) (3, "no")
Nothing
>>> preview (fold0 listToMaybe) "foo"
Just 'f'

ixfold0 :: (s -> Maybe (i, a)) -> Ixfold0 i s a Source #

Create an Ixfold0 from a partial function.

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.

toFold0 :: View s (Maybe a) -> Fold0 s a Source #

Obtain a Fold0 from a View.

toFold0 o ≡ o . just
toFold0 o ≡ fold0 (view o)

fromFold0 :: AFold0 a s a -> View s (Maybe a) Source #

Obtain a partial View from a Fold0

Optics

folded0 :: Fold0 (Maybe a) a Source #

Obtain a Fold0 from a partial function.

>>> [Just 1, Nothing] ^.. folded . folded0
[1]

Primitive operators

withFold0 :: Optic (Fold0Rep r) s t a b -> (a -> Maybe r) -> s -> Maybe r Source #

TODO: Document

withIxfold0 :: AIxfold0 r i s a -> (i -> a -> Maybe r) -> i -> s -> Maybe r Source #

TODO: Document

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

preview :: MonadReader s m => AFold0 a s a -> m (Maybe a) Source #

TODO: Document

preuse :: MonadState s m => AFold0 a s a -> m (Maybe a) Source #

TODO: Document

Indexed operators

ixpreview :: Monoid i => AIxfold0 (i, a) i s a -> s -> Maybe (i, a) Source #

TODO: Document

ixpreviews :: Monoid i => AIxfold0 r i s a -> (i -> a -> r) -> s -> Maybe r Source #

TODO: Document

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 e SomeException 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 e SomeException e -> m a -> (e -> m a) -> m a
catches 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 #

Constructors

Fold0Rep 

Fields

Instances
Representable (Fold0Rep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Associated Types

type Rep (Fold0Rep r) :: Type -> Type #

Methods

tabulate :: (d -> Rep (Fold0Rep r) c) -> Fold0Rep r d c #

Choice (Fold0Rep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

left' :: Fold0Rep r a b -> Fold0Rep r (Either a c) (Either b c) #

right' :: Fold0Rep r a b -> Fold0Rep r (Either c a) (Either c b) #

Cochoice (Fold0Rep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

unleft :: Fold0Rep r (Either a d) (Either b d) -> Fold0Rep r a b #

unright :: Fold0Rep r (Either d a) (Either d b) -> Fold0Rep r a b #

Strong (Fold0Rep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

first' :: Fold0Rep r a b -> Fold0Rep r (a, c) (b, c) #

second' :: Fold0Rep r a b -> Fold0Rep r (c, a) (c, b) #

Profunctor (Fold0Rep r) Source # 
Instance details

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 # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

sieve :: Fold0Rep r a b -> a -> Pre r b #

Functor (Fold0Rep r a) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

fmap :: (a0 -> b) -> Fold0Rep r a a0 -> Fold0Rep r a b #

(<$) :: a0 -> Fold0Rep r a b -> Fold0Rep r a a0 #

Contravariant (Fold0Rep r a) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

contramap :: (a0 -> b) -> Fold0Rep r a b -> Fold0Rep r a a0 #

(>$) :: b -> Fold0Rep r a b -> Fold0Rep r a a0 #

type Rep (Fold0Rep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

type Rep (Fold0Rep r) = Pre r

type AFold0 r s a = Optic' (Fold0Rep r) s a Source #

type AIxfold0 r i s a = IndexedOptic' (Fold0Rep r) i s a Source #

newtype Pre a b Source #

Pre is Maybe with a phantom type variable.

Constructors

Pre 

Fields

Instances
Functor (Pre a) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

fmap :: (a0 -> b) -> Pre a a0 -> Pre a b #

(<$) :: a0 -> Pre a b -> Pre a a0 #

Contravariant (Pre a) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

contramap :: (a0 -> b) -> Pre a b -> Pre a a0 #

(>$) :: b -> Pre a b -> Pre a a0 #

Sieve (Fold0Rep r) (Pre r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

sieve :: Fold0Rep r a b -> a -> Pre r b #

Eq a => Eq (Pre a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

(==) :: Pre a b -> Pre a b -> Bool #

(/=) :: Pre a b -> Pre a b -> Bool #

Ord a => Ord (Pre a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

compare :: Pre a b -> Pre a b -> Ordering #

(<) :: Pre a b -> Pre a b -> Bool #

(<=) :: Pre a b -> Pre a b -> Bool #

(>) :: Pre a b -> Pre a b -> Bool #

(>=) :: Pre a b -> Pre a b -> Bool #

max :: Pre a b -> Pre a b -> Pre a b #

min :: Pre a b -> Pre a b -> Pre a b #

Show a => Show (Pre a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

showsPrec :: Int -> Pre a b -> ShowS #

show :: Pre a b -> String #

showList :: [Pre a b] -> ShowS #

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

Minimal complete definition

first' | second'

Methods

first' :: p a b -> p (a, c) (b, c) #

Laws:

first'dimap swap swap . second'
lmap fstrmap fst . first'
lmap (second f) . first'rmap (second f) . first
first' . first'dimap assoc unassoc . first' where
  assoc ((a,b),c) = (a,(b,c))
  unassoc (a,(b,c)) = ((a,b),c)

second' :: p a b -> p (c, a) (c, b) #

Laws:

second'dimap swap swap . first'
lmap sndrmap snd . second'
lmap (first f) . second'rmap (first f) . second'
second' . second'dimap unassoc assoc . second' where
  assoc ((a,b),c) = (a,(b,c))
  unassoc (a,(b,c)) = ((a,b),c)
Instances
Monad m => Strong (Kleisli m) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Kleisli m a b -> Kleisli m (a, c) (b, c) #

second' :: Kleisli m a b -> Kleisli m (c, a) (c, b) #

Strong (Pastro p) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Pastro p a b -> Pastro p (a, c) (b, c) #

second' :: Pastro p a b -> Pastro p (c, a) (c, b) #

Strong p => Strong (Coyoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

first' :: Coyoneda p a b -> Coyoneda p (a, c) (b, c) #

second' :: Coyoneda p a b -> Coyoneda p (c, a) (c, b) #

Strong p => Strong (Yoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

first' :: Yoneda p a b -> Yoneda p (a, c) (b, c) #

second' :: Yoneda p a b -> Yoneda p (c, a) (c, b) #

Strong p => Strong (Closure p) 
Instance details

Defined in Data.Profunctor.Closed

Methods

first' :: Closure p a b -> Closure p (a, c) (b, c) #

second' :: Closure p a b -> Closure p (c, a) (c, b) #

Profunctor p => Strong (Tambara p) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Tambara p a b -> Tambara p (a, c) (b, c) #

second' :: Tambara p a b -> Tambara p (c, a) (c, b) #

Functor m => Strong (Star m) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Star m a b -> Star m (a, c) (b, c) #

second' :: Star m a b -> Star m (c, a) (c, b) #

Comonad f => Strong (Costar f) Source # 
Instance details

Defined in Data.Profunctor.Optic.Type

Methods

first' :: Costar f a b -> Costar f (a, c) (b, c) #

second' :: Costar f a b -> Costar f (c, a) (c, b) #

Arrow p => Strong (WrappedArrow p)

Arrow is Strong Category

Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: WrappedArrow p a b -> WrappedArrow p (a, c) (b, c) #

second' :: WrappedArrow p a b -> WrappedArrow p (c, a) (c, b) #

Strong (Forget r) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Forget r a b -> Forget r (a, c) (b, c) #

second' :: Forget r a b -> Forget r (c, a) (c, b) #

Strong (Fold0Rep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

first' :: Fold0Rep r a b -> Fold0Rep r (a, c) (b, c) #

second' :: Fold0Rep r a b -> Fold0Rep r (c, a) (c, b) #

Strong ((->) :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: (a -> b) -> (a, c) -> (b, c) #

second' :: (a -> b) -> (c, a) -> (c, b) #

Strong (LensRep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Lens

Methods

first' :: LensRep a b a0 b0 -> LensRep a b (a0, c) (b0, c) #

second' :: LensRep a b a0 b0 -> LensRep a b (c, a0) (c, b0) #

Strong (Traversal0Rep u v) Source # 
Instance details

Defined in Data.Profunctor.Optic.Traversal0

Methods

first' :: Traversal0Rep u v a b -> Traversal0Rep u v (a, c) (b, c) #

second' :: Traversal0Rep u v a b -> Traversal0Rep u v (c, a) (c, b) #

Contravariant f => Strong (Clown f :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Clown f a b -> Clown f (a, c) (b, c) #

second' :: Clown f a b -> Clown f (c, a) (c, b) #

Costrong p => Strong (Re p s t) Source # 
Instance details

Defined in Data.Profunctor.Optic.Type

Methods

first' :: Re p s t a b -> Re p s t (a, c) (b, c) #

second' :: Re p s t a b -> Re p s t (c, a) (c, b) #

Strong (IxlensRep i a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Lens

Methods

first' :: IxlensRep i a b a0 b0 -> IxlensRep i a b (a0, c) (b0, c) #

second' :: IxlensRep i a b a0 b0 -> IxlensRep i a b (c, a0) (c, b0) #

(Strong p, Strong q) => Strong (Product p q) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Product p q a b -> Product p q (a, c) (b, c) #

second' :: Product p q a b -> Product p q (c, a) (c, b) #

(Functor f, Strong p) => Strong (Tannen f p) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Tannen f p a b -> Tannen f p (a, c) (b, c) #

second' :: Tannen f p a b -> Tannen f p (c, a) (c, b) #

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.

Minimal complete definition

left' | right'

Methods

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 Leftlmap 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 Rightlmap 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
Monad m => Choice (Kleisli m) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Kleisli m a b -> Kleisli m (Either a c) (Either b c) #

right' :: Kleisli m a b -> Kleisli m (Either c a) (Either c b) #

Choice (PastroSum p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: PastroSum p a b -> PastroSum p (Either a c) (Either b c) #

right' :: PastroSum p a b -> PastroSum p (Either c a) (Either c b) #

Choice p => Choice (Coyoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

left' :: Coyoneda p a b -> Coyoneda p (Either a c) (Either b c) #

right' :: Coyoneda p a b -> Coyoneda p (Either c a) (Either c b) #

Choice p => Choice (Yoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

left' :: Yoneda p a b -> Yoneda p (Either a c) (Either b c) #

right' :: Yoneda p a b -> Yoneda p (Either c a) (Either c b) #

Profunctor p => Choice (TambaraSum p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: TambaraSum p a b -> TambaraSum p (Either a c) (Either b c) #

right' :: TambaraSum p a b -> TambaraSum p (Either c a) (Either c b) #

Choice p => Choice (Tambara p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Tambara p a b -> Tambara p (Either a c) (Either b c) #

right' :: Tambara p a b -> Tambara p (Either c a) (Either c b) #

Applicative f => Choice (Star f) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Star f a b -> Star f (Either a c) (Either b c) #

right' :: Star f a b -> Star f (Either c a) (Either c b) #

Traversable w => Choice (Costar w) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Costar w a b -> Costar w (Either a c) (Either b c) #

right' :: Costar w a b -> Costar w (Either c a) (Either c b) #

ArrowChoice p => Choice (WrappedArrow p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: WrappedArrow p a b -> WrappedArrow p (Either a c) (Either b c) #

right' :: WrappedArrow p a b -> WrappedArrow p (Either c a) (Either c b) #

Monoid r => Choice (Forget r) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Forget r a b -> Forget r (Either a c) (Either b c) #

right' :: Forget r a b -> Forget r (Either c a) (Either c b) #

Choice (Tagged :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Tagged a b -> Tagged (Either a c) (Either b c) #

right' :: Tagged a b -> Tagged (Either c a) (Either c b) #

Choice (Fold0Rep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Fold0

Methods

left' :: Fold0Rep r a b -> Fold0Rep r (Either a c) (Either b c) #

right' :: Fold0Rep r a b -> Fold0Rep r (Either c a) (Either c b) #

Choice ((->) :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: (a -> b) -> Either a c -> Either b c #

right' :: (a -> b) -> Either c a -> Either c b #

Comonad w => Choice (Cokleisli w)

extract approximates costrength

Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Cokleisli w a b -> Cokleisli w (Either a c) (Either b c) #

right' :: Cokleisli w a b -> Cokleisli w (Either c a) (Either c b) #

Choice (PrismRep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Prism

Methods

left' :: PrismRep a b a0 b0 -> PrismRep a b (Either a0 c) (Either b0 c) #

right' :: PrismRep a b a0 b0 -> PrismRep a b (Either c a0) (Either c b0) #

Choice (Traversal0Rep u v) Source # 
Instance details

Defined in Data.Profunctor.Optic.Traversal0

Methods

left' :: Traversal0Rep u v a b -> Traversal0Rep u v (Either a c) (Either b c) #

right' :: Traversal0Rep u v a b -> Traversal0Rep u v (Either c a) (Either c b) #

Functor f => Choice (Joker f :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Joker f a b -> Joker f (Either a c) (Either b c) #

right' :: Joker f a b -> Joker f (Either c a) (Either c b) #

Cochoice p => Choice (Re p s t) Source # 
Instance details

Defined in Data.Profunctor.Optic.Type

Methods

left' :: Re p s t a b -> Re p s t (Either a c) (Either b c) #

right' :: Re p s t a b -> Re p s t (Either c a) (Either c b) #

(Choice p, Choice q) => Choice (Product p q) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Product p q a b -> Product p q (Either a c) (Either b c) #

right' :: Product p q a b -> Product p q (Either c a) (Either c b) #

(Functor f, Choice p) => Choice (Tannen f p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Tannen f p a b -> Tannen f p (Either a c) (Either b c) #

right' :: Tannen f p a b -> Tannen f p (Either c a) (Either c b) #