{-# language
BangPatterns
, CPP
, DeriveAnyClass
, DeriveFunctor
, DeriveGeneric
, DerivingStrategies
, InstanceSigs
, ScopedTypeVariables
, TemplateHaskell
, TypeApplications
, RankNTypes
#-}
module Data.Vector.Circular
(
CircularVector(..)
, singleton
, replicate
, replicate1
, generate
, generate1
, iterateN
, iterateN1
, replicateM
, replicate1M
, generateM
, generate1M
, iterateNM
, iterateN1M
, create
, unsafeCreate
, createT
, unsafeCreateT
, unfoldr
, unfoldr1
, unfoldrN
, unfoldr1N
, unfoldrM
, unfoldr1M
, unfoldrNM
, unfoldr1NM
, constructN
, constructrN
, enumFromN
, enumFromN1
, enumFromStepN
, enumFromStepN1
, enumFromTo
, enumFromThenTo
, cons
, consV
, snoc
, snocV
, (Data.Vector.Circular.++)
, concat
, concat1
, force
, vec
, toVector
, fromVector
, fromVector'
, unsafeFromVector
, toNonEmptyVector
, toList
, fromList
, fromListN
, unsafeFromList
, unsafeFromListN
, rotateLeft
, rotateRight
, equivalent
, canonise
, leastRotation
, foldMap
, foldMap'
, foldr
, foldl
, foldr'
, foldl'
, foldr1
, foldl1
, foldMap1
, foldMap1'
, toNonEmpty
, all
, any
, and
, or
, sum
, product
, maximum
, maximumBy
, minimum
, minimumBy
, rotateToMinimumBy
, rotateToMaximumBy
, index
, head
, last
, map
, imap
, concatMap
, mapM
, imapM
, mapM_
, imapM_
, forM
, forM_
, zipWith
, zipWith3
, zip
, zip3
, unzip
, unzip3
, uniq
, mapMaybe
, imapMaybe
, filter
, ifilter
, filterM
, ifilterM
, takeWhile
, dropWhile
, partition
, unstablePartition
, span
, break
, elem
, notElem
, find
, findIndex
, findIndices
, elemIndex
, elemIndices
, reverse
, backpermute
, unsafeBackpermute
, modify
, sequence
, sequence_
) where
import qualified Control.Monad (when, forM_)
import Control.Monad.ST (ST, runST)
import Control.DeepSeq
#if MIN_VERSION_base(4,13,0)
#endif /* MIN_VERSION_base(4,13,0) */
import Data.List.NonEmpty (NonEmpty((:|)))
import Data.Primitive.MutVar ( newMutVar, readMutVar, writeMutVar )
import Data.Semigroup.Foldable.Class (Foldable1)
import Data.Monoid (All(..))
import Data.Vector (Vector)
import Data.Vector.NonEmpty (NonEmptyVector)
import Data.Functor.Classes
import Text.Read (readPrec)
import GHC.Base (modInt)
import GHC.Generics (Generic)
import Prelude hiding (head, length, last, map, concat, takeWhile
,dropWhile, span, break, elem, notElem, reverse
,mapM, mapM_, foldMap, foldr
,foldl, foldr1, foldl1, all, any, and, or, sum
,product, maximum, minimum, concatMap
,zipWith, zipWith3, zip, zip3, replicate, enumFromTo
,enumFromThenTo, (++), filter)
import Language.Haskell.TH.Syntax
import qualified Data.Foldable as Foldable
import qualified Data.Semigroup.Foldable.Class as Foldable1
import qualified Data.Vector as Vector
import qualified Data.Vector.Mutable as MVector
import qualified Data.Vector.NonEmpty as NonEmpty
import qualified Prelude
data CircularVector a = CircularVector
{ CircularVector a -> NonEmptyVector a
vector :: {-# UNPACK #-} !(NonEmptyVector a)
, CircularVector a -> Int
rotation :: {-# UNPACK #-} !Int
}
deriving stock
( Functor
, Generic
, Ord
, Read
, Show
)
deriving anyclass
( NFData
)
instance Traversable CircularVector where
traverse :: (Applicative f) => (a -> f b) -> CircularVector a -> f (CircularVector b)
traverse :: (a -> f b) -> CircularVector a -> f (CircularVector b)
traverse a -> f b
f (CircularVector NonEmptyVector a
v Int
rot) =
NonEmptyVector b -> Int -> CircularVector b
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector (NonEmptyVector b -> Int -> CircularVector b)
-> f (NonEmptyVector b) -> f (Int -> CircularVector b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> NonEmptyVector a -> f (NonEmptyVector b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f NonEmptyVector a
v f (Int -> CircularVector b) -> f Int -> f (CircularVector b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> f Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
rot
instance Eq a => Eq (CircularVector a) where
(==) :: CircularVector a -> CircularVector a -> Bool
== :: CircularVector a -> CircularVector a -> Bool
(==) = (a -> a -> Bool) -> CircularVector a -> CircularVector a -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
instance Eq1 CircularVector where
liftEq :: (a -> b -> Bool) -> CircularVector a -> CircularVector b -> Bool
liftEq :: (a -> b -> Bool) -> CircularVector a -> CircularVector b -> Bool
liftEq a -> b -> Bool
eq c0 :: CircularVector a
c0@(CircularVector NonEmptyVector a
x Int
rx) c1 :: CircularVector b
c1@(CircularVector NonEmptyVector b
y Int
ry)
| NonEmptyVector a -> Int
forall a. NonEmptyVector a -> Int
NonEmpty.length NonEmptyVector a
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= NonEmptyVector b -> Int
forall a. NonEmptyVector a -> Int
NonEmpty.length NonEmptyVector b
y = Bool
False
| Int
rx Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
ry = (a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq NonEmptyVector a
x NonEmptyVector b
y
| Bool
otherwise = All -> Bool
getAll (All -> Bool) -> All -> Bool
forall a b. (a -> b) -> a -> b
$ ((Int -> All) -> [Int] -> All) -> [Int] -> (Int -> All) -> All
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int -> All) -> [Int] -> All
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Prelude.foldMap [Int
0..NonEmptyVector a -> Int
forall a. NonEmptyVector a -> Int
NonEmpty.length NonEmptyVector a
xInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] ((Int -> All) -> All) -> (Int -> All) -> All
forall a b. (a -> b) -> a -> b
$ \Int
i ->
Bool -> All
All (CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
c0 Int
i a -> b -> Bool
`eq` CircularVector b -> Int -> b
forall a. CircularVector a -> Int -> a
index CircularVector b
c1 Int
i)
instance Ord1 CircularVector where
liftCompare :: (a -> b -> Ordering) -> CircularVector a -> CircularVector b -> Ordering
liftCompare :: (a -> b -> Ordering)
-> CircularVector a -> CircularVector b -> Ordering
liftCompare a -> b -> Ordering
cmp (CircularVector NonEmptyVector a
x Int
rx) (CircularVector NonEmptyVector b
y Int
ry)
= (a -> b -> Ordering)
-> NonEmptyVector a -> NonEmptyVector b -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
cmp NonEmptyVector a
x NonEmptyVector b
y Ordering -> Ordering -> Ordering
forall a. Semigroup a => a -> a -> a
<> Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
rx Int
ry
instance Show1 CircularVector where
liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> CircularVector a -> ShowS
liftShowsPrec :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> CircularVector a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d (CircularVector NonEmptyVector a
x Int
rx) =
(Int -> NonEmptyVector a -> ShowS)
-> (Int -> Int -> ShowS)
-> String
-> Int
-> NonEmptyVector a
-> Int
-> ShowS
forall a b.
(Int -> a -> ShowS)
-> (Int -> b -> ShowS) -> String -> Int -> a -> b -> ShowS
showsBinaryWith ((Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec String
"CircularVector" Int
d NonEmptyVector a
x Int
rx
instance Read1 CircularVector where
liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (CircularVector a)
liftReadPrec ReadPrec a
rp ReadPrec [a]
rl = ReadPrec (CircularVector a) -> ReadPrec (CircularVector a)
forall a. ReadPrec a -> ReadPrec a
readData (ReadPrec (CircularVector a) -> ReadPrec (CircularVector a))
-> ReadPrec (CircularVector a) -> ReadPrec (CircularVector a)
forall a b. (a -> b) -> a -> b
$
ReadPrec (NonEmptyVector a)
-> ReadPrec Int
-> String
-> (NonEmptyVector a -> Int -> CircularVector a)
-> ReadPrec (CircularVector a)
forall a b t.
ReadPrec a -> ReadPrec b -> String -> (a -> b -> t) -> ReadPrec t
readBinaryWith (ReadPrec a -> ReadPrec [a] -> ReadPrec (NonEmptyVector a)
forall (f :: * -> *) a.
Read1 f =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (f a)
liftReadPrec ReadPrec a
rp ReadPrec [a]
rl) ReadPrec Int
forall a. Read a => ReadPrec a
readPrec String
"CircularVector" NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector
liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [CircularVector a]
liftReadListPrec = ReadPrec a -> ReadPrec [a] -> ReadPrec [CircularVector a]
forall (f :: * -> *) a.
Read1 f =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [f a]
liftReadListPrecDefault
instance Semigroup (CircularVector a) where
(<>) :: CircularVector a -> CircularVector a -> CircularVector a
CircularVector a
lhs <> :: CircularVector a -> CircularVector a -> CircularVector a
<> CircularVector a
rhs = NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v Int
0
where
szLhs :: Int
szLhs = CircularVector a -> Int
forall a. CircularVector a -> Int
length CircularVector a
lhs
szRhs :: Int
szRhs = CircularVector a -> Int
forall a. CircularVector a -> Int
length CircularVector a
rhs
sz :: Int
sz = Int
szLhs Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
szRhs
v :: NonEmptyVector a
v = Vector a -> NonEmptyVector a
forall a. Vector a -> NonEmptyVector a
NonEmpty.unsafeFromVector
(Vector a -> NonEmptyVector a) -> Vector a -> NonEmptyVector a
forall a b. (a -> b) -> a -> b
$ Int -> (Int -> a) -> Vector a
forall a. Int -> (Int -> a) -> Vector a
Vector.generate Int
sz
((Int -> a) -> Vector a) -> (Int -> a) -> Vector a
forall a b. (a -> b) -> a -> b
$ \Int
ix -> if Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
szLhs
then CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
lhs Int
ix
else CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
rhs (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
szLhs)
{-# inline (<>) #-}
instance Foldable CircularVector where
foldMap :: Monoid m => (a -> m) -> CircularVector a -> m
foldMap :: (a -> m) -> CircularVector a -> m
foldMap = (a -> m) -> CircularVector a -> m
forall m a. Monoid m => (a -> m) -> CircularVector a -> m
Data.Vector.Circular.foldMap
{-# inline foldMap #-}
#if MIN_VERSION_base(4,13,0)
foldMap' :: Monoid m => (a -> m) -> CircularVector a -> m
foldMap' :: (a -> m) -> CircularVector a -> m
foldMap' = (a -> m) -> CircularVector a -> m
forall m a. Monoid m => (a -> m) -> CircularVector a -> m
Data.Vector.Circular.foldMap'
{-# inline foldMap' #-}
#endif /* MIN_VERSION_base(4,13,0) */
null :: CircularVector a -> Bool
null :: CircularVector a -> Bool
null CircularVector a
_ = Bool
False
{-# inline null #-}
length :: CircularVector a -> Int
length :: CircularVector a -> Int
length = CircularVector a -> Int
forall a. CircularVector a -> Int
Data.Vector.Circular.length
{-# inline length #-}
instance Foldable1 CircularVector where
foldMap1 :: Semigroup m => (a -> m) -> CircularVector a -> m
foldMap1 :: (a -> m) -> CircularVector a -> m
foldMap1 = (a -> m) -> CircularVector a -> m
forall m a. Semigroup m => (a -> m) -> CircularVector a -> m
Data.Vector.Circular.foldMap1
{-# inline foldMap1 #-}
instance Lift a => Lift (CircularVector a) where
lift :: CircularVector a -> Q Exp
lift CircularVector a
c = do
Exp
v <- [|NonEmpty.toVector (vector c)|]
Exp
r <- [|rotation c|]
Exp -> Q Exp
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Exp -> Q Exp) -> Exp -> Q Exp
forall a b. (a -> b) -> a -> b
$ Name -> Exp
ConE ''CircularVector
Exp -> Exp -> Exp
`AppE` (Name -> Exp
VarE 'NonEmpty.unsafeFromVector Exp -> Exp -> Exp
`AppE` Exp
v)
Exp -> Exp -> Exp
`AppE` Exp
r
#if MIN_VERSION_template_haskell(2,16,0)
liftTyped :: CircularVector a -> Q (TExp (CircularVector a))
liftTyped = Q Exp -> Q (TExp (CircularVector a))
forall a. Q Exp -> Q (TExp a)
unsafeTExpCoerce (Q Exp -> Q (TExp (CircularVector a)))
-> (CircularVector a -> Q Exp)
-> CircularVector a
-> Q (TExp (CircularVector a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> Q Exp
forall t. Lift t => t -> Q Exp
lift
#endif /* MIN_VERSION_template_haskell(2,16,0) */
length :: CircularVector a -> Int
length :: CircularVector a -> Int
length (CircularVector NonEmptyVector a
v Int
_) = NonEmptyVector a -> Int
forall a. NonEmptyVector a -> Int
NonEmpty.length NonEmptyVector a
v
{-# inline length #-}
foldMap :: Monoid m => (a -> m) -> CircularVector a -> m
foldMap :: (a -> m) -> CircularVector a -> m
foldMap a -> m
f = \CircularVector a
v ->
let len :: Int
len = CircularVector a -> Int
forall a. CircularVector a -> Int
Data.Vector.Circular.length CircularVector a
v
go :: Int -> m
go !Int
ix
| Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
len = a -> m
f (CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v Int
ix) m -> m -> m
forall a. Semigroup a => a -> a -> a
<> Int -> m
go (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = m
forall a. Monoid a => a
mempty
in Int -> m
go Int
0
{-# inline foldMap #-}
foldMap' :: Monoid m => (a -> m) -> CircularVector a -> m
foldMap' :: (a -> m) -> CircularVector a -> m
foldMap' a -> m
f = \CircularVector a
v ->
let len :: Int
len = CircularVector a -> Int
forall a. CircularVector a -> Int
Data.Vector.Circular.length CircularVector a
v
go :: Int -> m -> m
go !Int
ix !m
acc
| Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
len = Int -> m -> m
go (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (m
acc m -> m -> m
forall a. Semigroup a => a -> a -> a
<> a -> m
f (CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v Int
ix))
| Bool
otherwise = m
acc
in Int -> m -> m
go Int
0 m
forall a. Monoid a => a
mempty
{-# inline foldMap' #-}
foldr :: (a -> b -> b) -> b -> CircularVector a -> b
foldr :: (a -> b -> b) -> b -> CircularVector a -> b
foldr = (a -> b -> b) -> b -> CircularVector a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr
foldl :: (b -> a -> b) -> b -> CircularVector a -> b
foldl :: (b -> a -> b) -> b -> CircularVector a -> b
foldl = (b -> a -> b) -> b -> CircularVector a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl
foldr' :: (a -> b -> b) -> b -> CircularVector a -> b
foldr' :: (a -> b -> b) -> b -> CircularVector a -> b
foldr' = (a -> b -> b) -> b -> CircularVector a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr'
foldl' :: (b -> a -> b) -> b -> CircularVector a -> b
foldl' :: (b -> a -> b) -> b -> CircularVector a -> b
foldl' = (b -> a -> b) -> b -> CircularVector a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl'
foldr1 :: (a -> a -> a) -> CircularVector a -> a
foldr1 :: (a -> a -> a) -> CircularVector a -> a
foldr1 = (a -> a -> a) -> CircularVector a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
Foldable.foldr1
foldl1 :: (a -> a -> a) -> CircularVector a -> a
foldl1 :: (a -> a -> a) -> CircularVector a -> a
foldl1 = (a -> a -> a) -> CircularVector a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
Foldable.foldl1
toNonEmpty :: CircularVector a -> NonEmpty a
toNonEmpty :: CircularVector a -> NonEmpty a
toNonEmpty = CircularVector a -> NonEmpty a
forall (t :: * -> *) a. Foldable1 t => t a -> NonEmpty a
Foldable1.toNonEmpty
foldMap1 :: Semigroup m => (a -> m) -> CircularVector a -> m
foldMap1 :: (a -> m) -> CircularVector a -> m
foldMap1 a -> m
f = \CircularVector a
v ->
let len :: Int
len = CircularVector a -> Int
forall a. CircularVector a -> Int
Data.Vector.Circular.length CircularVector a
v
go :: Int -> m
go !Int
ix
| Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1 = a -> m
f (CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v Int
ix) m -> m -> m
forall a. Semigroup a => a -> a -> a
<> Int -> m
go (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = a -> m
f (CircularVector a -> a
forall a. CircularVector a -> a
last CircularVector a
v)
in Int -> m
go Int
0
{-# inline foldMap1 #-}
foldMap1' :: Semigroup m => (a -> m) -> CircularVector a -> m
foldMap1' :: (a -> m) -> CircularVector a -> m
foldMap1' a -> m
f = \CircularVector a
v ->
let len :: Int
len = CircularVector a -> Int
forall a. CircularVector a -> Int
Data.Vector.Circular.length CircularVector a
v
go :: Int -> m -> m
go !Int
ix !m
acc
| Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
len = Int -> m -> m
go (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (m
acc m -> m -> m
forall a. Semigroup a => a -> a -> a
<> a -> m
f (CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v Int
ix))
| Bool
otherwise = m
acc
in Int -> m -> m
go Int
1 (a -> m
f (CircularVector a -> a
forall a. CircularVector a -> a
head CircularVector a
v))
{-# inline foldMap1' #-}
toVector :: CircularVector a -> Vector a
toVector :: CircularVector a -> Vector a
toVector CircularVector a
v = Int -> (Int -> a) -> Vector a
forall a. Int -> (Int -> a) -> Vector a
Vector.generate (CircularVector a -> Int
forall a. CircularVector a -> Int
length CircularVector a
v) (CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v)
toNonEmptyVector :: CircularVector a -> NonEmptyVector a
toNonEmptyVector :: CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
v = Int -> (Int -> a) -> NonEmptyVector a
forall a. Int -> (Int -> a) -> NonEmptyVector a
NonEmpty.generate1 (CircularVector a -> Int
forall a. CircularVector a -> Int
length CircularVector a
v) (CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v)
fromVector :: NonEmptyVector a -> CircularVector a
fromVector :: NonEmptyVector a -> CircularVector a
fromVector NonEmptyVector a
v = NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v Int
0
{-# inline fromVector #-}
fromVector' :: Vector a -> Maybe (CircularVector a)
fromVector' :: Vector a -> Maybe (CircularVector a)
fromVector' Vector a
v = NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector (NonEmptyVector a -> Int -> CircularVector a)
-> Maybe (NonEmptyVector a) -> Maybe (Int -> CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector a -> Maybe (NonEmptyVector a)
forall a. Vector a -> Maybe (NonEmptyVector a)
NonEmpty.fromVector Vector a
v Maybe (Int -> CircularVector a)
-> Maybe Int -> Maybe (CircularVector a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Maybe Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
0
{-# inline fromVector' #-}
unsafeFromVector :: Vector a -> CircularVector a
unsafeFromVector :: Vector a -> CircularVector a
unsafeFromVector = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (Vector a -> NonEmptyVector a) -> Vector a -> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> NonEmptyVector a
forall a. Vector a -> NonEmptyVector a
NonEmpty.unsafeFromVector
toList :: CircularVector a -> [a]
toList :: CircularVector a -> [a]
toList = Vector a -> [a]
forall a. Vector a -> [a]
Vector.toList (Vector a -> [a])
-> (CircularVector a -> Vector a) -> CircularVector a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> Vector a
forall a. CircularVector a -> Vector a
toVector
fromList :: [a] -> Maybe (CircularVector a)
fromList :: [a] -> Maybe (CircularVector a)
fromList [a]
xs = Int -> [a] -> Maybe (CircularVector a)
forall a. Int -> [a] -> Maybe (CircularVector a)
fromListN ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [a]
xs) [a]
xs
{-# inline fromList #-}
fromListN :: Int -> [a] -> Maybe (CircularVector a)
fromListN :: Int -> [a] -> Maybe (CircularVector a)
fromListN Int
n [a]
xs = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> Maybe (NonEmptyVector a) -> Maybe (CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> [a] -> Maybe (NonEmptyVector a)
forall a. Int -> [a] -> Maybe (NonEmptyVector a)
NonEmpty.fromListN Int
n [a]
xs)
{-# inline fromListN #-}
unsafeFromList :: [a] -> CircularVector a
unsafeFromList :: [a] -> CircularVector a
unsafeFromList [a]
xs = Int -> [a] -> CircularVector a
forall a. Int -> [a] -> CircularVector a
unsafeFromListN ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [a]
xs) [a]
xs
unsafeFromListN :: Int -> [a] -> CircularVector a
unsafeFromListN :: Int -> [a] -> CircularVector a
unsafeFromListN Int
n [a]
xs
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = String -> CircularVector a
forall a. HasCallStack => String -> a
error String
"Data.Vector.Circular.unsafeFromListN: invalid length!"
| Bool
otherwise = Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> [a] -> Vector a
forall a. Int -> [a] -> Vector a
Vector.fromListN Int
n [a]
xs)
singleton :: a -> CircularVector a
singleton :: a -> CircularVector a
singleton = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (a -> NonEmptyVector a) -> a -> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> NonEmptyVector a
forall a. a -> NonEmptyVector a
NonEmpty.singleton
{-# inline singleton #-}
index :: CircularVector a -> Int -> a
index :: CircularVector a -> Int -> a
index (CircularVector NonEmptyVector a
v Int
r) = \ !Int
ix ->
let len :: Int
len = NonEmptyVector a -> Int
forall a. NonEmptyVector a -> Int
NonEmpty.length NonEmptyVector a
v
in NonEmptyVector a -> Int -> a
forall a. NonEmptyVector a -> Int -> a
NonEmpty.unsafeIndex NonEmptyVector a
v (Int -> Int -> Int
unsafeMod (Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
r) Int
len)
{-# inline index #-}
head :: CircularVector a -> a
head :: CircularVector a -> a
head CircularVector a
v = CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v Int
0
{-# inline head #-}
last :: CircularVector a -> a
last :: CircularVector a -> a
last CircularVector a
v = CircularVector a -> Int -> a
forall a. CircularVector a -> Int -> a
index CircularVector a
v (CircularVector a -> Int
forall a. CircularVector a -> Int
Data.Vector.Circular.length CircularVector a
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
{-# inline last #-}
rotateRight :: Int -> CircularVector a -> CircularVector a
rotateRight :: Int -> CircularVector a -> CircularVector a
rotateRight Int
r' (CircularVector NonEmptyVector a
v Int
r) = NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v Int
h
where
len :: Int
len = NonEmptyVector a -> Int
forall a. NonEmptyVector a -> Int
NonEmpty.length NonEmptyVector a
v
h :: Int
h = Int -> Int -> Int
unsafeMod (Int
r Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
unsafeMod Int
r' Int
len) Int
len
{-# inline rotateRight #-}
rotateLeft :: Int -> CircularVector a -> CircularVector a
rotateLeft :: Int -> CircularVector a -> CircularVector a
rotateLeft Int
r' (CircularVector NonEmptyVector a
v Int
r) = NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v Int
h
where
len :: Int
len = NonEmptyVector a -> Int
forall a. NonEmptyVector a -> Int
NonEmpty.length NonEmptyVector a
v
h :: Int
h = Int -> Int -> Int
unsafeMod (Int
r Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int -> Int
unsafeMod Int
r' Int
len) Int
len
{-# inline rotateLeft #-}
vec :: Lift a => [a] -> Q (TExp (CircularVector a))
vec :: [a] -> Q (TExp (CircularVector a))
vec [] = String -> Q (TExp (CircularVector a))
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Cannot create an empty CircularVector!"
vec [a]
xs =
#if MIN_VERSION_template_haskell(2,16,0)
CircularVector a -> Q (TExp (CircularVector a))
forall t. Lift t => t -> Q (TExp t)
liftTyped ([a] -> CircularVector a
forall a. [a] -> CircularVector a
unsafeFromList [a]
xs)
#else
unsafeTExpCoerce [|unsafeFromList xs|]
#endif /* MIN_VERSION_template_haskell(2,16,0) */
equivalent :: Ord a => CircularVector a -> CircularVector a -> Bool
equivalent :: CircularVector a -> CircularVector a -> Bool
equivalent CircularVector a
x CircularVector a
y = CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector (CircularVector a -> CircularVector a
forall a. Ord a => CircularVector a -> CircularVector a
canonise CircularVector a
x) NonEmptyVector a -> NonEmptyVector a -> Bool
forall a. Eq a => a -> a -> Bool
== CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector (CircularVector a -> CircularVector a
forall a. Ord a => CircularVector a -> CircularVector a
canonise CircularVector a
y)
canonise :: Ord a => CircularVector a -> CircularVector a
canonise :: CircularVector a -> CircularVector a
canonise (CircularVector NonEmptyVector a
v Int
r) = NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v' (Int
r Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
lr)
where
lr :: Int
lr = Vector a -> Int
forall a. Ord a => Vector a -> Int
leastRotation (NonEmptyVector a -> Vector a
forall a. NonEmptyVector a -> Vector a
NonEmpty.toVector NonEmptyVector a
v)
v' :: NonEmptyVector a
v' = CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector (Int -> CircularVector a -> CircularVector a
forall a. Int -> CircularVector a -> CircularVector a
rotateRight Int
lr (NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v Int
0))
leastRotation :: forall a. (Ord a) => Vector a -> Int
leastRotation :: Vector a -> Int
leastRotation Vector a
v = (forall s. ST s Int) -> Int
forall a. (forall s. ST s a) -> a
runST forall s. ST s Int
go
where
go :: forall s. ST s Int
go :: ST s Int
go = do
let s :: Vector a
s = Vector a
v Vector a -> Vector a -> Vector a
forall a. Semigroup a => a -> a -> a
<> Vector a
v
let len :: Int
len = Vector a -> Int
forall a. Vector a -> Int
Vector.length Vector a
s
MVector s Int
f <- Int -> Int -> ST s (MVector (PrimState (ST s)) Int)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MVector (PrimState m) a)
MVector.replicate @_ @Int Int
len (-Int
1)
MutVar s Int
kVar <- Int -> ST s (MutVar (PrimState (ST s)) Int)
forall (m :: * -> *) a.
PrimMonad m =>
a -> m (MutVar (PrimState m) a)
newMutVar @_ @Int Int
0
[Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
Control.Monad.forM_ [Int
1..Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Int
j -> do
a
sj <- Vector a -> Int -> ST s a
forall (m :: * -> *) a. Monad m => Vector a -> Int -> m a
Vector.indexM Vector a
s Int
j
Int
i0 <- MutVar (PrimState (ST s)) Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar ST s Int -> (Int -> ST s Int) -> ST s Int
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
k -> MVector (PrimState (ST s)) Int -> Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> m a
MVector.read MVector s Int
MVector (PrimState (ST s)) Int
f (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
let loop :: Int -> ST s Int
loop Int
i = do
a
a <- MutVar (PrimState (ST s)) Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar ST s Int -> (Int -> ST s a) -> ST s a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
k -> Vector a -> Int -> ST s a
forall (m :: * -> *) a. Monad m => Vector a -> Int -> m a
Vector.indexM Vector a
s (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
if (Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= (-Int
1) Bool -> Bool -> Bool
&& a
sj a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
a)
then do
Bool -> ST s () -> ST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Control.Monad.when (a
sj a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
a) (MutVar (PrimState (ST s)) Int -> Int -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> a -> m ()
writeMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
Int -> ST s Int
loop (Int -> ST s Int) -> ST s Int -> ST s Int
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< MVector (PrimState (ST s)) Int -> Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> m a
MVector.read MVector s Int
MVector (PrimState (ST s)) Int
f Int
i
else Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
i
Int
i <- Int -> ST s Int
loop Int
i0
a
a <- MutVar (PrimState (ST s)) Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar ST s Int -> (Int -> ST s a) -> ST s a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
k -> Vector a -> Int -> ST s a
forall (m :: * -> *) a. Monad m => Vector a -> Int -> m a
Vector.indexM Vector a
s (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
if a
sj a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
a
then do
MutVar (PrimState (ST s)) Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar ST s Int -> (Int -> ST s ()) -> ST s ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
k -> Bool -> ST s () -> ST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
Control.Monad.when (a
sj a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< (Vector a
s Vector a -> Int -> a
forall a. Vector a -> Int -> a
Vector.! Int
k)) (MutVar (PrimState (ST s)) Int -> Int -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> a -> m ()
writeMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar Int
j)
MutVar (PrimState (ST s)) Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar ST s Int -> (Int -> ST s ()) -> ST s ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
k -> MVector (PrimState (ST s)) Int -> Int -> Int -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> a -> m ()
MVector.write MVector s Int
MVector (PrimState (ST s)) Int
f (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k) (-Int
1)
else do
MutVar (PrimState (ST s)) Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar ST s Int -> (Int -> ST s ()) -> ST s ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
k -> MVector (PrimState (ST s)) Int -> Int -> Int -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> a -> m ()
MVector.write MVector s Int
MVector (PrimState (ST s)) Int
f (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k) (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
MutVar (PrimState (ST s)) Int -> ST s Int
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar s Int
MutVar (PrimState (ST s)) Int
kVar
unsafeMod :: Int -> Int -> Int
unsafeMod :: Int -> Int -> Int
unsafeMod = Int -> Int -> Int
GHC.Base.modInt
{-# inline unsafeMod #-}
zipWith :: (a -> b -> c) -> CircularVector a -> CircularVector b -> CircularVector c
zipWith :: (a -> b -> c)
-> CircularVector a -> CircularVector b -> CircularVector c
zipWith a -> b -> c
f CircularVector a
a CircularVector b
b = NonEmptyVector c -> CircularVector c
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector c -> CircularVector c)
-> NonEmptyVector c -> CircularVector c
forall a b. (a -> b) -> a -> b
$ (a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
NonEmpty.zipWith a -> b -> c
f (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
a) (CircularVector b -> NonEmptyVector b
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector b
b)
zipWith3 :: (a -> b -> c -> d) -> CircularVector a -> CircularVector b -> CircularVector c
-> CircularVector d
zipWith3 :: (a -> b -> c -> d)
-> CircularVector a
-> CircularVector b
-> CircularVector c
-> CircularVector d
zipWith3 a -> b -> c -> d
f CircularVector a
a CircularVector b
b CircularVector c
c = NonEmptyVector d -> CircularVector d
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector d -> CircularVector d)
-> NonEmptyVector d -> CircularVector d
forall a b. (a -> b) -> a -> b
$
(a -> b -> c -> d)
-> NonEmptyVector a
-> NonEmptyVector b
-> NonEmptyVector c
-> NonEmptyVector d
forall a b c d.
(a -> b -> c -> d)
-> NonEmptyVector a
-> NonEmptyVector b
-> NonEmptyVector c
-> NonEmptyVector d
NonEmpty.zipWith3 a -> b -> c -> d
f (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
a) (CircularVector b -> NonEmptyVector b
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector b
b) (CircularVector c -> NonEmptyVector c
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector c
c)
zip :: CircularVector a -> CircularVector b -> CircularVector (a,b)
zip :: CircularVector a -> CircularVector b -> CircularVector (a, b)
zip CircularVector a
a CircularVector b
b = NonEmptyVector (a, b) -> CircularVector (a, b)
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector (a, b) -> CircularVector (a, b))
-> NonEmptyVector (a, b) -> CircularVector (a, b)
forall a b. (a -> b) -> a -> b
$ NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
NonEmpty.zip (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
a) (CircularVector b -> NonEmptyVector b
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector b
b)
zip3 :: CircularVector a -> CircularVector b -> CircularVector c -> CircularVector (a,b,c)
zip3 :: CircularVector a
-> CircularVector b -> CircularVector c -> CircularVector (a, b, c)
zip3 CircularVector a
a CircularVector b
b CircularVector c
c = NonEmptyVector (a, b, c) -> CircularVector (a, b, c)
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector (a, b, c) -> CircularVector (a, b, c))
-> NonEmptyVector (a, b, c) -> CircularVector (a, b, c)
forall a b. (a -> b) -> a -> b
$ NonEmptyVector a
-> NonEmptyVector b -> NonEmptyVector c -> NonEmptyVector (a, b, c)
forall a b c.
NonEmptyVector a
-> NonEmptyVector b -> NonEmptyVector c -> NonEmptyVector (a, b, c)
NonEmpty.zip3 (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
a) (CircularVector b -> NonEmptyVector b
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector b
b) (CircularVector c -> NonEmptyVector c
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector c
c)
reverse :: CircularVector a -> CircularVector a
reverse :: CircularVector a -> CircularVector a
reverse = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyVector a -> NonEmptyVector a
forall a. NonEmptyVector a -> NonEmptyVector a
NonEmpty.reverse (NonEmptyVector a -> NonEmptyVector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> NonEmptyVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
rotateToMinimumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a
rotateToMinimumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a
rotateToMinimumBy a -> a -> Ordering
f (CircularVector NonEmptyVector a
v Int
_rot) =
NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v ((a -> a -> Ordering) -> NonEmptyVector a -> Int
forall a. (a -> a -> Ordering) -> NonEmptyVector a -> Int
NonEmpty.minIndexBy a -> a -> Ordering
f NonEmptyVector a
v)
rotateToMaximumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a
rotateToMaximumBy :: (a -> a -> Ordering) -> CircularVector a -> CircularVector a
rotateToMaximumBy a -> a -> Ordering
f (CircularVector NonEmptyVector a
v Int
_rot) =
NonEmptyVector a -> Int -> CircularVector a
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector NonEmptyVector a
v ((a -> a -> Ordering) -> NonEmptyVector a -> Int
forall a. (a -> a -> Ordering) -> NonEmptyVector a -> Int
NonEmpty.maxIndexBy a -> a -> Ordering
f NonEmptyVector a
v)
all :: (a -> Bool) -> CircularVector a -> Bool
all :: (a -> Bool) -> CircularVector a -> Bool
all a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Bool
forall a. (a -> Bool) -> NonEmptyVector a -> Bool
NonEmpty.all a -> Bool
f (NonEmptyVector a -> Bool)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
any :: (a -> Bool) -> CircularVector a -> Bool
any :: (a -> Bool) -> CircularVector a -> Bool
any a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Bool
forall a. (a -> Bool) -> NonEmptyVector a -> Bool
NonEmpty.any a -> Bool
f (NonEmptyVector a -> Bool)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
and :: CircularVector Bool -> Bool
and :: CircularVector Bool -> Bool
and = NonEmptyVector Bool -> Bool
NonEmpty.and (NonEmptyVector Bool -> Bool)
-> (CircularVector Bool -> NonEmptyVector Bool)
-> CircularVector Bool
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector Bool -> NonEmptyVector Bool
forall a. CircularVector a -> NonEmptyVector a
vector
or :: CircularVector Bool -> Bool
or :: CircularVector Bool -> Bool
or = NonEmptyVector Bool -> Bool
NonEmpty.or (NonEmptyVector Bool -> Bool)
-> (CircularVector Bool -> NonEmptyVector Bool)
-> CircularVector Bool
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector Bool -> NonEmptyVector Bool
forall a. CircularVector a -> NonEmptyVector a
vector
sum :: Num a => CircularVector a -> a
sum :: CircularVector a -> a
sum = NonEmptyVector a -> a
forall a. Num a => NonEmptyVector a -> a
NonEmpty.sum (NonEmptyVector a -> a)
-> (CircularVector a -> NonEmptyVector a) -> CircularVector a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
product :: Num a => CircularVector a -> a
product :: CircularVector a -> a
product = NonEmptyVector a -> a
forall a. Num a => NonEmptyVector a -> a
NonEmpty.sum (NonEmptyVector a -> a)
-> (CircularVector a -> NonEmptyVector a) -> CircularVector a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
maximum :: Ord a => CircularVector a -> a
maximum :: CircularVector a -> a
maximum = NonEmptyVector a -> a
forall a. Ord a => NonEmptyVector a -> a
NonEmpty.maximum (NonEmptyVector a -> a)
-> (CircularVector a -> NonEmptyVector a) -> CircularVector a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
maximumBy :: (a -> a -> Ordering) -> CircularVector a -> a
maximumBy :: (a -> a -> Ordering) -> CircularVector a -> a
maximumBy a -> a -> Ordering
f = (a -> a -> Ordering) -> NonEmptyVector a -> a
forall a. (a -> a -> Ordering) -> NonEmptyVector a -> a
NonEmpty.maximumBy a -> a -> Ordering
f (NonEmptyVector a -> a)
-> (CircularVector a -> NonEmptyVector a) -> CircularVector a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
minimum :: Ord a => CircularVector a -> a
minimum :: CircularVector a -> a
minimum = NonEmptyVector a -> a
forall a. Ord a => NonEmptyVector a -> a
NonEmpty.minimum (NonEmptyVector a -> a)
-> (CircularVector a -> NonEmptyVector a) -> CircularVector a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
minimumBy :: (a -> a -> Ordering) -> CircularVector a -> a
minimumBy :: (a -> a -> Ordering) -> CircularVector a -> a
minimumBy a -> a -> Ordering
f = (a -> a -> Ordering) -> NonEmptyVector a -> a
forall a. (a -> a -> Ordering) -> NonEmptyVector a -> a
NonEmpty.minimumBy a -> a -> Ordering
f (NonEmptyVector a -> a)
-> (CircularVector a -> NonEmptyVector a) -> CircularVector a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
vector
replicate :: Int -> a -> Maybe (CircularVector a)
replicate :: Int -> a -> Maybe (CircularVector a)
replicate Int
n a
a = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> a -> Vector a
forall a. Int -> a -> Vector a
Vector.replicate Int
n a
a)
replicate1 :: Int -> a -> CircularVector a
replicate1 :: Int -> a -> CircularVector a
replicate1 Int
n a
a = Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> a -> Vector a
forall a. Int -> a -> Vector a
Vector.replicate (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1) a
a)
generate :: Int -> (Int -> a) -> Maybe (CircularVector a)
generate :: Int -> (Int -> a) -> Maybe (CircularVector a)
generate Int
n Int -> a
f = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (Int -> a) -> Vector a
forall a. Int -> (Int -> a) -> Vector a
Vector.generate Int
n Int -> a
f)
generate1 :: Int -> (Int -> a) -> CircularVector a
generate1 :: Int -> (Int -> a) -> CircularVector a
generate1 Int
n Int -> a
f = Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> (Int -> a) -> Vector a
forall a. Int -> (Int -> a) -> Vector a
Vector.generate (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1) Int -> a
f)
iterateN :: Int -> (a -> a) -> a -> Maybe (CircularVector a)
iterateN :: Int -> (a -> a) -> a -> Maybe (CircularVector a)
iterateN Int
n a -> a
f a
a = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (a -> a) -> a -> Vector a
forall a. Int -> (a -> a) -> a -> Vector a
Vector.iterateN Int
n a -> a
f a
a)
iterateN1 :: Int -> (a -> a) -> a -> CircularVector a
iterateN1 :: Int -> (a -> a) -> a -> CircularVector a
iterateN1 Int
n a -> a
f a
a = Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> (a -> a) -> a -> Vector a
forall a. Int -> (a -> a) -> a -> Vector a
Vector.iterateN (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1) a -> a
f a
a)
replicateM :: Monad m => Int -> m a -> m (Maybe (CircularVector a))
replicateM :: Int -> m a -> m (Maybe (CircularVector a))
replicateM Int
n m a
a = (Vector a -> Maybe (CircularVector a))
-> m (Vector a) -> m (Maybe (CircularVector a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> m a -> m (Vector a)
forall (m :: * -> *) a. Monad m => Int -> m a -> m (Vector a)
Vector.replicateM Int
n m a
a)
replicate1M :: Monad m => Int -> m a -> m (CircularVector a)
replicate1M :: Int -> m a -> m (CircularVector a)
replicate1M Int
n m a
a = (Vector a -> CircularVector a)
-> m (Vector a) -> m (CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> m a -> m (Vector a)
forall (m :: * -> *) a. Monad m => Int -> m a -> m (Vector a)
Vector.replicateM (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1) m a
a)
generateM :: Monad m => Int -> (Int -> m a) -> m (Maybe (CircularVector a))
generateM :: Int -> (Int -> m a) -> m (Maybe (CircularVector a))
generateM Int
n Int -> m a
f = (Vector a -> Maybe (CircularVector a))
-> m (Vector a) -> m (Maybe (CircularVector a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (Int -> m a) -> m (Vector a)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
Vector.generateM Int
n Int -> m a
f)
generate1M :: Monad m => Int -> (Int -> m a) -> m (CircularVector a)
generate1M :: Int -> (Int -> m a) -> m (CircularVector a)
generate1M Int
n Int -> m a
f = (Vector a -> CircularVector a)
-> m (Vector a) -> m (CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> (Int -> m a) -> m (Vector a)
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> m (Vector a)
Vector.generateM (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1) Int -> m a
f)
iterateNM :: Monad m => Int -> (a -> m a) -> a -> m (Maybe (CircularVector a))
iterateNM :: Int -> (a -> m a) -> a -> m (Maybe (CircularVector a))
iterateNM Int
n a -> m a
f a
a = (Vector a -> Maybe (CircularVector a))
-> m (Vector a) -> m (Maybe (CircularVector a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (a -> m a) -> a -> m (Vector a)
forall (m :: * -> *) a.
Monad m =>
Int -> (a -> m a) -> a -> m (Vector a)
Vector.iterateNM Int
n a -> m a
f a
a)
iterateN1M :: Monad m => Int -> (a -> m a) -> a -> m (CircularVector a)
iterateN1M :: Int -> (a -> m a) -> a -> m (CircularVector a)
iterateN1M Int
n a -> m a
f a
a = (Vector a -> CircularVector a)
-> m (Vector a) -> m (CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> (a -> m a) -> a -> m (Vector a)
forall (m :: * -> *) a.
Monad m =>
Int -> (a -> m a) -> a -> m (Vector a)
Vector.iterateNM (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1) a -> m a
f a
a)
create :: (forall s. ST s (MVector.MVector s a)) -> Maybe (CircularVector a)
create :: (forall s. ST s (MVector s a)) -> Maybe (CircularVector a)
create forall s. ST s (MVector s a)
p = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' ((forall s. ST s (MVector s a)) -> Vector a
forall a. (forall s. ST s (MVector s a)) -> Vector a
Vector.create forall s. ST s (MVector s a)
p)
unsafeCreate :: (forall s. ST s (MVector.MVector s a)) -> CircularVector a
unsafeCreate :: (forall s. ST s (MVector s a)) -> CircularVector a
unsafeCreate forall s. ST s (MVector s a)
p = Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector ((forall s. ST s (MVector s a)) -> Vector a
forall a. (forall s. ST s (MVector s a)) -> Vector a
Vector.create forall s. ST s (MVector s a)
p)
createT
:: Traversable t
=> (forall s. ST s (t (MVector.MVector s a)))
-> t (Maybe (CircularVector a))
createT :: (forall s. ST s (t (MVector s a))) -> t (Maybe (CircularVector a))
createT forall s. ST s (t (MVector s a))
p = (Vector a -> Maybe (CircularVector a))
-> t (Vector a) -> t (Maybe (CircularVector a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' ((forall s. ST s (t (MVector s a))) -> t (Vector a)
forall (f :: * -> *) a.
Traversable f =>
(forall s. ST s (f (MVector s a))) -> f (Vector a)
Vector.createT forall s. ST s (t (MVector s a))
p)
unsafeCreateT
:: Traversable t
=> (forall s. ST s (t (MVector.MVector s a)))
-> t (CircularVector a)
unsafeCreateT :: (forall s. ST s (t (MVector s a))) -> t (CircularVector a)
unsafeCreateT forall s. ST s (t (MVector s a))
p = (Vector a -> CircularVector a)
-> t (Vector a) -> t (CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector ((forall s. ST s (t (MVector s a))) -> t (Vector a)
forall (f :: * -> *) a.
Traversable f =>
(forall s. ST s (f (MVector s a))) -> f (Vector a)
Vector.createT forall s. ST s (t (MVector s a))
p)
unfoldr :: (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a)
unfoldr :: (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a)
unfoldr b -> Maybe (a, b)
f b
b = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' ((b -> Maybe (a, b)) -> b -> Vector a
forall b a. (b -> Maybe (a, b)) -> b -> Vector a
Vector.unfoldr b -> Maybe (a, b)
f b
b)
unfoldr1 :: (b -> Maybe (a, b)) -> a -> b -> CircularVector a
unfoldr1 :: (b -> Maybe (a, b)) -> a -> b -> CircularVector a
unfoldr1 b -> Maybe (a, b)
f a
a b
b = a -> CircularVector a -> CircularVector a
forall a. a -> CircularVector a -> CircularVector a
cons a
a (Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector ((b -> Maybe (a, b)) -> b -> Vector a
forall b a. (b -> Maybe (a, b)) -> b -> Vector a
Vector.unfoldr b -> Maybe (a, b)
f b
b))
unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a)
unfoldrN :: Int -> (b -> Maybe (a, b)) -> b -> Maybe (CircularVector a)
unfoldrN Int
n b -> Maybe (a, b)
f b
b = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (b -> Maybe (a, b)) -> b -> Vector a
forall b a. Int -> (b -> Maybe (a, b)) -> b -> Vector a
Vector.unfoldrN Int
n b -> Maybe (a, b)
f b
b)
unfoldr1N
:: Int
-> (b -> Maybe (a, b))
-> a
-> b
-> CircularVector a
unfoldr1N :: Int -> (b -> Maybe (a, b)) -> a -> b -> CircularVector a
unfoldr1N Int
n b -> Maybe (a, b)
f a
a b
b = a -> CircularVector a -> CircularVector a
forall a. a -> CircularVector a -> CircularVector a
cons a
a (Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (Int -> (b -> Maybe (a, b)) -> b -> Vector a
forall b a. Int -> (b -> Maybe (a, b)) -> b -> Vector a
Vector.unfoldrN Int
n b -> Maybe (a, b)
f b
b))
unfoldrM
:: Monad m
=> (b -> m (Maybe (a, b)))
-> b
-> m (Maybe (CircularVector a))
unfoldrM :: (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a))
unfoldrM b -> m (Maybe (a, b))
f b
b = (Vector a -> Maybe (CircularVector a))
-> m (Vector a) -> m (Maybe (CircularVector a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' ((b -> m (Maybe (a, b))) -> b -> m (Vector a)
forall (m :: * -> *) b a.
Monad m =>
(b -> m (Maybe (a, b))) -> b -> m (Vector a)
Vector.unfoldrM b -> m (Maybe (a, b))
f b
b)
unfoldr1M
:: Monad m
=> (b -> m (Maybe (a, b)))
-> a
-> b
-> m (CircularVector a)
unfoldr1M :: (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a)
unfoldr1M b -> m (Maybe (a, b))
f a
a b
b = (Vector a -> CircularVector a)
-> m (Vector a) -> m (CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> CircularVector a -> CircularVector a
forall a. a -> CircularVector a -> CircularVector a
cons a
a (CircularVector a -> CircularVector a)
-> (Vector a -> CircularVector a) -> Vector a -> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector) ((b -> m (Maybe (a, b))) -> b -> m (Vector a)
forall (m :: * -> *) b a.
Monad m =>
(b -> m (Maybe (a, b))) -> b -> m (Vector a)
Vector.unfoldrM b -> m (Maybe (a, b))
f b
b)
unfoldrNM
:: Monad m
=> Int
-> (b -> m (Maybe (a, b)))
-> b
-> m (Maybe (CircularVector a))
unfoldrNM :: Int -> (b -> m (Maybe (a, b))) -> b -> m (Maybe (CircularVector a))
unfoldrNM Int
n b -> m (Maybe (a, b))
f b
b = (Vector a -> Maybe (CircularVector a))
-> m (Vector a) -> m (Maybe (CircularVector a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (b -> m (Maybe (a, b))) -> b -> m (Vector a)
forall (m :: * -> *) b a.
Monad m =>
Int -> (b -> m (Maybe (a, b))) -> b -> m (Vector a)
Vector.unfoldrNM Int
n b -> m (Maybe (a, b))
f b
b)
unfoldr1NM
:: Monad m
=> Int
-> (b -> m (Maybe (a, b)))
-> a
-> b
-> m (CircularVector a)
unfoldr1NM :: Int -> (b -> m (Maybe (a, b))) -> a -> b -> m (CircularVector a)
unfoldr1NM Int
n b -> m (Maybe (a, b))
f a
a b
b = (Vector a -> CircularVector a)
-> m (Vector a) -> m (CircularVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> CircularVector a -> CircularVector a
forall a. a -> CircularVector a -> CircularVector a
cons a
a (CircularVector a -> CircularVector a)
-> (Vector a -> CircularVector a) -> Vector a -> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector) (Int -> (b -> m (Maybe (a, b))) -> b -> m (Vector a)
forall (m :: * -> *) b a.
Monad m =>
Int -> (b -> m (Maybe (a, b))) -> b -> m (Vector a)
Vector.unfoldrNM Int
n b -> m (Maybe (a, b))
f b
b)
constructN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
constructN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
constructN Int
n Vector a -> a
f = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (Vector a -> a) -> Vector a
forall a. Int -> (Vector a -> a) -> Vector a
Vector.constructN Int
n Vector a -> a
f)
constructrN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
constructrN :: Int -> (Vector a -> a) -> Maybe (CircularVector a)
constructrN Int
n Vector a -> a
f = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (Int -> (Vector a -> a) -> Vector a
forall a. Int -> (Vector a -> a) -> Vector a
Vector.constructrN Int
n Vector a -> a
f)
enumFromN :: Num a => a -> Int -> Maybe (CircularVector a)
enumFromN :: a -> Int -> Maybe (CircularVector a)
enumFromN a
a Int
n = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (a -> Int -> Vector a
forall a. Num a => a -> Int -> Vector a
Vector.enumFromN a
a Int
n)
enumFromN1 :: Num a => a -> Int -> CircularVector a
enumFromN1 :: a -> Int -> CircularVector a
enumFromN1 a
a Int
n = Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (a -> Int -> Vector a
forall a. Num a => a -> Int -> Vector a
Vector.enumFromN a
a (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1))
enumFromStepN :: Num a => a -> a -> Int -> Maybe (CircularVector a)
enumFromStepN :: a -> a -> Int -> Maybe (CircularVector a)
enumFromStepN a
a0 a
a1 Int
n = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (a -> a -> Int -> Vector a
forall a. Num a => a -> a -> Int -> Vector a
Vector.enumFromStepN a
a0 a
a1 Int
n)
enumFromStepN1 :: Num a => a -> a -> Int -> CircularVector a
enumFromStepN1 :: a -> a -> Int -> CircularVector a
enumFromStepN1 a
a0 a
a1 Int
n = Vector a -> CircularVector a
forall a. Vector a -> CircularVector a
unsafeFromVector (a -> a -> Int -> Vector a
forall a. Num a => a -> a -> Int -> Vector a
Vector.enumFromStepN a
a0 a
a1 (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
n Int
1))
enumFromTo :: Enum a => a -> a -> Maybe (CircularVector a)
enumFromTo :: a -> a -> Maybe (CircularVector a)
enumFromTo a
a0 a
a1 = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (a -> a -> Vector a
forall a. Enum a => a -> a -> Vector a
Vector.enumFromTo a
a0 a
a1)
enumFromThenTo :: Enum a => a -> a -> a -> Maybe (CircularVector a)
enumFromThenTo :: a -> a -> a -> Maybe (CircularVector a)
enumFromThenTo a
a0 a
a1 a
a2 = Vector a -> Maybe (CircularVector a)
forall a. Vector a -> Maybe (CircularVector a)
fromVector' (a -> a -> a -> Vector a
forall a. Enum a => a -> a -> a -> Vector a
Vector.enumFromThenTo a
a0 a
a1 a
a2)
cons :: a -> CircularVector a -> CircularVector a
cons :: a -> CircularVector a -> CircularVector a
cons a
a CircularVector a
cv = a -> Vector a -> CircularVector a
forall a. a -> Vector a -> CircularVector a
consV a
a (CircularVector a -> Vector a
forall a. CircularVector a -> Vector a
toVector CircularVector a
cv)
{-# INLINE cons #-}
consV :: a -> Vector a -> CircularVector a
consV :: a -> Vector a -> CircularVector a
consV a
a = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (Vector a -> NonEmptyVector a) -> Vector a -> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Vector a -> NonEmptyVector a
forall a. a -> Vector a -> NonEmptyVector a
NonEmpty.consV a
a
{-# INLINE consV #-}
snoc :: CircularVector a -> a -> CircularVector a
snoc :: CircularVector a -> a -> CircularVector a
snoc = Vector a -> a -> CircularVector a
forall a. Vector a -> a -> CircularVector a
snocV (Vector a -> a -> CircularVector a)
-> (CircularVector a -> Vector a)
-> CircularVector a
-> a
-> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> Vector a
forall a. CircularVector a -> Vector a
toVector
snocV :: Vector a -> a -> CircularVector a
snocV :: Vector a -> a -> CircularVector a
snocV Vector a
as = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (a -> NonEmptyVector a) -> a -> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> a -> NonEmptyVector a
forall a. Vector a -> a -> NonEmptyVector a
NonEmpty.snocV Vector a
as
(++) :: CircularVector a -> CircularVector a -> CircularVector a
CircularVector a
v ++ :: CircularVector a -> CircularVector a -> CircularVector a
++ CircularVector a
v' = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
v NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
forall a. NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
NonEmpty.++ CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
v')
concat :: [CircularVector a] -> Maybe (CircularVector a)
concat :: [CircularVector a] -> Maybe (CircularVector a)
concat [] = Maybe (CircularVector a)
forall a. Maybe a
Nothing
concat (CircularVector a
a:[CircularVector a]
as) = CircularVector a -> Maybe (CircularVector a)
forall a. a -> Maybe a
Just (NonEmpty (CircularVector a) -> CircularVector a
forall a. NonEmpty (CircularVector a) -> CircularVector a
concat1 (CircularVector a
a CircularVector a
-> [CircularVector a] -> NonEmpty (CircularVector a)
forall a. a -> [a] -> NonEmpty a
:| [CircularVector a]
as))
{-# INLINE concat #-}
concat1 :: NonEmpty (CircularVector a) -> CircularVector a
concat1 :: NonEmpty (CircularVector a) -> CircularVector a
concat1 = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (NonEmpty (CircularVector a) -> NonEmptyVector a)
-> NonEmpty (CircularVector a)
-> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (NonEmptyVector a) -> NonEmptyVector a
forall a. NonEmpty (NonEmptyVector a) -> NonEmptyVector a
NonEmpty.concat1 (NonEmpty (NonEmptyVector a) -> NonEmptyVector a)
-> (NonEmpty (CircularVector a) -> NonEmpty (NonEmptyVector a))
-> NonEmpty (CircularVector a)
-> NonEmptyVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CircularVector a -> NonEmptyVector a)
-> NonEmpty (CircularVector a) -> NonEmpty (NonEmptyVector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
map :: (a -> b) -> CircularVector a -> CircularVector b
map :: (a -> b) -> CircularVector a -> CircularVector b
map a -> b
f (CircularVector NonEmptyVector a
v Int
rot) = NonEmptyVector b -> Int -> CircularVector b
forall a. NonEmptyVector a -> Int -> CircularVector a
CircularVector ((a -> b) -> NonEmptyVector a -> NonEmptyVector b
forall a b. (a -> b) -> NonEmptyVector a -> NonEmptyVector b
NonEmpty.map a -> b
f NonEmptyVector a
v) Int
rot
imap :: (Int -> a -> b) -> CircularVector a -> CircularVector b
imap :: (Int -> a -> b) -> CircularVector a -> CircularVector b
imap Int -> a -> b
f = NonEmptyVector b -> CircularVector b
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector b -> CircularVector b)
-> (CircularVector a -> NonEmptyVector b)
-> CircularVector a
-> CircularVector b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> a -> b) -> NonEmptyVector a -> NonEmptyVector b
forall a b. (Int -> a -> b) -> NonEmptyVector a -> NonEmptyVector b
NonEmpty.imap Int -> a -> b
f (NonEmptyVector a -> NonEmptyVector b)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> NonEmptyVector b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
concatMap
:: (a -> CircularVector b)
-> CircularVector a
-> CircularVector b
concatMap :: (a -> CircularVector b) -> CircularVector a -> CircularVector b
concatMap a -> CircularVector b
f = NonEmptyVector b -> CircularVector b
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector b -> CircularVector b)
-> (CircularVector a -> NonEmptyVector b)
-> CircularVector a
-> CircularVector b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> NonEmptyVector b) -> NonEmptyVector a -> NonEmptyVector b
forall a b.
(a -> NonEmptyVector b) -> NonEmptyVector a -> NonEmptyVector b
NonEmpty.concatMap (CircularVector b -> NonEmptyVector b
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector (CircularVector b -> NonEmptyVector b)
-> (a -> CircularVector b) -> a -> NonEmptyVector b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> CircularVector b
f) (NonEmptyVector a -> NonEmptyVector b)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> NonEmptyVector b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
mapM :: Monad m => (a -> m b) -> CircularVector a -> m (CircularVector b)
mapM :: (a -> m b) -> CircularVector a -> m (CircularVector b)
mapM a -> m b
f = (NonEmptyVector b -> CircularVector b)
-> m (NonEmptyVector b) -> m (CircularVector b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmptyVector b -> CircularVector b
forall a. NonEmptyVector a -> CircularVector a
fromVector (m (NonEmptyVector b) -> m (CircularVector b))
-> (CircularVector a -> m (NonEmptyVector b))
-> CircularVector a
-> m (CircularVector b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m b) -> NonEmptyVector a -> m (NonEmptyVector b)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonEmptyVector a -> m (NonEmptyVector b)
NonEmpty.mapM a -> m b
f (NonEmptyVector a -> m (NonEmptyVector b))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> m (NonEmptyVector b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
imapM
:: Monad m
=> (Int -> a -> m b)
-> CircularVector a
-> m (CircularVector b)
imapM :: (Int -> a -> m b) -> CircularVector a -> m (CircularVector b)
imapM Int -> a -> m b
f = (NonEmptyVector b -> CircularVector b)
-> m (NonEmptyVector b) -> m (CircularVector b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmptyVector b -> CircularVector b
forall a. NonEmptyVector a -> CircularVector a
fromVector (m (NonEmptyVector b) -> m (CircularVector b))
-> (CircularVector a -> m (NonEmptyVector b))
-> CircularVector a
-> m (CircularVector b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> a -> m b) -> NonEmptyVector a -> m (NonEmptyVector b)
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> NonEmptyVector a -> m (NonEmptyVector b)
NonEmpty.imapM Int -> a -> m b
f (NonEmptyVector a -> m (NonEmptyVector b))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> m (NonEmptyVector b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
mapM_ :: Monad m => (a -> m b) -> CircularVector a -> m ()
mapM_ :: (a -> m b) -> CircularVector a -> m ()
mapM_ a -> m b
f = (a -> m b) -> NonEmptyVector a -> m ()
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonEmptyVector a -> m ()
NonEmpty.mapM_ a -> m b
f (NonEmptyVector a -> m ())
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
imapM_ :: Monad m => (Int -> a -> m b) -> CircularVector a -> m ()
imapM_ :: (Int -> a -> m b) -> CircularVector a -> m ()
imapM_ Int -> a -> m b
f = (Int -> a -> m b) -> NonEmptyVector a -> m ()
forall (m :: * -> *) a b.
Monad m =>
(Int -> a -> m b) -> NonEmptyVector a -> m ()
NonEmpty.imapM_ Int -> a -> m b
f (NonEmptyVector a -> m ())
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
forM :: Monad m => CircularVector a -> (a -> m b) -> m (CircularVector b)
forM :: CircularVector a -> (a -> m b) -> m (CircularVector b)
forM CircularVector a
cv a -> m b
f = NonEmptyVector b -> CircularVector b
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector b -> CircularVector b)
-> m (NonEmptyVector b) -> m (CircularVector b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmptyVector a -> (a -> m b) -> m (NonEmptyVector b)
forall (m :: * -> *) a b.
Monad m =>
NonEmptyVector a -> (a -> m b) -> m (NonEmptyVector b)
NonEmpty.forM (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
cv) a -> m b
f
forM_ :: Monad m => CircularVector a -> (a -> m b) -> m ()
forM_ :: CircularVector a -> (a -> m b) -> m ()
forM_ CircularVector a
cv a -> m b
f = NonEmptyVector a -> (a -> m b) -> m ()
forall (m :: * -> *) a b.
Monad m =>
NonEmptyVector a -> (a -> m b) -> m ()
NonEmpty.forM_ (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
cv) a -> m b
f
uniq :: Eq a => CircularVector a -> CircularVector a
uniq :: CircularVector a -> CircularVector a
uniq = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyVector a -> NonEmptyVector a
forall a. Eq a => NonEmptyVector a -> NonEmptyVector a
trim (NonEmptyVector a -> NonEmptyVector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> NonEmptyVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyVector a -> NonEmptyVector a
forall a. Eq a => NonEmptyVector a -> NonEmptyVector a
NonEmpty.uniq (NonEmptyVector a -> NonEmptyVector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> NonEmptyVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
where
trim :: NonEmptyVector a -> NonEmptyVector a
trim NonEmptyVector a
v
| NonEmptyVector a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Foldable.length NonEmptyVector a
v Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 Bool -> Bool -> Bool
|| NonEmptyVector a -> a
forall a. NonEmptyVector a -> a
NonEmpty.head NonEmptyVector a
v a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= NonEmptyVector a -> a
forall a. NonEmptyVector a -> a
NonEmpty.last NonEmptyVector a
v
= NonEmptyVector a
v
| Bool
otherwise
= NonEmptyVector a -> NonEmptyVector a
trim (Vector a -> NonEmptyVector a
forall a. Vector a -> NonEmptyVector a
NonEmpty.unsafeFromVector (Vector a -> NonEmptyVector a) -> Vector a -> NonEmptyVector a
forall a b. (a -> b) -> a -> b
$ NonEmptyVector a -> Vector a
forall a. NonEmptyVector a -> Vector a
NonEmpty.init NonEmptyVector a
v)
mapMaybe
:: (a -> Maybe b)
-> CircularVector a
-> Vector b
mapMaybe :: (a -> Maybe b) -> CircularVector a -> Vector b
mapMaybe a -> Maybe b
f = (a -> Maybe b) -> NonEmptyVector a -> Vector b
forall a b. (a -> Maybe b) -> NonEmptyVector a -> Vector b
NonEmpty.mapMaybe a -> Maybe b
f (NonEmptyVector a -> Vector b)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
imapMaybe
:: (Int -> a -> Maybe b)
-> CircularVector a
-> Vector b
imapMaybe :: (Int -> a -> Maybe b) -> CircularVector a -> Vector b
imapMaybe Int -> a -> Maybe b
f = (Int -> a -> Maybe b) -> NonEmptyVector a -> Vector b
forall a b. (Int -> a -> Maybe b) -> NonEmptyVector a -> Vector b
NonEmpty.imapMaybe Int -> a -> Maybe b
f (NonEmptyVector a -> Vector b)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
takeWhile :: (a -> Bool) -> CircularVector a -> Vector a
takeWhile :: (a -> Bool) -> CircularVector a -> Vector a
takeWhile a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Vector a
forall a. (a -> Bool) -> NonEmptyVector a -> Vector a
NonEmpty.takeWhile a -> Bool
f (NonEmptyVector a -> Vector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
dropWhile :: (a -> Bool) -> CircularVector a -> Vector a
dropWhile :: (a -> Bool) -> CircularVector a -> Vector a
dropWhile a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Vector a
forall a. (a -> Bool) -> NonEmptyVector a -> Vector a
NonEmpty.dropWhile a -> Bool
f (NonEmptyVector a -> Vector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
partition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
partition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
partition a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
forall a. (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
NonEmpty.partition a -> Bool
f (NonEmptyVector a -> (Vector a, Vector a))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> (Vector a, Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
unstablePartition
:: (a -> Bool)
-> CircularVector a
-> (Vector a, Vector a)
unstablePartition :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
unstablePartition a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
forall a. (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
NonEmpty.unstablePartition a -> Bool
f (NonEmptyVector a -> (Vector a, Vector a))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> (Vector a, Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
span :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
span :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
span a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
forall a. (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
NonEmpty.span a -> Bool
f (NonEmptyVector a -> (Vector a, Vector a))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> (Vector a, Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
break :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
break :: (a -> Bool) -> CircularVector a -> (Vector a, Vector a)
break a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
forall a. (a -> Bool) -> NonEmptyVector a -> (Vector a, Vector a)
NonEmpty.break a -> Bool
f (NonEmptyVector a -> (Vector a, Vector a))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> (Vector a, Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
elem :: Eq a => a -> CircularVector a -> Bool
elem :: a -> CircularVector a -> Bool
elem a
a = a -> NonEmptyVector a -> Bool
forall a. Eq a => a -> NonEmptyVector a -> Bool
NonEmpty.elem a
a (NonEmptyVector a -> Bool)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
notElem :: Eq a => a -> CircularVector a -> Bool
notElem :: a -> CircularVector a -> Bool
notElem a
a = a -> NonEmptyVector a -> Bool
forall a. Eq a => a -> NonEmptyVector a -> Bool
NonEmpty.notElem a
a (NonEmptyVector a -> Bool)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
find :: (a -> Bool) -> CircularVector a -> Maybe a
find :: (a -> Bool) -> CircularVector a -> Maybe a
find a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Maybe a
forall a. (a -> Bool) -> NonEmptyVector a -> Maybe a
NonEmpty.find a -> Bool
f (NonEmptyVector a -> Maybe a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
findIndex :: (a -> Bool) -> CircularVector a -> Maybe Int
findIndex :: (a -> Bool) -> CircularVector a -> Maybe Int
findIndex a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Maybe Int
forall a. (a -> Bool) -> NonEmptyVector a -> Maybe Int
NonEmpty.findIndex a -> Bool
f (NonEmptyVector a -> Maybe Int)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
findIndices :: (a -> Bool) -> CircularVector a -> Vector Int
findIndices :: (a -> Bool) -> CircularVector a -> Vector Int
findIndices a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Vector Int
forall a. (a -> Bool) -> NonEmptyVector a -> Vector Int
NonEmpty.findIndices a -> Bool
f (NonEmptyVector a -> Vector Int)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
elemIndex :: Eq a => a -> CircularVector a -> Maybe Int
elemIndex :: a -> CircularVector a -> Maybe Int
elemIndex a
a = a -> NonEmptyVector a -> Maybe Int
forall a. Eq a => a -> NonEmptyVector a -> Maybe Int
NonEmpty.elemIndex a
a (NonEmptyVector a -> Maybe Int)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
elemIndices :: Eq a => a -> CircularVector a -> Vector Int
elemIndices :: a -> CircularVector a -> Vector Int
elemIndices a
a = a -> NonEmptyVector a -> Vector Int
forall a. Eq a => a -> NonEmptyVector a -> Vector Int
NonEmpty.elemIndices a
a (NonEmptyVector a -> Vector Int)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
filter :: (a -> Bool) -> CircularVector a -> Vector a
filter :: (a -> Bool) -> CircularVector a -> Vector a
filter a -> Bool
f = (a -> Bool) -> NonEmptyVector a -> Vector a
forall a. (a -> Bool) -> NonEmptyVector a -> Vector a
NonEmpty.filter a -> Bool
f (NonEmptyVector a -> Vector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
ifilter
:: (Int -> a -> Bool)
-> CircularVector a
-> Vector a
ifilter :: (Int -> a -> Bool) -> CircularVector a -> Vector a
ifilter Int -> a -> Bool
f = (Int -> a -> Bool) -> NonEmptyVector a -> Vector a
forall a. (Int -> a -> Bool) -> NonEmptyVector a -> Vector a
NonEmpty.ifilter Int -> a -> Bool
f (NonEmptyVector a -> Vector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
filterM
:: Monad m
=> (a -> m Bool)
-> CircularVector a
-> m (Vector a)
filterM :: (a -> m Bool) -> CircularVector a -> m (Vector a)
filterM a -> m Bool
f = (a -> m Bool) -> NonEmptyVector a -> m (Vector a)
forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> NonEmptyVector a -> m (Vector a)
NonEmpty.filterM a -> m Bool
f (NonEmptyVector a -> m (Vector a))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> m (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
ifilterM
:: Monad m
=> (Int -> a -> m Bool)
-> CircularVector a
-> m (Vector a)
ifilterM :: (Int -> a -> m Bool) -> CircularVector a -> m (Vector a)
ifilterM Int -> a -> m Bool
f = (Int -> a -> m Bool) -> NonEmptyVector a -> m (Vector a)
forall (m :: * -> *) a.
Monad m =>
(Int -> a -> m Bool) -> NonEmptyVector a -> m (Vector a)
NonEmpty.ifilterM Int -> a -> m Bool
f (NonEmptyVector a -> m (Vector a))
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> m (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector
backpermute :: CircularVector a -> CircularVector Int -> CircularVector a
backpermute :: CircularVector a -> CircularVector Int -> CircularVector a
backpermute CircularVector a
v CircularVector Int
i = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> NonEmptyVector a -> CircularVector a
forall a b. (a -> b) -> a -> b
$ NonEmptyVector a -> NonEmptyVector Int -> NonEmptyVector a
forall a.
NonEmptyVector a -> NonEmptyVector Int -> NonEmptyVector a
NonEmpty.backpermute (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
v) (CircularVector Int -> NonEmptyVector Int
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector Int
i)
unsafeBackpermute
:: CircularVector a
-> CircularVector Int
-> CircularVector a
unsafeBackpermute :: CircularVector a -> CircularVector Int -> CircularVector a
unsafeBackpermute CircularVector a
v CircularVector Int
i = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> NonEmptyVector Int -> NonEmptyVector a
forall a.
NonEmptyVector a -> NonEmptyVector Int -> NonEmptyVector a
NonEmpty.unsafeBackpermute (CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector a
v) (CircularVector Int -> NonEmptyVector Int
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector CircularVector Int
i))
modify
:: (forall s. MVector.MVector s a -> ST s ())
-> CircularVector a
-> CircularVector a
modify :: (forall s. MVector s a -> ST s ())
-> CircularVector a -> CircularVector a
modify forall s. MVector s a -> ST s ()
p = NonEmptyVector a -> CircularVector a
forall a. NonEmptyVector a -> CircularVector a
fromVector (NonEmptyVector a -> CircularVector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> CircularVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s. MVector s a -> ST s ())
-> NonEmptyVector a -> NonEmptyVector a
forall a.
(forall s. MVector s a -> ST s ())
-> NonEmptyVector a -> NonEmptyVector a
NonEmpty.modify forall s. MVector s a -> ST s ()
p (NonEmptyVector a -> NonEmptyVector a)
-> (CircularVector a -> NonEmptyVector a)
-> CircularVector a
-> NonEmptyVector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CircularVector a -> NonEmptyVector a
forall a. CircularVector a -> NonEmptyVector a
toNonEmptyVector