| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Optic.Iso
Synopsis
- type Equality s t a b = forall p. Optic p s t a b
- type Equality' s a = Equality s s a a
- type Iso s t a b = forall p. Profunctor p => Optic p s t a b
- type Iso' s a = Iso s s a a
- iso :: (s -> a) -> (b -> t) -> Iso s t a b
- isoVl :: (forall f g. Functor f => Functor g => (g a -> f b) -> g s -> f t) -> Iso s t a b
- fmapping :: Functor f => Functor g => AIso s t a b -> Iso (f s) (g t) (f a) (g b)
- contramapping :: Contravariant f => Contravariant g => AIso s t a b -> Iso (f a) (g b) (f s) (g t)
- dimapping :: Profunctor p => Profunctor q => AIso s1 t1 a1 b1 -> AIso s2 t2 a2 b2 -> Iso (p a1 s2) (q b1 t2) (p s1 a2) (q t1 b2)
- toYoneda :: Profunctor p => Iso s t a b -> p a b -> Yoneda p s t
- toCoyoneda :: Iso s t a b -> p a b -> Coyoneda p s t
- cloneIso :: AIso s t a b -> Iso s t a b
- equaled :: s ~ a => t ~ b => Iso s t a b
- coerced :: Coercible s a => Coercible t b => Iso s t a b
- wrapped :: Newtype s => Iso' s (O s)
- rewrapped :: Newtype s => Newtype t => Iso s t (O s) (O t)
- rewrapped' :: Newtype s => Newtype t => (O s -> s) -> Iso s t (O s) (O t)
- generic :: Generic a => Generic b => Iso a b (Rep a c) (Rep b c)
- generic1 :: Generic1 f => Generic1 g => Iso (f a) (g b) (Rep1 f a) (Rep1 g b)
- adjuncted :: Adjunction f u => Iso (f a -> b) (f s -> t) (a -> u b) (s -> u t)
- tabulated :: Representable f => Representable g => Iso (f a) (g b) (Rep f -> a) (Rep g -> b)
- transposed :: Functor f => Distributive g => Iso (f (g a)) (g (f a)) (g (f a)) (f (g a))
- flipped :: Iso (a -> b -> c) (d -> e -> f) (b -> a -> c) (e -> d -> f)
- curried :: Iso (a -> b -> c) (d -> e -> f) ((a, b) -> c) ((d, e) -> f)
- unzipped :: Adjunction f u => Iso (u a, u b) (u c, u d) (u (a, b)) (u (c, d))
- cozipped :: Adjunction f u => Iso (f a + f b) (f c + f d) (f (a + b)) (f (c + d))
- swapped :: Iso (a, b) (c, d) (b, a) (d, c)
- coswapped :: Iso (a + b) (c + d) (b + a) (d + c)
- associated :: Iso (a, (b, c)) (d, (e, f)) ((a, b), c) ((d, e), f)
- coassociated :: Iso (a + (b + c)) (d + (e + f)) ((a + b) + c) ((d + e) + f)
- involuted :: (s -> a) -> Iso s a a s
- anon :: a -> (a -> Bool) -> Iso' (Maybe a) a
- non :: Eq a => a -> Iso' (Maybe a) a
- withIso :: AIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
- invert :: AIso s t a b -> Iso b a t s
- reover :: AIso s t a b -> (t -> s) -> b -> a
- op :: (Newtype n, o ~ O n) => (o -> n) -> n -> o
- au :: Functor f => AIso s t a b -> ((b -> t) -> f s) -> f a
- aup :: Profunctor p => Functor f => AIso s t a b -> (p c a -> f b) -> p c s -> f t
- ala :: Newtype s => Newtype t => Functor f => (O s -> s) -> ((O t -> t) -> f s) -> f (O s)
- newtype Re p s t a b = Re {
- runRe :: p b a -> p t s
Types
type Iso s t a b = forall p. Profunctor p => Optic p s t a b Source #
\( \mathsf{Iso}\;S\;A = S \cong A \)
iso :: (s -> a) -> (b -> t) -> Iso s t a b Source #
Obtain an Iso from two inverses.
o .reo ≡idreo . o ≡idviewo (reviewo b) ≡ breviewo (viewo s) ≡ s
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions satisfy the following properties:
sa . bt ≡ id
bt . sa ≡ id
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.
fmapping :: Functor f => Functor g => AIso s t a b -> Iso (f s) (g t) (f a) (g b) Source #
Lift an Iso into a pair of functors.
contramapping :: Contravariant f => Contravariant g => AIso s t a b -> Iso (f a) (g b) (f s) (g t) Source #
Lift an Iso into a pair of Contravariant functors.
contramapping ::Contravariantf =>Isos t a b ->Iso(f a) (f b) (f s) (f t)
dimapping :: Profunctor p => Profunctor q => AIso s1 t1 a1 b1 -> AIso s2 t2 a2 b2 -> Iso (p a1 s2) (q b1 t2) (p s1 a2) (q t1 b2) Source #
Lift a pair of Isos into a pair of profunctors.
Optics
equaled :: s ~ a => t ~ b => Iso s t a b Source #
Obtain an Iso' directly from type equality constraints.
>>>:t (^. equaled)(^. equaled) :: b -> b
coerced :: Coercible s a => Coercible t b => Iso s t a b Source #
Obtain an Iso from data types that are representationally equal.
>>>view coerced 'x' :: Identity CharIdentity 'x'
rewrapped :: Newtype s => Newtype t => Iso s t (O s) (O t) Source #
Work between newtype wrappers.
>>>Const "hello" & rewrapped ..~ Prelude.length & getConst5
rewrapped' :: Newtype s => Newtype t => (O s -> s) -> Iso s t (O s) (O t) Source #
Variant of rewrapped that ignores its argument.
generic :: Generic a => Generic b => Iso a b (Rep a c) (Rep b c) Source #
Obtain an Iso from a Generic representation.
>>>view (generic . re generic) "hello" :: String"hello"
generic1 :: Generic1 f => Generic1 g => Iso (f a) (g b) (Rep1 f a) (Rep1 g b) Source #
Obtain an Iso from a Generic1 representation.
adjuncted :: Adjunction f u => Iso (f a -> b) (f s -> t) (a -> u b) (s -> u t) Source #
Obtain an Iso from a functor and its adjoint.
Useful for converting between lens-like optics and grate-like optics:
overadjuncted::Adjunctionf u => ((a -> u b) -> s -> u t) -> (f a -> b) -> f s -> t
tabulated :: Representable f => Representable g => Iso (f a) (g b) (Rep f -> a) (Rep g -> b) Source #
Obtain an Iso from a functor and its function representation.
transposed :: Functor f => Distributive g => Iso (f (g a)) (g (f a)) (g (f a)) (f (g a)) Source #
TODO: Document
flipped :: Iso (a -> b -> c) (d -> e -> f) (b -> a -> c) (e -> d -> f) Source #
Flip two arguments of a function.
>>>(view flipped (,)) 1 2(2,1)
curried :: Iso (a -> b -> c) (d -> e -> f) ((a, b) -> c) ((d, e) -> f) Source #
Curry a function.
>>>(fst ^. invert curried) 3 43
unzipped :: Adjunction f u => Iso (u a, u b) (u c, u d) (u (a, b)) (u (c, d)) Source #
A right adjoint admits an intrinsic notion of zipping.
cozipped :: Adjunction f u => Iso (f a + f b) (f c + f d) (f (a + b)) (f (c + d)) Source #
A left adjoint must be inhabited by exactly one element.
associated :: Iso (a, (b, c)) (d, (e, f)) ((a, b), c) ((d, e), f) Source #
Iso defined by left-association of nested tuples.
coassociated :: Iso (a + (b + c)) (d + (e + f)) ((a + b) + c) ((d + e) + f) Source #
Iso defined by left-association of nested tuples.
non :: Eq a => a -> Iso' (Maybe a) a Source #
Remove a single value from a type.
>>>review (non "foo") "foo"Nothing>>>review (non "foo") "foobar"Just "foobar"
Primitive operators
withIso :: AIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r Source #
Extract the two functions that characterize an Iso.
Operators
op :: (Newtype n, o ~ O n) => (o -> n) -> n -> o #
This function serves two purposes:
- Giving you the unpack of a newtype without you needing to remember the name.
- Showing that the first parameter is completely ignored on the value level, meaning the only reason you pass in the constructor is to provide type information. Typeclasses sure are neat.
>>>op Identity (Identity 3)3
ala :: Newtype s => Newtype t => Functor f => (O s -> s) -> ((O t -> t) -> f s) -> f (O s) Source #
This combinator is based on ala from Conor McBride's work on Epigram.
As with rewrapped', the user supplied function for the newtype is ignored.
>>>ala Sum foldMap [1,2,3,4]10>>>ala All foldMap [True,True]True>>>ala All foldMap [True,False]False>>>ala Any foldMap [False,False]False>>>ala Any foldMap [True,False]True>>>ala Product foldMap [1,2,3,4]24
ala::Newtypes =>Newtypet => (Os -> s) -> ((Ot -> t) -> e -> s) -> e -> O s
Auxilliary Types
The Re type and its instances witness the symmetry between the parameters of a Profunctor.
Instances
| (Profunctor p, forall x. Contravariant (p x)) => Bifunctor (Re p s t) Source # | |
| Cochoice p => Choice (Re p s t) Source # | |
| Choice p => Cochoice (Re p s t) Source # | |
| Costrong p => Strong (Re p s t) Source # | |
| Strong p => Costrong (Re p s t) Source # | |
| Profunctor p => Profunctor (Re p s t) Source # | |
Defined in Data.Profunctor.Optic.Types | |
| Bifunctor p => Contravariant (Re p s t a) Source # | |