vector-circular-0.1.3: circular vectors
Safe HaskellNone
LanguageHaskell2010

Data.Vector.Circular

Synopsis

Types

data CircularVector a Source #

A circular, immutable vector. This type is equivalent to cycle xs for some finite, nonempty xs, but with O(1) access and O(1) rotations. Indexing into this type is always total.

Constructors

CircularVector 

Fields

Instances

Instances details
Functor CircularVector Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Methods

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

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

Foldable CircularVector Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Methods

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

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

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

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

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

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

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

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

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

toList :: CircularVector a -> [a] #

null :: CircularVector a -> Bool #

length :: CircularVector a -> Int #

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

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

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

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

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

Traversable CircularVector Source #

Since: 0.1.1

Instance details

Defined in Data.Vector.Circular

Methods

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

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

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

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

Eq1 CircularVector Source #

Since: 0.1.2

Instance details

Defined in Data.Vector.Circular

Methods

liftEq :: (a -> b -> Bool) -> CircularVector a -> CircularVector b -> Bool #

Ord1 CircularVector Source #

Since: 0.1.2

Instance details

Defined in Data.Vector.Circular

Methods

liftCompare :: (a -> b -> Ordering) -> CircularVector a -> CircularVector b -> Ordering #

Read1 CircularVector Source #

Since: 0.1.2

Instance details

Defined in Data.Vector.Circular

Show1 CircularVector Source #

Since: 0.1.2

Instance details

Defined in Data.Vector.Circular

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> CircularVector a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [CircularVector a] -> ShowS #

Foldable1 CircularVector Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Methods

fold1 :: Semigroup m => CircularVector m -> m #

foldMap1 :: Semigroup m => (a -> m) -> CircularVector a -> m #

toNonEmpty :: CircularVector a -> NonEmpty a #

Lift a => Lift (CircularVector a :: Type) Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Eq a => Eq (CircularVector a) Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Ord a => Ord (CircularVector a) Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Read a => Read (CircularVector a) Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Show a => Show (CircularVector a) Source #

Since: 0.1

Instance details

Defined in Data.Vector.Circular

Generic (CircularVector a) Source #

Since: 0.1.1

Instance details

Defined in Data.Vector.Circular

Associated Types

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

Semigroup (CircularVector a) Source #

The Semigroup (<>) operation behaves by un-rolling the two vectors so that their rotation is 0, concatenating them, returning a new vector with a 0-rotation.

Since: 0.1

Instance details

Defined in Data.Vector.Circular

NFData a => NFData (CircularVector a) Source #

Since: 0.1.1

Instance details

Defined in Data.Vector.Circular

Methods

rnf :: CircularVector a -> () #

type Rep (CircularVector a) Source # 
Instance details

Defined in Data.Vector.Circular

