1{-# language DerivingVia #-}
2{-# language GeneralizedNewtypeDeriving #-}
3{-# language NamedFieldPuns #-}
4{-# language StandaloneKindSignatures #-}
7 ( Aggregate(..), foldInputs, mapInputs
8 , Aggregator(..), unsafeMakeAggregate
13import Data.Functor.Const ( Const( Const ), getConst )
14import Data.Kind ( Type )
18import qualified Opaleye.Internal.Aggregate as Opaleye
19import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
20import qualified Opaleye.Internal.PackMap as Opaleye
23import Data.Functor.Apply ( Apply, WrappedApplicative(..) )
26type Aggregate :: Type -> Type
27newtype Aggregate a = Aggregate (Opaleye.Aggregator () a)
28 deriving newtype Functor
29 deriving Apply via (WrappedApplicative (Opaleye.Aggregator ()))
33 => (Maybe Aggregator -> Opaleye.PrimExpr -> b) -> Aggregate a -> b
34foldInputs f (Aggregate (Opaleye.Aggregator (Opaleye.PackMap agg))) =
35 getConst $ flip agg () $ \(aggregator, a) ->
36 Const $ f (detuplize <$> aggregator) a
38 detuplize (operation, ordering, distinction) =
39 Aggregator {operation, ordering, distinction}
43 => (Opaleye.PrimExpr -> Opaleye.PrimExpr) -> Aggregate a -> Aggregate a
44mapInputs transform (Aggregate (Opaleye.Aggregator (Opaleye.PackMap agg))) =
45 Aggregate $ Opaleye.Aggregator $ Opaleye.PackMap $ agg . \f input ->
46 f (fmap transform input)
49type Aggregator :: Type
50data Aggregator = Aggregator
51 { operation :: Opaleye.AggrOp
52 , ordering :: [Opaleye.OrderExpr]
53 , distinction :: Opaleye.AggrDistinct
57unsafeMakeAggregate :: ()
58 => (input -> Opaleye.PrimExpr)
59 -> (Opaleye.PrimExpr -> output)
63unsafeMakeAggregate input output aggregator expr =
64 Aggregate $ Opaleye.Aggregator $ Opaleye.PackMap $ \f _ ->
65 output <$> f (tuplize <$> aggregator, input expr)
67 tuplize Aggregator {operation, ordering, distinction} =
68 (operation, ordering, distinction)
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