on master help sign in
Add someTabulation and manyTabulation
commite48c73e1e942d7a87a555264c4f0436994dff649 authorShane O'Brien <shane.obrien@circuithub.com> dateThu 6 May 2021, 23:05 (6 years ago) parent8cb6d48
1 file changed+20−2
src/Rel8/Tabulate.hs+20−2
src/Rel8/Tabulate.hs+20−2
@@ -25,6 +25,8 @@ module Rel8.Tabulate
2525 , difference
2626 , aggregateTabulation
2727 , optionalTabulation
28+ , manyTabulation
29+ , someTabulation
2830 )
2931where
3032
@@ -47,9 +49,11 @@ import Rel8.Query.Filter ( filter, where_ )
4749import Rel8.Query.Maybe ( optional )
4850import Rel8.Query.These ( alignBy )
4951import Rel8.Table ( Table )
50−import Rel8.Table.Aggregate ( groupBy )
52+import Rel8.Table.Aggregate ( groupBy, listAgg, nonEmptyAgg )
5153import 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 )
5357import Rel8.Table.These ( TheseTable, theseTable )
5458import Rel8.Table.Undefined ( undefined )
5559
@@ -333,6 +337,20 @@ optionalTabulation as = Tabulation $ \k -> do
333337 pure (Just k, ma)
334338
335339
340+manyTabulation :: (EqTable k, Table Expr a)
341+ => Tabulation k a -> Tabulation k (ListTable a)
342+manyTabulation =
343+ fmap (maybeTable mempty id) .
344+ optionalTabulation .
345+ aggregateTabulation .
346+ fmap listAgg
347+
348+
349+someTabulation :: (EqTable k, Table Expr a)
350+ => Tabulation k a -> Tabulation k (NonEmptyTable a)
351+someTabulation = aggregateTabulation . fmap nonEmptyAgg
352+
353+
336354toQuery :: Tabulation k a -> Tabulation k (Query (k, a))
337355toQuery (Tabulation as) = Tabulation $ \k ->
338356 pure (Nothing, first (fromMaybe k) <$> as k)