on master help sign in
Document various catList operations
commit7568c75e031452b270abb5bce03e45d9e39bc323 authorOllie Charles <ollie@ocharles.org.uk> dateFri 18 Jun 2021, 11:25 (5 years ago) parent4ec1182
1 file changed+17−1
src/Rel8/Query/List.hs+17−1
src/Rel8/Query/List.hs+17−1
@@ -42,7 +42,7 @@ import Rel8.Type.Information ( TypeInformation )
4242-- rows, this function will produce a 'Query' that returns one row containing
4343-- the empty @ListTable@. If the supplied @Query@ does return rows, @many@ will
4444-- return exactly one row, with a @ListTable@ collecting all returned rows.
45−--
45+--
4646-- @many@ is analogous to 'Control.Applicative.many' from
4747-- @Control.Applicative@.
4848many :: Table Expr a => Query a -> Query (ListTable a)
@@ -78,20 +78,36 @@ someExpr :: Sql DBType a => Query (Expr a) -> Query (Expr (NonEmpty a))
7878someExpr = aggregate . fmap nonEmptyAggExpr
7979
8080
81+-- | Expand a 'ListTable' into a 'Query', where each row in the query is an
82+-- element of the given @ListTable@.
83+--
84+-- @catListTable@ is an inverse to 'many'.
8185catListTable :: Table Expr a => ListTable a -> Query a
8286catListTable (ListTable as) = pure $ fromColumns $ runIdentity $
8387 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
8488
8589
90+-- | Expand a 'NonEmptyTable' into a 'Query', where each row in the query is an
91+-- element of the given @NonEmptyTable@.
92+--
93+-- @catNonEmptyTable@ is an inverse to 'some'.
8694catNonEmptyTable :: Table Expr a => NonEmptyTable a -> Query a
8795catNonEmptyTable (NonEmptyTable as) = pure $ fromColumns $ runIdentity $
8896 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
8997
9098
99+-- | Expand an expression that contains a list into a 'Query', where each row
100+-- in the query is an element of the given list.
101+--
102+-- @catList@ is an inverse to 'manyExpr'.
91103catList :: Sql DBType a => Expr [a] -> Query (Expr a)
92104catList = pure . sunnest typeInformation
93105
94106
107+-- | Expand an expression that contains a non-empty list into a 'Query', where
108+-- each row in the query is an element of the given list.
109+--
110+-- @catNonEmpty@ is an inverse to 'someExpr'.
95111catNonEmpty :: Sql DBType a => Expr (NonEmpty a) -> Query (Expr a)
96112catNonEmpty = pure . sunnest typeInformation
97113