1{-# language FlexibleContexts #-}
2{-# language TupleSections #-}
4module Rel8.Query.Evaluate
10import Control.Monad ( (>=>) )
11import Data.Foldable ( foldl' )
12import Data.List.NonEmpty ( NonEmpty( (:|) ), nonEmpty )
13import Data.Monoid ( Any( Any ) )
14import Prelude hiding ( undefined )
17import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
20import Rel8.Expr ( Expr )
21import Rel8.Expr.Bool ( (&&.) )
22import Rel8.Expr.Opaleye ( fromPrimExpr )
23import Rel8.Query ( Query( Query ) )
24import Rel8.Query.Rebind ( rebind )
25import Rel8.Table ( Table )
26import Rel8.Table.Bool ( case_ )
27import Rel8.Table.Undefined ( undefined )
30-- | 'evaluate' takes expressions that could potentially have side effects and
31-- \"runs\" them in the 'Query' monad. The returned expressions have no side
32-- effects and can safely be reused.
33evaluate :: Table Expr a => a -> Query a
34evaluate = laterally >=> rebind "eval"
37laterally :: Table Expr a => a -> Query a
38laterally a = Query $ \bindings -> pure $ (Any True,) $
39 case nonEmpty bindings of
41 Just bindings' -> case_ [(condition, a)] undefined
43 condition = foldl1' (&&.) (fmap go bindings')
45 go = fromPrimExpr . Opaleye.UnExpr Opaleye.OpIsNotNull
48foldl1' :: (a -> a -> a) -> NonEmpty a -> a
49foldl1' f (a :| as) = foldl' f a as
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