1{-# language FlexibleContexts #-}
3module Rel8.Query.Either
6 , bitraverseEitherTable
14import Rel8.Expr ( Expr )
15import Rel8.Expr.Eq ( (==.) )
16import Rel8.Query ( Query )
17import Rel8.Query.Filter ( where_ )
18import Rel8.Query.Maybe ( optional )
19import Rel8.Table.Either
20 ( EitherTable( EitherTable )
21 , isLeftTable, isRightTable
23import Rel8.Table.Maybe ( MaybeTable( MaybeTable ), isJustTable )
26-- | Filter 'EitherTable's, keeping only 'leftTable's.
27keepLeftTable :: EitherTable Expr a b -> Query a
28keepLeftTable e@(EitherTable _ a _) = do
29 where_ $ isLeftTable e
33-- | Filter 'EitherTable's, keeping only 'rightTable's.
34keepRightTable :: EitherTable Expr a b -> Query b
35keepRightTable e@(EitherTable _ _ b) = do
36 where_ $ isRightTable e
40-- | @bitraverseEitherTable f g x@ will pass all @leftTable@s through @f@ and
41-- all @rightTable@s through @g@. The results are then lifted back into
42-- @leftTable@ and @rightTable@, respectively. This is similar to 'bitraverse'
49-- x <- values (map lit [ Left True, Right (42 :: Int32) ])
50-- bitraverseEitherTable (\y -> values [y, not_ y]) (\y -> pure (y * 100)) x
56bitraverseEitherTable :: ()
59 -> EitherTable Expr a b
60 -> Query (EitherTable Expr c d)
61bitraverseEitherTable f g e@(EitherTable tag _ _) = do
62 mc@(MaybeTable _ c) <- optional (f =<< keepLeftTable e)
63 md@(MaybeTable _ d) <- optional (g =<< keepRightTable e)
64 where_ $ isJustTable mc ==. isLeftTable e
65 where_ $ isJustTable md ==. isRightTable e
66 pure $ EitherTable tag c d
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list