module Frames.RecLens where
import Control.Applicative
import qualified Data.Vinyl as V
import Data.Vinyl.Functor (Identity(..))
import Data.Vinyl.TypeLevel
import Frames.Col ((:->)(..))
import Frames.Rec (Record)
rlens' :: (i ~ RIndex r rs, V.RElem r rs i, Functor f, Functor g)
=> sing r
-> (g r -> f (g r))
-> V.Rec g rs
-> f (V.Rec g rs)
rlens' = V.rlens
rget' :: Functor g
=> (forall f. Functor f
=> (g (s :-> a) -> f (g (s :-> a))) -> V.Rec g rs -> f (V.Rec g rs))
-> V.Rec g rs -> g a
rget' l = fmap getCol . getConst . l Const
rput' :: Functor g
=> (forall f. Functor f
=> (g (s :-> a) -> f (g (s :-> a))) -> V.Rec g rs -> f (V.Rec g rs))
-> g a -> V.Rec g rs -> V.Rec g rs
rput' l y = getIdentity . l (\_ -> Identity (fmap Col y))
rlens :: (Functor f, V.RElem (s :-> a) rs (RIndex (s :-> a) rs))
=> proxy (s :-> a) -> (a -> f a) -> Record rs -> f (Record rs)
rlens k f = rlens' k (fmap Identity . getIdentity . fmap f')
where f' (Col x) = fmap Col (f x)
rget :: (forall f. Functor f => (a -> f a) -> Record rs -> f (Record rs))
-> Record rs -> a
rget l = getConst . l Const
rput :: (forall f. Functor f => (a -> f a) -> Record rs -> f (Record rs))
-> a -> Record rs -> Record rs
rput l y = getIdentity . l (\_ -> Identity y)