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

Data.RAVec

Description

Synopsis

Random access list

data RAVec (b :: Bin ) a where Source #

Length indexed random access lists.

Constructors

Empty :: RAVec ' BZ a
NonEmpty :: NERAVec b a -> RAVec (' BP b) a

Instances

Instances details
Functor ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Methods

fmap :: (a -> b0) -> RAVec b a -> RAVec b b0 Source #

(<$) :: a -> RAVec b b0 -> RAVec b a Source #

SBinI b => Applicative ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Foldable ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Methods

fold :: Monoid m => RAVec b m -> m Source #

foldMap :: Monoid m => (a -> m) -> RAVec b a -> m Source #

foldMap' :: Monoid m => (a -> m) -> RAVec b a -> m Source #

foldr :: (a -> b0 -> b0) -> b0 -> RAVec b a -> b0 Source #

foldr' :: (a -> b0 -> b0) -> b0 -> RAVec b a -> b0 Source #

foldl :: (b0 -> a -> b0) -> b0 -> RAVec b a -> b0 Source #

foldl' :: (b0 -> a -> b0) -> b0 -> RAVec b a -> b0 Source #

foldr1 :: (a -> a -> a) -> RAVec b a -> a Source #

foldl1 :: (a -> a -> a) -> RAVec b a -> a Source #

toList :: RAVec b a -> [a] Source #

null :: RAVec b a -> Bool Source #

length :: RAVec b a -> Int Source #

elem :: Eq a => a -> RAVec b a -> Bool Source #

maximum :: Ord a => RAVec b a -> a Source #

minimum :: Ord a => RAVec b a -> a Source #

sum :: Num a => RAVec b a -> a Source #

product :: Num a => RAVec b a -> a Source #

Traversable ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Methods

traverse :: Applicative f => (a -> f b0) -> RAVec b a -> f ( RAVec b b0) Source #

sequenceA :: Applicative f => RAVec b (f a) -> f ( RAVec b a) Source #

mapM :: Monad m => (a -> m b0) -> RAVec b a -> m ( RAVec b b0) Source #

sequence :: Monad m => RAVec b (m a) -> m ( RAVec b a) Source #

SBinI b => Arbitrary1 ( RAVec b) Source #
Instance details

Defined in Data.RAVec

SBinI b => Distributive ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Methods

distribute :: Functor f => f ( RAVec b a) -> RAVec b (f a) Source #

collect :: Functor f => (a -> RAVec b b0) -> f a -> RAVec b (f b0) Source #

distributeM :: Monad m => m ( RAVec b a) -> RAVec b (m a) Source #

collectM :: Monad m => (a -> RAVec b b0) -> m a -> RAVec b (m b0) Source #

SBinI b => Representable ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Associated Types

type Rep ( RAVec b) Source #

b ~ ' BP n => Traversable1 ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Methods

traverse1 :: Apply f => (a -> f b0) -> RAVec b a -> f ( RAVec b b0) Source #

sequence1 :: Apply f => RAVec b (f b0) -> f ( RAVec b b0) Source #

Apply ( RAVec b) Source #
Instance details

Defined in Data.RAVec

b ~ ' BP n => Foldable1 ( RAVec b) Source #
Instance details

Defined in Data.RAVec

Eq a => Eq ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

Ord a => Ord ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

Show a => Show ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

Semigroup a => Semigroup ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

( Monoid a, SBinI b) => Monoid ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

( SBinI b, Function a) => Function ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

Methods

function :: ( RAVec b a -> b0) -> RAVec b a :-> b0 Source #

( SBinI b, Arbitrary a) => Arbitrary ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

CoArbitrary a => CoArbitrary ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

NFData a => NFData ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

Methods

rnf :: RAVec b a -> () Source #

Hashable a => Hashable ( RAVec b a) Source #
Instance details

Defined in Data.RAVec

type Rep ( RAVec b) Source #
Instance details

Defined in Data.RAVec

type Rep ( RAVec b) = Pos b

Construction

cons :: a -> RAVec b a -> RAVec ( Succ b) a Source #

Cons an element in front of RAVec .

>>> reifyList "xyz" (print . toList . cons 'a')
"axyz"

withCons :: SBinI b => a -> RAVec b a -> ( SBinPI ( Succ' b) => RAVec ( Succ b) a -> r) -> r Source #

Variant of cons which computes the SBinI dictionary at the same time.

head :: RAVec (' BP b) a -> a Source #

The first element of a non-empty RAVec .

>>> reifyNonEmpty ('x' :| "yz") head
'x'

last :: RAVec (' BP b) a -> a Source #

The last element of a non-empty RAVec .

>>> reifyNonEmpty ('x' :| "yz") last
'z'

Conversion

fromList :: forall b a. SBinI b => [a] -> Maybe ( RAVec b a) Source #

Convert a list [a] to RAVec b a . Returns Nothing if lengths don't match.

>>> fromList "foo" :: Maybe (RAVec B.Bin3 Char)
Just (NonEmpty (NE (Cons1 (Leaf 'f') (Last (Node (Leaf 'o') (Leaf 'o'))))))
>>> fromList "quux" :: Maybe (RAVec B.Bin3 Char)
Nothing
>>> fromList "xy" :: Maybe (RAVec B.Bin3 Char)
Nothing

reifyNonEmpty :: NonEmpty a -> ( forall b. SBinPI b => RAVec (' BP b) a -> r) -> r Source #

Indexing

(!) :: RAVec b a -> Pos b -> a Source #

Indexing.

>>> let ral :: RAVec B.Bin4 Char; Just ral = fromList "abcd"
>>> ral ! minBound
'a'
>>> ral ! maxBound
'd'
>>> ral ! pop top
'b'

tabulate :: forall b a. SBinI b => ( Pos b -> a) -> RAVec b a Source #

Folds

foldMap :: Monoid m => (a -> m) -> RAVec n a -> m Source #

ifoldMap :: Monoid m => ( Pos b -> a -> m) -> RAVec b a -> m Source #

ifoldMap1 :: Semigroup m => ( Pos (' BP b) -> a -> m) -> RAVec (' BP b) a -> m Source #

foldr :: (a -> b -> b) -> b -> RAVec n a -> b Source #

ifoldr :: ( Pos n -> a -> b -> b) -> b -> RAVec n a -> b Source #

Mapping

map :: (a -> b) -> RAVec n a -> RAVec n b Source #

imap :: ( Pos n -> a -> b) -> RAVec n a -> RAVec n b Source #

traverse :: Applicative f => (a -> f b) -> RAVec n a -> f ( RAVec n b) Source #

itraverse :: Applicative f => ( Pos n -> a -> f b) -> RAVec n a -> f ( RAVec n b) Source #

traverse1 :: Apply f => (a -> f b) -> RAVec (' BP n) a -> f ( RAVec (' BP n) b) Source #

itraverse1 :: Apply f => ( Pos (' BP n) -> a -> f b) -> RAVec (' BP n) a -> f ( RAVec (' BP n) b) Source #

Zipping

zipWith :: (a -> b -> c) -> RAVec n a -> RAVec n b -> RAVec n c Source #

Zip two RAVec s with a function.

izipWith :: ( Pos n -> a -> b -> c) -> RAVec n a -> RAVec n b -> RAVec n c Source #

Zip two RAVec s with a function which also takes Pos index.

Universe

universe :: forall b. SBinI b => RAVec b ( Pos b) Source #

>>> universe :: RAVec B.Bin2 (Pos B.Bin2)
NonEmpty (NE (Cons0 (Last (Node (Leaf 0) (Leaf 1)))))
>>> let u = universe :: RAVec B.Bin3 (Pos B.Bin3)
>>> u
NonEmpty (NE (Cons1 (Leaf 0) (Last (Node (Leaf 1) (Leaf 2)))))
>>> P.explicitShow $ u ! Pos (PosP (Here WE))
"Pos (PosP (Here WE))"
>>> let u' = universe :: RAVec B.Bin5 (Pos B.Bin5)
>>> toList u' == sort (toList u')
True

repeat :: forall b a. SBinI b => a -> RAVec b a Source #

Repeat a value.

>>> repeat 'x' :: RAVec B.Bin5 Char
NonEmpty (NE (Cons1 (Leaf 'x') (Cons0 (Last (Node (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x')))))))

QuickCheck

liftShrink :: (a -> [a]) -> RAVec b a -> [ RAVec b a] Source #