type Rep (CircularVector a) = D1 ('MetaData "CircularVector" "Data.Vector.Circular" "vector-circular-0.1.3-2kMF7aKUe1AIDdGfGFR4UU" 'False) (C1 ('MetaCons "CircularVector" 'PrefixI 'True) (S1 ('MetaSel ('Just "vector") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 (NonEmptyVector a)) :*: S1 ('MetaSel ('Just "rotation") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)))

Construction

Initialization

singleton :: a -> CircularVector a Source #

O(1) Construct a singleton 'CircularVector.

Since: 0.1

replicate :: Int -> a -> Maybe (CircularVector a) Source #

O(n) Circular vector of the given length with the same value in each position.

When given a index n <= 0, then Nothing is returned, otherwise Just.

>>> replicate 3 "a"
Just (CircularVector {vector = ["a","a","a"], rotation = 0})
>>> replicate 0 "a"
Nothing

Since: 0.1.2

replicate1 :: Int -> a -> CircularVector a Source #

O(n) Circular vector of the given length with the same value in each position.

This variant takes max n 1 for the supplied length parameter.

>>> replicate1 3 "a"
CircularVector {vector = ["a","a","a"], rotation = 0}
>>> replicate1 0 "a"
CircularVector {vector = ["a"], rotation = 0}
>>> replicate1 (-1) "a"
CircularVector {vector = ["a"], rotation = 0}

Since: 0.1.2

generate :: Int -> (Int -> a) -> Maybe (CircularVector a) Source #

O(n) Construct a circular vector of the given length by applying the function to each index.

When given a index n <= 0, then Nothing is returned, otherwise Just.

>>> let f 0 = "a"; f _ = "k"; f :: Int -> String
>>> generate 1 f
Just (CircularVector {vector = ["a"], rotation = 0})
>>> generate 0 f
Nothing
>>> generate 2 f
Just (CircularVector {vector = ["a","k"], rotation = 0})

Since: 0.1.2

generate1 :: Int -> (Int -> a) -> CircularVector a Source #

O(n) Construct a circular vector of the given length by applying the function to each index.

This variant takes max n 1 for the supplied length parameter.

>>> let f 0 = "a"; f _ = "k"; f :: Int -> String
>>> toList $ generate1 2 f
["a","k"]
>>> toList $ generate1 0 f
["a"]
>>> toList $ generate1 (-1) f
["a"]

Since: 0.1.2

iterateN :: Int -> (a -> a) -> a -> Maybe (CircularVector a) Source #

O(n) Apply function n times to value. Zeroth element is original value.

When given a index n <= 0, then Nothing is returned, otherwise Just.

>>> iterateN 3 (+1) 0
Just (CircularVector {vector = [0,1,2], rotation = 0})
>>> iterateN 0 (+1) 0
Nothing
>>> iterateN (-1) (+1) 0
Nothing

Since: 0.1.2

iterateN1 :: Int -> (a -> a) -> a -> CircularVector a Source #

O(n) Apply function n times to value. Zeroth element is original value.

This variant takes max n 1 for the supplied length parameter.

>>> iterateN1 3 (+1) 0
CircularVector {vector = [0,1,2], rotation = 0}
>>> iterateN1 0 (+1) 0
CircularVector {vector = [0], rotation = 0}
>>> iterateN1 (-1) (+1) 0
CircularVector {vector = [0], rotation = 0}

Since: 0.1.2

Monad Initialization

replicateM :: Monad m => Int -> m a -> m (Maybe (CircularVector a)) Source #

O(n) Execute the monadic action the given number of times and store the results in a circular vector.

When given a index n <= 0, then Nothing is returned, otherwise Just.

>>> replicateM @Maybe 3 (Just "a")
Just (Just (CircularVector {vector = ["a","a","a"], rotation = 0}))
>>> replicateM @Maybe 3 Nothing
Nothing
>>> replicateM @Maybe 0 (Just "a")
Just Nothing
>>> replicateM @Maybe (-1) (Just "a")
Just Nothing

Since: 0.1.2

replicate1M :: Monad m => Int -> m a -> m (CircularVector a) Source #

O(n) Execute the monadic action the given number of times and store the results in a circular vector.

This variant takes max n 1 for the supplied length parameter.

>>> replicate1M @Maybe 3 (Just "a")
Just (CircularVector {vector = ["a","a","a"], rotation = 0})
>>> replicate1M @Maybe 3 Nothing
Nothing
>>> replicate1M @Maybe 0 (Just "a")
Just (CircularVector {vector = ["a"], rotation = 0})
>>> replicate1M @Maybe (-1) (Just "a")
Just (CircularVector {vector = ["a"], rotation = 0})

Since: 0.1.2

generateM :: Monad m => Int -> (Int -> m a) -> m (Maybe (CircularVector a)) Source #

O(n) Construct a circular vector of the given length by applying the monadic action to each index

When given a index n <= 0, then Nothing is returned, otherwise Just.

>>> generateM 3 (\i -> if i < 1 then ["a"] else ["b"])
[Just (CircularVector {vector = ["a","b","b"], rotation = 0})]
>>> generateM @[] @Int 3 (const [])
[]
>>> generateM @[] @Int 0 (const [1])
[Nothing]
>>> generateM @Maybe @Int (-1) (const Nothing)
Just Nothing

Since: 0.1.2

generate1M :: Monad m => Int -> (Int -> m a) -> m (CircularVector a) Source #

O(n) Construct a circular vector of the given length by applying the monadic action to each index

This variant takes max n 1 for the supplied length parameter.

>>> generate1M 3 (\i -> if i < 1 then Just "a" else Just "b")
Just (CircularVector {vector = ["a","b","b"], rotation = 0})
>>> generate1M 3 (const [])
[]
>>> generate1M 0 (const $ Just 1)
Just (CircularVector {vector = [1], rotation = 0})
>>> generate1M (-1) (const Nothing)
Nothing

Since: 0.1.2

iterateNM :: Monad m => Int -> (a -> m a) -> a -> m (Maybe (CircularVector a)) Source #

O(n) Apply monadic function n times to value. Zeroth element is original value.

When given a index n <= 0, then Nothing is returned, otherwise Just.

>>> iterateNM @Maybe 3 return "a"
Just (Just (CircularVector {vector = ["a","a","a"], rotation = 0}))
>>> iterateNM @Maybe 3 (const Nothing) "a"
Nothing
>>> iterateNM @Maybe 0 return "a"
Just Nothing

Since: 0.1.2

iterateN1M :: Monad m => Int -> (a -> m a) -> a -> m (CircularVector a) Source #

O(n) Apply monadic function n times to value. Zeroth element is original value.

This variant takes max n 1 for the supplied length parameter.

>>> iterateN1M @Maybe 3 return "a"
Just (CircularVector {vector = ["a","a","a"], rotation = 0})
>>> iterateN1M @Maybe 3 (const Nothing) "a"
Nothing
>>> iterateN1M @Maybe 0 return "a"
Just (CircularVector {vector = ["a"], rotation = 0})
>>> iterateN1M @Maybe (-1) return "a"
Just (CircularVector {vector = ["a"], rotation = 0})

Since: 0.1.2

create :: (forall s. ST s (MVector s a)) -> Maybe (CircularVector a) Source #

Execute the monadic action and freeze the resulting circular vector.

Since: 0.1.2

unsafeCreate :: (forall s. ST s (MVector s a)) -> CircularVector a Source #

Execute the monadic action and freeze the resulting circular vector, bypassing emptiness checks.

The onus is on the caller to guarantee the created vector is non-empty.

Since: 0.1.2

createT :: Traversable t => (forall s. ST s (t (MVector s a))) -> t (Maybe (CircularVector a)) Source #

Execute the monadic action and freeze the resulting circular vector.

Since: 0.1.2

unsafeCreateT :: Traversable t => (forall s. ST s (t (MVector s a))) -> t (CircularVector a) Source #

Execute the monadic action and freeze the resulting circular vector.

The onus is on the caller to guarantee the created vector is non-empty.

Since: 0.1.2

Unfolding

unfoldr :: (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a) Source #

O(n) Construct a circular vector by repeatedly applying the generator function to a seed. The generator function yields Just the next element and the new seed or Nothing if there are no more elements.

If an unfold does not create meaningful values, Nothing is returned. Otherwise, Just containing a circular vector is returned.

>>> unfoldr (\b -> case b of "a" -> Just ("a", "b"); _ ->  Nothing) "a"
Just (CircularVector {vector = ["a"], rotation = 0})
>>> unfoldr (const Nothing) "a"
Nothing

Since: 0.1.2

unfoldr1 :: (b -> Maybe (a, b)) -> a -> b -> CircularVector a Source #

O(n) Construct a circular vector by repeatedly applying the generator function to a seed and a first element.

This variant of unfoldr guarantees the resulting vector is non- empty by supplying an initial element a.

>>> unfoldr1 (\b -> case b of "a" -> Just ("a", "b"); _ ->  Nothing) "first" "a"
CircularVector {vector = ["first","a"], rotation = 0}
>>> unfoldr1 (const Nothing) "first" "a"
CircularVector {vector = ["first"], rotation = 0}

Since: 0.1.2

unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a) Source #

O(n) Construct a circular vector with at most n elements by repeatedly applying the generator function to a seed. The generator function yields Just the next element and the new seed or Nothing if there are no more elements.

If an unfold does not create meaningful values, Nothing is returned. Otherwise, Just containing a circular vector is returned.

>>> unfoldrN 3 (\b -> Just (b+1, b+1)) 0
Just (CircularVector {vector = [1,2,3], rotation = 0})
>>> unfoldrN 3 (const Nothing) 0
Nothing
>>> unfoldrN 0 (\b -> Just (b+1, b+1)) 0
Nothing

Since: 0.1.2

unfoldr1N :: Int -> (b -> Maybe (a, b)) -> a -> b -> CircularVector a Source #

O(n) Construct a circular vector with at most n elements by repeatedly applying the generator function to a seed. The generator function yields Just the next element and the new seed or Nothing if there are no more elements.

This variant of unfoldrN guarantees the resulting vector is non- empty by supplying an initial element a.

>>> unfoldr1N 3 (\b -> Just (b+1, b+1)) 0 0
CircularVector {vector = [0,1,2,3], rotation = 0}
>>> unfoldr1N 3 (const Nothing) 0 0
CircularVector {vector = [0], rotation = 0}
>>> unfoldr1N 0 (\b -> Just (b+1, b+1)) 0 0
CircularVector {vector = [0], rotation = 0}

Since: 0.1.2

unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a)) Source #

O(n) Construct a circular vector by repeatedly applying the monadic generator function to a seed. The generator function yields Just the next element and the new seed or Nothing if there are no more elements.

If an unfold does not create meaningful values, Nothing is returned. Otherwise, Just containing a circular vector is returned.

Since: 0.1.2

unfoldr1M :: Monad m => (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a) Source #

O(n) Construct a circular vector by repeatedly applying the monadic generator function to a seed. The generator function yields Just the next element and the new seed or Nothing if there are no more elements.

This variant of unfoldrM guarantees the resulting vector is non- empty by supplying an initial element a.

Since: 0.1.2

unfoldrNM :: Monad m => Int -> (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a)) Source #

