@@ -1,5 +1,7 @@
1+{-# language FlexibleContexts #-}
1{-# language FlexibleInstances #-}
2{-# language FlexibleInstances #-}
2{-# language MultiParamTypeClasses #-}
3{-# language MultiParamTypeClasses #-}
4+{-# language NamedFieldPuns #-}
3{-# language ScopedTypeVariables #-}
5{-# language ScopedTypeVariables #-}
4{-# language StandaloneKindSignatures #-}
6{-# language StandaloneKindSignatures #-}
5{-# language TypeApplications #-}
7{-# language TypeApplications #-}
@@ -9,22 +11,24 @@
9module Rel8.Table.NonEmpty
11module Rel8.Table.NonEmpty
10 ( NonEmptyTable(..)
12 ( NonEmptyTable(..)
11 , HNonEmptyTable
13 , HNonEmptyTable
16import Data.Functor.Identity ( Identity( Identity ) )
19import Data.Functor.Identity ( Identity( Identity ) )
17import Data.Kind ( Type )
20import Data.Kind ( Type )
21+import Data.List.NonEmpty ( NonEmpty )
18import Prelude
22import Prelude
21import Rel8.Expr ( Expr, Col(..) )
25import Rel8.Expr ( Expr, Col(..) )
22−import Rel8.Expr.Array ( sappend1 )
26+import Rel8.Expr.Array ( sappend1, snonEmptyOf )
23import Rel8.Schema.Dict ( Dict( Dict ) )
27import Rel8.Schema.Dict ( Dict( Dict ) )
24import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
28import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
25import Rel8.Schema.HTable.Vectorize ( happend, hvectorize )
29import Rel8.Schema.HTable.Vectorize ( happend, hvectorize )
26import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
30import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
27−import Rel8.Schema.Spec ( SSpec( SSpec ) )
31+import Rel8.Schema.Spec ( SSpec(..) )
28import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
32import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
29import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
33import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
30import Rel8.Table.Alternative ( AltTable, (<|>:) )
34import Rel8.Table.Alternative ( AltTable, (<|>:) )
@@ -79,3 +83,10 @@ instance AltTable NonEmptyTable where
79instance Table Expr a => Semigroup (NonEmptyTable a) where
83instance Table Expr a => Semigroup (NonEmptyTable a) where
80 NonEmptyTable as <> NonEmptyTable bs = NonEmptyTable $
84 NonEmptyTable as <> NonEmptyTable bs = NonEmptyTable $
81 happend (\_ _ (DB a) (DB b) -> DB (sappend1 a b)) as bs
85 happend (\_ _ (DB a) (DB b) -> DB (sappend1 a b)) as bs
88+nonEmptyTable :: Table Expr a => NonEmpty a -> NonEmptyTable a
91+ hvectorize (\SSpec {info} -> DB . snonEmptyOf info . fmap unDB) .