Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Functor.Elastic
Synopsis
- class Expansive (f :: Type -> Type)
- class Compactable (f :: Type -> Type)
- class (Compactable f, Expansive f) => Elastic f
Documentation
class Expansive (f :: Type -> Type) Source #
Partial inverse of Compactable
expand (unite x y) = uniteDichotomy x y
unite = emapThese id
map Just = expand
(\x -> unite x x) = map (\x -> These x x)
emapThese f a b = map f (unite a b)
unite (f <$> x) (g <$> y) = bimap f g <$> unite x y
expand (unite x y) = swap <$> unite y x
emapThese f a b = f <$> unite a b
unite empty = map That
flip unite empty = map This
unite mempty = map That
flip unite mempty = map This
Instances
class Compactable (f :: Type -> Type) Source #
A generalization of catMaybes
compact . map Just = id
compact . mapMaybe id
compact (pure Just <*> a) = a
applyMaybe (pure Just) = id
applyMaybe (pure id) = compact
bindMaybe (return . Just) = id
bindMaybe return = compact
compact (return . Just =<< a) = a
mapMaybe (l <=< r) = mapMaybe l . mapMaybe r
compact (Nothing <$ a) = empty
compact (Nothing <$ a) = mempty
compact empty = empty
compact mempty = mempty
traverseMaybe (Just . Just) = Just
traverseMaybe (map Just . f) = traverse f
Minimal complete definition