O(n) Construct a circular vector by repeatedly applying the monadic generator function to a seed. The generator function yields Just the next element and the new seed or Nothing if there are no more elements.

If an unfold does not create meaningful values, Nothing is returned. Otherwise, Just containing a circular vector is returned.

Since: 0.1.2

unfoldr1NM :: Monad m => Int -> (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a) Source #

O(n) Construct a circular vector by repeatedly applying the monadic generator function to a seed. The generator function yields Just the next element and the new seed or Nothing if there are no more elements.

This variant of unfoldrNM guarantees the resulting vector is non- empty by supplying an initial element a.

Since: 0.1.2

constructN :: Int -> (Vector a -> a) -> Maybe (CircularVector a) Source #

O(n) Construct a circular vector with n elements by repeatedly applying the generator function to the already constructed part of the vector.

If constructN does not create meaningful values, Nothing is returned. Otherwise, Just containing a circular vector is returned.

Since: 0.1.2

constructrN :: Int -> (Vector a -> a) -> Maybe (CircularVector a) Source #

O(n) Construct a circular vector with n elements from right to left by repeatedly applying the generator function to the already constructed part of the vector.

If constructrN does not create meaningful values, Nothing is returned. Otherwise, Just containing a circular vector is returned.

Since: 0.1.2

