-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A generalization for containers that can be stripped of Nothings. -- -- Sometimes you have a collection of Maybes, and you want to extract the -- values. Actually that happens a whole lot. @package compactable @version 0.1.0.2 module Control.Compactable -- | This is a generalization of catMaybes as a new function compact. -- Compact has relations with Functor, Applicative, Monad, Alternative, -- and Traversable. In that we can use these class to provide the ability -- to operate on a data type by throwing away intermediate Nothings. This -- is useful for representing stripping out values or failure. -- -- To be compactable alone, no laws must be satisfied other than the type -- signature. -- -- If the data type is also a Functor the following should hold: -- -- -- -- According to Kmett, (Compactable f, Functor f) is a functor from the -- kleisli category of Maybe to the category of haskell data types. -- Kleisli Maybe -> Hask. -- -- If the data type is also Applicative the following should hold: -- -- -- -- If the data type is also a Monad the following should hold: -- -- -- -- If the data type is also Alternative the following should hold: -- -- -- -- If the data type is also Traversable the following should hold: -- -- -- -- If you know of more useful laws, or have better names for the ones -- above (especially those marked "name me"). Please let me know. class Compactable (f :: * -> *) where compact = (>>= maybe empty return) fmapMaybe f = compact . fmap f applyMaybe fa = compact . (fa <*>) bindMaybe x = compact . (x >>=) traverseMaybe f = fmap compact . traverse f filter f = fmapMaybe $ \ a -> if f a then Just a else Nothing compact :: Compactable f => f (Maybe a) -> f a compact :: (Compactable f, Monad f, Alternative f) => f (Maybe a) -> f a fmapMaybe :: (Compactable f, Functor f) => (a -> Maybe b) -> f a -> f b applyMaybe :: (Compactable f, Applicative f) => f (a -> Maybe b) -> f a -> f b bindMaybe :: (Compactable f, Monad f) => f a -> (a -> f (Maybe b)) -> f b traverseMaybe :: (Compactable f, Applicative g, Traversable f) => (a -> g (Maybe b)) -> f a -> g (f b) filter :: (Compactable f, Functor f) => (a -> Bool) -> f a -> f a fforMaybe :: (Compactable f, Functor f) => f a -> (a -> Maybe b) -> f b fmapMaybeM :: (Compactable f, Monad f) => (a -> MaybeT f b) -> f a -> f b fforMaybeM :: (Compactable f, Monad f) => f a -> (a -> MaybeT f b) -> f b applyMaybeM :: (Compactable f, Monad f) => f (a -> MaybeT f b) -> f a -> f b bindMaybeM :: (Compactable f, Monad f) => f a -> (a -> f (MaybeT f b)) -> f b traverseMaybeM :: (Monad m, Compactable t, Traversable t) => (a -> MaybeT m b) -> t a -> m (t b) instance Control.Compactable.Compactable GHC.Base.Maybe instance Control.Compactable.Compactable [] instance Control.Compactable.Compactable GHC.Types.IO instance Control.Compactable.Compactable GHC.Conc.Sync.STM instance Control.Compactable.Compactable Data.Proxy.Proxy instance Control.Compactable.Compactable Data.Semigroup.Option instance Control.Compactable.Compactable Text.ParserCombinators.ReadP.ReadP instance Control.Compactable.Compactable Text.ParserCombinators.ReadPrec.ReadPrec instance (Control.Compactable.Compactable f, Control.Compactable.Compactable g) => Control.Compactable.Compactable (Data.Functor.Product.Product f g) instance (GHC.Base.Functor f, GHC.Base.Functor g, Control.Compactable.Compactable g) => Control.Compactable.Compactable (Data.Functor.Compose.Compose f g) instance Control.Compactable.Compactable Data.IntMap.Base.IntMap instance Control.Compactable.Compactable (Data.Map.Base.Map k) instance Control.Compactable.Compactable Data.Sequence.Seq instance Control.Compactable.Compactable Data.Vector.Vector instance Control.Compactable.Compactable (Data.Functor.Const.Const r) instance GHC.Base.Monoid m => Control.Compactable.Compactable (Data.Either.Either m)