nonempty-zipper-1.0.0.4: A non-empty comonadic list zipper
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.List.NonEmpty.Zipper

Synopsis

Documentation

data Zipper a Source #

Instances

Instances details
Functor Zipper Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

Methods

fmap :: (a -> b) -> Zipper a -> Zipper b #

(<$) :: a -> Zipper b -> Zipper a #

Foldable Zipper Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

Methods

fold :: Monoid m => Zipper m -> m #

foldMap :: Monoid m => (a -> m) -> Zipper a -> m #

foldMap' :: Monoid m => (a -> m) -> Zipper a -> m #

foldr :: (a -> b -> b) -> b -> Zipper a -> b #

foldr' :: (a -> b -> b) -> b -> Zipper a -> b #

foldl :: (b -> a -> b) -> b -> Zipper a -> b #

foldl' :: (b -> a -> b) -> b -> Zipper a -> b #

foldr1 :: (a -> a -> a) -> Zipper a -> a #

foldl1 :: (a -> a -> a) -> Zipper a -> a #

toList :: Zipper a -> [a] #

null :: Zipper a -> Bool #

length :: Zipper a -> Int #

elem :: Eq a => a -> Zipper a -> Bool #

maximum :: Ord a => Zipper a -> a #

minimum :: Ord a => Zipper a -> a #

sum :: Num a => Zipper a -> a #

product :: Num a => Zipper a -> a #

Traversable Zipper Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

Methods

traverse :: Applicative f => (a -> f b) -> Zipper a -> f (Zipper b) #

sequenceA :: Applicative f => Zipper (f a) -> f (Zipper a) #

mapM :: Monad m => (a -> m b) -> Zipper a -> m (Zipper b) #

sequence :: Monad m => Zipper (m a) -> m (Zipper a) #

Comonad Zipper Source #

The list zipper is a basic comonad

This instance allows us to create a zipper of all possible states of traversing the zipper with left and right.

>>> duplicate $ fromNonEmpty $ NE.fromList [1, 2, 3]
Zipper [] (Zipper [] 1 [2,3]) [Zipper [1] 2 [3],Zipper [2,1] 3 []]
Instance details

Defined in Data.List.NonEmpty.Zipper

Methods

extract :: Zipper a -> a #

duplicate :: Zipper a -> Zipper (Zipper a) #

extend :: (Zipper a -> b) -> Zipper a -> Zipper b #

Eq a => Eq (Zipper a) Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

Methods

(==) :: Zipper a -> Zipper a -> Bool #

(/=) :: Zipper a -> Zipper a -> Bool #

Show a => Show (Zipper a) Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

Methods

showsPrec :: Int -> Zipper a -> ShowS #

show :: Zipper a -> String #

showList :: [Zipper a] -> ShowS #

Generic (Zipper a) Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

Associated Types

type Rep (Zipper a) :: Type -> Type #

Methods

from :: Zipper a -> Rep (Zipper a) x #

to :: Rep (Zipper a) x -> Zipper a #

NFData a => NFData (Zipper a) Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

Methods

rnf :: Zipper a -> () #

type Rep (Zipper a) Source # 
Instance details

Defined in Data.List.NonEmpty.Zipper