Enumeration

enumFromN :: Num a => a -> Int -> Maybe (CircularVector a) Source #

O(n) Yield a circular vector of the given length containing the values x, x+1 etc. This operation is usually more efficient than enumFromTo.

If an enumeration does not use meaningful indices, Nothing is returned, otherwise, Just containing a circular vector.

Since: 0.1.2

enumFromN1 :: Num a => a -> Int -> CircularVector a Source #

O(n) Yield a circular vector of length max n 1 containing the values x, x+1 etc. This operation is usually more efficient than enumFromTo.

Since: 0.1.2

enumFromStepN :: Num a => a -> a -> Int -> Maybe (CircularVector a) Source #

O(n) Yield a circular vector of the given length containing the values x, x+y, x+y+y etc. This operations is usually more efficient than enumFromThenTo.

If an enumeration does not use meaningful indices, Nothing is returned, otherwise, Just containing a circular vector.

Since: 0.1.2

enumFromStepN1 :: Num a => a -> a -> Int -> CircularVector a Source #

O(n) Yield a circular vector of length max n 1 containing the values x, x+y, x+y+y etc. This operations is usually more efficient than enumFromThenTo.

Since: 0.1.2

enumFromTo :: Enum a => a -> a -> Maybe (CircularVector a) Source #

O(n) Enumerate values from x to y.

If an enumeration does not use meaningful indices, Nothing is returned, otherwise, Just containing a circular vector.

WARNING: This operation can be very inefficient. If at all possible, use enumFromN instead.

Since: 0.1.2

enumFromThenTo :: Enum a => a -> a -> a -> Maybe (CircularVector a) Source #

O(n) Enumerate values from x to y with a specific step z.

If an enumeration does not use meaningful indices, Nothing is returned, otherwise, Just containing a circular vector.

WARNING: This operation can be very inefficient. If at all possible, use enumFromStepN instead.

Since: 0.1.2

Concatenation

cons :: a -> CircularVector a -> CircularVector a Source #

O(n) Prepend an element

>>> cons 1 (unsafeFromList [2,3])
CircularVector {vector = [1,2,3], rotation = 0}

Since: 0.1.2

consV :: a -> Vector a -> CircularVector a Source #

O(n) Prepend an element to a Vector

>>> consV 1 (Vector.fromList [2,3])
CircularVector {vector = [1,2,3], rotation = 0}

Since: 0.1.2

snoc :: CircularVector a -> a -> CircularVector a Source #

O(n) Append an element

>>> snoc (unsafeFromList [1,2]) 3
CircularVector {vector = [1,2,3], rotation = 0}

Since: 0.1.2

snocV :: Vector a -> a -> CircularVector a Source #

O(n) Append an element to a Vector

>>> snocV (Vector.fromList [1,2]) 3
CircularVector {vector = [1,2,3], rotation = 0}

Since: 0.1.2

(++) :: CircularVector a -> CircularVector a -> CircularVector a Source #

O(m+n) Concatenate two circular vectors

>>> (unsafeFromList [1..3]) ++ (unsafeFromList [4..6])
CircularVector {vector = [1,2,3,4,5,6], rotation = 0}

Since: 0.1.2

concat :: [CircularVector a] -> Maybe (CircularVector a) Source #

O(n) Concatenate all circular vectors in the list

If list is empty, Nothing is returned, otherwise Just containing the concatenated circular vectors

>>> concat [(unsafeFromList [1..3]), (unsafeFromList [4..6])]
Just (CircularVector {vector = [1,2,3,4,5,6], rotation = 0})

Since: 0.1.2

concat1 :: NonEmpty (CircularVector a) -> CircularVector a Source #

O(n) Concatenate all circular vectors in a non-empty list.

>>> concat1 ((unsafeFromList [1..3]) :| [(unsafeFromList [4..6])])
CircularVector {vector = [1,2,3,4,5,6], rotation = 0}

Since: 0.1.2

Restricting memory usage

force :: NFData a => a -> a #

a variant of deepseq that is useful in some circumstances:

