packages feed

zipper-extra 0.1.0.1 → 0.1.1.0

raw patch · 3 files changed

+29/−4 lines, 3 filesdep +exceptionsPVP ok

version bump matches the API change (PVP)

Dependencies added: exceptions

API changes (from Hackage documentation)

+ Control.Comonad.Zipper.Extra: EmptyContentsError :: PaginationException
+ Control.Comonad.Zipper.Extra: UnknownPaginationException :: PaginationException
+ Control.Comonad.Zipper.Extra: ZeroPageSize :: PaginationException
+ Control.Comonad.Zipper.Extra: data PaginationException
+ Control.Comonad.Zipper.Extra: instance GHC.Classes.Eq Control.Comonad.Zipper.Extra.PaginationException
+ Control.Comonad.Zipper.Extra: instance GHC.Exception.Type.Exception Control.Comonad.Zipper.Extra.PaginationException
+ Control.Comonad.Zipper.Extra: instance GHC.Show.Show Control.Comonad.Zipper.Extra.PaginationException
+ Control.Comonad.Zipper.Extra: paginate' :: MonadThrow m => Int -> [a] -> m (Zipper [] [a])

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for zipper-extra +## v0.1.1.0++Add paginate' and exception handling for pagination failure.+ ## v0.1.0.0  Reexport `Control.Comonad.Store.Zipper` with some utility functions.
src/Control/Comonad/Zipper/Extra.hs view
@@ -5,19 +5,40 @@ , Control.Comonad.Store.Zipper.unzipper , Control.Comonad.Store.Zipper.size , paginate+, paginate'+, PaginationException(..) , zipperNextMaybe , zipperPreviousMaybe , zipperWithin ) where +import Control.Monad.Catch+import Control.Exception import Control.Comonad.Store import Control.Comonad.Store.Zipper import Data.List.Split+import Data.Typeable  -- | Turn a list into a zipper of chunks of length n paginate :: Int -> [a] -> Maybe (Zipper [] [a]) paginate n = zipper . chunksOf n +data PaginationException = EmptyContentsError | ZeroPageSize | UnknownPaginationException+  deriving (Show, Eq, Typeable)++instance Exception PaginationException where+  displayException EmptyContentsError         = "Can not create a Zipper of length zero."+  displayException ZeroPageSize               = "Can not divide into pages of size zero."+  displayException UnknownPaginationException = "Unknown pagination exception."++-- | Like `paginate`, but throw an exception if it can't create the zipper.+paginate' :: MonadThrow m => Int -> [a] -> m (Zipper [] [a])+paginate' n xs = case paginate n xs of+                    Just x -> return x+                    Nothing -> if n == 0 then throwM ZeroPageSize+                               else if length xs == 0 then throwM EmptyContentsError+                               else throwM UnknownPaginationException+ -- | Return the peek of the next element if it exists. zipperNextMaybe :: Zipper t a -> Maybe a zipperNextMaybe xs = if pos xs < size xs-1 then Just (peeks (+1) xs) else Nothing@@ -26,7 +47,6 @@ zipperPreviousMaybe :: Zipper t a -> Maybe a zipperPreviousMaybe xs = if pos xs > 0 then Just (peeks (+ (-1)) xs) else Nothing --- | Return a list of elements within 'r' hops either side of the zipper target.+-- Return a list of elements within 'r' hops either side of the zipper target. zipperWithin :: Int -> Zipper t a -> [a] zipperWithin r xs = (`peek` xs) <$>  [(max 0 (pos xs - r)) .. (min (size xs -1) (pos xs + r))]-
zipper-extra.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: fa71157dc7a8376ed0e8f8a20812d39df880a96a1eda7888c3ae86b87c2e18a9+-- hash: e264b1d11839e03ca02e542e1a114ee5af7a47a5bca3ad75cacf1cfd5bfc49e4  name:           zipper-extra-version:        0.1.0.1+version:        0.1.1.0 synopsis:       Zipper utils that weren't in Control.Comonad.Store.Zipper description:    Adds some utility functions for and reexports Control.Comonad.Store.Zipper category:       Comonads@@ -32,5 +32,6 @@       base >=4.7 && <5     , comonad     , comonad-extras+    , exceptions     , split   default-language: Haskell2010