Copyright | © 2016–2017 Mark Karpov |
---|---|

License | BSD 3 clause |

Maintainer | Mark Karpov <markkarpov92@gmail.com> |

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 :: (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.

:: 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.

Functor 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 # | |

:: (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) |