packages feed

pointedlist 0.2 → 0.3

raw patch · 3 files changed

+20/−1 lines, 3 filesdep +data-accessor

Dependencies added: data-accessor

Files

Data/List/PointedList.hs view
@@ -6,6 +6,7 @@  import Control.Applicative import Control.Monad+import Data.Accessor import Data.Binary import Data.Foldable hiding (find) import Data.List hiding (length, foldl, foldr, find, elem)@@ -56,6 +57,10 @@ focus :: PointedList a -> a focus (PointedList _ x _) = x +-- | Accessor to read and edit the focus.+focusA :: Accessor (PointedList a) a+focusA = accessor focus $ \b (PointedList a _ c) -> PointedList a b c+ -- | Possibly move the focus to the next element in the list. next :: PointedList a -> Maybe (PointedList a) next (PointedList _  _ []) = Nothing@@ -115,6 +120,10 @@ deleteRight (PointedList ls _ (r:rs)) = Just $ PointedList ls r rs deleteRight (PointedList (l:ls) _ []) = Just $ PointedList ls l [] +-- | Delete all elements in the list except the focus.+deleteOthers :: PointedList a -> PointedList a+deleteOthers (PointedList _ b _) = PointedList [] b []+ -- | The length of the list. length :: PointedList a -> Int length = foldr (const (+1)) 0@@ -144,6 +153,12 @@ -- > contextMap atStart (fromJust $ fromList [1..5]) contextMap :: (PointedList a -> b) -> PointedList a -> PointedList b contextMap f z = fmap f $ positions z++-- | Create a @PointedList a@ of @(a, Bool)@, in which the boolean values+--   specify whether the current element has the focus. That is, all of the+--   booleans will be @False@, except the focused element.+withFocus :: PointedList a -> PointedList (a, Bool)+withFocus (PointedList a b c) = PointedList (zip a (repeat False)) (b, True) (zip c (repeat False))  -- | Move the focus to the specified index.  move :: Int -> PointedList a -> Maybe (PointedList a)
Data/List/PointedList/Circular.hs view
@@ -16,12 +16,15 @@   , fromList   , fromListEnd   , focus+  , focusA   , insert   , insertLeft   , insertRight+  , deleteOthers   , length   , positions   , contextMap+  , withFocus   , move   , find   , index
pointedlist.cabal view
@@ -1,5 +1,5 @@ Name:          pointedlist-Version:       0.2+Version:       0.3 Synopsis:      A zipper-like comonad which works as a list, tracking a position. Category:      Data Description:@@ -16,5 +16,6 @@ Build-type:    Custom Build-depends: base>=4 Build-depends: binary+Build-depends: data-accessor Exposed-modules: Data.List.PointedList                  Data.List.PointedList.Circular