module Frames.Rec where
import Data.Proxy
import Data.Vinyl (recordToList, rmap, reifyConstraint, Dict(..), Rec)
import Data.Vinyl.TypeLevel (RecAll)
import Data.Vinyl.Functor (Identity(..), Const(..), Compose(..), (:.))
import Frames.Col
import Frames.RecF
type Record = Rec Identity
(&:) :: a -> Record rs -> Record (s :-> a ': rs)
x &: xs = frameCons (Identity x) xs
infixr 5 &:
type family RecordColumns t where
RecordColumns (Record ts) = ts
recUncons :: Record (s :-> a ': rs) -> (a, Record rs)
recUncons (Identity x :& xs) = (x, xs)
recUncons x = case x of
recMaybe :: Rec Maybe cs -> Maybe (Record cs)
recMaybe = rtraverse (fmap Identity)
showFields :: (RecAll Identity (UnColumn ts) Show, AsVinyl ts)
=> Record ts -> [String]
showFields = recordToList . rmap aux . reifyConstraint p . toVinyl
where p = Proxy :: Proxy Show
aux :: (Dict Show :. Identity) a -> Const String a
aux (Compose (Dict x)) = Const (show x)