filtrable-0.1.6.0: Class of filtrable containers
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Filtrable

Description

Synopsis

Documentation

class Functor f => Filtrable (f :: Type -> Type) where #

Class of filtrable containers, i.e. containers we can map over while selectively dropping elements.

Laws:

Laws if Foldable f:

Minimal complete definition

mapMaybe | catMaybes

Methods

mapMaybe :: (a -> Maybe b) -> f a -> f b #

Map the container with the given function, dropping the elements for which it returns Nothing.

catMaybes :: f (Maybe a) -> f a #

filter :: (a -> Bool) -> f a -> f a #

Drop the elements for which the given predicate is False.

mapMaybeA :: (Traversable f, Applicative p) => (a -> p (Maybe b)) -> f a -> p (f b) #

Traverse the container with the given function, dropping the elements for which it returns Nothing.

filterA :: (Traversable f, Applicative p) => (a -> p Bool) -> f a -> p (f a) #

Drop the elements for which the given predicate is False.

mapEither :: (a -> Either b c) -> f a -> (f b, f c) #

Map the container with the given function, collecting the Lefts and the Rights separately.

mapEitherA :: (Traversable f, Applicative p) => (a -> p (Either b c)) -> f a -> p (f b, f c) #

Traverse the container with the given function, collecting the Lefts and the Rights separately.

partitionEithers :: f (Either a b) -> (f a, f b) #

Instances

Instances details
Filtrable IntMap # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> IntMap a -> IntMap b #

catMaybes :: IntMap (Maybe a) -> IntMap a #

filter :: (a -> Bool) -> IntMap a -> IntMap a #

mapMaybeA :: (Traversable IntMap, Applicative p) => (a -> p (Maybe b)) -> IntMap a -> p (IntMap b) #

filterA :: (Traversable IntMap, Applicative p) => (a -> p Bool) -> IntMap a -> p (IntMap a) #

mapEither :: (a -> Either b c) -> IntMap a -> (IntMap b, IntMap c) #

mapEitherA :: (Traversable IntMap, Applicative p) => (a -> p (Either b c)) -> IntMap a -> p (IntMap b, IntMap c) #

partitionEithers :: IntMap (Either a b) -> (IntMap a, IntMap b) #

Filtrable Seq # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Seq a -> Seq b #

catMaybes :: Seq (Maybe a) -> Seq a #

filter :: (a -> Bool) -> Seq a -> Seq a #

mapMaybeA :: (Traversable Seq, Applicative p) => (a -> p (Maybe b)) -> Seq a -> p (Seq b) #

filterA :: (Traversable Seq, Applicative p) => (a -> p Bool) -> Seq a -> p (Seq a) #

mapEither :: (a -> Either b c) -> Seq a -> (Seq b, Seq c) #

mapEitherA :: (Traversable Seq, Applicative p) => (a -> p (Either b c)) -> Seq a -> p (Seq b, Seq c) #

partitionEithers :: Seq (Either a b) -> (Seq a, Seq b) #

Filtrable Maybe # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Maybe a -> Maybe b #

catMaybes :: Maybe (Maybe a) -> Maybe a #

filter :: (a -> Bool) -> Maybe a -> Maybe a #

mapMaybeA :: (Traversable Maybe, Applicative p) => (a -> p (Maybe b)) -> Maybe a -> p (Maybe b) #

filterA :: (Traversable Maybe, Applicative p) => (a -> p Bool) -> Maybe a -> p (Maybe a) #

mapEither :: (a -> Either b c) -> Maybe a -> (Maybe b, Maybe c) #

mapEitherA :: (Traversable Maybe, Applicative p) => (a -> p (Either b c)) -> Maybe a -> p (Maybe b, Maybe c) #

partitionEithers :: Maybe (Either a b) -> (Maybe a, Maybe b) #

Filtrable [] # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> [a] -> [b] #

catMaybes :: [Maybe a] -> [a] #

filter :: (a -> Bool) -> [a] -> [a] #

mapMaybeA :: (Traversable [], Applicative p) => (a -> p (Maybe b)) -> [a] -> p [b] #

filterA :: (Traversable [], Applicative p) => (a -> p Bool) -> [a] -> p [a] #

mapEither :: (a -> Either b c) -> [a] -> ([b], [c]) #

