Skip to content

Commit c89c5a1

Browse files
committed
feat: Typed derive should add new columns to the end of the schema.
1 parent ecb804d commit c89c5a1

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/DataFrame/Typed/Operations.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ derive ::
215215
, Columnable a
216216
, AssertAbsent name cols
217217
) =>
218-
TExpr cols a -> TypedDataFrame cols -> TypedDataFrame (T.Column name a ': cols)
218+
TExpr cols a -> TypedDataFrame cols -> TypedDataFrame (Snoc cols (T.Column name a))
219219
derive (TExpr expr) (TDF df) = unsafeFreeze (D.derive colName expr df)
220220
where
221221
colName = T.pack (symbolVal (Proxy @name))

src/DataFrame/Typed/Schema.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module DataFrame.Typed.Schema (
2323
RenameInSchema,
2424
RenameManyInSchema,
2525
Append,
26+
Snoc,
2627
Reverse,
2728
ColumnNames,
2829
AssertAbsent,
@@ -76,6 +77,11 @@ type family Lookup (name :: Symbol) (cols :: [Type]) :: Type where
7677
TypeError
7778
('Text "Column '" ':<>: 'Text name ':<>: 'Text "' not found in schema")
7879

80+
-- | Add type to the end of a list.
81+
type family Snoc (xs :: [k]) (x :: k) :: [k] where
82+
Snoc '[] x = '[x]
83+
Snoc (y ': ys) x = y ': Snoc ys x
84+
7985
-- | Check whether a column name exists in a schema (type-level Bool).
8086
type family HasName (name :: Symbol) (cols :: [Type]) :: Bool where
8187
HasName name (Column name _ ': _) = 'True

0 commit comments

Comments
 (0)