Copyright | © 2016–2017 Mark Karpov |
---|---|
License | BSD 3 clause |
Maintainer | Mark Karpov <markkarpov92@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Data.Pagination
Description
Framework-agnostic pagination boilerplate.
- 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
Arguments
:: MonadThrow m | |
=> Natural | Page size |
-> Natural | Page index |
-> m Pagination | The pagination settings |
Create a Pagination
value. May throw PaginationException
.
pageSize :: Pagination -> Natural #
Get page size (maximum number of items on a page) from a Pagination
.
pageIndex :: Pagination -> Natural #
Get page index from a Pagination
.
Paginated data
Data in the paginated form.
Arguments
:: (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] #
Get subset of items for current page.
paginatedPagination :: Paginated a -> Pagination #
Get Pagination
parameters that were used to create this paginated
result.
paginatedPagesTotal :: Paginated a -> Natural #
Get the total number of pages in this collection.
paginatedItemsTotal :: Paginated a -> Natural #
Get the total number of items in this collection.
hasOtherPages :: Paginated a -> Bool #
Test whether there are other pages.
Arguments
:: 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 #
Is there previous page?
hasNextPage :: Paginated a -> Bool #
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.
Arguments
:: 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 #
Exception indicating various problems when working with paginated data.
Constructors
ZeroPageSize | Page size (number of items per page) was zero |
ZeroPageIndex | Page index was zero (they start from one) |