Remove bind*Table

This commit is contained in:
Shane O'Brien 2021-06-18 17:18:57 +01:00
parent bff98fedbd
commit 421fe3ff76
No known key found for this signature in database
GPG Key ID: 35A00ED1B695C1A1
5 changed files with 3 additions and 45 deletions

View File

@ -56,7 +56,6 @@ module Rel8
, isNothingTable, isJustTable
, optional
, catMaybeTable
, bindMaybeTable
, traverseMaybeTable
, nameMaybeTable
@ -66,7 +65,6 @@ module Rel8
, isLeftTable, isRightTable
, keepLeftTable
, keepRightTable
, bindEitherTable
, bitraverseEitherTable
, nameEitherTable
@ -82,7 +80,6 @@ module Rel8
, keepThisTable, loseThisTable
, keepThatTable, loseThatTable
, keepThoseTable, loseThoseTable
, bindTheseTable
, bitraverseTheseTable
, nameTheseTable

View File

@ -3,23 +3,18 @@
module Rel8.Query.Either
( keepLeftTable
, keepRightTable
, bindEitherTable
, bitraverseEitherTable
)
where
-- base
import Data.Functor ( (<&>) )
import Prelude
-- rel8
import Rel8.Expr ( Expr )
import Rel8.Expr.Eq ( (==.) )
import Rel8.Query ( Query )
import Rel8.Query.Filter ( where_ )
import Rel8.Query.Maybe ( optional )
import Rel8.Table ( Table )
import Rel8.Table.Bool ( bool )
import Rel8.Table.Either
( EitherTable( EitherTable )
, isLeftTable, isRightTable
@ -41,17 +36,6 @@ keepRightTable e@(EitherTable _ _ b) = do
pure b
-- | Extend an 'EitherTable' with a 'Query' if it's a 'rightTable'. If the
-- @EitherTable@ is a 'leftTable', the original value is preserved.
--
-- This is like the '>>=' implementation for @ExceptT@.
bindEitherTable :: (Table Expr a, Functor m)
=> (i -> m (EitherTable a b)) -> EitherTable a i -> m (EitherTable a b)
bindEitherTable query e@(EitherTable input a i) = do
query i <&> \(EitherTable output a' b) ->
EitherTable (input <> output) (bool a a' (isRightTable e)) b
-- | @bitraverseEitherTable f g x@ will pass all @leftTable@s through @f@ and
-- all @rightTable@s through @g@. The results are then lifted back into
-- @leftTable@ and @rightTable@, respectively. This is similar to 'bitraverse'

View File

@ -1,13 +1,11 @@
module Rel8.Query.Maybe
( optional
, catMaybeTable
, bindMaybeTable
, traverseMaybeTable
)
where
-- base
import Data.Functor ( (<&>) )
import Prelude
-- opaleye
@ -59,19 +57,6 @@ catMaybeTable ma@(MaybeTable _ a) = do
pure a
-- | @bindMaybeTable f x@ is similar to the monadic bind (@>>=@) operation. It
-- allows you to "extend" an optional query with another query. If either the
-- input or output are 'Rel8.nothingTable', then the result is
-- 'Rel8.nothingTable'.
--
-- This is similar to 'traverseMaybeTable', followed by a @join@ on the
-- resulting @MaybeTable@s.
bindMaybeTable :: Functor m
=> (a -> m (MaybeTable b)) -> MaybeTable a -> m (MaybeTable b)
bindMaybeTable query (MaybeTable input a) =
query a <&> \(MaybeTable output b) -> MaybeTable (input <> output) b
-- | Extend an optional query with another query. This is useful if you want
-- to step through multiple @LEFT JOINs@.
--

View File

@ -7,13 +7,11 @@ module Rel8.Query.These
, keepThisTable, loseThisTable
, keepThatTable, loseThatTable
, keepThoseTable, loseThoseTable
, bindTheseTable
, bitraverseTheseTable
)
where
-- base
import Data.Functor ( (<&>) )
import Prelude
-- opaleye
@ -57,10 +55,12 @@ alignBy condition as bs =
on = toColumn . toPrimExpr . uncurry condition
-- | Filter 'TheseTable's, keeping only 'thisTable's and 'thoseTable's.
keepHereTable :: TheseTable a b -> Query (a, MaybeTable b)
keepHereTable = loseThatTable
-- | Filter 'TheseTable's, keeping on
loseHereTable :: TheseTable a b -> Query b
loseHereTable = keepThatTable
@ -112,13 +112,6 @@ loseThoseTable t@(TheseTable (MaybeTable _ a) (MaybeTable _ b)) = do
result = (mempty `asTypeOf` result) {expr = tag}
bindTheseTable :: (Table Expr a, Semigroup a, Functor m)
=> (i -> m (TheseTable a b)) -> TheseTable a i -> m (TheseTable a b)
bindTheseTable query (TheseTable here (MaybeTable input i)) =
query i <&> \(TheseTable here' (MaybeTable output b)) ->
TheseTable (here <> here') (MaybeTable (input <> output) b)
bitraverseTheseTable :: ()
=> (a -> Query c)
-> (b -> Query d)

View File

@ -101,8 +101,7 @@ instance Bind MaybeTable where
MaybeTable tag' b -> MaybeTable (tag <> tag') b
-- | Has the same behavior as the @Monad@ instance for @Maybe@. See also:
-- 'Rel8.bindMaybeTable'.
-- | Has the same behavior as the @Monad@ instance for @Maybe@.
instance Monad MaybeTable where
(>>=) = (>>-)