module Data.List.PointedList.Circular
(
module Data.List.PointedList
, next
, previous
, delete
, deleteLeft
, deleteRight
, moveN
) where
import Data.List.PointedList
( PointedList(..)
, focus
, singleton
, fromList
, fromListEnd
, replace
, insert
, insertLeft
, insertRight
, deleteOthers
, length
, positions
, contextMap
, withFocus
, find
, index
)
import qualified Data.List.PointedList as PL
next :: PointedList a -> PointedList a
next pl@(PointedList [] b []) = pl
next (PointedList a b []) = let (x:xs) = reverse a in
PointedList [] x (xs ++ [b])
next pl = PL.tryNext pl
previous :: PointedList a -> PointedList a
previous pl@(PointedList [] b []) = pl
previous (PointedList [] b c ) = let (x:xs) = reverse c in
PointedList (xs ++ [b]) x []
previous pl = PL.tryPrevious pl
delete :: PointedList a -> Maybe (PointedList a)
delete = deleteRight
deleteLeft :: PointedList a -> Maybe (PointedList a)
deleteLeft (PointedList [] _ []) = Nothing
deleteLeft (PointedList (l:ls) _ rs) = Just $ PointedList ls l rs
deleteLeft (PointedList [] _ rs) = let (x:xs) = reverse rs in
Just $ PointedList xs x []
deleteRight :: PointedList a -> Maybe (PointedList a)
deleteRight (PointedList [] _ [] ) = Nothing
deleteRight (PointedList ls _ (r:rs)) = Just $ PointedList ls r rs
deleteRight (PointedList ls _ [] ) = let (x:xs) = reverse ls in
Just $ PointedList [] x xs
moveN :: Int -> PointedList a -> PointedList a
moveN 0 pl = pl
moveN n pl | n > 0 = moveN (n1) $ next pl
| otherwise = moveN (n+1) $ previous pl