| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Optic.Lens
Synopsis
- type Lens s t a b = forall p. Strong p => Optic p s t a b
- type Lens' s a = Lens s s a a
- type Ixlens i s t a b = forall p. Strong p => IndexedOptic p i s t a b
- type Ixlens' i s a = Ixlens i s s a a
- lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- ilens :: (s -> (i, a)) -> (s -> b -> t) -> Ixlens i s t a b
- lensVl :: (forall f. Functor f => (a -> f b) -> s -> f t) -> Lens s t a b
- ilensVl :: (forall f. Functor f => (i -> a -> f b) -> s -> f t) -> Ixlens i s t a b
- matching :: (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
- cloneLens :: ALens s t a b -> Lens s t a b
- united :: Lens' a ()
- voided :: Lens' Void a
- indexed :: Representable f => Eq (Rep f) => Rep f -> Lens' (f a) a
- ifirst :: Ixlens i (a, c) (b, c) a b
- isecond :: Ixlens i (c, a) (c, b) a b
- withLens :: ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
- withLensVl :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
- withIxlens :: (Additive - Monoid) i => AIxlens i s t a b -> ((s -> (i, a)) -> (s -> b -> t) -> r) -> r
- toPastro :: ALens s t a b -> p a b -> Pastro p s t
- toTambara :: Strong p => ALens s t a b -> p a b -> Tambara p s t
- class Profunctor p => Strong (p :: Type -> Type -> Type) where
Lens & Ixlens
type Lens s t a b = forall p. Strong p => Optic p s t a b Source #
Lenses access one piece of a product.
\( \mathsf{Lens}\;S\;A = \exists C, S \cong C \times A \)
type Ixlens i s t a b = forall p. Strong p => IndexedOptic p i s t a b Source #
ilens :: (s -> (i, a)) -> (s -> b -> t) -> Ixlens i s t a b Source #
Obtain an indexed Lens from an indexed getter and a setter.
Compare lens and itraversal.
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions constitute a legal indexed lens:
snd . sia (sbt s a) ≡ a
sbt s (snd $ sia s) ≡ s
sbt (sbt s a1) a2 ≡ sbt s a2
See Property.
lensVl :: (forall f. Functor f => (a -> f b) -> s -> f t) -> Lens s t a b Source #
Transform a Van Laarhoven lens into a profunctor lens.
Compare grateVl and traversalVl.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
abst Identity ≡ Identity
fmap (abst f) . (abst g) ≡ getCompose . abst (Compose . fmap f . g)
More generally, a profunctor optic must be monoidal as a natural transformation:
o id ≡ id
o (
Procomposep q) ≡Procompose(o p) (o q)
ilensVl :: (forall f. Functor f => (i -> a -> f b) -> s -> f t) -> Ixlens i s t a b Source #
Transform an indexed Van Laarhoven lens into an indexed profunctor Lens.
An Ixlens is a valid Ixtraversal. Compare itraversalVl.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
iabst (const Identity) ≡ Identity
fmap (iabst $ const f) . (iabst $ const g) ≡ getCompose . iabst (const $ Compose . fmap f . g)
More generally, a profunctor optic must be monoidal as a natural transformation:
o id ≡ id
o (
Procomposep q) ≡Procompose(o p) (o q)
See Property.
matching :: (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b Source #
Obtain a Lens from its free tensor representation.
Optics
There is a '()' in everything.
>>>"hello" ^. united()>>>"hello" & united .~ ()"hello"
voided :: Lens' Void a Source #
There is everything in a Void.
>>>[] & fmapped . voided <>~ "Void"[]>>>Nothing & fmapped . voided ..~ absNothing
indexed :: Representable f => Eq (Rep f) => Rep f -> Lens' (f a) a Source #
Obtain a Lens from a representable functor.
>>>V2 3 1 ^. indexed E213>>>V3 "foo" "bar" "baz" & indexed E32 .~ "bip"V3 "foo" "bip" "baz"
Indexed optics
ifirst :: Ixlens i (a, c) (b, c) a b Source #
TODO: Document
>>>ilists (ix @Int traversed . ifirst . ix traversed) [("foo",1), ("bar",2)][(0,'f'),(1,'o'),(2,'o'),(0,'b'),(1,'a'),(2,'r')]>>>ilists (ix @Int traversed % ifirst % ix traversed) [("foo",1), ("bar",2)][(0,'f'),(1,'o'),(2,'o'),(2,'b'),(3,'a'),(4,'r')]
Primitive operators
withLens :: ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r Source #
Extract the two functions that characterize a Lens.
withLensVl :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t Source #
withIxlens :: (Additive - Monoid) i => AIxlens i s t a b -> ((s -> (i, a)) -> (s -> b -> t) -> r) -> r Source #
Extract the two functions that characterize a Lens.
Operators
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.
Methods
Instances
| Monad m => Strong (Kleisli m) | |
| Strong (Pastro p) | |
| Strong p => Strong (Coyoneda p) | |
| Strong p => Strong (Yoneda p) | |
| Strong p => Strong (Closure p) | |
| Profunctor p => Strong (Tambara p) | |
| Functor m => Strong (Star m) | |
| Arrow p => Strong (WrappedArrow p) | |
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) | |
| Strong (Conjoin j) Source # | |
| Strong (OptionRep r) Source # | |
| Strong ((->) :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Strong | |
| Strong (AffineRep a b) Source # | |
| Strong (LensRep a b) Source # | |
| Contravariant f => Strong (Clown f :: Type -> Type -> Type) | |
| Costrong p => Strong (Re p s t) Source # | |
| Strong (IxlensRep i a b) Source # | |
| (Strong p, Strong q) => Strong (Sum p q) | |
| (Strong p, Strong q) => Strong (Product p q) | |
| (Functor f, Strong p) => Strong (Tannen f p) | |