functor-utils 1.0 → 1.1
raw patch · 2 files changed
+70/−31 lines, 2 filesdep +ghc-primPVP ok
version bump matches the API change (PVP)
Dependencies added: ghc-prim
API changes (from Hackage documentation)
+ Data.Functor.Utils: (<<$>>) :: (Functor f, Functor f1) => (a -> b) -> f (f1 a) -> f (f1 b)
+ Data.Functor.Utils: (<<∘>>) :: (Functor f, Functor f1, Functor f2) => (a -> b) -> f (f1 (f2 a)) -> f (f1 (f2 b))
+ Data.Functor.Utils: (<∘>) :: (Functor f, Functor f1) => (a -> b) -> f (f1 a) -> f (f1 b)
+ Data.Functor.Utils: (<∘∘>) :: (Functor f, Functor f1, Functor f2) => (a -> b) -> f (f1 (f2 a)) -> f (f1 (f2 b))
+ Data.Functor.Utils: (<∘∘∘>) :: (Functor f, Functor f1, Functor f2, Functor f3) => (a -> b) -> f (f1 (f2 (f3 a))) -> f (f1 (f2 (f3 b)))
+ Data.Functor.Utils: (<∘∘∘∘>) :: (Functor f, Functor f1, Functor f2, Functor f3, Functor f4) => (a -> b) -> f (f1 (f2 (f3 (f4 a)))) -> f (f1 (f2 (f3 (f4 b))))
+ Data.Functor.Utils: (<∘∘∘∘∘>) :: (Functor f, Functor f1, Functor f2, Functor f3, Functor f4, Functor f5) => (a -> b) -> f (f1 (f2 (f3 (f4 (f5 a))))) -> f (f1 (f2 (f3 (f4 (f5 b)))))
+ Data.Functor.Utils: (∘) :: Functor f => (a -> b) -> f a -> f b
+ Data.Functor.Utils: (∘∘) :: (Functor f, Functor f1) => (a -> b) -> f (f1 a) -> f (f1 b)
+ Data.Functor.Utils: (∘∘∘) :: (Functor f, Functor f1, Functor f2) => (a -> b) -> f (f1 (f2 a)) -> f (f1 (f2 b))
+ Data.Functor.Utils: (∘∘∘∘) :: (Functor f, Functor f1, Functor f2, Functor f3) => (a -> b) -> f (f1 (f2 (f3 a))) -> f (f1 (f2 (f3 b)))
+ Data.Functor.Utils: (∘∘∘∘∘) :: (Functor f, Functor f1, Functor f2, Functor f3, Functor f4) => (a -> b) -> f (f1 (f2 (f3 (f4 a)))) -> f (f1 (f2 (f3 (f4 b))))
+ Data.Functor.Utils: fmap1 :: Functor f => (a -> b) -> f a -> f b
Files
- functor-utils.cabal +3/−2
- src/Data/Functor/Utils.hs +67/−29
functor-utils.cabal view
@@ -1,5 +1,5 @@ name: functor-utils-version: 1.0+version: 1.1 cabal-version: >=1.10 build-type: Simple license: Apache-2.0@@ -17,7 +17,8 @@ exposed-modules: Data.Functor.Utils build-depends:- base >=4.6 && <4.9+ base >=4.6 && <4.9,+ ghc-prim >=0.4.0.0 default-language: Haskell2010 default-extensions: ConstraintKinds DataKinds DefaultSignatures DeriveDataTypeable DeriveFoldable DeriveFunctor DeriveGeneric
src/Data/Functor/Utils.hs view
@@ -3,35 +3,45 @@ module Data.Functor.Utils where import Prelude hiding ((.))-+import GHC.Prim (Constraint) -- Nested fmaps -fmap2 = fmap.fmap-fmap3 = fmap.fmap2-fmap4 = fmap.fmap3-fmap5 = fmap.fmap4-fmap6 = fmap.fmap5-fmap7 = fmap.fmap6-fmap8 = fmap.fmap7-fmap9 = fmap.fmap8-+fmap1 = fmap ; {-# INLINE fmap1 #-}+fmap2 = fmap.fmap ; {-# INLINE fmap2 #-}+fmap3 = fmap.fmap2 ; {-# INLINE fmap3 #-}+fmap4 = fmap.fmap3 ; {-# INLINE fmap4 #-}+fmap5 = fmap.fmap4 ; {-# INLINE fmap5 #-}+fmap6 = fmap.fmap5 ; {-# INLINE fmap6 #-}+fmap7 = fmap.fmap6 ; {-# INLINE fmap7 #-}+fmap8 = fmap.fmap7 ; {-# INLINE fmap8 #-}+fmap9 = fmap.fmap8 ; {-# INLINE fmap9 #-} -- Dots -dot1 = (.)-dot2 = dot1 . dot1-dot3 = dot1 . dot2-dot4 = dot1 . dot3-dot5 = dot1 . dot4-dot6 = dot1 . dot5-dot7 = dot1 . dot6-dot8 = dot1 . dot7-dot9 = dot1 . dot8-+dot1 = (.) ; {-# INLINE dot1 #-}+dot2 = dot1 . dot1 ; {-# INLINE dot2 #-}+dot3 = dot1 . dot2 ; {-# INLINE dot3 #-}+dot4 = dot1 . dot3 ; {-# INLINE dot4 #-}+dot5 = dot1 . dot4 ; {-# INLINE dot5 #-}+dot6 = dot1 . dot5 ; {-# INLINE dot6 #-}+dot7 = dot1 . dot6 ; {-# INLINE dot7 #-}+dot8 = dot1 . dot7 ; {-# INLINE dot8 #-}+dot9 = dot1 . dot8 ; {-# INLINE dot9 #-} -- Operators +infixr 9 ∘+infixr 9 ∘∘+infixr 9 ∘∘∘+infixr 9 ∘∘∘∘+infixr 9 ∘∘∘∘∘+(∘) = fmap ; {-# INLINE (∘) #-}+(∘∘) = dot2 ; {-# INLINE (∘∘) #-}+(∘∘∘) = dot3 ; {-# INLINE (∘∘∘) #-}+(∘∘∘∘) = dot4 ; {-# INLINE (∘∘∘∘) #-}+(∘∘∘∘∘) = dot5 ; {-# INLINE (∘∘∘∘∘) #-}+ infixr 9 . infixr 9 .: infixr 9 .:.@@ -42,17 +52,39 @@ infixr 9 .:::: infixr 9 .::::. (.) :: (Functor f) => (a -> b) -> f a -> f b-(.) = fmap-(.:) = dot2-(.:.) = dot3-(.::) = dot4-(.::.) = dot5-(.:::) = dot6-(.:::.) = dot7-(.::::) = dot8-(.::::.) = dot9+(.) = fmap ; {-# INLINE (.) #-}+(.:) = dot2 ; {-# INLINE (.:) #-}+(.:.) = dot3 ; {-# INLINE (.:.) #-}+(.::) = dot4 ; {-# INLINE (.::) #-}+(.::.) = dot5 ; {-# INLINE (.::.) #-}+(.:::) = dot6 ; {-# INLINE (.:::) #-}+(.:::.) = dot7 ; {-# INLINE (.:::.) #-}+(.::::) = dot8 ; {-# INLINE (.::::) #-}+(.::::.) = dot9 ; {-# INLINE (.::::.) #-} ++infixl 4 <∘>+infixl 4 <∘∘>+infixl 4 <∘∘∘>+infixl 4 <∘∘∘∘>+infixl 4 <∘∘∘∘∘>+f <∘> a = fmap f ∘ a ; {-# INLINE (<∘>) #-}+f <∘∘> a = fmap f ∘∘ a ; {-# INLINE (<∘∘>) #-}+f <∘∘∘> a = fmap f ∘∘∘ a ; {-# INLINE (<∘∘∘>) #-}+f <∘∘∘∘> a = fmap f ∘∘∘∘ a ; {-# INLINE (<∘∘∘∘>) #-}+f <∘∘∘∘∘> a = fmap f ∘∘∘∘∘ a ; {-# INLINE (<∘∘∘∘∘>) #-}++++f <<∘>> a = fmap2 f ∘ a++infixl 4 <<$>>+f <<$>> a = fmap f <$> a++{-# INLINE (<<∘>>) #-}+{-# INLINE (<<$>>) #-}+ -- nested lenses -- | following functions are usefull when operating on nested structures with lenses, for example -- | given function foo :: a -> m (n a) and a lens l :: Lens' x a, we can use @@ -63,3 +95,9 @@ --nested :: (Functor m, Functor n) => Lens a b c d -> (c -> m (n d)) -> (a -> m (n b)) nested l f = fromNestedFunctor . l (fmap NestedFunctor f)+{-# INLINE nested #-}+++type family Functors lst :: Constraint where + Functors '[] = ()+ Functors (f ': fs) = (Functor f, Functors fs)