on da76712 help sign in
rel8/src/Rel8/Query/Indexed.hs
21 lines 490 B history raw
1module Rel8.Query.Indexed
2 ( indexed
3 )
4where
6-- base
7import Control.Applicative ( liftA2 )
8import Data.Int ( Int64 )
9import Prelude
11-- rel8
12import Rel8.Expr ( Expr )
13import Rel8.Expr.Window ( rowNumber )
14import Rel8.Query ( Query )
15import Rel8.Query.Window ( window )
16import Rel8.Table.Window ( currentRow )
19-- | Pair each row of a query with its index within the query.
20indexed :: Query a -> Query (Expr Int64, a)
21indexed = window (liftA2 (,) (subtract 1 <$> rowNumber) currentRow)