module Data.Functor.Context (
Ctxt(..),
mapCtxt,
extractCtxt,
) where
import Control.Comonad
import Control.Applicative
import Control.Lens.Wrapped
import Control.Lens.Iso
newtype Ctxt a = Ctxt { getCtxt :: (Maybe a, a, Maybe a) }
deriving (Functor)
instance Wrapped (Ctxt a) where
type Unwrapped (Ctxt a) = (Maybe a, a, Maybe a)
_Wrapped' = iso getCtxt Ctxt
instance Rewrapped (Ctxt a) (Ctxt b)
instance Applicative Ctxt where
pure x = Ctxt (Nothing, x, Nothing)
Ctxt (b,x,a) <*> Ctxt (b',x',a') = Ctxt (b <*> b', x x', a <*> a')
mapCtxt :: (a -> b) -> Ctxt a -> Ctxt b
mapCtxt = fmap
extractCtxt :: Ctxt a -> a
extractCtxt (Ctxt (_,x,_)) = x