-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add head and last functions for extracting elements of ListTable (#245)
- Loading branch information
1 parent
3e282ee
commit 0357176
Showing
7 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Rel8.Expr.List ( | ||
headExpr, | ||
indexExpr, | ||
lastExpr, | ||
) where | ||
|
||
-- base | ||
import Data.Int (Int64) | ||
import Prelude | ||
|
||
-- opaleye | ||
import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye | ||
|
||
-- rel8 | ||
import Rel8.Expr (Expr) | ||
import Rel8.Expr.Opaleye (fromPrimExpr, toPrimExpr) | ||
import Rel8.Schema.Null (Nullify) | ||
|
||
|
||
headExpr :: Expr [a] -> Expr (Nullify a) | ||
headExpr array = indexExpr array index | ||
where | ||
index = fromPrimExpr $ Opaleye.FunExpr "array_lower" [toPrimExpr array, one] | ||
where | ||
one = Opaleye.ConstExpr (Opaleye.IntegerLit 1) | ||
|
||
|
||
indexExpr :: Expr [a] -> Expr Int64 -> Expr (Nullify a) | ||
indexExpr array index = | ||
fromPrimExpr (Opaleye.ArrayIndex (toPrimExpr array) (toPrimExpr index)) | ||
|
||
|
||
lastExpr :: Expr [a] -> Expr (Nullify a) | ||
lastExpr array = indexExpr array index | ||
where | ||
index = fromPrimExpr $ Opaleye.FunExpr "array_upper" [toPrimExpr array, one] | ||
where | ||
one = Opaleye.ConstExpr (Opaleye.IntegerLit 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Rel8.Expr.NonEmpty ( | ||
head1Expr, | ||
index1Expr, | ||
last1Expr, | ||
) where | ||
|
||
-- base | ||
import Data.Int (Int64) | ||
import Data.List.NonEmpty (NonEmpty) | ||
import Prelude | ||
|
||
-- opaleye | ||
import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye | ||
|
||
-- rel8 | ||
import Rel8.Expr (Expr) | ||
import Rel8.Expr.Opaleye (fromPrimExpr, toPrimExpr) | ||
import Rel8.Schema.Null (Nullify) | ||
|
||
|
||
head1Expr :: Expr (NonEmpty a) -> Expr a | ||
head1Expr array = fromPrimExpr $ toPrimExpr $ index1Expr array index | ||
where | ||
index = fromPrimExpr $ Opaleye.FunExpr "array_lower" [toPrimExpr array, one] | ||
where | ||
one = Opaleye.ConstExpr (Opaleye.IntegerLit 1) | ||
|
||
|
||
index1Expr :: Expr (NonEmpty a) -> Expr Int64 -> Expr (Nullify a) | ||
index1Expr array index = | ||
fromPrimExpr (Opaleye.ArrayIndex (toPrimExpr array) (toPrimExpr index)) | ||
|
||
|
||
last1Expr :: Expr (NonEmpty a) -> Expr a | ||
last1Expr array = fromPrimExpr $ toPrimExpr $ index1Expr array index | ||
where | ||
index = fromPrimExpr $ Opaleye.FunExpr "array_upper" [toPrimExpr array, one] | ||
where | ||
one = Opaleye.ConstExpr (Opaleye.IntegerLit 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters