ral-0.1: Random access lists
Safe Haskell Safe-Inferred
Language Haskell2010

Data.RAList.NonEmpty

Description

Non-empty random access list.

This module is designed to imported qualifed.

Synopsis

Documentation

newtype NERAList a Source #

Non-empty random access list.

Constructors

NE ( NERAList' Leaf a)

Instances

Instances details
Functor NERAList Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Foldable NERAList Source #
>>> I.length $ fromNonEmpty $ 'x' :| ['a' .. 'z']
27
Instance details

Defined in Data.RAList.NonEmpty.Internal

Traversable NERAList Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Arbitrary1 NERAList Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Traversable1 NERAList Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Foldable1 NERAList Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

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

Defined in Data.RAList.NonEmpty.Internal

Ord a => Ord ( NERAList a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

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

Defined in Data.RAList.NonEmpty.Internal

Semigroup ( NERAList a) Source #
>>> fromNonEmpty ('a' :| "bc") <> fromNonEmpty ('x' :| "yz")
fromNonEmpty ('a' :| "bcxyz")
Instance details

Defined in Data.RAList.NonEmpty.Internal

Function a => Function ( NERAList a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Arbitrary a => Arbitrary ( NERAList a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

CoArbitrary a => CoArbitrary ( NERAList a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

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

Defined in Data.RAList.NonEmpty.Internal

Hashable a => Hashable ( NERAList a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

data NERAList' f a Source #

Non-empty random access list, underlying representation.

The structure doesn't need to be hidden, as polymorphic recursion of Node s starting from Leaf keeps the NERAList values well-formed.

Constructors

Last (f a)
Cons0 ( NERAList' ( Node f) a)
Cons1 (f a) ( NERAList' ( Node f) a)

Instances

Instances details
Functor f => Functor ( NERAList' f) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Foldable f => Foldable ( NERAList' f) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Traversable f => Traversable ( NERAList' f) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Traversable1 t => Traversable1 ( NERAList' t) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Foldable1 t => Foldable1 ( NERAList' t) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Eq (f a) => Eq ( NERAList' f a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

( Ord a, Foldable f, Eq (f a)) => Ord ( NERAList' f a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Show (f a) => Show ( NERAList' f a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

NFData (t a) => NFData ( NERAList' t a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Methods

rnf :: NERAList' t a -> () Source #

Hashable (t a) => Hashable ( NERAList' t a) Source #
Instance details

Defined in Data.RAList.NonEmpty.Internal

Showing

Construction

cons :: a -> NERAList a -> NERAList a Source #

cons for non-empty rals.

Indexing

(!) :: NERAList a -> Int -> a Source #

List index.

>>> fromNonEmpty ('a' :| ['b'..'f']) ! 0
'a'
>>> fromNonEmpty ('a' :| ['b'..'f']) ! 5
'f'
>>> fromNonEmpty ('a' :| ['b'..'f']) ! 6
*** Exception: array index out of range: NERAList
...

(!?) :: NERAList a -> Int -> Maybe a Source #

safe list index.

>>> fromNonEmpty ('a' :| ['b'..'f']) !? 0
Just 'a'
>>> fromNonEmpty ('a' :| ['b'..'f']) !? 5
Just 'f'
>>> fromNonEmpty ('a' :| ['b'..'f']) !? 6
Nothing

head :: NERAList a -> a Source #

First value, head of the list.

>>> head $ fromNonEmpty $ 'a' :| ['b'..'f']
'a'

last :: NERAList a -> a Source #

Last value of the list

>>> last $ fromNonEmpty $  'a' :| ['b'..'f']
'f'

uncons :: NERAList a -> (a, RAList a) Source #

>>> uncons $ fromNonEmpty $ 'a' :| "bcdef"
('a',fromList "bcdef")

tail :: NERAList a -> RAList a Source #

Tail of non-empty list can be empty.

>>> tail $ fromNonEmpty $ 'a' :| "bcdef"
fromList "bcdef"

Conversions

fromNonEmpty :: NonEmpty a -> NERAList a Source #

>>> fromNonEmpty ('a' :| ['b'..'f'])
fromNonEmpty ('a' :| "bcdef")
>>> explicitShow (fromNonEmpty ('a' :| ['b'..'f']))
"NE (Cons0 (Cons1 (Nd (Lf 'a') (Lf 'b')) (Last (Nd (Nd (Lf 'c') (Lf 'd')) (Nd (Lf 'e') (Lf 'f'))))))"

Folding

foldMap1 :: forall a s. Semigroup s => (a -> s) -> NERAList a -> s Source #

foldr1Map :: (a -> b -> b) -> (a -> b) -> NERAList a -> b Source #

ifoldMap1 :: forall a s. Semigroup s => ( Int -> a -> s) -> NERAList a -> s Source #

>>> import Data.Semigroup (Min (..))
>>> ifoldMap1 (\_ x -> Min x) $ fromNonEmpty $ 5 :| [3,1,2,4]
Min {getMin = 1}
>>> ifoldMap1 (\i x -> Min (i + x)) $ fromNonEmpty $ 5 :| [3,1,2,4]
Min {getMin = 3}

ifoldr1Map :: forall a b. ( Int -> a -> b -> b) -> ( Int -> a -> b) -> NERAList a -> b Source #

Mapping

adjust :: forall a. Int -> (a -> a) -> NERAList a -> NERAList a Source #

Adjust a value in the list.

>>> adjust 3 toUpper $ fromNonEmpty $ 'a' :| "bcdef"
fromNonEmpty ('a' :| "bcDef")

If index is out of bounds, the list is returned unmodified.

>>> adjust 10 toUpper $ fromNonEmpty $ 'a' :| "bcdef"
fromNonEmpty ('a' :| "bcdef")
>>> adjust (-1) toUpper $ fromNonEmpty $ 'a' :| "bcdef"
fromNonEmpty ('a' :| "bcdef")

map :: (a -> b) -> NERAList a -> NERAList b Source #

>>> map toUpper (fromNonEmpty ('a' :| ['b'..'f']))
fromNonEmpty ('A' :| "BCDEF")

imap :: ( Int -> a -> b) -> NERAList a -> NERAList b Source #

>>> imap (,) (fromNonEmpty ('a' :| ['b'..'f']))
fromNonEmpty ((0,'a') :| [(1,'b'),(2,'c'),(3,'d'),(4,'e'),(5,'f')])

itraverse :: forall f a b. Applicative f => ( Int -> a -> f b) -> NERAList a -> f ( NERAList b) Source #

itraverse1 :: forall f a b. Apply f => ( Int -> a -> f b) -> NERAList a -> f ( NERAList b) Source #