packages feed

pointedlist 0.4.0.1 → 0.4.0.2

raw patch · 2 files changed

+35/−33 lines, 2 filesdep +derivedep ~fclabels

Dependencies added: derive

Dependency ranges changed: fclabels

Files

Data/List/PointedList.hs view
@@ -8,7 +8,8 @@  import Control.Applicative import Control.Monad-import Data.Binary ()+import Data.Binary+import Data.DeriveTH import Data.Foldable hiding (find) import Data.List hiding (length, foldl, foldr, find, elem) import qualified Data.List as List@@ -22,13 +23,11 @@   { reversedPrefix :: [a]   , _focus         :: a   , suffix         :: [a]-  } deriving ({-! Binary !-})+  } deriving (Eq) +$(derive makeBinary ''PointedList) $(mkLabels [''PointedList]) --- | Focus element accessor label.-focus :: PointedList a :-> a- instance (Show a) => Show (PointedList a) where  show (PointedList ls x rs) = show (reverse ls) ++ " " ++ show x ++ " " ++ show rs @@ -67,7 +66,7 @@  -- | Replace the focus of the list, retaining the prefix and suffix. replace :: a -> PointedList a -> PointedList a-replace = set focus+replace = setL focus  -- | Possibly move the focus to the next element in the list. next :: PointedList a -> Maybe (PointedList a)@@ -169,22 +168,23 @@ withFocus (PointedList a b c) =     PointedList (zip a (repeat False)) (b, True) (zip c (repeat False)) --- | Move the focus to the specified index. +-- | Move the focus to the specified index. The first element is at index 0. moveTo :: Int -> PointedList a -> Maybe (PointedList a)-moveTo n pl@(PointedList a _ _)-    | n < 0     = Nothing-    | atEnd pl  = Nothing-    | i == n    = Just pl-    | i >  n    = moveTo n $ tryPrevious pl-    | otherwise = moveTo n $ tryNext pl-  where i = index pl -- Cache length of the prefix+moveTo n pl = moveN (n - (index pl)) pl   -- | Move the focus by @n@, relative to the current index. Negative values move --   the focus backwards, positive values more forwards through the list. moveN :: Int -> PointedList a -> Maybe (PointedList a)-moveN 0 pl = Just pl-moveN n pl | n < 0 = maybe Nothing (moveN (n+1)) $ previous pl-           | n > 0 = maybe Nothing (moveN (n-1)) $ next pl+moveN n pl@(PointedList left x right) = go n left x right +  where+  go n left x right = case compare n 0 of+   GT -> case right of+     [] -> Nothing+     (r:rs) -> go (n-1) (x:left) r rs+   LT -> case left of+     [] -> Nothing+     (l:ls) -> go (n+1) ls l (x:right)+   EQ -> Just $ PointedList left x right  -- | Move the focus to the specified element, if it is present. --@@ -192,21 +192,13 @@ --   0.3.2. Improved again by Runar Bjarnason for version 0.3.3 to support --   infinite lists on both sides of the focus. find :: Eq a => a -> PointedList a -> Maybe (PointedList a)-find x pl = find' ((x ==) . (get focus)) $ positions pl+find x pl = find' ((x ==) . (getL focus)) $ positions pl   where find' pred (PointedList a b c) =           if pred b then Just b                     else List.find pred (merge a c)         merge []     ys = ys         merge (x:xs) ys = x : merge ys xs --- | The index of the focus.+-- | The index of the focus, leftmost is 0. index :: PointedList a -> Int index (PointedList a _ _) = Prelude.length a---- GENERATED START-- -instance (Eq a) => Eq (PointedList a) where-        PointedList x1 x2 x3 == PointedList y1 y2 y3-          = x1 == y1 && x2 == y2 && x3 == y3--- GENERATED STOP
pointedlist.cabal view
@@ -1,5 +1,5 @@ Name:          pointedlist-Version:       0.4.0.1+Version:       0.4.0.2 Synopsis:      A zipper-like comonad which works as a list, tracking a position. Category:      Data Description:@@ -13,9 +13,19 @@ License-file:  LICENSE Author:        Jeff Wheeler Maintainer:    jeffwheeler@gmail.com+ Build-type:    Simple-Build-depends: base >= 4 && < 5-Build-depends: binary-Build-depends: fclabels < 0.5-Exposed-modules: Data.List.PointedList-                 Data.List.PointedList.Circular+Cabal-version: >= 1.6++Source-repository head+  type:     git+  location: git://github.com/jeffwheeler/pointedlist.git++Library+  Build-depends: base >= 4 && < 5+  Build-depends: binary+  Build-depends: fclabels > 0.11.0 && < 0.12+  Build-depends: derive++  Exposed-modules: Data.List.PointedList+                   Data.List.PointedList.Circular