| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Id
Description
Id f a — a newtype around f a, with optics and instances for switching
the type constructor f.
Synopsis
- newtype Id (f :: Type -> Type) a = Id (f a)
- unId :: Id f a -> f a
- mapId :: (f a -> g b) -> Id f a -> Id g b
- type IdProxy a = Id (Proxy :: Type -> Type) a
- type IdMaybe a = Id Maybe a
- type IdIdentity a = Id Identity a
- type IdEither e a = Id (Either e) a
- type IdWriter w a = Id ((,) w) a
- type IdList a = Id [] a
- type IdNonEmpty a = Id NonEmpty a
- type IdConst c a = Id (Const c :: Type -> Type) a
- type IdTagged f a = Id (Tagged f) a
- class GetterId a (f :: Type -> Type) x | a -> f x where
- class GetterId a f x => HasId a (f :: Type -> Type) x | a -> f x where
- class ReviewId a (f :: Type -> Type) x | a -> f x where
- class ReviewId a f x => AsId a (f :: Type -> Type) x | a -> f x where
- __Wrapped :: forall f1 a f' a' p f2. (Profunctor p, Functor f2) => p (f1 a) (f2 (f' a')) -> p (Id f1 a) (f2 (Id f' a'))
- __Unwrapped :: forall f1 a f' a' p f2. (Profunctor p, Functor f2) => p (Id f1 a) (f2 (Id f' a')) -> p (f1 a) (f2 (f' a'))
- idIdentity :: forall a a' p f. (Profunctor p, Functor f) => p a (f a') -> p (IdIdentity a) (f (IdIdentity a'))
- idTagged :: forall (f :: Type -> Type) a a' s s'. Rewrapped (f a) (f a) => Iso (Id f a) (IdIdentity a') (Id (Tagged s) (Unwrapped (f a))) (Id (Tagged s') a')
- idProxy :: forall a a' p f. (Profunctor p, Functor f) => p () (f ()) -> p (IdProxy a) (f (IdProxy a'))
- just :: (Unwrapped s ~ Maybe (Unwrapped (Unwrapped a)), Unwrapped t ~ Maybe (Unwrapped (Unwrapped b)), Rewrapped s t, Rewrapped t s, Rewrapped b a, Rewrapped a b, Rewrapped (Unwrapped b) (Unwrapped a), Rewrapped (Unwrapped a) (Unwrapped b)) => Prism s t a b
- rejust :: (Unwrapped t ~ Maybe (Unwrapped (Unwrapped b)), Rewrapped t t, Rewrapped b b, Rewrapped (Unwrapped b) (Unwrapped b)) => Getter b t
- nothing :: (Unwrapped t ~ Maybe x, Unwrapped s ~ Maybe x, Unwrapped (Unwrapped a) ~ (), Unwrapped (Unwrapped b) ~ (), Rewrapped s t, Rewrapped t s, Rewrapped b a, Rewrapped a b, Rewrapped (Unwrapped b) (Unwrapped a), Rewrapped (Unwrapped a) (Unwrapped b)) => Prism s t a b
- renothing :: (Unwrapped t ~ Maybe x, Unwrapped (Unwrapped a) ~ (), Rewrapped t t, Rewrapped a a, Rewrapped (Unwrapped a) (Unwrapped a)) => Getter a t
Id data type
newtype Id (f :: Type -> Type) a Source #
>>>Id [1,2,3]Id [1,2,3]
>>>Id [1,2,3] == Id [1,2,3]True
>>>Id [1,2,3] == Id [4,5,6]False
>>>compare (Id [1,2,3]) (Id [1,2,4])LT
>>>Id [1,2,3] <= Id [1,2,3]True
Constructors
| Id (f a) |
Instances
| BindTrans Id Source # |
|
| MonadTrans Id Source # |
|
| MonadRWS r w s f => MonadRWS r w s (Id f) Source # | |
Defined in Data.Id | |
| Generic1 (Id f :: Type -> Type) Source # | |
| FoldableWithIndex i f => FoldableWithIndex i (Id f) Source # |
|
| FunctorWithIndex i f => FunctorWithIndex i (Id f) Source # |
|
| TraversableWithIndex i f => TraversableWithIndex i (Id f) Source # |
|
| MonadError a f => MonadError a (Id f) Source # |
|
Defined in Data.Id | |
| MonadReader a f => MonadReader a (Id f) Source # |
|
| MonadState a f => MonadState a (Id f) Source # |
|
| MonadWriter a f => MonadWriter a (Id f) Source # |
|
| MonadFail f => MonadFail (Id f) Source # |
|
| MonadFix f => MonadFix (Id f) Source # |
|
| MonadIO f => MonadIO (Id f) Source # |
|
| MonadZip f => MonadZip (Id f) Source # |
|
| Foldable f => Foldable (Id f) Source # |
|
Defined in Data.Id Methods fold :: Monoid m => Id f m -> m # foldMap :: Monoid m => (a -> m) -> Id f a -> m # foldMap' :: Monoid m => (a -> m) -> Id f a -> m # foldr :: (a -> b -> b) -> b -> Id f a -> b # foldr' :: (a -> b -> b) -> b -> Id f a -> b # foldl :: (b -> a -> b) -> b -> Id f a -> b # foldl' :: (b -> a -> b) -> b -> Id f a -> b # foldr1 :: (a -> a -> a) -> Id f a -> a # foldl1 :: (a -> a -> a) -> Id f a -> a # elem :: Eq a => a -> Id f a -> Bool # maximum :: Ord a => Id f a -> a # | |
| Foldable1 f => Foldable1 (Id f) Source # |
|
Defined in Data.Id Methods fold1 :: Semigroup m => Id f m -> m # foldMap1 :: Semigroup m => (a -> m) -> Id f a -> m # foldMap1' :: Semigroup m => (a -> m) -> Id f a -> m # toNonEmpty :: Id f a -> NonEmpty a # maximum :: Ord a => Id f a -> a # minimum :: Ord a => Id f a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Id f a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Id f a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Id f a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Id f a -> b # | |
| Eq1 f => Eq1 (Id f) Source # |
|
| Ord1 f => Ord1 (Id f) Source # |
|
| Show1 f => Show1 (Id f) Source # |
|
| Contravariant f => Contravariant (Id f) Source # |
|
| Traversable f => Traversable (Id f) Source # |
|
| Alternative f => Alternative (Id f) Source # |
|
| Applicative f => Applicative (Id f) Source # |
|
| Functor f => Functor (Id f) Source # |
|
| Monad f => Monad (Id f) Source # |
|
| MonadPlus f => MonadPlus (Id f) Source # |
|
| Comonad f => Comonad (Id f) Source # |
|
| Decidable f => Decidable (Id f) Source # |
|
| Divisible f => Divisible (Id f) Source # |
|
| NFData1 f => NFData1 (Id f) Source # | |
| Distributive f => Distributive (Id f) Source # | |
| MonadCont f => MonadCont (Id f) Source # |
|
| Selective f => Selective (Id f) Source # |
|
| Alt f => Alt (Id f) Source # |
|
| Apply f => Apply (Id f) Source # |
|
| Bind f => Bind (Id f) Source # |
|
| Extend f => Extend (Id f) Source # |
|
| Plus f => Plus (Id f) Source # |
|
| Traversable1 f => Traversable1 (Id f) Source # |
|
| (Typeable f, Typeable a, Data (f a)) => Data (Id f a) Source # | |
Defined in Data.Id Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Id f a -> c (Id f a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Id f a) # toConstr :: Id f a -> Constr # dataTypeOf :: Id f a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Id f a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Id f a)) # gmapT :: (forall b. Data b => b -> b) -> Id f a -> Id f a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Id f a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Id f a -> r # gmapQ :: (forall d. Data d => d -> u) -> Id f a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Id f a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Id f a -> m (Id f a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Id f a -> m (Id f a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Id f a -> m (Id f a) # | |
| Monoid (f a) => Monoid (Id f a) Source # |
|
| Semigroup (f a) => Semigroup (Id f a) Source # |
|
| Floating (f a) => Floating (Id f a) Source # | |
| Generic (Id f a) Source # | |
| Num (f a) => Num (Id f a) Source # | |
| Fractional (f a) => Fractional (Id f a) Source # | |
| Show (f a) => Show (Id f a) Source # | |
| NFData (f a) => NFData (Id f a) Source # | |
| Eq (f a) => Eq (Id f a) Source # | |
| Ord (f a) => Ord (Id f a) Source # | |
| Hashable (f a) => Hashable (Id f a) Source # | |
| Wrapped (Id f a) Source # |
|
| Id f a ~ x => Rewrapped (Id f a') x Source # | |
Defined in Data.Id | |
| AsId (Id f a) f a Source # | |
| GetterId (Id f a) f a Source # | |
| HasId (Id f a) f a Source # | |
| ReviewId (Id f a) f a Source # | |
| type Rep1 (Id f :: Type -> Type) Source # | |
| type Rep (Id f a) Source # | |
| type Unwrapped (Id f a) Source # | |
Functions
mapId :: (f a -> g b) -> Id f a -> Id g b Source #
>>>mapId reverse (Id [1,2,3])Id [3,2,1]
>>>mapId (Just . head) (Id [1,2,3])Id (Just 1)
>>>mapId Identity (Id [1,2,3])Id (Identity [1,2,3])
Type aliases
type IdProxy a = Id (Proxy :: Type -> Type) a Source #
>>>let x = Id Proxy :: IdProxy Int in xId Proxy
type IdMaybe a = Id Maybe a Source #
>>>Id (Just 3) :: IdMaybe IntId (Just 3)
>>>Id Nothing :: IdMaybe IntId Nothing
type IdIdentity a = Id Identity a Source #
>>>Id (Identity 7) :: IdIdentity IntId (Identity 7)
type IdEither e a = Id (Either e) a Source #
>>>Id (Left "err") :: IdEither String IntId (Left "err")
>>>Id (Right 7) :: IdEither String IntId (Right 7)
type IdList a = Id [] a Source #
>>>Id [1,2,3] :: IdList IntId [1,2,3]
>>>Id [] :: IdList IntId []
type IdNonEmpty a = Id NonEmpty a Source #
>>>Id (1 :| [2,3]) :: IdNonEmpty IntId (1 :| [2,3])
type IdConst c a = Id (Const c :: Type -> Type) a Source #
>>>Id (Const "hello") :: IdConst String IntId (Const "hello")
Type classes
GetterId
class GetterId a (f :: Type -> Type) x | a -> f x where Source #
>>>view getId (Id [1,2,3])Id [1,2,3]
>>>view getId (Id (Identity 7))Id (Identity 7)
Instances
| GetterId (Identity a) Identity a Source # | |
| GetterId (NonEmpty a) NonEmpty a Source # | |
| GetterId (Maybe a) Maybe a Source # | |
| GetterId [a] [] a Source # | |
| GetterId (Id f a) f a Source # | |
| GetterId (Either e a) (Either e) a Source # | |
| GetterId (Proxy a) (Proxy :: Type -> Type) a Source # | |
| GetterId (w, a) ((,) w) a Source # | |
| GetterId (Const c a) (Const c :: Type -> Type) a Source # | |
| GetterId (Tagged s a) (Tagged s) a Source # | |
HasId
class GetterId a f x => HasId a (f :: Type -> Type) x | a -> f x where Source #
>>>view id' (Id [1,2,3])Id [1,2,3]
>>>set id' (Id [4,5]) (Id [1,2,3])Id [4,5]
Minimal complete definition
Instances
| HasId (Identity a) Identity a Source # | |
| HasId (NonEmpty a) NonEmpty a Source # | |
| HasId (Maybe a) Maybe a Source # | |
| HasId [a] [] a Source # | |
| HasId (Id f a) f a Source # | |
| HasId (Either e a) (Either e) a Source # | |
| HasId (Proxy a) (Proxy :: Type -> Type) a Source # | |
| HasId (w, a) ((,) w) a Source # | |
| HasId (Const c a) (Const c :: Type -> Type) a Source # | |
| HasId (Tagged s a) (Tagged s) a Source # | |
ReviewId
class ReviewId a (f :: Type -> Type) x | a -> f x where Source #
>>>review reviewId (Id [1,2,3]) :: Id [] IntId [1,2,3]
>>>review reviewId (Id (Identity 7)) :: IdIdentity IntId (Identity 7)
Instances
| ReviewId (Identity a) Identity a Source # | |
| ReviewId (NonEmpty a) NonEmpty a Source # | |
| ReviewId (Maybe a) Maybe a Source # | |
| ReviewId [a] [] a Source # | |
| ReviewId (Id f a) f a Source # | |
| ReviewId (Either e a) (Either e) a Source # | |
| ReviewId (Proxy a) (Proxy :: Type -> Type) a Source # | |
| ReviewId (w, a) ((,) w) a Source # | |
| ReviewId (Const c a) (Const c :: Type -> Type) a Source # | |
| ReviewId (Tagged s a) (Tagged s) a Source # | |
AsId
class ReviewId a f x => AsId a (f :: Type -> Type) x | a -> f x where Source #
>>>preview _Id (Id [1,2,3])Just (Id [1,2,3])
>>>review _Id (Id [1,2,3]) :: Id [] IntId [1,2,3]
Minimal complete definition
Instances
| AsId (Identity a) Identity a Source # | |
| AsId (NonEmpty a) NonEmpty a Source # | |
| AsId (Maybe a) Maybe a Source # | |
| AsId [a] [] a Source # | |
| AsId (Id f a) f a Source # | |
| AsId (Either e a) (Either e) a Source # | |
| AsId (Proxy a) (Proxy :: Type -> Type) a Source # | |
| AsId (w, a) ((,) w) a Source # | |
| AsId (Const c a) (Const c :: Type -> Type) a Source # | |
| AsId (Tagged s a) (Tagged s) a Source # | |
Optics
__Wrapped :: forall f1 a f' a' p f2. (Profunctor p, Functor f2) => p (f1 a) (f2 (f' a')) -> p (Id f1 a) (f2 (Id f' a')) Source #
>>>view __Wrapped (Id [1,2,3])[1,2,3]
>>>view (from __Wrapped) [1,2,3] :: Id [] IntId [1,2,3]
>>>over __Wrapped (fmap (+1)) (Id [1,2,3])Id [2,3,4]
__Unwrapped :: forall f1 a f' a' p f2. (Profunctor p, Functor f2) => p (Id f1 a) (f2 (Id f' a')) -> p (f1 a) (f2 (f' a')) Source #
>>>view __Unwrapped [1,2,3] :: Id [] IntId [1,2,3]
>>>view (from __Unwrapped) (Id [1,2,3])[1,2,3]
>>>over __Unwrapped (mapId (fmap (+1))) [1,2,3] :: [Int][2,3,4]
idIdentity :: forall a a' p f. (Profunctor p, Functor f) => p a (f a') -> p (IdIdentity a) (f (IdIdentity a')) Source #
idTagged :: forall (f :: Type -> Type) a a' s s'. Rewrapped (f a) (f a) => Iso (Id f a) (IdIdentity a') (Id (Tagged s) (Unwrapped (f a))) (Id (Tagged s') a') Source #
>>>view idTagged (Id (Identity 7)) :: IdTagged Bool IntId (Tagged 7)
>>>view (from idTagged) (Id (Tagged 7) :: IdTagged Bool Int) :: IdIdentity IntId (Identity 7)
idProxy :: forall a a' p f. (Profunctor p, Functor f) => p () (f ()) -> p (IdProxy a) (f (IdProxy a')) Source #
>>>view idProxy (Id Proxy :: IdProxy Int)()
>>>set idProxy () (Id Proxy :: IdProxy Int)Id Proxy
just :: (Unwrapped s ~ Maybe (Unwrapped (Unwrapped a)), Unwrapped t ~ Maybe (Unwrapped (Unwrapped b)), Rewrapped s t, Rewrapped t s, Rewrapped b a, Rewrapped a b, Rewrapped (Unwrapped b) (Unwrapped a), Rewrapped (Unwrapped a) (Unwrapped b)) => Prism s t a b Source #
>>>preview (just :: Prism (IdMaybe Int) (IdMaybe Int) (IdIdentity Int) (IdIdentity Int)) (Id (Just 7))Just (Id (Identity 7))
>>>preview (just :: Prism (IdMaybe Int) (IdMaybe Int) (IdIdentity Int) (IdIdentity Int)) (Id Nothing)Nothing
>>>review (just :: Prism (IdMaybe Int) (IdMaybe Int) (IdIdentity Int) (IdIdentity Int)) (Id (Identity 7))Id (Just 7)
rejust :: (Unwrapped t ~ Maybe (Unwrapped (Unwrapped b)), Rewrapped t t, Rewrapped b b, Rewrapped (Unwrapped b) (Unwrapped b)) => Getter b t Source #
>>>view (rejust :: Getter (IdIdentity Int) (IdMaybe Int)) (Id (Identity 7))Id (Just 7)
nothing :: (Unwrapped t ~ Maybe x, Unwrapped s ~ Maybe x, Unwrapped (Unwrapped a) ~ (), Unwrapped (Unwrapped b) ~ (), Rewrapped s t, Rewrapped t s, Rewrapped b a, Rewrapped a b, Rewrapped (Unwrapped b) (Unwrapped a), Rewrapped (Unwrapped a) (Unwrapped b)) => Prism s t a b Source #
>>>preview (nothing :: Prism (IdMaybe Int) (IdMaybe Int) (IdIdentity ()) (IdIdentity ())) (Id Nothing)Just (Id (Identity ()))
>>>preview (nothing :: Prism (IdMaybe Int) (IdMaybe Int) (IdIdentity ()) (IdIdentity ())) (Id (Just 7))Nothing
>>>review (nothing :: Prism (IdMaybe Int) (IdMaybe Int) (IdIdentity ()) (IdIdentity ())) (Id (Identity ()))Id Nothing