packages feed

non-empty-zipper 0.1.0.2 → 0.1.0.3

raw patch · 2 files changed

+18/−5 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Data/List/NonEmptyZipper.hs view
@@ -21,34 +21,45 @@ import           Data.List.NonEmpty (NonEmpty (..)) import           Data.Semigroup +-- | A Zipper with a "current element". The current element represent a singular,+-- focus on a single element in a list. So @NonEmptyZipper [1,2] 3 [4]@ is+-- roughly eqivelant to @[1,2,3,4]@, where @3@ is the current element. This is+-- useful, since we are now guarenteed that the current element is an element in+-- the list. data NonEmptyZipper a = NonEmptyZipper     { _before  :: ![a]+    -- ^ A list of elements preceeding the current element.     , _current :: !a+    -- ^ The current element.     , _after   :: ![a] }+    -- ^ A list of element succeeding the current element.     deriving (Show, Eq, Ord) +-- | Map to @_before@, useful as a lens before :: Functor f => ([a] -> f [a]) -> NonEmptyZipper a -> f (NonEmptyZipper a) before f x = (\c' -> x { _before = c' }) <$> f (_before x) +-- | Map to @current@, useful as a lens current :: Functor f => (a -> f a) -> NonEmptyZipper a -> f (NonEmptyZipper a) current f x = (\c' -> x { _current = c' }) <$> f (_current x) +-- | Map to @after@, useful as a lens after :: Functor f => ([a] -> f [a]) -> NonEmptyZipper a -> f (NonEmptyZipper a) after f x = (\c' -> x { _after = c' }) <$> f (_after x) +-- | Its a Functor instance Functor NonEmptyZipper where     fmap f (NonEmptyZipper xs y zs) =         NonEmptyZipper (f <$> xs) (f y) (f <$> zs) +-- | Its Applicative, but @pure@ might not be what you expect instance Applicative NonEmptyZipper where     pure x = NonEmptyZipper [x] x [x]     NonEmptyZipper fxs fy fzs <*> NonEmptyZipper xs y zs =         NonEmptyZipper (fxs <*> xs) (fy y) (fzs <*> zs) -{-|-Advance the current element forward by one.-If the current is the last element in the list, we do nothing.--}+-- | Advance the current element forward by one.+-- If the current is the last element in the list, we do nothing. next :: NonEmptyZipper a -> NonEmptyZipper a next (NonEmptyZipper xs y (z:zs)) =     NonEmptyZipper (xs <> [y]) z zs@@ -101,6 +112,8 @@ length :: NonEmptyZipper a -> Int length (NonEmptyZipper xs _ zs) = Prelude.length xs + 1 + Prelude.length zs +-- | Its a @Semigroup@ by appending the second+-- @NonEmptyZipper@ to the @_after@ list. instance Semigroup (NonEmptyZipper a) where     NonEmptyZipper xs y zs <> z =         NonEmptyZipper xs y $ zs <> toList z
non-empty-zipper.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                non-empty-zipper-version:             0.1.0.2+version:             0.1.0.3 synopsis:            The Zipper for NonEmpty description:         The Zipper for NonEmpty. Useful for things like tabs,                      button groups, and slideshows. Basically any case in which