pointedlist 0.3.1 → 0.3.2
raw patch · 2 files changed
+11/−8 lines, 2 files
Files
- Data/List/PointedList.hs +10/−7
- pointedlist.cabal +1/−1
Data/List/PointedList.hs view
@@ -10,6 +10,7 @@ import Data.Binary import Data.Foldable hiding (find) import Data.List hiding (length, foldl, foldr, find, elem)+import qualified Data.List as List import Data.Maybe import Data.Traversable @@ -143,8 +144,8 @@ -- focus of the sets. positions :: PointedList a -> PointedList (PointedList a) positions p@(PointedList ls x rs) = PointedList left p right- where left = unfoldr (\p -> fmap (join (,)) $ previous p) p- right = unfoldr (\p -> fmap (join (,)) $ next p) p+ where left = unfoldr (\p -> fmap (join (,)) $ previous p) p+ right = unfoldr (\p -> fmap (join (,)) $ next p) p -- | Map over the @PointedList@s created via 'positions', such that @f@ is -- called with each element of the list focused in the provided@@ -169,12 +170,14 @@ | otherwise = move n (tryNext pl) -- | Move the focus to the specified element, if it is present.+--+-- Patch with much faster algorithm provided by Runar Bjarnason for version+-- 0.3.2. find :: Eq a => a -> PointedList a -> Maybe (PointedList a)-find x pl@(PointedList a b c)- | x == b = Just pl- | x `elem` a = find x (tryPrevious pl)- | x `elem` c = find x (tryNext pl)- | otherwise = Nothing+find x pl = find' ((x ==) . focus) $ positions pl+ where find' pred (PointedList a b c) =+ if pred b then Just b+ else List.find pred (a ++ c) -- | The index of the focus. index :: PointedList a -> Int
pointedlist.cabal view
@@ -1,5 +1,5 @@ Name: pointedlist-Version: 0.3.1+Version: 0.3.2 Synopsis: A zipper-like comonad which works as a list, tracking a position. Category: Data Description: