filtrable 0.1.0.5 → 0.1.1.0
raw patch · 2 files changed
+31/−11 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Filtrable: instance Data.Filtrable.Filtrable (Control.Applicative.Const a)
+ Data.Filtrable: instance Data.Filtrable.Filtrable (Data.Functor.Const.Const a)
+ Data.Filtrable: mapEither :: Filtrable f => (a -> Either b c) -> f a -> (f b, f c)
+ Data.Filtrable: mapEitherA :: (Filtrable f, Traversable f, Applicative p) => (a -> p (Either b c)) -> f a -> p (f b, f c)
+ Data.Filtrable: partitionEithers :: Filtrable f => f (Either a b) -> (f a, f b)
- Data.Filtrable: class Functor f => Filtrable f where mapMaybe f = catMaybes . fmap f catMaybes = mapMaybe id filter f = mapMaybe (liftA2 (<$) id (guard . f))
+ Data.Filtrable: class Functor f => Filtrable f
Files
- Data/Filtrable.hs +22/−8
- filtrable.cabal +9/−3
Data/Filtrable.hs view
@@ -1,4 +1,4 @@-module Data.Filtrable where+module Data.Filtrable (Filtrable (..)) where import Prelude hiding (filter) @@ -33,11 +33,31 @@ catMaybes = mapMaybe id filter :: (a -> Bool) -> f a -> f a- filter f = mapMaybe (liftA2 (<$) id (guard . f))+ filter f = mapMaybe ((<$) <*> guard . f) + mapMaybeA :: (Traversable f, Applicative p) => (a -> p (Maybe b)) -> f a -> p (f b)+ mapMaybeA f xs = catMaybes <$> traverse f xs++ filterA :: (Traversable f, Applicative p) => (a -> p Bool) -> f a -> p (f a)+ filterA f = mapMaybeA (\ x -> (x <$) . guard <$> f x)++ mapEither :: (a -> Either b c) -> f a -> (f b, f c)+ mapEither f = (,) <$> mapMaybe (either Just (pure Nothing) . f)+ <*> mapMaybe (either (pure Nothing) Just . f)++ mapEitherA :: (Traversable f, Applicative p) => (a -> p (Either b c)) -> f a -> p (f b, f c)+ mapEitherA f = liftA2 (,) <$> mapMaybeA (fmap (Just `either` pure Nothing) . f)+ <*> mapMaybeA (fmap (pure Nothing `either` Just) . f)++ partitionEithers :: f (Either a b) -> (f a, f b)+ partitionEithers = mapEither id+ instance Filtrable [] where mapMaybe f = foldr (maybe id (:) . f) [] + mapMaybeA _ [] = pure []+ mapMaybeA f (x:xs) = maybe id (:) <$> f x <*> mapMaybeA f xs+ instance Filtrable Maybe where mapMaybe = (=<<) catMaybes = join@@ -47,9 +67,3 @@ instance Filtrable (Const a) where mapMaybe _ (Const x) = Const x--mapMaybeA :: (Filtrable f, Traversable f, Applicative p) => (a -> p (Maybe b)) -> f a -> p (f b)-mapMaybeA f xs = catMaybes <$> traverse f xs--filterA :: (Filtrable f, Traversable f, Applicative p) => (a -> p Bool) -> f a -> p (f a)-filterA f = mapMaybeA (\ x -> (x <$) . guard <$> f x)
filtrable.cabal view
@@ -1,5 +1,5 @@ name: filtrable-version: 0.1.0.5+version: 0.1.1.0 synopsis: Class of filtrable containers homepage: https://github.com/strake/filtrable.hs license: BSD3@@ -8,8 +8,14 @@ maintainer: strake888@gmail.com category: Data build-type: Simple-cabal-version: >=1.9.2+cabal-version: >=1.10+tested-with: GHC ==7.8.*,+ GHC ==7.10.*,+ GHC ==7.12.*,+ GHC ==8.0.* library exposed-modules: Data.Filtrable- build-depends: base >=4.7 && <4.9+ build-depends: base >=4.7 && <5+ default-language: Haskell2010+ default-extensions: ConstrainedClassMethods