force x = x `deepseq` x

force x fully evaluates x, and then returns it. Note that force x only performs evaluation when the value of force x itself is demanded, so essentially it turns shallow evaluation into deep evaluation.

force can be conveniently used in combination with ViewPatterns:

{-# LANGUAGE BangPatterns, ViewPatterns #-}
import Control.DeepSeq

someFun :: ComplexData -> SomeResult
someFun (force -> !arg) = {- 'arg' will be fully evaluated -}

Another useful application is to combine force with evaluate in order to force deep evaluation relative to other IO operations:

import Control.Exception (evaluate)
import Control.DeepSeq

main = do
  result <- evaluate $ force $ pureComputation
  {- 'result' will be fully evaluated at this point -}
  return ()

Finally, here's an exception safe variant of the readFile' example:

readFile' :: FilePath -> IO String
readFile' fn = bracket (openFile fn ReadMode) hClose $ \h ->
                       evaluate . force =<< hGetContents h

Since: deepseq-1.2.0.0

Template Haskell

vec :: Lift a => [a] -> Q (TExp (CircularVector a)) Source #

Construct a CircularVector at compile-time using typed Template Haskell.

Since: 0.1

Conversion

toVector :: CircularVector a -> Vector a Source #

O(n) Construct a Vector from a CircularVector.

Since: 0.1

fromVector :: NonEmptyVector a -> CircularVector a Source #

O(1) Construct a CircularVector from a NonEmptyVector.

Since: 0.1

fromVector' :: Vector a -> Maybe (CircularVector a) Source #

O(1) Construct a CircularVector from a NonEmptyVector.

Since: 0.1.2

unsafeFromVector :: Vector a -> CircularVector a Source #

O(1) Construct a CircularVector from a Vector.

Calls error if the input vector is empty.

Since: 0.1

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

O(n) Convert from a circular vector to a list.

>>> let nev = unsafeFromList [1..3] in toList nev
[1,2,3]

Since: 0.1.2

fromList :: [a] -> Maybe (CircularVector a) Source #

O(n) Construct a CircularVector from a list.

Since: 0.1

fromListN :: Int -> [a] -> Maybe (CircularVector a) Source #

Construct a CircularVector from a list with a size hint.

Since: 0.1

unsafeFromList :: [a] -> CircularVector a Source #

O(n) Construct a CircularVector from a list.

Calls error if the input list is empty.

Since: 0.1

unsafeFromListN :: Int -> [a] -> CircularVector a Source #

O(n) Construct a CircularVector from a list with a size hint.

Calls error if the input list is empty, or if the size hint is <= 0.

Since: 0.1

Rotation

rotateLeft :: Int -> CircularVector a -> CircularVector a Source #

O(1) Rotate the vector to the left by n number of elements.

Note: Left rotations start to break down due to arithmetic underflow when the size of the input vector is > maxBound Int@

Since: 0.1

rotateRight :: Int -> CircularVector a -> CircularVector a Source #

O(1) Rotate the vector to left by n number of elements.

Note: Right rotations start to break down due to arithmetic overflow when the size of the input vector is > maxBound Int@

Since: 0.1

Comparisons

leastRotation :: forall a. Ord a => Vector a -> Int Source #

Since: 0.1

Folds

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

Lazily-accumulating monoidal fold over a CircularVector. @since 0.1

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

Strictly-accumulating monoidal fold over a CircularVector.

Since: 0.1

foldr :: (a -> b -> b) -> b -> CircularVector a -> b Source #

Since: 0.1

foldl :: (b -> a -> b) -> b -> CircularVector a -> b Source #

Since: 0.1

foldr' :: (a -> b -> b) -> b -> CircularVector a -> b Source #

Since: 0.1

foldl' :: (b -> a -> b) -> b -> CircularVector a -> b Source #

Since: 0.1

foldr1 :: (a -> a -> a) -> CircularVector a -> a Source #

Since: 0.1

foldl1 :: (a -> a -> a) -> CircularVector a -> a Source #

Since: 0.1

foldMap1 :: Semigroup m => (a -> m) -> CircularVector a -> m Source #

Lazily-accumulating semigroupoidal fold over a CircularVector.

Since: 0.1

foldMap1' :: Semigroup m => (a -> m) -> CircularVector a -> m Source #

Strictly-accumulating semigroupoidal fold over a CircularVector.

Since: 0.1

Specialized folds

all :: (a -> Bool) -> CircularVector a -> Bool Source #

O(n) Check if all elements satisfy the predicate.

Since: 0.1.1

any :: (a -> Bool) -> CircularVector a -> Bool Source #

O(n) Check if any element satisfies the predicate.

Since: 0.1.1

and :: CircularVector Bool -> Bool Source #

O(n) Check if all elements are True.

Since: 0.1.1

or :: CircularVector Bool -> Bool Source #

O(n) Check if any element is True.

Since: 0.1.1

sum :: Num a => CircularVector a -> a Source #

O(n) Compute the sum of the elements.

Since: 0.1.1

product :: Num a => CircularVector a -> a Source #

O(n) Compute the product of the elements.

Since: 0.1.1

maximum :: Ord a => CircularVector a -> a Source #

O(n) Yield the maximum element of the circular vector.

Since: 0.1.1

maximumBy :: (a -> a -> Ordering) -> CircularVector a -> a Source #

O(n) Yield the maximum element of a circular vector according to the given comparison function.

Since: 0.1.1

minimum :: Ord a => CircularVector a -> a Source #

O(n) Yield the minimum element of the circular vector.

Since: 0.1.1

minimumBy :: (a -> a -> Ordering) -> CircularVector a -> a Source #

O(n) Yield the minimum element of a circular vector according to the given comparison function.

Since: 0.1.1

rotateToMinimumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a Source #

O(n) Rotate to the minimum element of the circular vector according to the given comparison function.

Since: 0.1.1

rotateToMaximumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a Source #

O(n) Rotate to the maximum element of the circular vector according to the given comparison function.

Since: 0.1.1

Elementwise operations

Indexing

index :: CircularVector a -> Int -> a Source #

O(1) Index into a CircularVector. This is always total.

Since: 0.1

head :: CircularVector a -> a Source #

O(1) Get the first element of a CircularVector. This is always total.

Since: 0.1

last :: CircularVector a -> a Source #

O(1) Get the last element of a CircularVector. This is always total.

Since: 0.1

Mapping

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

O(n) Map a function over a circular vector.

>>> map (+1) $ unsafeFromList [1..3]
CircularVector {vector = [2,3,4], rotation = 0}

Since: 0.1.2

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

O(n) Apply a function to every element of a circular vector and its index.

>>> imap (\i a -> if i == 2 then a+1 else a+0) $ unsafeFromList [1..3]
CircularVector {vector = [1,2,4], rotation = 0}

Since: 0.1.2

concatMap :: (a -> CircularVector b) -> CircularVector a -> CircularVector b Source #

Map a function over a circular vector and concatenate the results.

>>> concatMap (\a -> unsafeFromList [a,a]) (unsafeFromList [1,2,3])
CircularVector {vector = [1,1,2,2,3,3], rotation = 0}

Since: 0.1.2

Monadic mapping

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

O(n) Apply the monadic action to all elements of the circular vector, yielding circular vector of results.

>>> mapM Just (unsafeFromList [1..3])
Just (CircularVector {vector = [1,2,3], rotation = 0})
>>> mapM (const Nothing) (unsafeFromList [1..3])
Nothing

Since: 0.1.2

imapM :: Monad m => (Int -> a -> m b) -> CircularVector a -> m (CircularVector b) Source #

O(n) Apply the monadic action to every element of a circular vector and its index, yielding a circular vector of results.

>>> imapM (\i a -> if i == 1 then Just a else Just 0) (unsafeFromList [1..3])
Just (CircularVector {vector = [0,2,0], rotation = 0})
>>> imapM (\_ _ -> Nothing) (unsafeFromList [1..3])
Nothing

Since: 0.1.2

mapM_ :: Monad m => (a -> m b) -> CircularVector a -> m () Source #

O(n) Apply the monadic action to all elements of a circular vector and ignore the results.

>>> mapM_ (const $ Just ()) (unsafeFromList [1..3])
Just ()
>>> mapM_ (const Nothing) (unsafeFromList [1..3])
Nothing

Since: 0.1.2

imapM_ :: Monad m => (Int -> a -> m b) -> CircularVector a -> m () Source #

O(n) Apply the monadic action to every element of a circular vector and its index, ignoring the results

>>> imapM_ (\i a -> if i == 1 then print a else putStrLn "0") (unsafeFromList [1..3])
0
2
0
>>> imapM_ (\_ _ -> Nothing) (unsafeFromList [1..3])
Nothing

Since: 0.1.2

forM :: Monad m => CircularVector a -> (a -> m b) -> m (CircularVector b) Source #

O(n) Apply the monadic action to all elements of the circular vector, yielding a circular vector of results.

Equivalent to flip mapM.

Since: 0.1.2

forM_ :: Monad m => CircularVector a -> (a -> m b) -> m () Source #

O(n) Apply the monadic action to all elements of a circular vector and ignore the results.

Equivalent to flip mapM_.

Since: 0.1.2

Zipping

zipWith :: (a -> b -> c) -> CircularVector a -> CircularVector b -> CircularVector c Source #

O(min(m,n)) Zip two circular vectors with the given function.

Since: 0.1.1

zipWith3 :: (a -> b -> c -> d) -> CircularVector a -> CircularVector b -> CircularVector c -> CircularVector d Source #

Zip three circular vectors with the given function.

Since: 0.1.1

zip :: CircularVector a -> CircularVector b -> CircularVector (a, b) Source #

O(min(n,m)) Elementwise pairing of circular vector elements. This is a special case of zipWith where the function argument is (,)

Since: 0.1.1

zip3 :: CircularVector a -> CircularVector b -> CircularVector c -> CircularVector (a, b, c) Source #

Zip together three circular vectors.

Since: 0.1.1

Unzipping

unzip :: [(a, b)] -> ([a], [b]) #

unzip transforms a list of pairs into a list of first components and a list of second components.

unzip3 :: [(a, b, c)] -> ([a], [b], [c]) #

The unzip3 function takes a list of triples and returns three lists, analogous to unzip.

Filtering

uniq :: Eq a => CircularVector a -> CircularVector a Source #

O(n) Drop repeated adjacent elements.

>>> toList $ uniq $ unsafeFromList [1,1,2,2,3,3,1]
[1,2,3]
>>> toList $ uniq $ unsafeFromList [1,2,3,1]
[1,2,3]
>>> toList $ uniq $ unsafeFromList [1]
[1]

mapMaybe :: (a -> Maybe b) -> CircularVector a -> Vector b Source #

O(n) Drop elements when predicate returns Nothing

If no elements satisfy the predicate, the resulting vector may be empty.

>>> mapMaybe (\a -> if a == 2 then Nothing else Just a) (unsafeFromList [1..3])
[1,3]

Since: 0.1.2

imapMaybe :: (Int -> a -> Maybe b) -> CircularVector a -> Vector b Source #

O(n) Drop elements when predicate, applied to index and value, returns Nothing

If no elements satisfy the predicate, the resulting vector may be empty.

>>> imapMaybe (\i a -> if a == 2 || i == 2 then Nothing else Just a) (unsafeFromList [1..3])
[1]

Since: 0.1.2

filter :: (a -> Bool) -> CircularVector a -> Vector a Source #

O(n) Drop elements that do not satisfy the predicate.

If no elements satisfy the predicate, the resulting vector may be empty.

>>> filter (\a -> if a == 2 then False else True) (unsafeFromList [1..3])
[1,3]
>>> filter (const False) (unsafeFromList [1..3])
[]

ifilter :: (Int -> a -> Bool) -> CircularVector a -> Vector a Source #

O(n) Drop elements that do not satisfy the predicate which is applied to values and their indices.

If no elements satisfy the predicate, the resulting vector may be empty.

>>> ifilter (\i a -> if a == 2 || i == 0 then False else True) (unsafeFromList [1..3])
[3]
>>> ifilter (\_ _ -> False) (unsafeFromList [1..3])
[]

Since: 0.1.2

filterM :: Monad m => (a -> m Bool) -> CircularVector a -> m (Vector a) Source #

O(n) Drop elements that do not satisfy the monadic predicate.

If no elements satisfy the predicate, the resulting vector may be empty.

>>> filterM (\a -> if a == 2 then Just False else Just True) (unsafeFromList [1..3])
Just [1,3]
>>> filterM (\a -> if a == 2 then Nothing else Just True) (unsafeFromList [1..3])
Nothing
>>> filterM (const $ Just False) (unsafeFromList [1..3])
Just []

Since: 0.1.2

ifilterM :: Monad m => (Int -> a -> m Bool) -> CircularVector a -> m (Vector a) Source #

O(n) Drop elements that do not satisfy the monadic predicate that is a function of index and value.

If no elements satisfy the predicate, the resulting vector may be empty.

>>> ifilterM (\i a -> if a == 2 || i == 0 then Just False else Just True) (unsafeFromList [1..3])
Just [3]
>>> ifilterM (\i a -> if a == 2 || i == 0 then Nothing else Just True) (unsafeFromList [1..3])
Nothing
>>> ifilterM (\_ _ -> Just False) (unsafeFromList [1..3])
Just []

Since: 0.1.2

takeWhile :: (a -> Bool) -> CircularVector a -> Vector a Source #

O(n) Yield the longest prefix of elements satisfying the predicate without copying.

If no elements satisfy the predicate, the resulting vector may be empty.

>>> takeWhile (/= 3) (unsafeFromList [1..3])
[1,2]

Since: 0.1.2

dropWhile :: (a -> Bool) -> CircularVector a -> Vector a Source #

O(n) Drop the longest prefix of elements that satisfy the predicate without copying.

If all elements satisfy the predicate, the resulting vector may be empty.

>>> dropWhile (/= 3) (unsafeFromList [1..3])
[3]

Since: 0.1.2

Partitioning

partition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) Source #

