hgeometry-combinatorial
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageGHC2021

HGeometry.List.Zipper

Description

 
Synopsis

Documentation

data Zipper a Source #

Simple Zipper for Lists.

Constructors

Zipper [a] [a] 

Instances

Instances details
Functor Zipper Source # 
Instance details

Defined in HGeometry.List.Zipper

Methods

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

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

Foldable Zipper Source # 
Instance details

Defined in HGeometry.List.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 #

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

Defined in HGeometry.List.Zipper

Methods

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

show :: Zipper a -> String #

showList :: [Zipper a] -> ShowS #

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

Defined in HGeometry.List.Zipper

Methods

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

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

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

Construct a Zipper from a list

running time: \(O(1)\)

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

Go to the Next Element

running time: \(O(1)\)

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

Go to the previous Element

running time: \(O(1)\)

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

Computes all nexts, even one that has no elements initially or at the end.

>>> mapM_ print $ allNexts $ fromList [1..5]
Zipper [] [1,2,3,4,5]
Zipper [1] [2,3,4,5]
Zipper [2,1] [3,4,5]
Zipper [3,2,1] [4,5]
Zipper [4,3,2,1] [5]
Zipper [5,4,3,2,1] []

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

Returns the next element, and the zipper without it

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

Drops the next element in the zipper.

running time: \(O(1)\)

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

Computes all list that still have next elements.

>>> mapM_ print $ allNonEmptyNexts $ fromList [1..5]
Zipper [] [1,2,3,4,5]
Zipper [1] [2,3,4,5]
Zipper [2,1] [3,4,5]
Zipper [3,2,1] [4,5]
Zipper [4,3,2,1] [5]