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

Safe HaskellNone
LanguageHaskell2010

Data.Profunctor.Optic.Traversal0

Contents

Synopsis

Traversal0 & Ixtraversal0

type Traversal0 s t a b = forall p. (Strong p, Choice p) => Optic p s t a b Source #

A Traversal0 processes at most one part of the whole, with no interactions.

\( \mathsf{Traversal0}\;S\;A = \exists C, D, S \cong D + C \times A \)

type Traversal0' s a = Traversal0 s s a a Source #

type Ixtraversal0 i s t a b = forall p. (Strong p, Choice p) => IndexedOptic p i s t a b Source #

type Ixtraversal0' i s a = Ixtraversal0 i s s a a Source #

type ATraversal0 s t a b = Optic (Traversal0Rep a b) s t a b Source #

type ATraversal0' s a = ATraversal0 s s a a Source #

traversal0 :: (s -> t + a) -> (s -> b -> t) -> Traversal0 s t a b Source #

Create a Traversal0 from a constructor and a matcheser.

Caution: In order for the Traversal0 to be well-defined, you must ensure that the input functions satisfy the following properties:

  • sta (sbt a s) ≡ either (Left . const a) Right (sta s)
  • either id (sbt s) (sta s) ≡ s
  • sbt (sbt s a1) a2 ≡ sbt s a2

More generally, a profunctor optic must be monoidal as a natural transformation:

See Property.

traversal0' :: (s -> Maybe a) -> (s -> a -> s) -> Traversal0' s a Source #

Obtain a Traversal0' from a constructor and a matcheser function.

ixtraversal0 :: (s -> t + (i, a)) -> (s -> b -> t) -> Ixtraversal0 i s t a b Source #

TODO: Document

ixtraversal0' :: (s -> Maybe (i, a)) -> (s -> a -> s) -> Ixtraversal0' i s a Source #

TODO: Document

traversal0Vl :: (forall f. Functor f => (forall c. c -> f c) -> (a -> f b) -> s -> f t) -> Traversal0 s t a b Source #

Transform a Van Laarhoven Traversal0 into a profunctor Traversal0.

ixtraversal0Vl :: (forall f. Functor f => (forall c. c -> f c) -> (i -> a -> f b) -> s -> f t) -> Ixtraversal0 i s t a b Source #

Transform an indexed Van Laarhoven Traversal0 into an indexed profunctor Traversal0.

Carriers

data Traversal0Rep a b s t Source #

The Traversal0Rep profunctor precisely characterizes an Traversal0.

Constructors

Traversal0Rep (s -> t + a) (s -> b -> t) 
Instances
Representable (Traversal0Rep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Traversal0

Associated Types

type Rep (Traversal0Rep a b) :: Type -> Type #

Methods

tabulate :: (d -> Rep (Traversal0Rep a b) c) -> Traversal0Rep a b d c #

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) #

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) #

Profunctor (Traversal0Rep u v) Source # 
Instance details

Defined in Data.Profunctor.Optic.Traversal0

Methods

dimap :: (a -> b) -> (c -> d) -> Traversal0Rep u v b c -> Traversal0Rep u v a d #

lmap :: (a -> b) -> Traversal0Rep u v b c -> Traversal0Rep u v a c #

rmap :: (b -> c) -> Traversal0Rep u v a b -> Traversal0Rep u v a c #

(#.) :: Coercible c b => q b c -> Traversal0Rep u v a b -> Traversal0Rep u v a c #

(.#) :: Coercible b a => Traversal0Rep u v b c -> q a b -> Traversal0Rep u v a c #

type Rep (Traversal0Rep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Traversal0

type Rep (Traversal0Rep a b)

Primitive operators

withTraversal0 :: ATraversal0 s t a b -> ((s -> t + a) -> (s -> b -> t) -> r) -> r Source #

TODO: Document

Optics

nulled :: Traversal0' s a Source #

TODO: Document

inserted :: (i -> s -> Maybe (i, a)) -> (i -> a -> s -> s) -> i -> Ixtraversal0' i s a Source #

Obtain a Ixtraversal0' from a pair of lookup and insert functions.

inserted (i s -> flip ifind s $ n _ -> n == i) (i a s -> modifyAt i (const a) s) :: Int -> Ixtraversal0' Int [a] a
inserted lookupGT insert :: Ord i => i -> Ixtraversal0' i (Map i a) a
inserted lookupGT insert :: Int -> Ixtraversal0' Int (IntMap a) a

selected :: (a -> Bool) -> Traversal0' (a, b) b Source #

TODO: Document

See also keyed.

>>> preview (selected even) (2, "hi")
Just "hi"
>>> preview (selected even) (3, "hi")
Nothing

predicated :: (a -> Bool) -> Traversal0' a a Source #

Filter result(s) that don't satisfy a predicate.

Caution: While this is a valid Traversal0, it is only a valid Traversal if the predicate always evaluates to True on the targets of the Traversal.

predicated p ≡ traversal0Vl $ point f a -> if p a then f a else point a
>>> [1..10] ^.. folded . predicated even
[2,4,6,8,10]

See also filtered.

Operators

is :: ATraversal0 s t a b -> s -> Bool Source #

Check whether the optic is matchesed.

>>> is just Nothing
False

isnt :: ATraversal0 s t a b -> s -> Bool Source #

Check whether the optic isn't matchesed.

>>> isnt just Nothing
True

matches :: ATraversal0 s t a b -> s -> t + a Source #

Test whether the optic matches or not.

>>> matches just (Just 2)
Right 2
>>> matches just (Nothing :: Maybe Int) :: Either (Maybe Bool) Int
Left Nothing