-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A typeclass for structures which can be catMaybed, filtered, and partitioned. -- -- 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. @package compactable @version 0.1.2.3 module Control.Compactable -- | Class Compactable provides two methods which can be writen in -- terms of each other, compact and separate. -- -- is generalization of catMaybes as a new function. 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: -- --
fmapMaybe (l <=< r) = -- fmapMaybe l . fmapMaybe r
compact . fmap Just = -- id
fmapMaybe Just = -- id
compact = fmapMaybe -- id
compact . (pure Just -- <*>) = id
applyMaybe (pure -- Just) = id
compact = applyMaybe (pure -- id)
flip bindMaybe (return . -- Just) = id
compact . (return . Just -- =<<) = id
compact = flip bindMaybe -- return
compact empty = -- empty
compact (const Nothing -- <$> xs) = empty
traverseMaybe -- (pure . Just) = pure
Compose . fmap -- (traverseMaybe f) . traverseMaybe g = traverseMaybe (Compose . fmap -- (traverseMaybe f) . g)
traverse f = -- traverseMaybe (fmap Just . f)
t . traverseMaybe f = -- traverseMaybe (t . f)
fst . separate . fmap Right -- = id
snd . separate . fmap Left = -- id
snd . separate . -- (pure Right <*>) = id
fst . separate . -- (pure Left <*>) = id
snd . separate . -- fmap (const Left) = empty
fst , separate . -- fmap (const Right) = empty
-- compact = compactFold ---- -- and -- --
-- separate = separateFold ---- -- as it's just a specialization. More exploration is needed on the -- relationship here. class Compactable f => CompactFold (f :: * -> *) compactFold :: (CompactFold f, Foldable g) => f (g a) -> f a compactFold :: (CompactFold f, Monad f, Alternative f, Foldable g) => f (g a) -> f a separateFold :: (CompactFold f, Bifoldable g) => f (g a b) -> (f a, f b) separateFold :: (CompactFold f, Monad f, Alternative f, Bifoldable g) => f (g a b) -> (f a, f b) fmapFold :: (CompactFold f, Functor f, Foldable g) => (a -> g b) -> f a -> f b fmapBifold :: (CompactFold f, Functor f, Bifoldable g) => (a -> g l r) -> f a -> (f l, f r) applyFold :: (CompactFold f, Applicative f, Foldable g) => f (a -> g b) -> f a -> f b applyBifold :: (CompactFold f, Applicative f, Bifoldable g) => f (a -> g l r) -> f a -> (f l, f r) bindFold :: (CompactFold f, Monad f, Foldable g) => f a -> (a -> f (g b)) -> f b bindBifold :: (CompactFold f, Monad f, Bifoldable g) => f a -> (a -> f (g l r)) -> (f l, f r) traverseFold :: (CompactFold f, Applicative h, Foldable g, Traversable f) => (a -> h (g b)) -> f a -> h (f b) traverseBifold :: (CompactFold f, Applicative h, Bifoldable g, Traversable f) => (a -> h (g l r)) -> f a -> h (f l, f r) fforMaybe :: (Compactable f, Functor f) => f a -> (a -> Maybe b) -> f b fforFold :: (CompactFold f, Functor f, Foldable g) => f a -> (a -> g b) -> f b fforEither :: (Compactable f, Functor f) => f a -> (a -> Either l r) -> (f l, f r) fforBifold :: (CompactFold f, Functor f, Bifoldable g) => f a -> (a -> g l r) -> (f l, f r) mfold' :: (Foldable f, Alternative m) => f a -> m a mlefts :: (Bifoldable f, Alternative m) => f a b -> m a mrights :: (Bifoldable f, Alternative m) => f a b -> m b fmapMaybeM :: (Compactable f, Monad f) => (a -> MaybeT f b) -> f a -> f b fmapEitherM :: (Compactable f, Monad f) => (a -> ExceptT l f r) -> f a -> (f l, f r) fforMaybeM :: (Compactable f, Monad f) => f a -> (a -> MaybeT f b) -> f b fforEitherM :: (Compactable f, Monad f) => f a -> (a -> ExceptT l f r) -> (f l, f r) 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) -- | While more constrained, when available, this default is going to be -- faster than the one provided in the typeclass altDefaultCompact :: (Alternative f, Monad f) => f (Maybe a) -> f a -- | While more constrained, when available, this default is going to be -- faster than the one provided in the typeclass altDefaultSeparate :: (Alternative f, Foldable f) => f (Either l r) -> (f l, f r) instance GHC.Base.Alternative f => GHC.Base.Alternative (Control.Compactable.AltSum f) instance GHC.Base.Applicative f => GHC.Base.Applicative (Control.Compactable.AltSum f) instance GHC.Base.Functor f => GHC.Base.Functor (Control.Compactable.AltSum f) instance Control.Compactable.CompactFold [] instance Control.Compactable.CompactFold GHC.Maybe.Maybe instance Control.Compactable.CompactFold GHC.Types.IO instance Control.Compactable.CompactFold Text.ParserCombinators.ReadP.ReadP instance Control.Compactable.CompactFold Text.ParserCombinators.ReadPrec.ReadPrec instance Control.Compactable.CompactFold GHC.Conc.Sync.STM instance Control.Compactable.CompactFold Control.Applicative.ZipList instance Control.Compactable.CompactFold Data.Semigroup.Option instance Control.Compactable.CompactFold GHC.Generics.U1 instance Control.Compactable.CompactFold Data.Proxy.Proxy instance (Control.Arrow.ArrowPlus a, Control.Arrow.ArrowApply a) => Control.Compactable.CompactFold (Control.Arrow.ArrowMonad a) instance GHC.Base.MonadPlus a => Control.Compactable.CompactFold (Control.Applicative.WrappedMonad a) instance (GHC.Base.Alternative a, GHC.Base.Monad a) => Control.Compactable.CompactFold (GHC.Generics.Rec1 a) instance (GHC.Base.Alternative a, GHC.Base.Monad a) => Control.Compactable.CompactFold (Data.Semigroup.Internal.Alt a) instance (GHC.Base.Alternative f, GHC.Base.Monad f, GHC.Base.Alternative g, GHC.Base.Monad g) => Control.Compactable.CompactFold (f GHC.Generics.:*: g) instance (Control.Compactable.Compactable f, GHC.Base.Alternative f, GHC.Base.Monad f, Control.Compactable.Compactable g, GHC.Base.Alternative g, GHC.Base.Monad g) => Control.Compactable.CompactFold (Data.Functor.Product.Product f g) instance (GHC.Base.Alternative f, GHC.Base.Monad f) => Control.Compactable.CompactFold (GHC.Generics.M1 i c f) instance GHC.Base.Alternative f => GHC.Base.Semigroup (Control.Compactable.AltSum f a) instance GHC.Base.Alternative f => GHC.Base.Monoid (Control.Compactable.AltSum f a) instance Control.Compactable.Compactable GHC.Maybe.Maybe instance GHC.Base.Monoid m => Control.Compactable.Compactable (Data.Either.Either m) instance Control.Compactable.Compactable [] instance Control.Compactable.Compactable Control.Applicative.ZipList 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 GHC.Generics.U1 instance Control.Compactable.Compactable Data.Semigroup.Option instance Control.Compactable.Compactable Text.ParserCombinators.ReadP.ReadP instance Control.Compactable.Compactable Text.ParserCombinators.ReadPrec.ReadPrec instance (GHC.Base.Functor f, GHC.Base.Functor g, 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.Internal.IntMap instance Control.Compactable.Compactable (Data.Map.Internal.Map k) instance Control.Compactable.Compactable Data.Sequence.Internal.Seq instance Control.Compactable.Compactable Data.Vector.Vector instance Control.Compactable.Compactable (Data.Functor.Const.Const r) instance Control.Compactable.Compactable Data.Set.Internal.Set instance (Control.Arrow.ArrowPlus a, Control.Arrow.ArrowApply a) => Control.Compactable.Compactable (Control.Arrow.ArrowMonad a) instance GHC.Base.Monad a => Control.Compactable.Compactable (Control.Applicative.WrappedMonad a) instance GHC.Base.Functor a => Control.Compactable.Compactable (GHC.Generics.Rec1 a) instance GHC.Base.Functor a => Control.Compactable.Compactable (Data.Semigroup.Internal.Alt a) instance (GHC.Base.Functor a, GHC.Base.Functor b) => Control.Compactable.Compactable (a GHC.Generics.:*: b) instance GHC.Base.Functor f => Control.Compactable.Compactable (GHC.Generics.M1 i c f) instance (GHC.Base.Functor f, GHC.Base.Functor g) => Control.Compactable.Compactable (f GHC.Generics.:.: g)