@@ -25,6 +25,8 @@ module Rel8.Tabulate
25 , difference
25 , difference
26 , aggregateTabulation
26 , aggregateTabulation
27 , optionalTabulation
27 , optionalTabulation
@@ -47,9 +49,11 @@ import Rel8.Query.Filter ( filter, where_ )
47import Rel8.Query.Maybe ( optional )
49import Rel8.Query.Maybe ( optional )
48import Rel8.Query.These ( alignBy )
50import Rel8.Query.These ( alignBy )
49import Rel8.Table ( Table )
51import Rel8.Table ( Table )
50−import Rel8.Table.Aggregate ( groupBy )
52+import Rel8.Table.Aggregate ( groupBy, listAgg, nonEmptyAgg )
51import Rel8.Table.Eq ( EqTable, (==:) )
53import Rel8.Table.Eq ( EqTable, (==:) )
52−import Rel8.Table.Maybe ( MaybeTable )
54+import Rel8.Table.List ( ListTable )
55+import Rel8.Table.Maybe ( MaybeTable, maybeTable )
56+import Rel8.Table.NonEmpty ( NonEmptyTable )
53import Rel8.Table.These ( TheseTable, theseTable )
57import Rel8.Table.These ( TheseTable, theseTable )
54import Rel8.Table.Undefined ( undefined )
58import Rel8.Table.Undefined ( undefined )
@@ -333,6 +337,20 @@ optionalTabulation as = Tabulation $ \k -> do
333 pure (Just k, ma)
337 pure (Just k, ma)
340+manyTabulation :: (EqTable k, Table Expr a)
341+ => Tabulation k a -> Tabulation k (ListTable a)
343+ fmap (maybeTable mempty id) .
344+ optionalTabulation .
345+ aggregateTabulation .
349+someTabulation :: (EqTable k, Table Expr a)
350+ => Tabulation k a -> Tabulation k (NonEmptyTable a)
351+someTabulation = aggregateTabulation . fmap nonEmptyAgg
336toQuery :: Tabulation k a -> Tabulation k (Query (k, a))
354toQuery :: Tabulation k a -> Tabulation k (Query (k, a))
337toQuery (Tabulation as) = Tabulation $ \k ->
355toQuery (Tabulation as) = Tabulation $ \k ->
338 pure (Nothing, first (fromMaybe k) <$> as k)
356 pure (Nothing, first (fromMaybe k) <$> as k)