Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
See Filtrable
.
Synopsis
- class Functor f => Filtrable f where
- mapMaybe :: (a -> Maybe b) -> f a -> f b
- catMaybes :: f (Maybe a) -> f a
- filter :: (a -> Bool) -> f a -> f a
- mapMaybeA :: (Traversable f, Applicative p) => (a -> p (Maybe b)) -> f a -> p (f b)
- filterA :: (Traversable f, Applicative p) => (a -> p Bool) -> f a -> p (f a)
- mapEither :: (a -> Either b c) -> f a -> (f b, f c)
- mapEitherA :: (Traversable f, Applicative p) => (a -> p (Either b c)) -> f a -> p (f b, f c)
- partitionEithers :: f (Either a b) -> (f a, f b)
- (<$?>) :: Filtrable f => (a -> Maybe b) -> f a -> f b
- (<*?>) :: (Applicative p, Filtrable p) => p (a -> Maybe b) -> p a -> p b
- nub :: (Filtrable f, Traversable f, Eq a) => f a -> f a
- nubBy :: (Filtrable f, Traversable f) => (a -> a -> Bool) -> f a -> f a
- nubOrd :: (Filtrable f, Traversable f, Ord a) => f a -> f a
- nubOrdBy :: (Filtrable f, Traversable f) => (a -> a -> Ordering) -> f a -> f a
Documentation
class Functor f => Filtrable f where Source #
Class of filtrable containers, i.e. containers we can map over while selectively dropping elements.
Laws:
mapMaybe
Just
= idmapMaybe
f =catMaybes
∘fmap
fcatMaybes
=mapMaybe
idfilter
f =mapMaybe
(\ x ->bool
Nothing
(Just
x) (f x))mapMaybe
g .mapMaybe
f =mapMaybe
(g<=<
f)
Laws if
:Foldable
f
mapMaybe :: (a -> Maybe b) -> f a -> f b Source #
Map the container with the given function, dropping the elements for which it returns Nothing
.
catMaybes :: f (Maybe a) -> f a Source #
filter :: (a -> Bool) -> f a -> f a Source #
Drop the elements for which the given predicate is False
.
mapMaybeA :: (Traversable f, Applicative p) => (a -> p (Maybe b)) -> f a -> p (f b) Source #
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) Source #
Drop the elements for which the given predicate is False
.
mapEither :: (a -> Either b c) -> f a -> (f b, f c) Source #
mapEitherA :: (Traversable f, Applicative p) => (a -> p (Either b c)) -> f a -> p (f b, f c) Source #
partitionEithers :: f (Either a b) -> (f a, f b) Source #
Instances
nub :: (Filtrable f, Traversable f, Eq a) => f a -> f a Source #
\(\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 Source #
\(\mathcal{O}(n^2)\) Delete all but the first copy of each element, with the given relation.