O(n) Split the circular vector in two parts, the first one containing those elements that satisfy the predicate and the second one those that don't. The relative order of the elements is preserved at the cost of a sometimes reduced performance compared to unstablePartition.

If all or no elements satisfy the predicate, one of the resulting vectors may be empty.

>>> partition (< 3) (unsafeFromList [1..5])
([1,2],[3,4,5])

Since: 0.1.2

unstablePartition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) Source #

O(n) Split the circular vector in two parts, the first one containing those elements that satisfy the predicate and the second one those that don't. The order of the elements is not preserved but the operation is often faster than partition.

If all or no elements satisfy the predicate, one of the resulting vectors may be empty.

Since: 0.1.2

span :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) Source #

O(n) Split the circular vector into the longest prefix of elements that satisfy the predicate and the rest without copying.

If all or no elements satisfy the predicate, one of the resulting vectors may be empty.

>>> span (== 1) (unsafeFromList [1,1,2,3,1])
([1,1],[2,3,1])

Since: 0.1.2

break :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) Source #

O(n) Split the circular vector into the longest prefix of elements that do not satisfy the predicate and the rest without copying.

If all or no elements satisfy the predicate, one of the resulting vectors may be empty.

>>> break (== 2) (unsafeFromList [1,1,2,3,1])
([1,1],[2,3,1])

