pagination 0.2.2 → 0.2.3
raw patch · 6 files changed
+54/−58 lines, 6 filesdep ~QuickChecksetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: QuickCheck
API changes (from Hackage documentation)
- Data.Pagination: instance Data.Data.Data Data.Pagination.Pagination
- Data.Pagination: instance Data.Data.Data Data.Pagination.PaginationException
- Data.Pagination: instance Data.Data.Data a => Data.Data.Data (Data.Pagination.Paginated a)
- Data.Pagination: instance Data.Foldable.Foldable Data.Pagination.Paginated
- Data.Pagination: instance Data.Traversable.Traversable Data.Pagination.Paginated
- Data.Pagination: instance GHC.Base.Functor Data.Pagination.Paginated
- Data.Pagination: instance GHC.Exception.Type.Exception Data.Pagination.PaginationException
- Data.Pagination: instance GHC.Generics.Generic (Data.Pagination.Paginated a)
- Data.Pagination: instance GHC.Generics.Generic Data.Pagination.Pagination
- Data.Pagination: instance GHC.Generics.Generic Data.Pagination.PaginationException
- Data.Pagination: instance GHC.Show.Show Data.Pagination.Pagination
- Data.Pagination: instance GHC.Show.Show Data.Pagination.PaginationException
- Data.Pagination: instance GHC.Show.Show a => GHC.Show.Show (Data.Pagination.Paginated a)
+ Data.Pagination: instance GHC.Internal.Base.Functor Data.Pagination.Paginated
+ Data.Pagination: instance GHC.Internal.Data.Data.Data Data.Pagination.Pagination
+ Data.Pagination: instance GHC.Internal.Data.Data.Data Data.Pagination.PaginationException
+ Data.Pagination: instance GHC.Internal.Data.Data.Data a => GHC.Internal.Data.Data.Data (Data.Pagination.Paginated a)
+ Data.Pagination: instance GHC.Internal.Data.Foldable.Foldable Data.Pagination.Paginated
+ Data.Pagination: instance GHC.Internal.Data.Traversable.Traversable Data.Pagination.Paginated
+ Data.Pagination: instance GHC.Internal.Exception.Type.Exception Data.Pagination.PaginationException
+ Data.Pagination: instance GHC.Internal.Generics.Generic (Data.Pagination.Paginated a)
+ Data.Pagination: instance GHC.Internal.Generics.Generic Data.Pagination.Pagination
+ Data.Pagination: instance GHC.Internal.Generics.Generic Data.Pagination.PaginationException
+ Data.Pagination: instance GHC.Internal.Show.Show Data.Pagination.Pagination
+ Data.Pagination: instance GHC.Internal.Show.Show Data.Pagination.PaginationException
+ Data.Pagination: instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Data.Pagination.Paginated a)
Files
- CHANGELOG.md +4/−0
- Data/Pagination.hs +22/−21
- README.md +2/−2
- Setup.hs +0/−6
- pagination.cabal +17/−18
- tests/Main.hs +9/−11
CHANGELOG.md view
@@ -1,3 +1,7 @@+## Pagination 0.2.3++* The test suite works with `QuickCheck-2.19`.+ ## Pagination 0.2.2 * Works with 9.0.1. Dropped support for GHC 8.6 and older.
Data/Pagination.hs view
@@ -43,39 +43,39 @@ import Control.Monad.Catch import Data.Data (Data) import Data.List.NonEmpty (NonEmpty (..))-import qualified Data.List.NonEmpty as NE-import Data.Typeable (Typeable)+import Data.List.NonEmpty qualified as NE import GHC.Generics import Numeric.Natural ---------------------------------------------------------------------------- -- Pagination settings --- | Settings that are required to organize data in paginated form.+-- | Pagination settings. data Pagination = Pagination Natural Natural- deriving (Eq, Show, Data, Typeable, Generic)+ deriving (Eq, Show, Data, Generic) instance NFData Pagination -- | Create a 'Pagination' value. May throw 'PaginationException'. mkPagination ::- MonadThrow m =>+ (MonadThrow m) => -- | Page size Natural -> -- | Page index Natural ->- -- | The pagination settings+ -- | Pagination settings m Pagination mkPagination size index | size == 0 = throwM ZeroPageSize | index == 0 = throwM ZeroPageIndex | otherwise = return (Pagination size index) --- | Get page size (maximum number of items on a page) from a 'Pagination'.+-- | Get the page size (the maximum number of items on a page) from a+-- 'Pagination'. pageSize :: Pagination -> Natural pageSize (Pagination size _) = size --- | Get page index from a 'Pagination'.+-- | Get the page index from a 'Pagination'. pageIndex :: Pagination -> Natural pageIndex (Pagination _ index) = index @@ -89,9 +89,9 @@ pgPagesTotal :: Natural, pgItemsTotal :: Natural }- deriving (Eq, Show, Data, Typeable, Generic, Functor)+ deriving (Eq, Show, Data, Generic, Functor) -instance NFData a => NFData (Paginated a)+instance (NFData a) => NFData (Paginated a) instance Foldable Paginated where foldr f x = foldr f x . pgItems@@ -128,7 +128,7 @@ index = min index' totalPages offset = (index - 1) * size --- | Get subset of items for current page.+-- | Get the items for the current page. paginatedItems :: Paginated a -> [a] paginatedItems = pgItems @@ -149,17 +149,18 @@ hasOtherPages :: Paginated a -> Bool hasOtherPages Paginated {..} = pgPagesTotal > 1 --- | Is there previous page?+-- | Is there a previous page? hasPrevPage :: Paginated a -> Bool hasPrevPage Paginated {..} = pageIndex pgPagination > 1 --- | Is there next page?+-- | Is there a next page? hasNextPage :: Paginated a -> Bool hasNextPage Paginated {..} = pageIndex pgPagination < pgPagesTotal --- | 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.+-- | Get the 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). The result of the function is always+-- sorted. pageRange :: -- | Paginated data Paginated a ->@@ -177,8 +178,8 @@ | otherwise = index - n - 1 in (+ shift) <$> NE.fromList [1 .. len] --- | Backward ellipsis appears when page range (pages around current page to--- jump to) has gap between its beginning and the first page.+-- | Backward ellipsis appears when the page range (pages around the current+-- page to jump to) has a gap between its beginning and the first page. backwardEllip :: -- | Paginated data Paginated a ->@@ -187,8 +188,8 @@ Bool backwardEllip p n = NE.head (pageRange p n) > 2 --- | Forward ellipsis appears when page range (pages around current page to--- jump to) has gap between its end and the last page.+-- | Forward ellipsis appears when the page range (pages around the current+-- page to jump to) has a gap between its end and the last page. forwardEllip :: -- | Paginated data Paginated a ->@@ -207,7 +208,7 @@ ZeroPageSize | -- | Page index was zero (they start from one) ZeroPageIndex- deriving (Eq, Show, Data, Typeable, Generic)+ deriving (Eq, Show, Data, Generic) instance NFData PaginationException
README.md view
@@ -4,7 +4,7 @@ [](https://hackage.haskell.org/package/pagination) [](http://stackage.org/nightly/package/pagination) [](http://stackage.org/lts/package/pagination)-+[](https://github.com/mrkkrp/pagination/actions/workflows/ci.yaml) The package implements pagination boilerplate in a framework-agnostic way. @@ -19,4 +19,4 @@ Copyright © 2016–present Mark Karpov -Distributed under BSD 3 clause license.+Distributed under the BSD 3-clause license.
− Setup.hs
@@ -1,6 +0,0 @@-module Main (main) where--import Distribution.Simple--main :: IO ()-main = defaultMain
pagination.cabal view
@@ -1,11 +1,11 @@-cabal-version: 1.18+cabal-version: 2.4 name: pagination-version: 0.2.2-license: BSD3+version: 0.2.3+license: BSD-3-Clause license-file: LICENSE.md maintainer: Mark Karpov <markkarpov92@gmail.com> author: Mark Karpov <markkarpov92@gmail.com>-tested-with: ghc ==8.8.4 ghc ==8.10.4 ghc ==9.0.1+tested-with: ghc ==9.10.3 ghc ==9.12.4 ghc ==9.14.1 homepage: https://github.com/mrkkrp/pagination bug-reports: https://github.com/mrkkrp/pagination/issues synopsis: Framework-agnostic pagination boilerplate@@ -27,37 +27,36 @@ library exposed-modules: Data.Pagination- default-language: Haskell2010+ default-language: GHC2021 build-depends:- base >=4.13 && <5.0,- deepseq >=1.3 && <1.5,+ base >=4.15 && <5,+ deepseq >=1.3 && <1.6, exceptions >=0.6 && <0.11 if flag(dev)- ghc-options: -Wall -Werror+ ghc-options:+ -Wall -Werror -Wredundant-constraints -Wpartial-fields+ -Wunused-packages -haddock -Winvalid-haddock else ghc-options: -O2 -Wall - if flag(dev)- ghc-options:- -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns- -Wnoncanonical-monad-instances- test-suite tests type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: tests- default-language: Haskell2010+ default-language: GHC2021 build-depends:- base >=4.13 && <5.0,- QuickCheck >=2.10 && <3.0,+ base >=4.15 && <5,+ QuickCheck >=2.17 && <3, exceptions >=0.6 && <0.11,- hspec >=2.0 && <3.0,+ hspec >=2 && <3, pagination if flag(dev)- ghc-options: -Wall -Werror+ ghc-options:+ -Wall -Werror -Wredundant-constraints -Wpartial-fields+ -Wunused-packages -haddock -Winvalid-haddock else ghc-options: -O2 -Wall
tests/Main.hs view
@@ -6,7 +6,7 @@ import Control.Monad import Control.Monad.Catch (SomeException, fromException) import Data.List.NonEmpty (NonEmpty (..))-import qualified Data.List.NonEmpty as NE+import Data.List.NonEmpty qualified as NE import Data.Maybe (fromJust) import Data.Pagination import Numeric.Natural@@ -43,7 +43,7 @@ describe "Foldable instance of Paginated" $ it "foldr works like with lists" $ property $ \p n ->- let f :: Foldable f => f Int -> Int+ let f :: (Foldable f) => f Int -> Int f = foldr (+) n in f p === f (paginatedItems p) describe "Traversable instance of Paginated" $@@ -145,9 +145,6 @@ ---------------------------------------------------------------------------- -- Arbitrary instances -instance Arbitrary Natural where- arbitrary = fromInteger . getNonNegative <$> arbitrary- instance Arbitrary Pagination where arbitrary = do size <- p@@ -156,7 +153,7 @@ where p = arbitrary `suchThat` (> 0) -instance Arbitrary a => Arbitrary (Paginated a) where+instance (Arbitrary a) => Arbitrary (Paginated a) where arbitrary = do pagination <- arbitrary total <- arbitrary@@ -166,14 +163,15 @@ ---------------------------------------------------------------------------- -- Helpers --- | Run computation inside 'MonadThrow' and return result as an 'Either'.+-- | Run a computation inside 'MonadThrow' and return its result as an+-- 'Either'. asEither :: Either SomeException a -> Either PaginationException a asEither = either (Left . fromJust . fromException) Right -- | Calculate number of items in paginated selection given total number of -- items, offset, and limit. plen ::- Integral n =>+ (Integral n) => -- | Total items Natural -> -- | Offset@@ -183,10 +181,10 @@ n plen total offset limit = fromIntegral (min (total - offset) limit) --- | Calculate total number of pages given total number of items, and page--- size.+-- | Calculate the total number of pages given the total number of items,+-- and the page size. ptotal ::- Integral n =>+ (Integral n) => -- | Total items Natural -> -- | Page size