Copyright | © 2016 Mark Karpov |
---|---|

License | BSD 3 clause |

Maintainer | Mark Karpov <markkarpov@openmailbox.org> |

Stability | experimental |

Portability | portable |

Safe Haskell | Safe |

Language | Haskell2010 |

Framework-agnostic pagination boilerplate.

- data Pagination
- mkPagination :: MonadThrow m => Natural -> Natural -> m Pagination
- pageSize :: Pagination -> Natural
- pageIndex :: Pagination -> Natural
- data Paginated a
- paginate :: (Monad 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 #

The data type represents settings that are required to organize data in paginated form.

:: MonadThrow m | |

=> Natural | Page size |

-> Natural | Page index |

-> m Pagination | The pagination settings |

Create a `Pagination`

value. Throws `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 paginated form.

Functor Paginated Source # | |

Applicative Paginated Source # | |

Foldable Paginated Source # | |

Traversable Paginated Source # | |

Eq a => Eq (Paginated a) Source # | |

Data a => Data (Paginated a) Source # | |

Show a => Show (Paginated a) Source # | |

Generic (Paginated a) Source # | |

NFData a => NFData (Paginated a) Source # | |

type Rep (Paginated a) Source # | |

:: (Monad 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 total number of pages in this collection.

paginatedItemsTotal :: Paginated a -> Natural Source #

Get 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 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) |