compactable 0.1.2.1 → 0.1.2.2
raw patch · 2 files changed
+25/−2 lines, 2 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Control.Compactable: partition :: (Compactable f, Functor f) => (a -> Bool) -> f a -> (f a, f a)
Files
- compactable.cabal +1/−1
- src/Control/Compactable.hs +24/−1
compactable.cabal view
@@ -1,5 +1,5 @@ name: compactable-version: 0.1.2.1+version: 0.1.2.2 synopsis: A typeclass for structures which can be catMaybed, filtered, and partitioned. description: This provides polymorphic implementations for filter, compact (catMaybes), and separate. It allows for higher performance implementations to be used in place of defaults for all data structures, and endeavors to centerally document those implementations. Compactable aims to be as general and unconstrained as possible, providing instances for non-Functors like Set, as well as some Contravariants (though not published here). Compactable fully subsumes Data.Witherable, offers more laws, and is more general. license: BSD3
src/Control/Compactable.hs view
@@ -48,6 +48,7 @@ import Data.Functor.Compose import qualified Data.Functor.Product as FP import qualified Data.IntMap as IntMap+import qualified Data.List as List import qualified Data.Map as Map import Data.Maybe import Data.Monoid@@ -199,6 +200,11 @@ filter f = fmapMaybe $ \a -> if f a then Just a else Nothing {-# INLINABLE filter #-} + partition :: (a -> Bool) -> f a -> (f a, f a)+ default partition :: Functor f => (a -> Bool) -> f a -> (f a, f a)+ partition f = fmapEither $ \a -> if f a then Right a else Left a+ {-# INLINEABLE partition #-}+ fmapMaybe :: Functor f => (a -> Maybe b) -> f a -> f b fmapMaybe f = compact . fmap f {-# INLINABLE fmapMaybe #-}@@ -268,6 +274,8 @@ {-# INLINABLE fmapMaybe #-} filter = Prelude.filter {-# INLINABLE filter #-}+ partition = List.partition+ {-# INLINABLE partition #-} separate = partitionEithers {-# INLINABLE separate #-} fmapEither f = foldl' (deal f) ([],[])@@ -298,6 +306,8 @@ {-# INLINABLE separate #-} filter _ _ = Proxy {-# INLINABLE filter #-}+ partition _ _ = (Proxy, Proxy)+ {-# INLINABLE partition #-} fmapMaybe _ _ = Proxy {-# INLINABLE fmapMaybe #-} applyMaybe _ _ = Proxy@@ -345,6 +355,8 @@ {-# INLINABLE fmapMaybe #-} filter = IntMap.filter {-# INLINABLE filter #-}+ partition = IntMap.partition+ {-# INLINABLE partition #-} separate = IntMap.mapEither id {-# INLINABLE separate #-} fmapEither = IntMap.mapEither@@ -357,6 +369,8 @@ {-# INLINABLE fmapMaybe #-} filter = Map.filter {-# INLINABLE filter #-}+ partition = Map.partition+ {-# INLINABLE partition #-} separate = Map.mapEither id {-# INLINABLE separate #-} fmapEither = Map.mapEither@@ -369,7 +383,10 @@ {-# INLINABLE separate #-} filter = Seq.filter {-# INLINABLE filter #-}+ partition = Seq.partition+ {-# INLINABLE partition #-} + instance Compactable V.Vector where compact = altDefaultCompact {-# INLINABLE compact #-}@@ -377,6 +394,8 @@ {-# INLINABLE separate #-} filter = V.filter {-# INLINABLE filter #-}+ partition = V.partition+ {-# INLINABLE partition #-} instance Compactable (Const r) where compact (Const r) = Const r@@ -395,6 +414,8 @@ {-# INLINABLE bindEither #-} filter _ (Const r) = Const r {-# INLINABLE filter #-}+ partition _ (Const r) = (Const r, Const r)+ {-# INLINABLE partition #-} instance Compactable Set.Set where compact = Set.fromDistinctAscList . compact . Set.toAscList@@ -402,7 +423,9 @@ separate = bimap Set.fromDistinctAscList Set.fromDistinctAscList . separate . Set.toAscList {-# INLINABLE separate #-} filter = Set.filter- {-# INLINABLE filter #-}+ {-# INLINABLE filter #-}+ partition = Set.partition+ {-# INLINABLE partition #-} instance (ArrowPlus a, ArrowApply a) => Compactable (ArrowMonad a) where instance Monad a => Compactable (WrappedMonad a) where