on master help sign in
Document filter
18574cdOllie Charles
src/Rel8/Query/Filter.hs+7
@@ -20,6 +20,13 @@ import Rel8.Query ( Query )
20import Rel8.Query.Opaleye ( fromOpaleye )
20import Rel8.Query.Opaleye ( fromOpaleye )
21
21
22
22
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.
27+--
28+-- >>> select c $ values [ lit x | x <- [ 1..5 :: Int32 ] ] >>= filter (>. 3)
29+-- [4,5]
23filter :: (a -> Expr Bool) -> a -> Query a
30filter :: (a -> Expr Bool) -> a -> Query a
24filter f a = a <$ where_ (f a)
31filter f a = a <$ where_ (f a)
25
32