| Safe Haskell | None | 
|---|---|
| Language | Haskell2010 | 
Data.Vector.Circular
Synopsis
- data CircularVector a = CircularVector {- vector :: !(NonEmptyVector a)
- rotation :: !Int
 
- singleton :: a -> CircularVector a
- replicate :: Int -> a -> Maybe (CircularVector a)
- replicate1 :: Int -> a -> CircularVector a
- generate :: Int -> (Int -> a) -> Maybe (CircularVector a)
- generate1 :: Int -> (Int -> a) -> CircularVector a
- iterateN :: Int -> (a -> a) -> a -> Maybe (CircularVector a)
- iterateN1 :: Int -> (a -> a) -> a -> CircularVector a
- replicateM :: Monad m => Int -> m a -> m (Maybe (CircularVector a))
- replicate1M :: Monad m => Int -> m a -> m (CircularVector a)
- generateM :: Monad m => Int -> (Int -> m a) -> m (Maybe (CircularVector a))
- generate1M :: Monad m => Int -> (Int -> m a) -> m (CircularVector a)
- iterateNM :: Monad m => Int -> (a -> m a) -> a -> m (Maybe (CircularVector a))
- iterateN1M :: Monad m => Int -> (a -> m a) -> a -> m (CircularVector a)
- create :: (forall s. ST s (MVector s a)) -> Maybe (CircularVector a)
- unsafeCreate :: (forall s. ST s (MVector s a)) -> CircularVector a
- createT :: Traversable t => (forall s. ST s (t (MVector s a))) -> t (Maybe (CircularVector a))
- unsafeCreateT :: Traversable t => (forall s. ST s (t (MVector s a))) -> t (CircularVector a)
- unfoldr :: (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a)
- unfoldr1 :: (b -> Maybe (a, b)) -> a -> b -> CircularVector a
- unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a)
- unfoldr1N :: Int -> (b -> Maybe (a, b)) -> a -> b -> CircularVector a
- unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a))
- unfoldr1M :: Monad m => (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a)
- unfoldrNM :: Monad m => Int -> (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a))
- unfoldr1NM :: Monad m => Int -> (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a)
- constructN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
- constructrN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
- enumFromN :: Num a => a -> Int -> Maybe (CircularVector a)
- enumFromN1 :: Num a => a -> Int -> CircularVector a
- enumFromStepN :: Num a => a -> a -> Int -> Maybe (CircularVector a)
- enumFromStepN1 :: Num a => a -> a -> Int -> CircularVector a
- enumFromTo :: Enum a => a -> a -> Maybe (CircularVector a)
- enumFromThenTo :: Enum a => a -> a -> a -> Maybe (CircularVector a)
- cons :: a -> CircularVector a -> CircularVector a
- consV :: a -> Vector a -> CircularVector a
- snoc :: CircularVector a -> a -> CircularVector a
- snocV :: Vector a -> a -> CircularVector a
- (++) :: CircularVector a -> CircularVector a -> CircularVector a
- concat :: [CircularVector a] -> Maybe (CircularVector a)
- concat1 :: NonEmpty (CircularVector a) -> CircularVector a
- force :: NFData a => a -> a
- vec :: Lift a => [a] -> Q (TExp (CircularVector a))
- toVector :: CircularVector a -> Vector a
- fromVector :: NonEmptyVector a -> CircularVector a
- fromVector' :: Vector a -> Maybe (CircularVector a)
- unsafeFromVector :: Vector a -> CircularVector a
- toNonEmptyVector :: CircularVector a -> NonEmptyVector a
- toList :: CircularVector a -> [a]
- fromList :: [a] -> Maybe (CircularVector a)
- fromListN :: Int -> [a] -> Maybe (CircularVector a)
- unsafeFromList :: [a] -> CircularVector a
- unsafeFromListN :: Int -> [a] -> CircularVector a
- rotateLeft :: Int -> CircularVector a -> CircularVector a
- rotateRight :: Int -> CircularVector a -> CircularVector a
- equivalent :: Ord a => CircularVector a -> CircularVector a -> Bool
- canonise :: Ord a => CircularVector a -> CircularVector a
- leastRotation :: forall a. Ord a => Vector a -> Int
- foldMap :: Monoid m => (a -> m) -> CircularVector a -> m
- foldMap' :: Monoid m => (a -> m) -> CircularVector a -> m
- foldr :: (a -> b -> b) -> b -> CircularVector a -> b
- foldl :: (b -> a -> b) -> b -> CircularVector a -> b
- foldr' :: (a -> b -> 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
- foldMap1 :: Semigroup m => (a -> m) -> CircularVector a -> m
- foldMap1' :: Semigroup m => (a -> m) -> CircularVector a -> m
- toNonEmpty :: CircularVector a -> NonEmpty a
- all :: (a -> Bool) -> CircularVector a -> Bool
- any :: (a -> Bool) -> CircularVector a -> Bool
- and :: CircularVector Bool -> Bool
- or :: CircularVector Bool -> Bool
- sum :: Num a => CircularVector a -> a
- product :: Num a => CircularVector a -> a
- maximum :: Ord a => CircularVector a -> a
- maximumBy :: (a -> a -> Ordering) -> CircularVector a -> a
- minimum :: Ord a => CircularVector a -> a
- minimumBy :: (a -> a -> Ordering) -> CircularVector a -> a
- rotateToMinimumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a
- rotateToMaximumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a
- index :: CircularVector a -> Int -> a
- head :: CircularVector a -> a
- last :: CircularVector a -> a
- map :: (a -> b) -> CircularVector a -> CircularVector b
- imap :: (Int -> a -> b) -> CircularVector a -> CircularVector b
- concatMap :: (a -> CircularVector b) -> CircularVector a -> CircularVector b
- mapM :: Monad m => (a -> m b) -> CircularVector a -> m (CircularVector b)
- imapM :: Monad m => (Int -> a -> m b) -> CircularVector a -> m (CircularVector b)
- mapM_ :: Monad m => (a -> m b) -> CircularVector a -> m ()
- imapM_ :: Monad m => (Int -> a -> m b) -> CircularVector a -> m ()
- forM :: Monad m => CircularVector a -> (a -> m b) -> m (CircularVector b)
- forM_ :: Monad m => CircularVector a -> (a -> m b) -> m ()
- zipWith :: (a -> b -> c) -> CircularVector a -> CircularVector b -> CircularVector c
- zipWith3 :: (a -> b -> c -> d) -> CircularVector a -> CircularVector b -> CircularVector c -> CircularVector d
- zip :: CircularVector a -> CircularVector b -> CircularVector (a, b)
- zip3 :: CircularVector a -> CircularVector b -> CircularVector c -> CircularVector (a, b, c)
- unzip :: [(a, b)] -> ([a], [b])
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- uniq :: Eq a => CircularVector a -> CircularVector a
- mapMaybe :: (a -> Maybe b) -> CircularVector a -> Vector b
- imapMaybe :: (Int -> a -> Maybe b) -> CircularVector a -> Vector b
- filter :: (a -> Bool) -> CircularVector a -> Vector a
- ifilter :: (Int -> a -> Bool) -> CircularVector a -> Vector a
- filterM :: Monad m => (a -> m Bool) -> CircularVector a -> m (Vector a)
- ifilterM :: Monad m => (Int -> a -> m Bool) -> CircularVector a -> m (Vector a)
- takeWhile :: (a -> Bool) -> CircularVector a -> Vector a
- dropWhile :: (a -> Bool) -> CircularVector a -> Vector a
- partition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
- unstablePartition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
- span :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
- break :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
- elem :: Eq a => a -> CircularVector a -> Bool
- notElem :: Eq a => a -> CircularVector a -> Bool
- find :: (a -> Bool) -> CircularVector a -> Maybe a
- findIndex :: (a -> Bool) -> CircularVector a -> Maybe Int
- findIndices :: (a -> Bool) -> CircularVector a -> Vector Int
- elemIndex :: Eq a => a -> CircularVector a -> Maybe Int
- elemIndices :: Eq a => a -> CircularVector a -> Vector Int
- reverse :: CircularVector a -> CircularVector a
- backpermute :: CircularVector a -> CircularVector Int -> CircularVector a
- unsafeBackpermute :: CircularVector a -> CircularVector Int -> CircularVector a
- modify :: (forall s. MVector s a -> ST s ()) -> CircularVector a -> CircularVector a
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
Types
data CircularVector a Source #
A circular, immutable vector. This type is equivalent to
   cycle xsxs, but
   with O(1) access and O(1) rotations. Indexing
   into this type is always total.
