@@ -1,5 +1,7 @@
1+{-# language FlexibleContexts #-}
12{-# language FlexibleInstances #-}
23{-# language MultiParamTypeClasses #-}
4+{-# language NamedFieldPuns #-}
35{-# language ScopedTypeVariables #-}
46{-# language StandaloneKindSignatures #-}
57{-# language TypeApplications #-}
@@ -9,22 +11,24 @@
911module Rel8.Table.NonEmpty
1012 ( NonEmptyTable(..)
1113 , HNonEmptyTable
14+ , nonEmptyTable
1215 )
1316where
1417
1518-- base
1619import Data.Functor.Identity ( Identity( Identity ) )
1720import Data.Kind ( Type )
21+import Data.List.NonEmpty ( NonEmpty )
1822import Prelude
1923
2024-- rel8
2125import Rel8.Expr ( Expr, Col(..) )
22−import Rel8.Expr.Array ( sappend1 )
26+import Rel8.Expr.Array ( sappend1, snonEmptyOf )
2327import Rel8.Schema.Dict ( Dict( Dict ) )
2428import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
2529import Rel8.Schema.HTable.Vectorize ( happend, hvectorize )
2630import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
27−import Rel8.Schema.Spec ( SSpec( SSpec ) )
31+import Rel8.Schema.Spec ( SSpec(..) )
2832import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
2933import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
3034import Rel8.Table.Alternative ( AltTable, (<|>:) )
@@ -79,3 +83,10 @@ instance AltTable NonEmptyTable where
7983instance Table Expr a => Semigroup (NonEmptyTable a) where
8084 NonEmptyTable as <> NonEmptyTable bs = NonEmptyTable $
8185 happend (\_ _ (DB a) (DB b) -> DB (sappend1 a b)) as bs
86+
87+
88+nonEmptyTable :: Table Expr a => NonEmpty a -> NonEmptyTable a
89+nonEmptyTable =
90+ NonEmptyTable .
91+ hvectorize (\SSpec {info} -> DB . snonEmptyOf info . fmap unDB) .
92+ fmap toColumns