Copyright | © 2016–present Mark Karpov |
---|---|
License | BSD 3 clause |
Maintainer | Mark Karpov <markkarpov92@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Framework-agnostic pagination boilerplate.
Synopsis
- data Pagination
- mkPagination :: MonadThrow m => Natural -> Natural -> m Pagination
- pageSize :: Pagination -> Natural
- pageIndex :: Pagination -> Natural
- data Paginated a
- paginate :: (Functor m, Integral n) => Pagination -> Natural -> (n -> n -> m [a]) -> m (Paginated a)
- paginatedItems :: Paginated a -> [a]
- paginatedPagination :: Paginated a -> Pagination
- paginatedPagesTotal :: Paginated a -> Natural
- paginatedItemsTotal :: Paginated a -> Natural
- hasOtherPages :: Paginated a -> Bool
- pageRange :: Paginated a -> Natural -> NonEmpty Natural
- hasPrevPage :: Paginated a -> Bool
- hasNextPage :: Paginated a -> Bool
- backwardEllip :: Paginated a -> Natural -> Bool
- forwardEllip :: Paginated a -> Natural -> Bool
- data PaginationException
Pagination settings
data Pagination Source #
Settings that are required to organize data in paginated form.
Instances
:: MonadThrow m | |
=> Natural | Page size |
-> Natural | Page index |
-> m Pagination | The pagination settings |
Create a Pagination
value. May throw PaginationException
.
pageSize :: Pagination -> Natural Source #
Get page size (maximum number of items on a page) from a Pagination
.
pageIndex :: Pagination -> Natural Source #
Get page index from a Pagination
.
Paginated data
Data in the paginated form.
Instances
Functor Paginated Source # | |
Foldable Paginated Source # | |
Defined in Data.Pagination fold :: Monoid m => Paginated m -> m # foldMap :: Monoid m => (a -> m) -> Paginated a -> m # foldMap' :: Monoid m => (a -> m) -> Paginated a -> m # foldr :: (a -> b -> b) -> b -> Paginated a -> b # foldr' :: (a -> b -> b) -> b -> Paginated a -> b # foldl :: (b -> a -> b) -> b -> Paginated a -> b # foldl' :: (b -> a -> b) -> b -> Paginated a -> b # foldr1 :: (a -> a -> a) -> Paginated a -> a # foldl1 :: (a -> a -> a) -> Paginated a -> a # toList :: Paginated a -> [a] # length :: Paginated a -> Int # elem :: Eq a => a -> Paginated a -> Bool # maximum :: Ord a => Paginated a -> a # minimum :: Ord a => Paginated a -> a # | |
Traversable Paginated Source # | |
Eq a => Eq (Paginated a) Source # | |
Data a => Data (Paginated a) Source # | |
Defined in Data.Pagination gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Paginated a -> c (Paginated a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Paginated a) # toConstr :: Paginated a -> Constr # dataTypeOf :: Paginated a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Paginated a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Paginated a)) # gmapT :: (forall b. Data b => b -> b) -> Paginated a -> Paginated a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Paginated a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Paginated a -> r # gmapQ :: (forall d. Data d => d -> u) -> Paginated a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Paginated a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Paginated a -> m (Paginated a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Paginated a -> m (Paginated a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Paginated a -> m (Paginated a) # | |
Show a => Show (Paginated a) Source # | |
Generic (Paginated a) Source # | |
NFData a => NFData (Paginated a) Source # | |
Defined in Data.Pagination | |
type Rep (Paginated a) Source # | |
Defined in Data.Pagination type Rep (Paginated a) = D1 ('MetaData "Paginated" "Data.Pagination" "pagination-0.2.2-AqQINAW4ekDJkRmvyXQYSI" 'False) (C1 ('MetaCons "Paginated" 'PrefixI 'True) ((S1 ('MetaSel ('Just "pgItems") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]) :*: S1 ('MetaSel ('Just "pgPagination") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pagination)) :*: (S1 ('MetaSel ('Just "pgPagesTotal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Natural) :*: S1 ('MetaSel ('Just "pgItemsTotal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Natural)))) |
:: (Functor m, Integral n) | |
=> Pagination | Pagination options |
-> Natural | Total number of items |
-> (n -> n -> m [a]) | The element producing callback. The function takes arguments: offset and limit. |
-> m (Paginated a) | The paginated data |
Create paginated data.
paginatedItems :: Paginated a -> [a] Source #
Get subset of items for current page.
paginatedPagination :: Paginated a -> Pagination Source #
Get Pagination
parameters that were used to create this paginated
result.
paginatedPagesTotal :: Paginated a -> Natural Source #
Get the total number of pages in this collection.
paginatedItemsTotal :: Paginated a -> Natural Source #
Get the total number of items in this collection.
hasOtherPages :: Paginated a -> Bool Source #
Test whether there are other pages.
:: Paginated a | Paginated data |
-> Natural | Number of pages to show before and after |
-> NonEmpty Natural | Page range |
Get range of pages to show before and after the current page. This does not necessarily include the first and the last pages (they are supposed to be shown in all cases). Result of the function is always sorted.
hasPrevPage :: Paginated a -> Bool Source #
Is there previous page?
hasNextPage :: Paginated a -> Bool Source #
Is there next page?
Backward ellipsis appears when page range (pages around current page to jump to) has gap between its beginning and the first page.
:: Paginated a | Paginated data |
-> Natural | Number of pages to show before and after |
-> Bool | Do we have forward ellipsis? |
Forward ellipsis appears when page range (pages around current page to jump to) has gap between its end and the last page.
Exceptions
data PaginationException Source #
Exception indicating various problems when working with paginated data.
ZeroPageSize | Page size (number of items per page) was zero |
ZeroPageIndex | Page index was zero (they start from one) |