mapEitherA :: (Traversable [], Applicative p) => (a -> p (Either b c)) -> [a] -> p ([b], [c]) #

partitionEithers :: [Either a b] -> ([a], [b]) #

Filtrable (Proxy :: Type -> Type) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Proxy a -> Proxy b #

catMaybes :: Proxy (Maybe a) -> Proxy a #

filter :: (a -> Bool) -> Proxy a -> Proxy a #

mapMaybeA :: (Traversable (Proxy :: Type -> Type), Applicative p) => (a -> p (Maybe b)) -> Proxy a -> p (Proxy b) #

filterA :: (Traversable (Proxy :: Type -> Type), Applicative p) => (a -> p Bool) -> Proxy a -> p (Proxy a) #

mapEither :: (a -> Either b c) -> Proxy a -> (Proxy b, Proxy c) #

mapEitherA :: (Traversable (Proxy :: Type -> Type), Applicative p) => (a -> p (Either b c)) -> Proxy a -> p (Proxy b, Proxy c) #

partitionEithers :: Proxy (Either a b) -> (Proxy a, Proxy b) #

Ord k => Filtrable (Map k) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Map k a -> Map k b #

catMaybes :: Map k (Maybe a) -> Map k a #

filter :: (a -> Bool) -> Map k a -> Map k a #

mapMaybeA :: (Traversable (Map k), Applicative p) => (a -> p (Maybe b)) -> Map k a -> p (Map k b) #

filterA :: (Traversable (Map k), Applicative p) => (a -> p Bool) -> Map k a -> p (Map k a) #

mapEither :: (a -> Either b c) -> Map k a -> (Map k b, Map k c) #

mapEitherA :: (Traversable (Map k), Applicative p) => (a -> p (Either b c)) -> Map k a -> p (Map k b, Map k c) #

partitionEithers :: Map k (Either a b) -> (Map k a, Map k b) #

Filtrable (Const a :: Type -> Type) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a0 -> Maybe b) -> Const a a0 -> Const a b #

catMaybes :: Const a (Maybe a0) -> Const a a0 #

filter :: (a0 -> Bool) -> Const a a0 -> Const a a0 #

mapMaybeA :: (Traversable (Const a :: Type -> Type), Applicative p) => (a0 -> p (Maybe b)) -> Const a a0 -> p (Const a b) #

filterA :: (Traversable (Const a :: Type -> Type), Applicative p) => (a0 -> p Bool) -> Const a a0 -> p (Const a a0) #

mapEither :: (a0 -> Either b c) -> Const a a0 -> (Const a b, Const a c) #

mapEitherA :: (Traversable (Const a :: Type -> Type), Applicative p) => (a0 -> p (Either b c)) -> Const a a0 -> p (Const a b, Const a c) #

partitionEithers :: Const a (Either a0 b) -> (Const a a0, Const a b) #

Filtrable f => Filtrable (Backwards f) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Backwards f a -> Backwards f b #

catMaybes :: Backwards f (Maybe a) -> Backwards f a #

filter :: (a -> Bool) -> Backwards f a -> Backwards f a #

mapMaybeA :: (Traversable (Backwards f), Applicative p) => (a -> p (Maybe b)) -> Backwards f a -> p (Backwards f b) #

filterA :: (Traversable (Backwards f), Applicative p) => (a -> p Bool) -> Backwards f a -> p (Backwards f a) #

mapEither :: (a -> Either b c) -> Backwards f a -> (Backwards f b, Backwards f c) #

mapEitherA :: (Traversable (Backwards f), Applicative p) => (a -> p (Either b c)) -> Backwards f a -> p (Backwards f b, Backwards f c) #

partitionEithers :: Backwards f (Either a b) -> (Backwards f a, Backwards f b) #

Filtrable f => Filtrable (Reverse f) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Reverse f a -> Reverse f b #

catMaybes :: Reverse f (Maybe a) -> Reverse f a #

filter :: (a -> Bool) -> Reverse f a -> Reverse f a #

mapMaybeA :: (Traversable (Reverse f), Applicative p) => (a -> p (Maybe b)) -> Reverse f a -> p (Reverse f b) #

filterA :: (Traversable (Reverse f), Applicative p) => (a -> p Bool) -> Reverse f a -> p (Reverse f a) #

