module Data.Extensible.Union (K1(..), Union(..), Gondola(..), reunion, rung, runGondolas) where
import Data.Extensible.Internal
import Data.Extensible.Internal.Rig
import Data.Extensible.Class
import Data.Extensible.Sum
import Data.Extensible.Product
import Data.Extensible.Wrapper
import Data.Profunctor
import Data.Typeable (Typeable)
newtype K1 a f = K1 { getK1 :: f a } deriving (Eq, Ord, Read, Typeable)
instance Wrapper (K1 a) where
type Repr (K1 a) f = f a
_Wrapper = dimap getK1 (fmap K1)
newtype Union xs a = Union { getUnion :: K1 a :| xs }
reunion :: Gondola m :* xs -> Union xs a -> m a
reunion gs = \(Union (EmbedAt i (K1 f))) -> views (pieceAt i) runGondola gs f
newtype Gondola f g = Gondola { runGondola :: forall a. g a -> f a }
rung :: (forall x. f x -> g x) -> Gondola g :* fs -> Gondola g :* (f ': fs)
rung f = (<:) (Gondola f)
infixr 0 `rung`
runGondolas :: (x ∈ xs) => Gondola f :* xs -> x a -> f a
runGondolas = views piece runGondola