Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Traversal0 s t a b = forall p. (Strong p, Choice p) => Optic p s t a b
- type Traversal0' s a = Traversal0 s s a a
- type Ixtraversal0 i s t a b = forall p. (Strong p, Choice p) => IndexedOptic p i s t a b
- type Ixtraversal0' i s a = Ixtraversal0 i s s a a
- type ATraversal0 s t a b = Optic (Traversal0Rep a b) s t a b
- type ATraversal0' s a = ATraversal0 s s a a
- traversal0 :: (s -> t + a) -> (s -> b -> t) -> Traversal0 s t a b
- traversal0' :: (s -> Maybe a) -> (s -> a -> s) -> Traversal0' s a
- ixtraversal0 :: (s -> t + (i, a)) -> (s -> b -> t) -> Ixtraversal0 i s t a b
- ixtraversal0' :: (s -> Maybe (i, a)) -> (s -> a -> s) -> Ixtraversal0' i s a
- traversal0Vl :: (forall f. Functor f => (forall c. c -> f c) -> (a -> f b) -> s -> f t) -> Traversal0 s t a b
- ixtraversal0Vl :: (forall f. Functor f => (forall c. c -> f c) -> (i -> a -> f b) -> s -> f t) -> Ixtraversal0 i s t a b
- data Traversal0Rep a b s t = Traversal0Rep (s -> t + a) (s -> b -> t)
- withTraversal0 :: ATraversal0 s t a b -> ((s -> t + a) -> (s -> b -> t) -> r) -> r
- nulled :: Traversal0' s a
- inserted :: (i -> s -> Maybe (i, a)) -> (i -> a -> s -> s) -> i -> Ixtraversal0' i s a
- selected :: (a -> Bool) -> Traversal0' (a, b) b
- predicated :: (a -> Bool) -> Traversal0' a a
- is :: ATraversal0 s t a b -> s -> Bool
- isnt :: ATraversal0 s t a b -> s -> Bool
- matches :: ATraversal0 s t a b -> s -> t + a
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:
o id ≡ id
o (
Procompose
p q) ≡Procompose
(o p) (o q)
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
.
Traversal0Rep (s -> t + a) (s -> b -> t) |
Instances
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 -> flipifind
s $ n _ -> n == i) (i a s ->modifyAt
i (const a) s) :: Int -> Ixtraversal0' Int [a] a insertedlookupGT
insert
:: Ord i => i -> Ixtraversal0' i (Map i a) a insertedlookupGT
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