type Rep (Zipper a) = D1 ('MetaData "Zipper" "Data.List.NonEmpty.Zipper" "nonempty-zipper-1.0.0.4-Akhc94dkNFlGOjsZPnEJvM" 'False) (C1 ('MetaCons "Zipper" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]))))

Accessors

lefts :: Zipper a -> [a] Source #

Get all values on the left of the cursor

>>> lefts . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
[1,2]

rights :: Zipper a -> [a] Source #

Get all values on the right of the cursor

>>> rights . fromNonEmpty $ NE.fromList [1, 2, 3]
[2,3]

current :: Zipper a -> a Source #

Get the current focus of the Zipper cursor

This is a synonym for extract

>>> current . fromNonEmpty $ NE.fromList [1, 2, 3]
1

Traversal

left :: Zipper a -> Maybe (Zipper a) Source #

Move the current focus of the cursor to the left

>>> left . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
Just (Zipper [1] 2 [3])

right :: Zipper a -> Maybe (Zipper a) Source #

Move the current focus of the cursor to the right

>>> right . fromNonEmpty $ NE.fromList [1, 2, 3]
Just (Zipper [1] 2 [3])

findLeft :: Eq a => a -> Zipper a -> Maybe (Zipper a) Source #

Move the current focus of the cursor to the first occurence of a value on the left

>>> findLeft 2 . fromNonEmptyEnd $ NE.fromList [2, 1, 2, 1, 1, 3]
Just (Zipper [1,2] 2 [1,1,3])

findRight :: Eq a => a -> Zipper a -> Maybe (Zipper a) Source #

Move the current focus of the cursor to the first occurence of a value on the right

>>> findRight 3 . fromNonEmpty $ NE.fromList [2, 1, 3, 1, 1, 3]
Just (Zipper [1,2] 3 [1,1,3])

start :: Zipper a -> Zipper a Source #

Move the current focus of the cursor to the start of the Zipper

>>> start . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
Zipper [] 1 [2,3]

end :: Zipper a -> Zipper a Source #

Move the current focus of the cursor to the end of the Zipper

>>> end . fromNonEmpty $ NE.fromList [1, 2, 3]
Zipper [2,1] 3 []

Construction

Update

replace :: a -> Zipper a -> Zipper a Source #

Replace the current item under the curosr

>>> replace 4 . fromNonEmpty $ NE.fromList [1, 2, 3]
Zipper [] 4 [2,3]

delete :: Zipper a -> Maybe (Zipper a) Source #

Delete the item currently under the cursor

The item currently under the cursor is removed. The cursors focus will move right. If at the end of the Zipper the cursor will move left.

>>> delete . fromNonEmpty $ NE.fromList [1, 2, 3]
Just (Zipper [] 2 [3])
>>> delete . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
Just (Zipper [1] 2 [])

push :: a -> Zipper a -> Zipper a Source #

Insert a value to the left of the cursor

>>> push 0 . fromNonEmpty $ NE.fromList [1, 2, 3]
Zipper [0] 1 [2,3]

pop :: Zipper a -> (Zipper a, Maybe a) Source #

Remove a value to the left of the cursor

>>> pop . fromNonEmpty $ NE.fromList [1, 2, 3]
(Zipper [] 1 [2,3],Nothing)
>>> pop . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
(Zipper [1] 3 [],Just 2)

shift :: Zipper a -> (Zipper a, Maybe a) Source #

Remove a value to the right of the cursor

>>> shift . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
(Zipper [2,1] 3 [],Nothing)
>>> shift . fromNonEmpty $ NE.fromList [1, 2, 3]
(Zipper [] 1 [3],Just 2)

unshift :: a -> Zipper a -> Zipper a Source #

Insert a value to the right of the cursor

>>> unshift 4 . fromNonEmpty $ NE.fromList [1, 2, 3]
Zipper [] 1 [4,2,3]

reverse :: Zipper a -> Zipper a Source #

Reverse the zipper keeping the cursor focus intact

>>> reverse . fromNonEmpty $ NE.fromList [1, 2, 3]
Zipper [2,3] 1 []

Predicates

isStart :: Zipper a -> Bool Source #

Determine if the Zipper is at the beginning

>>> isStart . fromNonEmpty $ NE.fromList [1, 2, 3]
True
>>> isStart . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
False

isEnd :: Zipper a -> Bool Source #

Determine if the Zipper is at the end

>>> isEnd . fromNonEmptyEnd $ NE.fromList [1, 2, 3]
True
>>> isEnd . fromNonEmpty $ NE.fromList [1, 2, 3]
False