-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathCommon.hs
More file actions
33 lines (27 loc) · 1.07 KB
/
Common.hs
File metadata and controls
33 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
module GitHub.Data.Actions.Common (
WithTotalCount(..),
) where
import GitHub.Internal.Prelude
import Prelude ()
-------------------------------------------------------------------------------
-- Common
-------------------------------------------------------------------------------
-- | A page of a paginated response.
data WithTotalCount a = WithTotalCount
{ withTotalCountItems :: !(Vector a)
-- ^ A snippet of the answer.
, withTotalCountTotalCount :: !Int
-- ^ The total size of the answer.
}
deriving (Show, Data, Eq, Ord, Generic)
-- | Joining two pages of a paginated response.
-- The 'withTotalCountTotalCount' is assumed to be the same in both pages,
-- but this is not checked.
instance Semigroup (WithTotalCount a) where
WithTotalCount items1 count1 <> WithTotalCount items2 _ =
WithTotalCount (items1 <> items2) count1
instance Foldable WithTotalCount where
foldMap f (WithTotalCount items _) = foldMap f items