non-empty-zipper-0.1.0.5: The Zipper for NonEmpty

Copyright(C) 2017 Isaac Shapira
LicenseBSD-style (see the file LICENSE)
MaintainerIsaac Shapira <fresheyeball@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Data.List.NonEmptyZipper

Description

Its the Zipper for NonEmpty lists.

Synopsis

Documentation

data NonEmptyZipper a Source #

A Zipper with a "current element". The current element represent a singular, focus on a single element in a list. So NonEmptyZipper [1,2] 3 [4] is roughly eqivelant to [1,2,3,4], where 3 is the current element. This is useful, since we are now guarenteed that the current element is an element in the list.

Constructors

NonEmptyZipper

A list of element succeeding the current element.

Fields

  • _before :: ![a]

    A list of elements preceeding the current element.

  • _current :: !a

    The current element.

  • _after :: ![a]
     

Instances

Functor NonEmptyZipper Source #

Its a Functor

Methods

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

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

Applicative NonEmptyZipper Source #

Its Applicative, but pure might not be what you expect

Foldable NonEmptyZipper Source #

Its Foldable

Methods

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

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

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

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

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

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

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

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

toList :: NonEmptyZipper a -> [a] #

null :: NonEmptyZipper a -> Bool #

length :: NonEmptyZipper a -> Int #

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

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

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

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

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

Eq a => Eq (NonEmptyZipper a) Source # 
Ord a => Ord (NonEmptyZipper a) Source # 
Show a => Show (NonEmptyZipper a) Source # 
Semigroup (NonEmptyZipper a) Source #

Its a Semigroup by appending the second NonEmptyZipper to the _after list.

before :: Functor f => ([a] -> f [a]) -> NonEmptyZipper a -> f (NonEmptyZipper a) Source #

Map to _before, useful as a lens

current :: Functor f => (a -> f a) -> NonEmptyZipper a -> f (NonEmptyZipper a) Source #

Map to current, useful as a lens

after :: Functor f => ([a] -> f [a]) -> NonEmptyZipper a -> f (NonEmptyZipper a) Source #

Map to after, useful as a lens

next :: NonEmptyZipper a -> NonEmptyZipper a Source #

Advance the current element forward by one. If the current is the last element in the list, we do nothing.

nextMod :: NonEmptyZipper a -> NonEmptyZipper a Source #

Advance the current element forward by one. If the current is the last element in the list, we loop back to the first.

previous :: NonEmptyZipper a -> NonEmptyZipper a Source #

Move the current element backward by one. If the current is the first element in the list, we do nothing.

previousMod :: NonEmptyZipper a -> NonEmptyZipper a Source #

Move the current element backward by one. If the current is the first element in the list, we loop to the last element.

toList :: NonEmptyZipper a -> [a] Source #

Convert to a standard list. Current element information will be lost.

fromNonEmpty :: NonEmpty a -> NonEmptyZipper a Source #

Convert from NonEmpty. The first element will be the current element.

inTheBeginning :: NonEmptyZipper a -> Bool Source #

Is the current selection the first item in the collection?

inTheEnd :: NonEmptyZipper a -> Bool Source #

Is the current selection the last item in the collection?

getPosition :: NonEmptyZipper a -> Int Source #

Get the index of the current element in the collection.

length :: NonEmptyZipper a -> Int Source #

Measure the size of the collection. Will be atleast 1.

head :: NonEmptyZipper a -> a Source #

Get the first element out of the NonEmptyZipper.

init :: NonEmptyZipper a -> Maybe (NonEmptyZipper a) Source #

Get all elements out of the NonEmptyZipper that are not the last element. If there is only one element in the collection, it's Nothing.

last :: NonEmptyZipper a -> a Source #

Get the last element out of the NonEmptyZipper.

tail :: NonEmptyZipper a -> Maybe (NonEmptyZipper a) Source #

Get all elements out of the NonEmptyZipper that are not the first element. If there is only one element in the collection, its Nothing.

reverse :: NonEmptyZipper a -> NonEmptyZipper a Source #

Flip the NonEmptyZipper, maintaining the current element.

cons :: a -> NonEmptyZipper a -> NonEmptyZipper a Source #

Add one element to the front of a NonEmptyZipper.

wrap :: a -> NonEmptyZipper a Source #

This is like pure but more intuitive. The Applicative instance for NonEmptyZipper is likely not what you expect.

setCurrent :: Eq a => a -> NonEmptyZipper a -> Maybe (NonEmptyZipper a) Source #

Set the current element in the NonEmptyZipper. If the element does not appear in the collection, the result with be Nothing

setCurrentIndex :: Int -> NonEmptyZipper a -> Maybe (NonEmptyZipper a) Source #

Set the current element in the NonEmptyZipper via index location. If the index is out of bounds the results will be Nothing.