1{-# language FlexibleContexts #-}
2{-# language TypeFamilies #-}
3{-# language ViewPatterns #-}
15import Rel8.Expr ( Expr, Col(..) )
16import Rel8.Expr.Bool ( boolExpr, caseExpr )
17import Rel8.Schema.HTable ( htabulate, hfield )
18import Rel8.Table ( Table, fromColumns, toColumns )
21-- | An if-then-else expression on tables.
23-- @bool x y p@ returns @x@ if @p@ is @False@, and returns @y@ if @p@ is
25bool :: Table Expr a => a -> a -> Expr Bool -> a
26bool (toColumns -> false) (toColumns -> true) condition =
27 fromColumns $ htabulate $ \field ->
28 case (hfield false field, hfield true field) of
29 (DB falseExpr, DB trueExpr) ->
30 DB (boolExpr falseExpr trueExpr condition)
34-- | Produce a table expression from a list of alternatives. Returns the first
35-- table where the @Expr Bool@ expression is @True@. If no alternatives are
36-- true, the given default is returned.
37case_ :: Table Expr a => [(Expr Bool, a)] -> a -> a
38case_ (map (fmap toColumns) -> branches) (toColumns -> fallback) =
39 fromColumns $ htabulate $ \field -> case hfield fallback field of
41 case map (fmap (unDB . (`hfield` field))) branches of
42 branchExprs -> DB (caseExpr branchExprs fallbackExpr)
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