| 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 As a = Equality' 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
- ixmapping :: Profunctor p => AIso s t a b -> IndexedOptic p i s t a b
- cxmapping :: Profunctor p => AIso s t a b -> CoindexedOptic p k 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)
- rewrapping :: 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)
- 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)
- swapped :: Iso (a, b) (c, d) (b, a) (d, c)
- eswapped :: Iso (a + b) (c + d) (b + a) (d + c)
- associated :: Iso (a, (b, c)) (d, (e, f)) ((a, b), c) ((d, e), f)
- eassociated :: Iso (a + (b + c)) (d + (e + f)) ((a + b) + c) ((d + e) + f)
- involuted :: (s -> a) -> Iso s a a s
- added :: Group a => a -> Iso' a a
- subtracted :: Group a => a -> Iso' a a
- viewedl :: Iso (Seq a) (Seq b) (ViewL a) (ViewL b)
- viewedr :: Iso (Seq a) (Seq b) (ViewR a) (ViewR b)
- non :: Eq a => a -> Iso' (Maybe a) a
- anon :: a -> (a -> Bool) -> Iso' (Maybe a) a
- u1 :: Iso (U1 p) (U1 q) () ()
- par1 :: Iso (Par1 p) (Par1 q) p q
- rec1 :: Iso (Rec1 f p) (Rec1 g q) (f p) (g q)
- k1 :: Iso (K1 i c p) (K1 j d q) c d
- m1 :: Iso (M1 i c f p) (M1 j d g q) (f p) (g q)
- 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
- reixed :: Profunctor p => AIso' i j -> IndexedOptic p i s t a b -> IndexedOptic p j s t a b
- recxed :: Profunctor p => AIso' k l -> CoindexedOptic p k s t a b -> CoindexedOptic p l s t a b
- 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
- type AIso s t a b = Optic (IsoRep a b) s t a b
- type AIso' s a = AIso s s a a
- data IsoRep a b s t = IsoRep (s -> a) (b -> t)
Types
type Iso s t a b = forall p. Profunctor p => Optic p s t a b Source #
Constructors
iso :: (s -> a) -> (b -> t) -> Iso s t a b Source #
Obtain an Iso from two inverses.
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.
ixmapping :: Profunctor p => AIso s t a b -> IndexedOptic p i s t a b Source #
Lift an Iso into an indexed version.
>>>ixlists (ixtraversed . ixmapping swapped) [(40,'f'),(41,'o'),(42,'o')][(0,('f',40)),(1,('o',41)),(2,('o',42))]
cxmapping :: Profunctor p => AIso s t a b -> CoindexedOptic p k s t a b Source #
Lift an Iso into a coindexed version.
fmapping :: Functor f => Functor g => AIso s t a b -> Iso (f s) (g t) (f a) (g b) Source #
TODO: Document
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 Contravariant functor.
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 #
TODO: Document
Optics
equaled :: s ~ a => t ~ b => Iso s t a b Source #
Capture type constraints as an Iso'.
>>>:t (^. equaled)(^. equaled) :: b -> b
coerced :: Coercible s a => Coercible t b => Iso s t a b Source #
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
rewrapping :: 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 #
Convert between a data type and its 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 #
Convert between a data type and its Generic1 representation.
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 #
TODO: Document
>>>(fst ^. curried) 3 43
>>>view curried fst 3 43
associated :: Iso (a, (b, c)) (d, (e, f)) ((a, b), c) ((d, e), f) Source #
Iso defined by left-association of nested tuples.
eassociated :: Iso (a + (b + c)) (d + (e + f)) ((a + b) + c) ((d + e) + f) Source #
Iso defined by left-association of nested tuples.
subtracted :: Group a => a -> Iso' a a Source #
The group isomorphism defined by an element's inverse action.
subtractedn =re(addedn)
Primitive operators
withIso :: AIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r Source #
Extract the two functions that characterize an Iso.
reixed :: Profunctor p => AIso' i j -> IndexedOptic p i s t a b -> IndexedOptic p j s t a b Source #
Remap the indices of an indexed optic.
recxed :: Profunctor p => AIso' k l -> CoindexedOptic p k s t a b -> CoindexedOptic p l s t a b Source #
Remap the indices of a coindexed optic.
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
au :: Functor f => AIso s t a b -> ((b -> t) -> f s) -> f a Source #
Based on ala from Conor McBride's work on Epigram.
This version is generalized to accept any Iso, not just a newtype.
>>>au (rewrapping Sum) foldMap [1,2,3,4]10
You may want to think of this combinator as having the following, simpler type:
au :: AnIso s t a b -> ((b -> t) -> e -> s) -> e -> a
aup :: Profunctor p => Functor f => AIso s t a b -> (p c a -> f b) -> p c s -> f t Source #
Variant of au for profunctors.
>>>:t flip aup runStarflip aup runStar :: Functor f => AIso s t a (f a) -> Star f c s -> c -> t
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 _Wrapping, 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 :: Newtype s => Newtype t => (O s -> s) -> ((O t -> 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.Type | |
| Bifunctor p => Contravariant (Re p s t a) Source # | |
Carriers
type AIso s t a b = Optic (IsoRep a b) s t a b Source #
When you see this as an argument to a function, it expects an Iso.
Constructors
| IsoRep (s -> a) (b -> t) |
Instances
| Profunctor (IsoRep a b) Source # | |
Defined in Data.Profunctor.Optic.Iso Methods dimap :: (a0 -> b0) -> (c -> d) -> IsoRep a b b0 c -> IsoRep a b a0 d # lmap :: (a0 -> b0) -> IsoRep a b b0 c -> IsoRep a b a0 c # rmap :: (b0 -> c) -> IsoRep a b a0 b0 -> IsoRep a b a0 c # (#.) :: Coercible c b0 => q b0 c -> IsoRep a b a0 b0 -> IsoRep a b a0 c # (.#) :: Coercible b0 a0 => IsoRep a b b0 c -> q a0 b0 -> IsoRep a b a0 c # | |
| Sieve (IsoRep a b) (Index a b) Source # | |
Defined in Data.Profunctor.Optic.Iso | |
| Cosieve (IsoRep a b) (Coindex a b) Source # | |
Defined in Data.Profunctor.Optic.Iso | |
| Functor (IsoRep a b s) Source # | |