Constructors
| CircularVector | |
| Fields 
 | |
Instances
Construction
Initialization
singleton :: a -> CircularVector a Source #
O(1) Construct a singleton 'CircularVector.
Since: 0.1
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 fJust (CircularVector {vector = ["a"], rotation = 0})
>>>generate 0 fNothing
>>>generate 2 fJust (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
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) 0CircularVector {vector = [0,1,2], rotation = 0}
>>>iterateN1 0 (+1) 0CircularVector {vector = [0], rotation = 0}
>>>iterateN1 (-1) (+1) 0CircularVector {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 NothingNothing
>>>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 NothingNothing
>>>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)) 0Just (CircularVector {vector = [1,2,3], rotation = 0})
>>>unfoldrN 3 (const Nothing) 0Nothing
>>>unfoldrN 0 (\b -> Just (b+1, b+1)) 0Nothing
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 0CircularVector {vector = [0,1,2,3], rotation = 0}
>>>unfoldr1N 3 (const Nothing) 0 0CircularVector {vector = [0], rotation = 0}
>>>unfoldr1N 0 (\b -> Just (b+1, b+1)) 0 0CircularVector {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 #
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]) 3CircularVector {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]) 3CircularVector {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 #
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
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 hSince: 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 #
toNonEmptyVector :: CircularVector a -> NonEmptyVector a Source #
O(n) Construct a NonEmptyVector from a CircularVector.
Since: 0.1.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 #
unsafeFromListN :: Int -> [a] -> CircularVector a Source #
O(n) Construct a CircularVector from a list with a size hint.
Calls error<= 0
Since: 0.1
Rotation
rotateLeft :: Int -> CircularVector a -> CircularVector a Source #
rotateRight :: Int -> CircularVector a -> CircularVector a Source #
Comparisons
equivalent :: Ord a => CircularVector a -> CircularVector a -> Bool Source #
Since: 0.1
canonise :: Ord a => CircularVector a -> CircularVector a 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
toNonEmpty :: CircularVector a -> NonEmpty a Source #
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
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.
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
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
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. This is equivalent to
 !imap (xs!) is
>>>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_.