-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | circular vectors -- -- nonempty circular vector data structure library. indexing is always -- total @package vector-circular @version 0.1.4 module Data.Vector.Circular -- | 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. data CircularVector a CircularVector :: {-# UNPACK #-} !NonEmptyVector a -> {-# UNPACK #-} !Int -> CircularVector a [vector] :: CircularVector a -> {-# UNPACK #-} !NonEmptyVector a [rotation] :: CircularVector a -> {-# UNPACK #-} !Int -- | O(1) Construct a singleton 'CircularVector. singleton :: a -> CircularVector a -- | 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 --replicate :: Int -> a -> Maybe (CircularVector a) -- | 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}
--
replicate1 :: Int -> a -> CircularVector a
-- | 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})
--
generate :: Int -> (Int -> a) -> Maybe (CircularVector a)
-- | 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"] --generate1 :: Int -> (Int -> a) -> CircularVector a -- | 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 --iterateN :: Int -> (a -> a) -> a -> Maybe (CircularVector a) -- | 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}
--
iterateN1 :: Int -> (a -> a) -> a -> CircularVector a
-- | 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 --replicateM :: Monad m => Int -> m a -> m (Maybe (CircularVector a)) -- | 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})
--
replicate1M :: Monad m => Int -> m a -> m (CircularVector a)
-- | 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 --generateM :: Monad m => Int -> (Int -> m a) -> m (Maybe (CircularVector a)) -- | 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 --generate1M :: Monad m => Int -> (Int -> m a) -> m (CircularVector a) -- | 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 --iterateNM :: Monad m => Int -> (a -> m a) -> a -> m (Maybe (CircularVector a)) -- | 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})
--
iterateN1M :: Monad m => Int -> (a -> m a) -> a -> m (CircularVector a)
-- | Execute the monadic action and freeze the resulting circular vector.
create :: (forall s. ST s (MVector s a)) -> Maybe (CircularVector a)
-- | 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.
unsafeCreate :: (forall s. ST s (MVector s a)) -> CircularVector a
-- | Execute the monadic action and freeze the resulting circular vector.
createT :: Traversable t => (forall s. ST s (t (MVector s a))) -> t (Maybe (CircularVector a))
-- | Execute the monadic action and freeze the resulting circular vector.
--
-- The onus is on the caller to guarantee the created vector is
-- non-empty.
unsafeCreateT :: Traversable t => (forall s. ST s (t (MVector s a))) -> t (CircularVector a)
-- | 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 --unfoldr :: (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a) -- | 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}
--
unfoldr1 :: (b -> Maybe (a, b)) -> a -> b -> CircularVector a
-- | 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 --unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a) -- | 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}
--
unfoldr1N :: Int -> (b -> Maybe (a, b)) -> a -> b -> CircularVector a
-- | 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.
unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a))
-- | 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.
unfoldr1M :: Monad m => (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a)
-- | 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.
unfoldrNM :: Monad m => Int -> (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a))
-- | 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.
unfoldr1NM :: Monad m => Int -> (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a)
-- | 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.
constructN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
-- | 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.
constructrN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
-- | 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.
enumFromN :: Num a => a -> Int -> Maybe (CircularVector a)
-- | 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.
enumFromN1 :: Num a => a -> Int -> CircularVector a
-- | 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.
enumFromStepN :: Num a => a -> a -> Int -> Maybe (CircularVector a)
-- | 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.
enumFromStepN1 :: Num a => a -> a -> Int -> CircularVector a
-- | 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.
enumFromTo :: Enum a => a -> a -> Maybe (CircularVector a)
-- | 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.
enumFromThenTo :: Enum a => a -> a -> a -> Maybe (CircularVector a)
-- | O(n) Prepend an element
--
--
-- >>> cons 1 (unsafeFromList [2,3])
-- CircularVector {vector = [1,2,3], rotation = 0}
--
cons :: a -> CircularVector a -> CircularVector a
-- | O(n) Prepend an element to a Vector
--
--
-- >>> consV 1 (Vector.fromList [2,3])
-- CircularVector {vector = [1,2,3], rotation = 0}
--
consV :: a -> Vector a -> CircularVector a
-- | O(n) Append an element
--
--
-- >>> snoc (unsafeFromList [1,2]) 3
-- CircularVector {vector = [1,2,3], rotation = 0}
--
snoc :: CircularVector a -> a -> CircularVector a
-- | O(n) Append an element to a Vector
--
--
-- >>> snocV (Vector.fromList [1,2]) 3
-- CircularVector {vector = [1,2,3], rotation = 0}
--
snocV :: Vector a -> a -> CircularVector a
-- | O(m+n) Concatenate two circular vectors
--
--
-- >>> (unsafeFromList [1..3]) ++ (unsafeFromList [4..6])
-- CircularVector {vector = [1,2,3,4,5,6], rotation = 0}
--
(++) :: CircularVector a -> CircularVector a -> CircularVector a
-- | 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})
--
concat :: [CircularVector a] -> Maybe (CircularVector a)
-- | 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}
--
concat1 :: NonEmpty (CircularVector a) -> CircularVector 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 --force :: NFData a => a -> a -- | Construct a CircularVector at compile-time using typed Template -- Haskell. vec :: Lift a => [a] -> Q (TExp (CircularVector a)) -- | O(n) Construct a Vector from a CircularVector. toVector :: CircularVector a -> Vector a -- | O(1) Construct a CircularVector from a -- NonEmptyVector. fromVector :: NonEmptyVector a -> CircularVector a -- | O(1) Construct a CircularVector from a -- NonEmptyVector. fromVector' :: Vector a -> Maybe (CircularVector a) -- | O(1) Construct a CircularVector from a Vector. -- -- Calls error if the input vector is empty. unsafeFromVector :: Vector a -> CircularVector a -- | O(n) Construct a NonEmptyVector from a -- CircularVector. toNonEmptyVector :: CircularVector a -> NonEmptyVector a -- | O(n) Convert from a circular vector to a list. -- --
-- >>> let nev = unsafeFromList [1..3] in toList nev -- [1,2,3] --toList :: CircularVector a -> [a] -- | O(n) Construct a CircularVector from a list. fromList :: [a] -> Maybe (CircularVector a) -- | Construct a CircularVector from a list with a size hint. fromListN :: Int -> [a] -> Maybe (CircularVector a) -- | O(n) Construct a CircularVector from a list. -- -- Calls error if the input list is empty. unsafeFromList :: [a] -> CircularVector a -- | 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. unsafeFromListN :: Int -> [a] -> CircularVector a -- | 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@ rotateLeft :: Int -> CircularVector a -> CircularVector a -- | 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@ 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 -- | Lazily-accumulating monoidal fold over a CircularVector. @since -- 0.1 foldMap :: Monoid m => (a -> m) -> CircularVector a -> m -- | Strictly-accumulating monoidal fold over a CircularVector. 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 -- | Lazily-accumulating semigroupoidal fold over a CircularVector. foldMap1 :: Semigroup m => (a -> m) -> CircularVector a -> m -- | Strictly-accumulating semigroupoidal fold over a -- CircularVector. foldMap1' :: Semigroup m => (a -> m) -> CircularVector a -> m toNonEmpty :: CircularVector a -> NonEmpty a -- | O(n) Check if all elements satisfy the predicate. all :: (a -> Bool) -> CircularVector a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: (a -> Bool) -> CircularVector a -> Bool -- | O(n) Check if all elements are True. and :: CircularVector Bool -> Bool -- | O(n) Check if any element is True. or :: CircularVector Bool -> Bool -- | O(n) Compute the sum of the elements. sum :: Num a => CircularVector a -> a -- | O(n) Compute the product of the elements. product :: Num a => CircularVector a -> a -- | O(n) Yield the maximum element of the circular vector. maximum :: Ord a => CircularVector a -> a -- | O(n) Yield the maximum element of a circular vector according -- to the given comparison function. maximumBy :: (a -> a -> Ordering) -> CircularVector a -> a -- | O(n) Yield the minimum element of the circular vector. minimum :: Ord a => CircularVector a -> a -- | O(n) Yield the minimum element of a circular vector according -- to the given comparison function. minimumBy :: (a -> a -> Ordering) -> CircularVector a -> a -- | O(n) Rotate to the minimum element of the circular vector -- according to the given comparison function. rotateToMinimumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a -- | O(n) Rotate to the maximum element of the circular vector -- according to the given comparison function. rotateToMaximumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a -- | O(1) Index into a CircularVector. This is always total. index :: CircularVector a -> Int -> a -- | O(1) Get the first element of a CircularVector. This is -- always total. head :: CircularVector a -> a -- | O(1) Get the last element of a CircularVector. This is -- always total. last :: CircularVector a -> a -- | O(n) Map a function over a circular vector. -- --
-- >>> map (+1) $ unsafeFromList [1..3]
-- CircularVector {vector = [2,3,4], rotation = 0}
--
map :: (a -> b) -> CircularVector a -> CircularVector b
-- | 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}
--
imap :: (Int -> a -> b) -> CircularVector a -> CircularVector b
-- | 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}
--
concatMap :: (a -> CircularVector b) -> CircularVector a -> CircularVector b
-- | 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 --mapM :: Monad m => (a -> m b) -> CircularVector a -> m (CircularVector b) -- | 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 --imapM :: Monad m => (Int -> a -> m b) -> CircularVector a -> m (CircularVector b) -- | 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 --mapM_ :: Monad m => (a -> m b) -> CircularVector a -> m () -- | 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 --imapM_ :: Monad m => (Int -> a -> m b) -> CircularVector a -> m () -- | O(n) Apply the monadic action to all elements of the circular -- vector, yielding a circular vector of results. -- -- Equivalent to flip mapM. forM :: Monad m => CircularVector a -> (a -> m b) -> m (CircularVector b) -- | O(n) Apply the monadic action to all elements of a circular -- vector and ignore the results. -- -- Equivalent to flip mapM_. forM_ :: Monad m => CircularVector a -> (a -> m b) -> m () -- | O(min(m,n)) Zip two circular vectors with the given function. zipWith :: (a -> b -> c) -> CircularVector a -> CircularVector b -> CircularVector c -- | Zip three circular vectors with the given function. zipWith3 :: (a -> b -> c -> d) -> CircularVector a -> CircularVector b -> CircularVector c -> CircularVector d -- | O(min(n,m)) Elementwise pairing of circular vector elements. -- This is a special case of zipWith where the function argument -- is (,) zip :: CircularVector a -> CircularVector b -> CircularVector (a, b) -- | Zip together three circular vectors. zip3 :: CircularVector a -> CircularVector b -> CircularVector c -> CircularVector (a, b, c) -- | unzip transforms a list of pairs into a list of first -- components and a list of second components. unzip :: [(a, b)] -> ([a], [b]) -- | The unzip3 function takes a list of triples and returns three -- lists, analogous to unzip. unzip3 :: [(a, b, c)] -> ([a], [b], [c]) -- | 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] --uniq :: Eq a => CircularVector a -> CircularVector a -- | 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] --mapMaybe :: (a -> Maybe b) -> CircularVector a -> Vector b -- | 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] --imapMaybe :: (Int -> a -> Maybe b) -> CircularVector a -> Vector b -- | 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]) -- [] --filter :: (a -> Bool) -> CircularVector a -> Vector a -- | 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]) -- [] --ifilter :: (Int -> a -> Bool) -> CircularVector a -> Vector a -- | 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 [] --filterM :: Monad m => (a -> m Bool) -> CircularVector a -> m (Vector a) -- | 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 [] --ifilterM :: Monad m => (Int -> a -> m Bool) -> CircularVector a -> m (Vector a) -- | 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] --takeWhile :: (a -> Bool) -> CircularVector a -> Vector a -- | 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] --dropWhile :: (a -> Bool) -> CircularVector a -> Vector a -- | 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]) --partition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) -- | 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. unstablePartition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) -- | 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]) --span :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) -- | 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]) --break :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a) -- | O(n) Check if the circular vector contains an element -- --
-- >>> elem 1 $ unsafeFromList [1..3] -- True -- -- >>> elem 4 $ unsafeFromList [1..3] -- False --elem :: Eq a => a -> CircularVector a -> Bool -- | 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 --notElem :: Eq a => a -> CircularVector a -> Bool -- | 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 --find :: (a -> Bool) -> CircularVector a -> Maybe a -- | 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 --findIndex :: (a -> Bool) -> CircularVector a -> Maybe Int -- | 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] -- [] --findIndices :: (a -> Bool) -> CircularVector a -> Vector Int -- | 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 --elemIndex :: Eq a => a -> CircularVector a -> Maybe Int -- | 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] -- [] --elemIndices :: Eq a => a -> CircularVector a -> Vector Int -- | O(n) Reverse a circular vector. reverse :: CircularVector a -> CircularVector a -- | 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] --backpermute :: CircularVector a -> CircularVector Int -> CircularVector a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: CircularVector a -> CircularVector Int -> CircularVector a -- | 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. modify :: (forall s. MVector s a -> ST s ()) -> CircularVector a -> CircularVector 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 :: (Traversable t, Monad m) => t (m a) -> m (t a) -- | 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. sequence_ :: (Foldable t, Monad m) => t (m a) -> m () instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Data.Vector.Circular.CircularVector a) instance GHC.Show.Show a => GHC.Show.Show (Data.Vector.Circular.CircularVector a) instance GHC.Read.Read a => GHC.Read.Read (Data.Vector.Circular.CircularVector a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Vector.Circular.CircularVector a) instance GHC.Generics.Generic (Data.Vector.Circular.CircularVector a) instance GHC.Base.Functor Data.Vector.Circular.CircularVector instance Data.Traversable.Traversable Data.Vector.Circular.CircularVector instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Vector.Circular.CircularVector a) instance Data.Functor.Classes.Eq1 Data.Vector.Circular.CircularVector instance Data.Functor.Classes.Ord1 Data.Vector.Circular.CircularVector instance Data.Functor.Classes.Show1 Data.Vector.Circular.CircularVector instance Data.Functor.Classes.Read1 Data.Vector.Circular.CircularVector instance GHC.Base.Semigroup (Data.Vector.Circular.CircularVector a) instance Data.Foldable.Foldable Data.Vector.Circular.CircularVector instance Data.Semigroup.Foldable.Class.Foldable1 Data.Vector.Circular.CircularVector instance Language.Haskell.TH.Syntax.Lift a => Language.Haskell.TH.Syntax.Lift (Data.Vector.Circular.CircularVector a) module Data.Vector.Circular.Generic -- | 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. data CircularVector v a CircularVector :: !v a -> {-# UNPACK #-} !Int -> CircularVector v a [vector] :: CircularVector v a -> !v a [rotation] :: CircularVector v a -> {-# UNPACK #-} !Int -- | O(1) Construct a singleton 'CircularVector. -- -- since 0.1.2 singleton :: Vector v a => a -> CircularVector v a -- | 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 @Vector 3 "a"
-- Just (CircularVector {vector = ["a","a","a"], rotation = 0})
--
--
-- -- >>> replicate @Vector 0 "a" -- Nothing --replicate :: Vector v a => Int -> a -> Maybe (CircularVector v a) -- | 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. -- --
-- >>> toList $ replicate1 @Vector 3 "a" -- ["a","a","a"] ---- --
-- >>> toList $ replicate1 @Vector 0 "a" -- ["a"] ---- --
-- >>> toList $ replicate1 @Vector (-1) "a" -- ["a"] --replicate1 :: Vector v a => Int -> a -> CircularVector v a -- | 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 @Vector 1 f
-- Just (CircularVector {vector = ["a"], rotation = 0})
--
--
-- -- >>> generate @Vector 0 f -- Nothing ---- --
-- >>> generate @Vector 2 f
-- Just (CircularVector {vector = ["a","k"], rotation = 0})
--
generate :: Vector v a => Int -> (Int -> a) -> Maybe (CircularVector v a)
-- | 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 @Vector 2 f -- ["a","k"] ---- --
-- >>> toList $ generate1 @Vector 0 f -- ["a"] ---- --
-- >>> toList $ generate1 @Vector (-1) f -- ["a"] --generate1 :: Vector v a => Int -> (Int -> a) -> CircularVector v a -- | 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 @Vector 3 (+1) 0
-- Just (CircularVector {vector = [0,1,2], rotation = 0})
--
--
-- -- >>> iterateN @Vector 0 (+1) 0 -- Nothing ---- --
-- >>> iterateN @Vector (-1) (+1) 0 -- Nothing --iterateN :: Vector v a => Int -> (a -> a) -> a -> Maybe (CircularVector v a) -- | 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 @Vector 3 (+1) 0
-- CircularVector {vector = [0,1,2], rotation = 0}
--
--
--
-- >>> iterateN1 @Vector 0 (+1) 0
-- CircularVector {vector = [0], rotation = 0}
--
--
--
-- >>> iterateN1 @Vector (-1) (+1) 0
-- CircularVector {vector = [0], rotation = 0}
--
iterateN1 :: Vector v a => Int -> (a -> a) -> a -> CircularVector v a
-- | 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 @Vector 3 (Just "a")
-- Just (Just (CircularVector {vector = ["a","a","a"], rotation = 0}))
--
--
-- -- >>> replicateM @Maybe @Vector 3 Nothing -- Nothing ---- --
-- >>> replicateM @Maybe @Vector 0 (Just "a") -- Just Nothing ---- --
-- >>> replicateM @Maybe @Vector (-1) (Just "a") -- Just Nothing --replicateM :: (Monad m, Vector v a) => Int -> m a -> m (Maybe (CircularVector v a)) -- | 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 @Vector 3 (Just "a")
-- Just (CircularVector {vector = ["a","a","a"], rotation = 0})
--
--
-- -- >>> replicate1M @Maybe @Vector 3 Nothing -- Nothing ---- --
-- >>> replicate1M @Maybe @Vector 0 (Just "a")
-- Just (CircularVector {vector = ["a"], rotation = 0})
--
--
--
-- >>> replicate1M @Maybe @Vector (-1) (Just "a")
-- Just (CircularVector {vector = ["a"], rotation = 0})
--
replicate1M :: (Monad m, Vector v a) => Int -> m a -> m (CircularVector v a)
-- | 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 @[] @Vector 3 (\i -> if i < 1 then ["a"] else ["b"])
-- [Just (CircularVector {vector = ["a","b","b"], rotation = 0})]
--
--
-- -- >>> generateM @[] @Vector @Int 3 (const []) -- [] ---- --
-- >>> generateM @[] @Vector @Int 0 (const [1]) -- [Nothing] ---- --
-- >>> generateM @Maybe @Vector @Int (-1) (const Nothing) -- Just Nothing --generateM :: (Monad m, Vector v a) => Int -> (Int -> m a) -> m (Maybe (CircularVector v a)) -- | 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 @Maybe @Vector 3 (\i -> if i < 1 then Just "a" else Just "b")
-- Just (CircularVector {vector = ["a","b","b"], rotation = 0})
--
--
-- -- >>> generate1M @[] @Vector 3 (const []) -- [] ---- --
-- >>> generate1M @Maybe @Vector 0 (const $ Just 1)
-- Just (CircularVector {vector = [1], rotation = 0})
--
--
-- -- >>> generate1M @Maybe @Vector (-1) (const Nothing) -- Nothing --generate1M :: (Monad m, Vector v a) => Int -> (Int -> m a) -> m (CircularVector v a) -- | 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 @Vector 3 return "a"
-- Just (Just (CircularVector {vector = ["a","a","a"], rotation = 0}))
--
--
-- -- >>> iterateNM @Maybe @Vector 3 (const Nothing) "a" -- Nothing ---- --
-- >>> iterateNM @Maybe @Vector 0 return "a" -- Just Nothing --iterateNM :: (Monad m, Vector v a) => Int -> (a -> m a) -> a -> m (Maybe (CircularVector v a)) -- | 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 @Vector 3 return "a"
-- Just (CircularVector {vector = ["a","a","a"], rotation = 0})
--
--
-- -- >>> iterateN1M @Maybe @Vector 3 (const Nothing) "a" -- Nothing ---- --
-- >>> iterateN1M @Maybe @Vector 0 return "a"
-- Just (CircularVector {vector = ["a"], rotation = 0})
--
--
--
-- >>> iterateN1M @Maybe @Vector (-1) return "a"
-- Just (CircularVector {vector = ["a"], rotation = 0})
--
iterateN1M :: (Monad m, Vector v a) => Int -> (a -> m a) -> a -> m (CircularVector v a)
-- | Execute the monadic action and freeze the resulting circular vector.
create :: Vector v a => (forall s. ST s (Mutable v s a)) -> Maybe (CircularVector v a)
-- | 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.
unsafeCreate :: Vector v a => (forall s. ST s (Mutable v s a)) -> CircularVector v a
-- | Execute the monadic action and freeze the resulting circular vector.
createT :: (Traversable t, Vector v a) => (forall s. ST s (t (Mutable v s a))) -> t (Maybe (CircularVector v a))
-- | Execute the monadic action and freeze the resulting circular vector.
--
-- The onus is on the caller to guarantee the created vector is
-- non-empty.
unsafeCreateT :: (Traversable t, Vector v a) => (forall s. ST s (t (Mutable v s a))) -> t (CircularVector v a)
-- | 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 @Vector (\b -> case b of "a" -> Just ("a", "b"); _ -> Nothing) "a"
-- Just (CircularVector {vector = ["a"], rotation = 0})
--
--
-- -- >>> unfoldr @Vector (const Nothing) "a" -- Nothing --unfoldr :: Vector v a => (b -> Maybe (a, b)) -> b -> Maybe (CircularVector v a) -- | 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 @Vector (\b -> case b of "a" -> Just ("a", "b"); _ -> Nothing) "first" "a"
-- CircularVector {vector = ["first","a"], rotation = 0}
--
--
--
-- >>> unfoldr1 @Vector (const Nothing) "first" "a"
-- CircularVector {vector = ["first"], rotation = 0}
--
unfoldr1 :: Vector v a => (b -> Maybe (a, b)) -> a -> b -> CircularVector v a
-- | 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 @Vector 3 (\b -> Just (b+1, b+1)) 0
-- Just (CircularVector {vector = [1,2,3], rotation = 0})
--
--
-- -- >>> unfoldrN @Vector 3 (const Nothing) 0 -- Nothing ---- --
-- >>> unfoldrN @Vector 0 (\b -> Just (b+1, b+1)) 0 -- Nothing --unfoldrN :: Vector v a => Int -> (b -> Maybe (a, b)) -> b -> Maybe (CircularVector v a) -- | 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 @Vector 3 (\b -> Just (b+1, b+1)) 0 0
-- CircularVector {vector = [0,1,2,3], rotation = 0}
--
--
--
-- >>> unfoldr1N @Vector 3 (const Nothing) 0 0
-- CircularVector {vector = [0], rotation = 0}
--
--
--
-- >>> unfoldr1N @Vector 0 (\b -> Just (b+1, b+1)) 0 0
-- CircularVector {vector = [0], rotation = 0}
--
unfoldr1N :: Vector v a => Int -> (b -> Maybe (a, b)) -> a -> b -> CircularVector v a
-- | 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.
unfoldrM :: (Monad m, Vector v a) => (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector v a))
-- | 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.
unfoldr1M :: (Monad m, Vector v a) => (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector v a)
-- | 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.
unfoldrNM :: (Monad m, Vector v a) => Int -> (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector v a))
-- | 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.
unfoldr1NM :: (Monad m, Vector v a) => Int -> (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector v a)
-- | 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.
constructN :: Vector v a => Int -> (v a -> a) -> Maybe (CircularVector v a)
-- | 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.
constructrN :: Vector v a => Int -> (v a -> a) -> Maybe (CircularVector v a)
-- | 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.
enumFromN :: (Vector v a, Num a) => a -> Int -> Maybe (CircularVector v a)
-- | 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.
enumFromN1 :: (Vector v a, Num a) => a -> Int -> CircularVector v a
-- | 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.
enumFromStepN :: (Vector v a, Num a) => a -> a -> Int -> Maybe (CircularVector v a)
-- | 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.
enumFromStepN1 :: (Vector v a, Num a) => a -> a -> Int -> CircularVector v a
-- | 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.
enumFromTo :: (Vector v a, Enum a) => a -> a -> Maybe (CircularVector v a)
-- | 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.
enumFromThenTo :: (Vector v a, Enum a) => a -> a -> a -> Maybe (CircularVector v a)
-- | O(n) Prepend an element
--
--
-- >>> cons 1 (unsafeFromList @Vector [2,3])
-- CircularVector {vector = [1,2,3], rotation = 0}
--
cons :: Vector v a => a -> CircularVector v a -> CircularVector v a
-- | O(n) Prepend an element to a Vector
--
--
-- >>> consV 1 (Data.Vector.fromList [2,3])
-- CircularVector {vector = [1,2,3], rotation = 0}
--
consV :: Vector v a => a -> v a -> CircularVector v a
-- | O(n) Append an element
--
--
-- >>> snoc (unsafeFromList @Vector [1,2]) 3
-- CircularVector {vector = [1,2,3], rotation = 0}
--
snoc :: Vector v a => CircularVector v a -> a -> CircularVector v a
-- | O(n) Append an element to a Vector
--
--
-- >>> snocV (Data.Vector.fromList [1,2]) 3
-- CircularVector {vector = [1,2,3], rotation = 0}
--
snocV :: Vector v a => v a -> a -> CircularVector v a
-- | O(m+n) Concatenate two circular vectors
--
--
-- >>> (unsafeFromList @Vector [1..3]) ++ (unsafeFromList [4..6])
-- CircularVector {vector = [1,2,3,4,5,6], rotation = 0}
--
(++) :: Vector v a => CircularVector v a -> CircularVector v a -> CircularVector v a
-- | 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 @Vector [1..3]), (unsafeFromList [4..6])]
-- Just (CircularVector {vector = [1,2,3,4,5,6], rotation = 0})
--
concat :: Vector v a => [CircularVector v a] -> Maybe (CircularVector v a)
-- | O(n) Concatenate all circular vectors in a non-empty list.
--
--
-- >>> concat1 ((unsafeFromList @Vector [1..3]) :| [(unsafeFromList [4..6])])
-- CircularVector {vector = [1,2,3,4,5,6], rotation = 0}
--
concat1 :: Vector v a => NonEmpty (CircularVector v a) -> CircularVector v 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 --force :: NFData a => a -> a -- | O(n) Construct a Vector from a CircularVector. -- -- since 0.1.2 toVector :: Vector v a => CircularVector v a -> v a -- | O(1) Construct a CircularVector from a vector. -- -- since 0.1.2 fromVector :: Vector v a => v a -> Maybe (CircularVector v a) -- | O(1) Construct a CircularVector from a Vector. -- -- Calls error if the input vector is empty. -- -- since 0.1.2 unsafeFromVector :: Vector v a => v a -> CircularVector v a -- | O(n) Construct a NonEmptyVector from a -- CircularVector. toNonEmptyVector :: Vector v a => CircularVector v a -> NonEmptyVector a -- | O(n) Convert from a circular vector to a list. -- --
-- >>> let nev = unsafeFromList @Vector [1..3] in toList nev -- [1,2,3] --toList :: Vector v a => CircularVector v a -> [a] -- | O(n) Construct a CircularVector from a list. -- -- since 0.1.2 fromList :: Vector v a => [a] -> Maybe (CircularVector v a) -- | Construct a CircularVector from a list with a size hint. -- -- since 0.1.2 fromListN :: Vector v a => Int -> [a] -> Maybe (CircularVector v a) -- | O(n) Construct a CircularVector from a list. -- -- Calls error if the input list is empty. -- -- since 0.1.2 unsafeFromList :: Vector v a => [a] -> CircularVector v a -- | 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.2 unsafeFromListN :: Vector v a => Int -> [a] -> CircularVector v a -- | 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.2 rotateLeft :: Vector v a => Int -> CircularVector v a -> CircularVector v a -- | 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.2 rotateRight :: Vector v a => Int -> CircularVector v a -> CircularVector v a -- | since 0.1.2 equivalent :: (Vector v a, Eq (v a), Ord a) => CircularVector v a -> CircularVector v a -> Bool -- | since 0.1.2 canonise :: (Vector v a, Ord a) => CircularVector v a -> CircularVector v a -- | since 0.1.2 leastRotation :: forall a. Ord a => NonEmptyVector a -> Int -- | Lazily-accumulating monoidal fold over a CircularVector. since -- 0.1.2 foldMap :: (Monoid m, Vector v a) => (a -> m) -> CircularVector v a -> m -- | Strictly-accumulating monoidal fold over a CircularVector. -- -- since 0.1.2 foldMap' :: (Monoid m, Vector v a) => (a -> m) -> CircularVector v a -> m -- | since 0.1.2 foldr :: Vector v a => (a -> b -> b) -> b -> CircularVector v a -> b foldl :: Vector v a => (b -> a -> b) -> b -> CircularVector v a -> b foldr' :: Vector v a => (a -> b -> b) -> b -> CircularVector v a -> b foldl' :: Vector v a => (b -> a -> b) -> b -> CircularVector v a -> b foldr1 :: Vector v a => (a -> a -> a) -> CircularVector v a -> a foldl1 :: Vector v a => (a -> a -> a) -> CircularVector v a -> a -- | Lazily-accumulating semigroupoidal fold over a CircularVector. -- -- since 0.1.2 foldMap1 :: (Vector v a, Semigroup m) => (a -> m) -> CircularVector v a -> m -- | Strictly-accumulating semigroupoidal fold over a -- CircularVector. -- -- since 0.1.2 foldMap1' :: (Vector v a, Semigroup m) => (a -> m) -> CircularVector v a -> m -- | since 0.1.2 toNonEmpty :: Vector v a => CircularVector v a -> NonEmpty a -- | O(n) Check if all elements satisfy the predicate. all :: Vector v a => (a -> Bool) -> CircularVector v a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: Vector v a => (a -> Bool) -> CircularVector v a -> Bool -- | O(n) Check if all elements are True. and :: Vector v Bool => CircularVector v Bool -> Bool -- | O(n) Check if any element is True. or :: Vector v Bool => CircularVector v Bool -> Bool -- | O(n) Compute the sum of the elements. sum :: (Vector v a, Num a) => CircularVector v a -> a -- | O(n) Compute the product of the elements. product :: (Vector v a, Num a) => CircularVector v a -> a -- | O(n) Yield the maximum element of the circular vector. maximum :: (Vector v a, Ord a) => CircularVector v a -> a -- | O(n) Yield the maximum element of a circular vector according -- to the given comparison function. maximumBy :: Vector v a => (a -> a -> Ordering) -> CircularVector v a -> a -- | O(n) Yield the minimum element of the circular vector. minimum :: (Vector v a, Ord a) => CircularVector v a -> a -- | O(n) Yield the minimum element of a circular vector according -- to the given comparison function. minimumBy :: Vector v a => (a -> a -> Ordering) -> CircularVector v a -> a -- | O(n) Rotate to the minimum element of the circular vector -- according to the given comparison function. rotateToMinimumBy :: Vector v a => (a -> a -> Ordering) -> CircularVector v a -> CircularVector v a -- | O(n) Rotate to the maximum element of the circular vector -- according to the given comparison function. rotateToMaximumBy :: Vector v a => (a -> a -> Ordering) -> CircularVector v a -> CircularVector v a -- | O(1) Index into a CircularVector. This is always total. -- -- since 0.1.2 index :: Vector v a => CircularVector v a -> Int -> a -- | O(1) Get the first element of a CircularVector. This is -- always total. -- -- since 0.1.2 head :: Vector v a => CircularVector v a -> a -- | O(1) Get the last element of a CircularVector. This is -- always total. -- -- since 0.1.2 last :: Vector v a => CircularVector v a -> a -- | O(n) Map a function over a circular vector. -- --
-- >>> map (+1) $ unsafeFromList @Vector [1..3]
-- CircularVector {vector = [2,3,4], rotation = 0}
--
map :: (Vector v a, Vector v b) => (a -> b) -> CircularVector v a -> CircularVector v b
-- | 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 @Vector [1..3]
-- CircularVector {vector = [1,2,4], rotation = 0}
--
imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> CircularVector v a -> CircularVector v b
-- | Map a function over a circular vector and concatenate the results.
--
--
-- >>> concatMap (\a -> unsafeFromList @Vector [a,a]) (unsafeFromList [1,2,3])
-- CircularVector {vector = [1,1,2,2,3,3], rotation = 0}
--
concatMap :: (Vector v a, Vector v b) => (a -> CircularVector v b) -> CircularVector v a -> CircularVector v b
-- | O(n) Apply the monadic action to all elements of the circular
-- vector, yielding circular vector of results.
--
--
-- >>> mapM Just (unsafeFromList @Vector [1..3])
-- Just (CircularVector {vector = [1,2,3], rotation = 0})
--
--
-- -- >>> mapM (const Nothing) (unsafeFromList @Vector [1..3]) -- Nothing --mapM :: (Monad m, Vector v a, Vector v b) => (a -> m b) -> CircularVector v a -> m (CircularVector v b) -- | 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 @Vector [1..3])
-- Just (CircularVector {vector = [0,2,0], rotation = 0})
--
--
-- -- >>> imapM (\_ _ -> Nothing) (unsafeFromList @Vector [1..3]) -- Nothing --imapM :: (Monad m, Vector v a, Vector v b) => (Int -> a -> m b) -> CircularVector v a -> m (CircularVector v b) -- | O(n) Apply the monadic action to all elements of a circular -- vector and ignore the results. -- --
-- >>> mapM_ (const $ Just ()) (unsafeFromList @Vector [1..3]) -- Just () ---- --
-- >>> mapM_ (const Nothing) (unsafeFromList @Vector [1..3]) -- Nothing --mapM_ :: (Monad m, Vector v a, Vector v b) => (a -> m b) -> CircularVector v a -> m () -- | 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 @Vector [1..3]) -- 0 -- 2 -- 0 ---- --
-- >>> imapM_ (\_ _ -> Nothing) (unsafeFromList @Vector [1..3]) -- Nothing --imapM_ :: (Monad m, Vector v a) => (Int -> a -> m b) -> CircularVector v a -> m () -- | O(n) Apply the monadic action to all elements of the circular -- vector, yielding a circular vector of results. -- -- Equivalent to flip mapM. forM :: (Monad m, Vector v a, Vector v b) => CircularVector v a -> (a -> m b) -> m (CircularVector v b) -- | O(n) Apply the monadic action to all elements of a circular -- vector and ignore the results. -- -- Equivalent to flip mapM_. forM_ :: (Monad m, Vector v a) => CircularVector v a -> (a -> m b) -> m () -- | O(min(m,n)) Zip two circular vectors with the given function. zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> CircularVector v a -> CircularVector v b -> CircularVector v c -- | Zip three circular vectors with the given function. zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> CircularVector v a -> CircularVector v b -> CircularVector v c -> CircularVector v d -- | O(min(n,m)) Elementwise pairing of circular vector elements. -- This is a special case of zipWith where the function argument -- is (,) zip :: (Vector v a, Vector v b, Vector v (a, b)) => CircularVector v a -> CircularVector v b -> CircularVector v (a, b) -- | Zip together three circular vectors. zip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => CircularVector v a -> CircularVector v b -> CircularVector v c -> CircularVector v (a, b, c) -- | unzip transforms a list of pairs into a list of first -- components and a list of second components. unzip :: [(a, b)] -> ([a], [b]) -- | The unzip3 function takes a list of triples and returns three -- lists, analogous to unzip. unzip3 :: [(a, b, c)] -> ([a], [b], [c]) -- | O(n) Drop repeated adjacent elements. -- --
-- >>> toList $ uniq $ unsafeFromList @Vector [1,1,2,2,3,3,1] -- [1,2,3] ---- --
-- >>> toList $ uniq $ unsafeFromList @Vector [1,2,3,1] -- [1,2,3] --uniq :: (Vector v a, Eq a) => CircularVector v a -> CircularVector v a -- | 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 @Vector [1..3]) -- [1,3] --mapMaybe :: (Vector v a, Vector v b) => (a -> Maybe b) -> CircularVector v a -> v b -- | 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 @Vector [1..3]) -- [1] --imapMaybe :: (Vector v a, Vector v b) => (Int -> a -> Maybe b) -> CircularVector v a -> v b -- | 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 @Vector [1..3]) -- [1,3] ---- --
-- >>> filter (const False) (unsafeFromList @Vector [1..3]) -- [] --filter :: Vector v a => (a -> Bool) -> CircularVector v a -> v a -- | 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 @Vector [1..3]) -- [3] ---- --
-- >>> ifilter (\_ _ -> False) (unsafeFromList @Vector [1..3]) -- [] --ifilter :: Vector v a => (Int -> a -> Bool) -> CircularVector v a -> v a -- | 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 @Vector [1..3]) -- Just [1,3] ---- --
-- >>> filterM (\a -> if a == 2 then Nothing else Just True) (unsafeFromList @Vector [1..3]) -- Nothing ---- --
-- >>> filterM (const $ Just False) (unsafeFromList @Vector [1..3]) -- Just [] --filterM :: (Monad m, Vector v a) => (a -> m Bool) -> CircularVector v a -> m (v a) -- | 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 @Vector [1..3]) -- [1,2] --takeWhile :: Vector v a => (a -> Bool) -> CircularVector v a -> v a -- | 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 @Vector [1..3]) -- [3] --dropWhile :: Vector v a => (a -> Bool) -> CircularVector v a -> v a -- | 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 @Vector [1..5]) -- ([1,2],[3,4,5]) --partition :: Vector v a => (a -> Bool) -> CircularVector v a -> (v a, v a) -- | 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. unstablePartition :: Vector v a => (a -> Bool) -> CircularVector v a -> (v a, v a) -- | 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 @Vector [1,1,2,3,1]) -- ([1,1],[2,3,1]) --span :: Vector v a => (a -> Bool) -> CircularVector v a -> (v a, v a) -- | 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 @Vector [1,1,2,3,1]) -- ([1,1],[2,3,1]) --break :: Vector v a => (a -> Bool) -> CircularVector v a -> (v a, v a) -- | O(n) Check if the circular vector contains an element -- --
-- >>> elem 1 $ unsafeFromList @Vector [1..3] -- True -- -- >>> elem 4 $ unsafeFromList @Vector [1..3] -- False --elem :: (Vector v a, Eq a) => a -> CircularVector v a -> Bool -- | O(n) Check if the circular vector does not contain an element -- (inverse of elem) -- --
-- >>> notElem 1 $ unsafeFromList @Vector [1..3] -- False ---- --
-- >>> notElem 4 $ unsafeFromList @Vector [1..3] -- True --notElem :: (Vector v a, Eq a) => a -> CircularVector v a -> Bool -- | O(n) Yield Just the first element matching the predicate -- or Nothing if no such element exists. -- --
-- >>> find (< 2) $ unsafeFromList @Vector [1..3] -- Just 1 ---- --
-- >>> find (< 0) $ unsafeFromList @Vector [1..3] -- Nothing --find :: Vector v a => (a -> Bool) -> CircularVector v a -> Maybe a -- | O(n) Yield Just the index of the first element matching -- the predicate or Nothing if no such element exists. -- --
-- >>> findIndex (< 2) $ unsafeFromList @Vector [1..3] -- Just 0 ---- --
-- >>> findIndex (< 0) $ unsafeFromList @Vector [1..3] -- Nothing ---- --
-- >>> findIndex (==1) $ rotateRight 1 (unsafeFromList @Vector [1..3]) -- Just 2 --findIndex :: Vector v a => (a -> Bool) -> CircularVector v a -> Maybe Int -- | O(n) Yield the indices of elements satisfying the predicate in -- ascending order. -- --
-- >>> findIndices (< 3) $ unsafeFromList @Vector [1..3] -- [0,1] ---- --
-- >>> findIndices (< 0) $ unsafeFromList @Vector [1..3] -- [] --findIndices :: (Vector v a, Vector v Int) => (a -> Bool) -> CircularVector v a -> v Int -- | 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 @Vector [1..3] -- Just 0 ---- --
-- >>> elemIndex 0 $ unsafeFromList @Vector [1..3] -- Nothing --elemIndex :: (Vector v a, Eq a) => a -> CircularVector v a -> Maybe Int -- | 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 @Vector [1,2,3,1] -- [0,3] ---- --
-- >>> elemIndices 0 $ unsafeFromList @Vector [1..3] -- [] --elemIndices :: (Vector v a, Vector v Int, Eq a) => a -> CircularVector v a -> v Int -- | O(n) Reverse a circular vector. reverse :: Vector v a => CircularVector v a -> CircularVector v a -- | 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 @Vector (unsafeFromList @Vector [1..3]) (unsafeFromList @Vector [2,0]) -- [3,1] --backpermute :: (Vector v a, Vector v Int) => CircularVector v a -> CircularVector v Int -> CircularVector v a -- | Same as backpermute but without bounds checking. unsafeBackpermute :: (Vector v a, Vector v Int) => CircularVector v a -> CircularVector v Int -> CircularVector v a -- | 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. modify :: Vector v a => (forall s. Mutable v s a -> ST s ()) -> CircularVector v a -> CircularVector v 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 :: (Traversable t, Monad m) => t (m a) -> m (t a) -- | 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. sequence_ :: (Foldable t, Monad m) => t (m a) -> m () instance Control.DeepSeq.NFData (v a) => Control.DeepSeq.NFData (Data.Vector.Circular.Generic.CircularVector v a) instance GHC.Show.Show (v a) => GHC.Show.Show (Data.Vector.Circular.Generic.CircularVector v a) instance GHC.Read.Read (v a) => GHC.Read.Read (Data.Vector.Circular.Generic.CircularVector v a) instance (Data.Vector.Generic.Base.Vector v a, GHC.Classes.Ord (v a), GHC.Classes.Eq a) => GHC.Classes.Ord (Data.Vector.Circular.Generic.CircularVector v a) instance GHC.Generics.Generic (Data.Vector.Circular.Generic.CircularVector v a) instance GHC.Base.Functor v => GHC.Base.Functor (Data.Vector.Circular.Generic.CircularVector v) instance (Data.Vector.Generic.Base.Vector v a, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Vector.Circular.Generic.CircularVector v a) instance Data.Vector.Generic.Base.Vector v a => GHC.Base.Semigroup (Data.Vector.Circular.Generic.CircularVector v a) instance Language.Haskell.TH.Syntax.Lift a => Language.Haskell.TH.Syntax.Lift (Data.Vector.Circular.Generic.CircularVector v a)