Skip to content

Commit

Permalink
Add alignMaybeTable (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-circuithub committed Aug 12, 2022
1 parent 71392dc commit c060f6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Rel8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module Rel8
, isThisTable, isThatTable, isThoseTable
, hasHereTable, hasThereTable
, justHereTable, justThereTable
, alignMaybeTable
, alignBy
, keepHereTable, loseHereTable
, keepThereTable, loseThereTable
Expand Down
17 changes: 14 additions & 3 deletions src/Rel8/Table/These.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Rel8.Table.These
, isThisTable, isThatTable, isThoseTable
, hasHereTable, hasThereTable
, justHereTable, justThereTable
, alignMaybeTable
, aggregateTheseTable
, nameTheseTable
)
Expand All @@ -29,13 +30,13 @@ where
import Data.Bifunctor ( Bifunctor, bimap )
import Data.Kind ( Type )
import Data.Maybe ( isJust )
import Prelude hiding ( undefined )
import Prelude hiding ( null, undefined )

-- rel8
import Rel8.Aggregate ( Aggregate )
import Rel8.Expr ( Expr )
import Rel8.Expr.Bool ( (&&.), not_ )
import Rel8.Expr.Null ( isNonNull )
import Rel8.Expr.Bool ( (&&.), (||.), boolExpr, not_ )
import Rel8.Expr.Null ( null, isNonNull )
import Rel8.Kind.Context ( Reifiable )
import Rel8.Schema.Context.Nullify ( Nullifiable )
import Rel8.Schema.Dict ( Dict( Dict ) )
Expand Down Expand Up @@ -288,6 +289,16 @@ justThereTable :: TheseTable context a b -> MaybeTable context b
justThereTable = there


-- | Construct a @TheseTable@ from two 'MaybeTable's.
alignMaybeTable :: ()
=> MaybeTable Expr a
-> MaybeTable Expr b
-> MaybeTable Expr (TheseTable Expr a b)
alignMaybeTable a b = MaybeTable tag (pure (TheseTable a b))
where
tag = boolExpr null mempty (isJustTable a ||. isJustTable b)


-- | Construct a @TheseTable@. Corresponds to 'This'.
thisTable :: Table Expr b => a -> TheseTable Expr a b
thisTable a = TheseTable (justTable a) nothingTable
Expand Down

0 comments on commit c060f6b

Please sign in to comment.