Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Frames/Melt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ type family RDeleteAll ss ts where
RDeleteAll '[] ts = ts
RDeleteAll (s ': ss) ts = RDeleteAll ss (RDelete s ts)

transform :: forall rs as bs . (as ⊆ rs, RDeleteAll as rs ⊆ rs)
=> (Record as -> Record bs) -> Record rs -> Record (RDeleteAll as rs ++ bs)
transform f xs = rcast @(RDeleteAll as rs) xs `rappend` f (rcast xs)

-- | Rename a column
retypeColumn :: forall x y rs . ( V.KnownField x
, V.KnownField y
, V.Snd x ~ V.Snd y
, ElemOf rs x
, RDelete x rs ⊆ rs)
=> Record rs -> Record (RDelete x rs V.++ '[y])
retypeColumn = transform @rs @'[x] @'[y] (\r -> (rgetField @x r &: V.RNil))

-- | This is 'melt', but the variables are at the front of the record,
-- which reads a bit odd.
meltRow' :: forall proxy vs ts ss. (vs ⊆ ts, ss ⊆ ts, vs ~ RDeleteAll ss ts,
Expand Down