Since: 0.1.2

Searching

elem :: Eq a => a -> CircularVector a -> Bool Source #

O(n) Check if the circular vector contains an element

>>> elem 1 $ unsafeFromList [1..3]
True
>>> elem 4 $ unsafeFromList [1..3]
False

Since: 0.1.2

notElem :: Eq a => a -> CircularVector a -> Bool Source #

O(n) Check if the circular vector does not contain an element (inverse of elem)

>>> notElem 1 $ unsafeFromList [1..3]
False
>>> notElem 4 $ unsafeFromList [1..3]
True

Since: 0.1.2

find :: (a -> Bool) -> CircularVector a -> Maybe a Source #

O(n) Yield Just the first element matching the predicate or Nothing if no such element exists.

>>> find (< 2) $ unsafeFromList [1..3]
Just 1
>>> find (< 0) $ unsafeFromList [1..3]
Nothing

Since: 0.1.2

findIndex :: (a -> Bool) -> CircularVector a -> Maybe Int Source #

O(n) Yield Just the index of the first element matching the predicate or Nothing if no such element exists.

>>> findIndex (< 2) $ unsafeFromList [1..3]
Just 0
>>> findIndex (< 0) $ unsafeFromList [1..3]
Nothing
>>> findIndex (==1) $ rotateRight 1 (unsafeFromList [1..3])
Just 2

