packages feed

zipper-extra 0.1.2.1 → 0.1.3.0

raw patch · 3 files changed

+40/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.Comonad.Zipper.Extra: ElemNotFoundException :: a -> [a] -> ElemNotFoundException a
+ Control.Comonad.Zipper.Extra: EmptyZipper :: ZipperException
+ Control.Comonad.Zipper.Extra: data ElemNotFoundException a
+ Control.Comonad.Zipper.Extra: data ZipperException
+ Control.Comonad.Zipper.Extra: elemIndexThrow :: (MonadThrow m, Eq a, Typeable a, Show a) => a -> [a] -> m Int
+ Control.Comonad.Zipper.Extra: instance (Data.Typeable.Internal.Typeable a, GHC.Show.Show a) => GHC.Exception.Type.Exception (Control.Comonad.Zipper.Extra.ElemNotFoundException a)
+ Control.Comonad.Zipper.Extra: instance GHC.Classes.Eq a => GHC.Classes.Eq (Control.Comonad.Zipper.Extra.ElemNotFoundException a)
+ Control.Comonad.Zipper.Extra: instance GHC.Show.Show a => GHC.Show.Show (Control.Comonad.Zipper.Extra.ElemNotFoundException a)
+ Control.Comonad.Zipper.Extra: seekOn :: Eq b => (a -> b) -> b -> Zipper [] a -> Maybe (Zipper [] a)
+ Control.Comonad.Zipper.Extra: seekOnThrow :: (MonadThrow m, Eq b, Typeable b, Show b) => (a -> b) -> b -> Zipper [] a -> m (Zipper [] a)

Files

ChangeLog.md view
@@ -1,13 +1,17 @@ # Changelog for zipper-extra +## v0.1.3.0++* Add `seekOn` and `seekOnThrow` and related exceptions.+ ## v0.1.2.0 -Add `zipper'`, `MonadThrow` version of regular `zipper`.+* Add `zipper'`, `MonadThrow` version of regular `zipper`.  ## v0.1.1.0 -Add paginate' and exception handling for pagination failure.+* Add paginate' and exception handling for pagination failure.  ## v0.1.0.0 -Reexport `Control.Comonad.Store.Zipper` with some utility functions.+* Reexport `Control.Comonad.Store.Zipper` with some utility functions.
src/Control/Comonad/Zipper/Extra.hs view
@@ -11,11 +11,17 @@ , zipperPreviousMaybe , zipperWithin , zipper'+, ZipperException(..)+, elemIndexThrow+, ElemNotFoundException(..)+, seekOn+, seekOnThrow ) where  import Control.Monad.Catch import Control.Comonad.Store import Control.Comonad.Store.Zipper+import Data.List import Data.List.Split import Data.Typeable @@ -60,3 +66,28 @@ -- | Like `zipper` but lifted to `MonadThrow`. zipper' :: (MonadThrow m, Traversable t) => t a -> m (Zipper t a) zipper' xs = maybe (throwM EmptyZipper) return $ zipper xs++data ElemNotFoundException a = ElemNotFoundException a [a]+    deriving (Show, Eq, Typeable)++instance (Typeable a, Show a) => Exception (ElemNotFoundException a) where+  displayException (ElemNotFoundException x xs) = "Elem " <> show x <> " not found in " <> show xs++-- | Lifted version of `Data.List.elemIndex` that throws an `ElemNotFoundException` if the target does not exist.+elemIndexThrow :: (MonadThrow m, Eq a, Typeable a, Show a) => a -> [a] -> m Int+elemIndexThrow x xs = case elemIndex x xs of+  Nothing -> throwM $ ElemNotFoundException x xs+  Just a -> return a++-- | Seek on a property of the elements of the zipper. Finds the index of the element to search for+--   and moves the tape to that position.+seekOn :: Eq b => (a -> b) -> b -> Zipper [] a -> Maybe (Zipper [] a)+seekOn f x ys = do+  k <- elemIndex x (f <$> unzipper ys)+  return $ seek k ys++-- | Lifted version of `seekOn` which throws an `ElemNotFoundException` if the target does not exist.+seekOnThrow :: (MonadThrow m, Eq b, Typeable b, Show b) => (a -> b) -> b -> Zipper [] a -> m (Zipper [] a)+seekOnThrow f x ys = do+  k <- elemIndexThrow x (f <$> unzipper ys)+  return $ seek k ys
zipper-extra.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: efbea88d20acdb5ae2f378dea5468ec8ea1e03c4b193105398ed5499d4d25184+-- hash: b0aba807b4c0f0eef767d30ec62bf9c0df2baee33ef15205c7b9e6a864ffcae4  name:           zipper-extra-version:        0.1.2.1+version:        0.1.3.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