mapEither :: (a -> Either b c) -> Reverse f a -> (Reverse f b, Reverse f c) #

mapEitherA :: (Traversable (Reverse f), Applicative p) => (a -> p (Either b c)) -> Reverse f a -> p (Reverse f b, Reverse f c) #

partitionEithers :: Reverse f (Either a b) -> (Reverse f a, Reverse f b) #

(Filtrable f, Filtrable g) => Filtrable (Product f g) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Product f g a -> Product f g b #

catMaybes :: Product f g (Maybe a) -> Product f g a #

filter :: (a -> Bool) -> Product f g a -> Product f g a #

mapMaybeA :: (Traversable (Product f g), Applicative p) => (a -> p (Maybe b)) -> Product f g a -> p (Product f g b) #

filterA :: (Traversable (Product f g), Applicative p) => (a -> p Bool) -> Product f g a -> p (Product f g a) #

mapEither :: (a -> Either b c) -> Product f g a -> (Product f g b, Product f g c) #

mapEitherA :: (Traversable (Product f g), Applicative p) => (a -> p (Either b c)) -> Product f g a -> p (Product f g b, Product f g c) #

partitionEithers :: Product f g (Either a b) -> (Product f g a, Product f g b) #

(Filtrable f, Filtrable g) => Filtrable (Sum f g) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Sum f g a -> Sum f g b #

catMaybes :: Sum f g (Maybe a) -> Sum f g a #

filter :: (a -> Bool) -> Sum f g a -> Sum f g a #

mapMaybeA :: (Traversable (Sum f g), Applicative p) => (a -> p (Maybe b)) -> Sum f g a -> p (Sum f g b) #

filterA :: (Traversable (Sum f g), Applicative p) => (a -> p Bool) -> Sum f g a -> p (Sum f g a) #

mapEither :: (a -> Either b c) -> Sum f g a -> (Sum f g b, Sum f g c) #

mapEitherA :: (Traversable (Sum f g), Applicative p) => (a -> p (Either b c)) -> Sum f g a -> p (Sum f g b, Sum f g c) #

partitionEithers :: Sum f g (Either a b) -> (Sum f g a, Sum f g b) #

(Functor f, Filtrable g) => Filtrable (Compose f g) # 
Instance details

Defined in Data.Filtrable

Methods

mapMaybe :: (a -> Maybe b) -> Compose f g a -> Compose f g b #

catMaybes :: Compose f g (Maybe a) -> Compose f g a #

filter :: (a -> Bool) -> Compose f g a -> Compose f g a #

mapMaybeA :: (Traversable (Compose f g), Applicative p) => (a -> p (Maybe b)) -> Compose f g a -> p (Compose f g b) #

filterA :: (Traversable (Compose f g), Applicative p) => (a -> p Bool) -> Compose f g a -> p (Compose f g a) #

mapEither :: (a -> Either b c) -> Compose f g a -> (Compose f g b, Compose f g c) #

mapEitherA :: (Traversable (Compose f g), Applicative p) => (a -> p (Either b c)) -> Compose f g a -> p (Compose f g b, Compose f g c) #

partitionEithers :: Compose f g (Either a b) -> (Compose f g a, Compose f g b) #

(<$?>) :: Filtrable f => (a -> Maybe b) -> f a -> f b infixl 4 #

Infix synonym of mapMaybe

(<*?>) :: (Applicative p, Filtrable p) => p (a -> Maybe b) -> p a -> p b infixl 4 #

f <*?> a = catMaybes (f <*> a)

nub :: (Filtrable f, Traversable f, Eq a) => f a -> f a #

\(\mathcal{O}(n^2)\) Delete all but the first copy of each element, special case of nubBy.

nubBy :: (Filtrable f, Traversable f) => (a -> a -> Bool) -> f a -> f a #

\(\mathcal{O}(n^2)\) Delete all but the first copy of each element, with the given relation.

nubOrd :: (Filtrable f, Traversable f, Ord a) => f a -> f a #

\(\mathcal{O}(n\;\mathrm{log}\;n)\) Delete all but the first copy of each element, special case of nubOrdBy.

nubOrdBy :: (Filtrable f, Traversable f) => (a -> a -> Ordering) -> f a -> f a #

\(\mathcal{O}(n\;\mathrm{log}\;n)\) Delete all but the first copy of each element, with the given relation.