Since: 0.1.2

findIndices :: (a -> Bool) -> CircularVector a -> Vector Int Source #

O(n) Yield the indices of elements satisfying the predicate in ascending order.

>>> findIndices (< 3) $ unsafeFromList [1..3]
[0,1]
>>> findIndices (< 0) $ unsafeFromList [1..3]
[]

Since: 0.1.2

elemIndex :: Eq a => a -> CircularVector a -> Maybe Int Source #

O(n) Yield Just the index of the first occurence of the given element or Nothing if the circular vector does not contain the element. This is a specialised version of findIndex.

>>> elemIndex 1 $ unsafeFromList [1..3]
Just 0
>>> elemIndex 0 $ unsafeFromList [1..3]
Nothing

Since: 0.1.2

elemIndices :: Eq a => a -> CircularVector a -> Vector Int Source #

O(n) Yield the indices of all occurences of the given element in ascending order. This is a specialised version of findIndices.

>>> elemIndices 1 $ unsafeFromList [1,2,3,1]
[0,3]
>>> elemIndices 0 $ unsafeFromList [1..3]
[]

Since: 0.1.2

Permutations

reverse :: CircularVector a -> CircularVector a Source #

O(n) Reverse a circular vector.

Since: 0.1.1

backpermute :: CircularVector a -> CircularVector Int -> CircularVector a Source #

O(n) Yield the circular vector obtained by replacing each element i of the circular index vector by xs!i. This is equivalent to map (xs!) is but is often much more efficient.

>>> toList $ backpermute (unsafeFromList [1..3]) (unsafeFromList [2,0])
[3,1]

Since: 0.1.2

unsafeBackpermute :: CircularVector a -> CircularVector Int -> CircularVector a Source #

Same as backpermute but without bounds checking.

Since: 0.1.2

Safe destructive updates

modify :: (forall s. MVector s a -> ST s ()) -> CircularVector a -> CircularVector a Source #

Apply a destructive operation to a circular vector. The operation will be performed in place if it is safe to do so and will modify a copy of the circular vector otherwise.

Since: 0.1.2

Monadic Sequencing

sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) #

Evaluate each monadic action in the structure from left to right, and collect the results. For a version that ignores the results see sequence_.

sequence_ :: (Foldable t, Monad m) => t (m a) -> m () #

Evaluate each monadic action in the structure from left to right, and ignore the results. For a version that doesn't ignore the results see sequence.

As of base 4.8.0.0, sequence_ is just sequenceA_, specialized to Monad.