on master help sign in
Project individual columns out of ListTable and NonEmptyTable (#125)
6fad4d1Shane
Changelog.md+4
@@ -1,3 +1,7 @@
1+# Unreleased
2+
3+ New `$*` and `$+` operators for projecting out of `ListTable` and `NonEmptyTable` respectively (analogous to the existing `$?` for `MaybeTable`).
4+
1# 1.1.0.0 (2021-07-16)
5# 1.1.0.0 (2021-07-16)
2
6
3## New features
7## New features
src/Rel8.hs+2−2
@@ -90,7 +90,7 @@ module Rel8
90
90
91 -- ** @ListTable@
91 -- ** @ListTable@
92 , ListTable
92 , ListTable
93− , listTable
93+ , listTable, ($*)
94 , nameListTable
94 , nameListTable
95 , many
95 , many
96 , manyExpr
96 , manyExpr
@@ -99,7 +99,7 @@ module Rel8
99
99
100 -- ** @NonEmptyTable@
100 -- ** @NonEmptyTable@
101 , NonEmptyTable
101 , NonEmptyTable
102− , nonEmptyTable
102+ , nonEmptyTable, ($+)
103 , nameNonEmptyTable
103 , nameNonEmptyTable
104 , some
104 , some
105 , someExpr
105 , someExpr
src/Rel8/Schema/HTable/Vectorize.hs+8−1
@@ -22,6 +22,7 @@ module Rel8.Schema.HTable.Vectorize
22 , hvectorize, hunvectorize
22 , hvectorize, hunvectorize
23 , happend, hempty
23 , happend, hempty
24 , hproject
24 , hproject
25+ , hcolumn
25 )
26 )
26where
27where
27
28
@@ -36,9 +37,11 @@ import Rel8.FCF ( Eval, Exp )
36import Rel8.Schema.Dict ( Dict( Dict ) )
37import Rel8.Schema.Dict ( Dict( Dict ) )
37import qualified Rel8.Schema.Kind as K
38import qualified Rel8.Schema.Kind as K
38import Rel8.Schema.HTable ( HTable, hfield, htabulate, htabulateA, hspecs )
39import Rel8.Schema.HTable ( HTable, hfield, htabulate, htabulateA, hspecs )
40+import Rel8.Schema.HTable.Identity ( HIdentity( HIdentity ) )
39import Rel8.Schema.HTable.MapTable
41import Rel8.Schema.HTable.MapTable
40− ( HMapTable, HMapTableField( HMapTableField )
42+ ( HMapTable( HMapTable ), HMapTableField( HMapTableField )
41 , MapSpec, mapInfo
43 , MapSpec, mapInfo
44+ , Precompose( Precompose )
42 )
45 )
43import qualified Rel8.Schema.HTable.MapTable as HMapTable ( hproject )
46import qualified Rel8.Schema.HTable.MapTable as HMapTable ( hproject )
44import Rel8.Schema.Null ( Unnullify, NotNull, Nullity( NotNull ) )
47import Rel8.Schema.Null ( Unnullify, NotNull, Nullity( NotNull ) )
@@ -133,3 +136,7 @@ hproject :: ()
133 => (forall ctx. t ctx -> t' ctx)
136 => (forall ctx. t ctx -> t' ctx)
134 -> HVectorize list t context -> HVectorize list t' context
137 -> HVectorize list t context -> HVectorize list t' context
135hproject f (HVectorize a) = HVectorize (HMapTable.hproject f a)
138hproject f (HVectorize a) = HVectorize (HMapTable.hproject f a)
139+
140+
141+hcolumn :: HVectorize list (HIdentity a) context -> context (list a)
142+hcolumn (HVectorize (HMapTable (HIdentity (Precompose a)))) = a
src/Rel8/Table/List.hs+14−3
@@ -11,7 +11,9 @@
11
11
12module Rel8.Table.List
12module Rel8.Table.List
13 ( ListTable(..)
13 ( ListTable(..)
14+ , ($*)
15+ , listTable
14− , listTable, nameListTable
16+ , nameListTable
15 )
17 )
16where
18where
17
19
@@ -28,7 +30,7 @@ import Rel8.Schema.HTable.List ( HListTable )
28import Rel8.Schema.HTable.Vectorize
30import Rel8.Schema.HTable.Vectorize
29 ( hvectorize, hunvectorize
31 ( hvectorize, hunvectorize
30 , happend, hempty
32 , happend, hempty
31− , hproject
33+ , hproject, hcolumn
32 )
34 )
33import qualified Rel8.Schema.Kind as K
35import qualified Rel8.Schema.Kind as K
34import Rel8.Schema.Name ( Name( Name ) )
36import Rel8.Schema.Name ( Name( Name ) )
@@ -46,7 +48,9 @@ import Rel8.Table.Alternative
46 )
48 )
47import Rel8.Table.Eq ( EqTable, eqTable )
49import Rel8.Table.Eq ( EqTable, eqTable )
48import Rel8.Table.Ord ( OrdTable, ordTable )
50import Rel8.Table.Ord ( OrdTable, ordTable )
49−import Rel8.Table.Projection ( Projectable, project, apply )
51+import Rel8.Table.Projection
52+ ( Projectable, Projecting, Projection, project, apply
53+ )
50import Rel8.Table.Serialize ( ToExprs )
54import Rel8.Table.Serialize ( ToExprs )
51
55
52
56
@@ -116,6 +120,13 @@ instance (context ~ Expr, Table Expr a) =>
116 mempty = ListTable $ hempty $ \Spec {info} -> sempty info
120 mempty = ListTable $ hempty $ \Spec {info} -> sempty info
117
121
118
122
123+-- | Project a single expression out of a 'ListTable'.
124+($*) :: Projecting a (Expr b)
125+ => Projection a (Expr b) -> ListTable Expr a -> Expr [b]
126+f $* ListTable a = hcolumn $ hproject (apply f) a
127+infixl 4 $*
128+
129+
119-- | Construct a @ListTable@ from a list of expressions.
130-- | Construct a @ListTable@ from a list of expressions.
120listTable :: Table Expr a => [a] -> ListTable Expr a
131listTable :: Table Expr a => [a] -> ListTable Expr a
121listTable =
132listTable =
src/Rel8/Table/NonEmpty.hs+14−3
@@ -11,7 +11,9 @@
11
11
12module Rel8.Table.NonEmpty
12module Rel8.Table.NonEmpty
13 ( NonEmptyTable(..)
13 ( NonEmptyTable(..)
14+ , ($+)
15+ , nonEmptyTable
14− , nonEmptyTable, nameNonEmptyTable
16+ , nameNonEmptyTable
15 )
17 )
16where
18where
17
19
@@ -29,7 +31,7 @@ import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
29import Rel8.Schema.HTable.Vectorize
31import Rel8.Schema.HTable.Vectorize
30 ( hvectorize, hunvectorize
32 ( hvectorize, hunvectorize
31 , happend
33 , happend
32− , hproject
34+ , hproject, hcolumn
33 )
35 )
34import qualified Rel8.Schema.Kind as K
36import qualified Rel8.Schema.Kind as K
35import Rel8.Schema.Name ( Name( Name ) )
37import Rel8.Schema.Name ( Name( Name ) )
@@ -44,7 +46,9 @@ import Rel8.Table
44import Rel8.Table.Alternative ( AltTable, (<|>:) )
46import Rel8.Table.Alternative ( AltTable, (<|>:) )
45import Rel8.Table.Eq ( EqTable, eqTable )
47import Rel8.Table.Eq ( EqTable, eqTable )
46import Rel8.Table.Ord ( OrdTable, ordTable )
48import Rel8.Table.Ord ( OrdTable, ordTable )
47−import Rel8.Table.Projection ( Projectable, project, apply )
49+import Rel8.Table.Projection
50+ ( Projectable, Projecting, Projection, project, apply
51+ )
48import Rel8.Table.Serialize ( ToExprs )
52import Rel8.Table.Serialize ( ToExprs )
49
53
50
54
@@ -110,6 +114,13 @@ instance (Table Expr a, context ~ Expr) => Semigroup (NonEmptyTable context a)
110 happend (const sappend1) as bs
114 happend (const sappend1) as bs
111
115
112
116
117+-- | Project a single expression out of a 'NonEmptyTable'.
118+($+) :: Projecting a (Expr b)
119+ => Projection a (Expr b) -> NonEmptyTable Expr a -> Expr (NonEmpty b)
120+f $+ NonEmptyTable a = hcolumn $ hproject (apply f) a
121+infixl 4 $+
122+
123+
113-- | Construct a @NonEmptyTable@ from a non-empty list of expressions.
124-- | Construct a @NonEmptyTable@ from a non-empty list of expressions.
114nonEmptyTable :: Table Expr a => NonEmpty a -> NonEmptyTable Expr a
125nonEmptyTable :: Table Expr a => NonEmpty a -> NonEmptyTable Expr a
115nonEmptyTable =
126nonEmptyTable =