1module Rel8.Query.Filter
8import Prelude hiding ( filter )
11import qualified Opaleye.Operators as Opaleye
14import Data.Profunctor ( lmap )
17import Rel8.Expr ( Expr )
18import Rel8.Expr.Opaleye ( toColumn, toPrimExpr )
19import Rel8.Query ( Query )
20import Rel8.Query.Opaleye ( fromOpaleye )
23-- | @filter f x@ will be a zero-row query when @f x@ is @False@, and will
24-- return @x@ unchanged when @f x@ is @True@. This is similar to
25-- 'Control.Monad.guard', but as the predicate is separate from the argument,
26-- it is easy to use in a pipeline of 'Query' transformations.
27filter :: (a -> Expr Bool) -> a -> Query a
28filter f a = a <$ where_ (f a)
31-- | Drop any rows that don't match a predicate. @where_ expr@ is equivalent
32-- to the SQL @WHERE expr@.
33where_ :: Expr Bool -> Query ()
35 fromOpaleye $ lmap (\_ -> toColumn $ toPrimExpr condition) Opaleye.restrict
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