| Copyright | (C) 2012-16 Edward Kmett Michael Sloan |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | experimental |
| Portability | Rank2, MPTCs, fundeps |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Control.Lens.Wrapped
Description
The Wrapped class provides similar functionality as Control.Newtype,
from the newtype package, but in a more convenient and efficient form.
There are a few functions from newtype that are not provided here, because
they can be done with the Iso directly:
Control.Newtype.overSumf ≡_UnwrappingSum%~f Control.Newtype.underSumf ≡_WrappingSum%~f Control.Newtype.overFSumf ≡mapping(_UnwrappingSum)%~f Control.Newtype.underFSumf ≡mapping(_WrappingSum)%~f
under can also be used with _Unwrapping to provide the equivalent of
Control.Newtype.under. Also, most use cases don't need full polymorphism,
so only the single constructor _Wrapping functions would be needed.
These equivalences aren't 100% honest, because newtype's operators
need to rely on two Newtype constraints. This means that the wrapper used
for the output is not necessarily the same as the input.
Synopsis
- class Wrapped s where
- _Unwrapped' :: Wrapped s => Iso' (Unwrapped s) s
- _Wrapping' :: Wrapped s => (Unwrapped s -> s) -> Iso' s (Unwrapped s)
- _Unwrapping' :: Wrapped s => (Unwrapped s -> s) -> Iso' (Unwrapped s) s
- class Wrapped s => Rewrapped s t
- class (Rewrapped s t, Rewrapped t s) => Rewrapping s t
- _Wrapped :: Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
- _Unwrapped :: Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
- _Wrapping :: Rewrapping s t => (Unwrapped s -> s) -> Iso s t (Unwrapped s) (Unwrapped t)
- _Unwrapping :: Rewrapping s t => (Unwrapped s -> s) -> Iso (Unwrapped t) (Unwrapped s) t s
- op :: Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
- ala :: (Functor f, Rewrapping s t) => (Unwrapped s -> s) -> ((Unwrapped t -> t) -> f s) -> f (Unwrapped s)
- alaf :: (Functor f, Functor g, Rewrapping s t) => (Unwrapped s -> s) -> (f t -> g s) -> f (Unwrapped t) -> g (Unwrapped s)
- pattern Wrapped :: Rewrapped s s => Unwrapped s -> s
- pattern Unwrapped :: Rewrapped t t => t -> Unwrapped t
- _GWrapped' :: forall s (d :: Meta) (c :: Meta) (s' :: Meta) a. (Generic s, D1 d (C1 c (S1 s' (Rec0 a))) ~ Rep s, Unwrapped s ~ GUnwrapped (Rep s)) => Iso' s (Unwrapped s)
Wrapping and Unwrapping monomorphically
class Wrapped s where Source #
Wrapped provides isomorphisms to wrap and unwrap newtypes or
data types with one constructor.
Minimal complete definition
Nothing
Methods
_Wrapped' :: Iso' s (Unwrapped s) Source #
An isomorphism between s and a.
If your type has a Generic instance, _Wrapped' will default to _GWrapped',
and you can choose to not override it with your own definition.
Instances
_Wrapping' :: Wrapped s => (Unwrapped s -> s) -> Iso' s (Unwrapped s) Source #
This is a convenient version of _Wrapped with an argument that's ignored.
The user supplied function is ignored, merely its type is used.
_Unwrapping' :: Wrapped s => (Unwrapped s -> s) -> Iso' (Unwrapped s) s Source #
This is a convenient version of _Wrapped with an argument that's ignored.
The user supplied function is ignored, merely its type is used.
Wrapping and unwrapping polymorphically
class Wrapped s => Rewrapped s t Source #
Instances
| t ~ IntSet => Rewrapped IntSet t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ NoMethodError => Rewrapped NoMethodError t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ PatternMatchFail => Rewrapped PatternMatchFail t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ RecConError => Rewrapped RecConError t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ RecSelError => Rewrapped RecSelError t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ RecUpdError => Rewrapped RecUpdError t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ TypeError => Rewrapped TypeError t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ All => Rewrapped All t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Any => Rewrapped Any t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ErrorCall => Rewrapped ErrorCall t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped Errno t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CBool t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CChar t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CClock t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CDouble t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CFloat t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CInt t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CIntMax t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CIntPtr t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CLLong t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CLong t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CPtrdiff t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CSChar t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CSUSeconds t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CShort t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CSigAtomic t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CSize t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CTime t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CUChar t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CUInt t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CUIntMax t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CUIntPtr t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CULLong t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CULong t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CUSeconds t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CUShort t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CWchar t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ AssertionFailed => Rewrapped AssertionFailed t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ CompactionFailed => Rewrapped CompactionFailed t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CBlkCnt t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CBlkSize t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CCc t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CClockId t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CDev t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CFsBlkCnt t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CFsFilCnt t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CGid t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CId t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CIno t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CKey t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CMode t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CNlink t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped COff t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CPid t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CRLim t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CSpeed t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CSsize t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CTcflag t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CTimer t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped CUid t Source # | |
Defined in Control.Lens.Wrapped | |
| Rewrapped Fd t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Comparison b => Rewrapped (Comparison a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Equivalence b => Rewrapped (Equivalence a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Predicate b => Rewrapped (Predicate a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ First b => Rewrapped (First a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Last b => Rewrapped (Last a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Max b => Rewrapped (Max a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Min b => Rewrapped (Min a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WrappedMonoid b => Rewrapped (WrappedMonoid a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ IntMap a' => Rewrapped (IntMap a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Seq a' => Rewrapped (Seq a) t Source # | |
Defined in Control.Lens.Wrapped | |
| (t ~ Set a', Ord a) => Rewrapped (Set a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ NonEmpty b => Rewrapped (NonEmpty a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Identity b => Rewrapped (Identity a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ First b => Rewrapped (First a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Last b => Rewrapped (Last a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Down b => Rewrapped (Down a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Dual b => Rewrapped (Dual a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Endo b => Rewrapped (Endo a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Product b => Rewrapped (Product a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Sum b => Rewrapped (Sum a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ZipList b => Rewrapped (ZipList a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Par1 p' => Rewrapped (Par1 p) t Source # | |
Defined in Control.Lens.Wrapped | |
| (t ~ HashSet a', Hashable a, Eq a) => Rewrapped (HashSet a) t Source # | Use |
Defined in Control.Lens.Wrapped | |
| t ~ Vector a' => Rewrapped (Vector a) t Source # | |
Defined in Control.Lens.Wrapped | |
| (Prim a, t ~ Vector a') => Rewrapped (Vector a) t Source # | |
Defined in Control.Lens.Wrapped | |
| (Storable a, t ~ Vector a') => Rewrapped (Vector a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Vector a' => Rewrapped (Vector a) t Source # | |
Defined in Control.Lens.Wrapped | |
| (Unbox a, t ~ Vector a') => Rewrapped (Vector a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WrappedMonad m' a' => Rewrapped (WrappedMonad m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Op a' b' => Rewrapped (Op a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| (t ~ Map k' a', Ord k) => Rewrapped (Map k a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ CatchT m' a' => Rewrapped (CatchT m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Alt f' a' => Rewrapped (Alt f a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ CoiterT w' a' => Rewrapped (CoiterT w a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ IterT m' a' => Rewrapped (IterT m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ArrowMonad m' a' => Rewrapped (ArrowMonad m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ MaybeApply f' a' => Rewrapped (MaybeApply f a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WrappedApplicative f' a' => Rewrapped (WrappedApplicative f a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ MaybeT n b => Rewrapped (MaybeT m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| (t ~ HashMap k' a', Hashable k, Eq k) => Rewrapped (HashMap k a) t Source # | Use |
Defined in Control.Lens.Wrapped | |
| t ~ WrappedArrow a' b' c' => Rewrapped (WrappedArrow a b c) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Fix p' a' => Rewrapped (Fix p a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Join p' a' => Rewrapped (Join p a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ TracedT m' w' a' => Rewrapped (TracedT m w a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Compose f' g' a' => Rewrapped (Compose f g a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ComposeCF f' g' a' => Rewrapped (ComposeCF f g a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ComposeFC f' g' a' => Rewrapped (ComposeFC f g a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ApT f' g' a' => Rewrapped (ApT f g a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ CofreeT f' w' a' => Rewrapped (CofreeT f w a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ FreeT f' m' a' => Rewrapped (FreeT f m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Kleisli m' a' b' => Rewrapped (Kleisli m a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Const a' x' => Rewrapped (Const a x) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Ap g b => Rewrapped (Ap f a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Alt g b => Rewrapped (Alt f a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Rec1 f' p' => Rewrapped (Rec1 f p) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Static f' a' b' => Rewrapped (Static f a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Tagged s' a' => Rewrapped (Tagged s a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Backwards g b => Rewrapped (Backwards f a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ExceptT e' m' a' => Rewrapped (ExceptT e m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ IdentityT n b => Rewrapped (IdentityT m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ReaderT s n b => Rewrapped (ReaderT r m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ StateT s' m' a' => Rewrapped (StateT s m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ StateT s' m' a' => Rewrapped (StateT s m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WriterT w' m' a' => Rewrapped (WriterT w m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WriterT w' m' a' => Rewrapped (WriterT w m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Constant a' b' => Rewrapped (Constant a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Reverse g b => Rewrapped (Reverse f a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ K1 i' c' p' => Rewrapped (K1 i c p) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Costar f' d' c' => Rewrapped (Costar f d c) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Forget r' a' b' => Rewrapped (Forget r a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Star f' d' c' => Rewrapped (Star f d c) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ ContT r' m' a' => Rewrapped (ContT r m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Compose f' g' a' => Rewrapped (Compose f g a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Clown f' a' b' => Rewrapped (Clown f a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Flip p' a' b' => Rewrapped (Flip p a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Joker g' a' b' => Rewrapped (Joker g a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WrappedBifunctor p' a' b' => Rewrapped (WrappedBifunctor p a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ (f' :.: g') p' => Rewrapped ((f :.: g) p) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ M1 i' c' f' p' => Rewrapped (M1 i c f p) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WrappedArrow p' a' b' => Rewrapped (WrappedArrow p a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Semi m' a' b' => Rewrapped (Semi m a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ WrappedCategory k' a' b' => Rewrapped (WrappedCategory k6 a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Dual k' a' b' => Rewrapped (Dual k6 a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ RWST r' w' s' m' a' => Rewrapped (RWST r w s m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ RWST r' w' s' m' a' => Rewrapped (RWST r w s m a) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Tannen f' p' a' b' => Rewrapped (Tannen f p a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Cayley f' p' a' b' => Rewrapped (Cayley f p a b) t Source # | |
Defined in Control.Lens.Wrapped | |
| t ~ Biff p' f' g' a' b' => Rewrapped (Biff p f g a b) t Source # | |
Defined in Control.Lens.Wrapped | |
class (Rewrapped s t, Rewrapped t s) => Rewrapping s t Source #
Instances
| (Rewrapped s t, Rewrapped t s) => Rewrapping s t Source # | |
Defined in Control.Lens.Wrapped | |
_Wrapped :: Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t) Source #
Work under a newtype wrapper.
>>>Const "hello" & _Wrapped %~ Prelude.length & getConst5
_Wrapped≡from_Unwrapped_Unwrapped≡from_Wrapped
_Unwrapped :: Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s Source #
_Wrapping :: Rewrapping s t => (Unwrapped s -> s) -> Iso s t (Unwrapped s) (Unwrapped t) Source #
This is a convenient version of _Wrapped with an argument that's ignored.
The user supplied function is ignored, merely its types are used.
_Unwrapping :: Rewrapping s t => (Unwrapped s -> s) -> Iso (Unwrapped t) (Unwrapped s) t s Source #
This is a convenient version of _Unwrapped with an argument that's ignored.
The user supplied function is ignored, merely its types are used.
Operations
ala :: (Functor f, Rewrapping s t) => (Unwrapped s -> s) -> ((Unwrapped t -> t) -> f s) -> f (Unwrapped 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
You may want to think of this combinator as having the following, simpler, type.
ala :: Rewrapping s t => (Unwrapped s -> s) -> ((Unwrapped t -> t) -> e -> s) -> e -> Unwrapped s
alaf :: (Functor f, Functor g, Rewrapping s t) => (Unwrapped s -> s) -> (f t -> g s) -> f (Unwrapped t) -> g (Unwrapped 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.
alaf :: Rewrapping s t => (Unwrapped s -> s) -> ((r -> t) -> e -> s) -> (r -> Unwrapped t) -> e -> Unwrapped s
>>>alaf Sum foldMap Prelude.length ["hello","world"]10