{-# LANGUAGE MultiParamTypeClasses
            ,TypeFamilies
            ,FlexibleInstances #-}
{-# OPTIONS -fno-warn-orphans #-}

module Data.ListLike.Vector.Vector ()

where

import           Prelude as P
import           Control.Monad
import qualified Data.Vector as V
import           Data.Vector ((!))
import           Data.ListLike.Base
import           Data.ListLike.FoldableLL
import           Data.ListLike.String
import           Data.String (IsString)

instance FoldableLL (V.Vector a) a where
    foldl :: (a -> a -> a) -> a -> Vector a -> a
foldl = (a -> a -> a) -> a -> Vector a -> a
forall a b. (a -> b -> a) -> a -> Vector b -> a
V.foldl
    foldl' :: (a -> a -> a) -> a -> Vector a -> a
foldl' = (a -> a -> a) -> a -> Vector a -> a
forall a b. (a -> b -> a) -> a -> Vector b -> a
V.foldl'
    foldl1 :: (a -> a -> a) -> Vector a -> a
foldl1 = (a -> a -> a) -> Vector a -> a
forall a. (a -> a -> a) -> Vector a -> a
V.foldl1
    foldr :: (a -> b -> b) -> b -> Vector a -> b
foldr = (a -> b -> b) -> b -> Vector a -> b
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr
    foldr' :: (a -> b -> b) -> b -> Vector a -> b
foldr' = (a -> b -> b) -> b -> Vector a -> b
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr'
    foldr1 :: (a -> a -> a) -> Vector a -> a
foldr1 = (a -> a -> a) -> Vector a -> a
forall a. (a -> a -> a) -> Vector a -> a
V.foldr1

instance ListLike (V.Vector a) a where
    empty :: Vector a
empty = Vector a
forall a. Vector a
V.empty
    singleton :: a -> Vector a
singleton = a -> Vector a
forall a. a -> Vector a
V.singleton
    cons :: a -> Vector a -> Vector a
cons = a -> Vector a -> Vector a
forall a. a -> Vector a -> Vector a
V.cons
    snoc :: Vector a -> a -> Vector a
snoc = Vector a -> a -> Vector a
forall a. Vector a -> a -> Vector a
V.snoc
    append :: Vector a -> Vector a -> Vector a
append = Vector a -> Vector a -> Vector a
forall a. Monoid a => a -> a -> a
mappend
    head :: Vector a -> a
head = Vector a -> a
forall a. Vector a -> a
V.head
    last :: Vector a -> a
last = Vector a -> a
forall a. Vector a -> a
V.last
    tail :: Vector a -> Vector a
tail = Vector a -> Vector a
forall a. Vector a -> Vector a
V.tail
    init :: Vector a -> Vector a
init = Vector a -> Vector a
forall a. Vector a -> Vector a
V.init
    null :: Vector a -> Bool
null = Vector a -> Bool
forall a. Vector a -> Bool
V.null
    length :: Vector a -> Int
length = Vector a -> Int
forall a. Vector a -> Int
V.length
    rigidMap :: (a -> a) -> Vector a -> Vector a
rigidMap = (a -> a) -> Vector a -> Vector a
forall a b. (a -> b) -> Vector a -> Vector b
V.map
    reverse :: Vector a -> Vector a
reverse = Vector a -> Vector a
forall a. Vector a -> Vector a
V.reverse
    --intersperse =
    concat :: full' -> Vector a
concat = [Vector a] -> Vector a
forall a. [Vector a] -> Vector a
V.concat ([Vector a] -> Vector a)
-> (full' -> [Vector a]) -> full' -> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. full' -> [Vector a]
forall l. IsList l => l -> [Item l]
toList
    rigidConcatMap :: (a -> Vector a) -> Vector a -> Vector a
rigidConcatMap = (a -> Vector a) -> Vector a -> Vector a
forall a b. (a -> Vector b) -> Vector a -> Vector b
V.concatMap
    any :: (a -> Bool) -> Vector a -> Bool
any = (a -> Bool) -> Vector a -> Bool
forall a. (a -> Bool) -> Vector a -> Bool
V.any
    all :: (a -> Bool) -> Vector a -> Bool
all = (a -> Bool) -> Vector a -> Bool
forall a. (a -> Bool) -> Vector a -> Bool
V.all
    maximum :: Vector a -> a
maximum = Vector a -> a
forall a. Ord a => Vector a -> a
V.maximum
    minimum :: Vector a -> a
minimum = Vector a -> a
forall a. Ord a => Vector a -> a
V.minimum
    replicate :: Int -> a -> Vector a
replicate = Int -> a -> Vector a
forall a. Int -> a -> Vector a
V.replicate
    take :: Int -> Vector a -> Vector a
take = Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
V.take
    drop :: Int -> Vector a -> Vector a
drop = Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
V.drop
    --splitAt =
    takeWhile :: (a -> Bool) -> Vector a -> Vector a
takeWhile = (a -> Bool) -> Vector a -> Vector a
forall a. (a -> Bool) -> Vector a -> Vector a
V.takeWhile
    dropWhile :: (a -> Bool) -> Vector a -> Vector a
dropWhile = (a -> Bool) -> Vector a -> Vector a
forall a. (a -> Bool) -> Vector a -> Vector a
V.dropWhile
    span :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
span = (a -> Bool) -> Vector a -> (Vector a, Vector a)
forall a. (a -> Bool) -> Vector a -> (Vector a, Vector a)
V.span
    break :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
break = (a -> Bool) -> Vector a -> (Vector a, Vector a)
forall a. (a -> Bool) -> Vector a -> (Vector a, Vector a)
V.break
    --group =
    --inits =
    --tails =
    isPrefixOf :: Vector a -> Vector a -> Bool
isPrefixOf = Vector a -> Vector a -> Bool
forall a. Eq a => Vector a -> Vector a -> Bool
isPrefixOf'
    isSuffixOf :: Vector a -> Vector a -> Bool
isSuffixOf = Vector a -> Vector a -> Bool
forall a. Eq a => Vector a -> Vector a -> Bool
isSuffixOf'
    elem :: a -> Vector a -> Bool
elem = a -> Vector a -> Bool
forall a. Eq a => a -> Vector a -> Bool
V.elem
    find :: (a -> Bool) -> Vector a -> Maybe a
find = (a -> Bool) -> Vector a -> Maybe a
forall a. (a -> Bool) -> Vector a -> Maybe a
V.find
    filter :: (a -> Bool) -> Vector a -> Vector a
filter = (a -> Bool) -> Vector a -> Vector a
forall a. (a -> Bool) -> Vector a -> Vector a
V.filter
    index :: Vector a -> Int -> a
index = (!)
    findIndex :: (a -> Bool) -> Vector a -> Maybe Int
findIndex = (a -> Bool) -> Vector a -> Maybe Int
forall a. (a -> Bool) -> Vector a -> Maybe Int
V.findIndex
    --toList = V.toList
    --fromList = V.fromList
    --fromListLike = fromList . toList
    --groupBy f =
    genericLength :: Vector a -> a
genericLength = Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> (Vector a -> Integer) -> Vector a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> (Vector a -> Int) -> Vector a -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> Int
forall a. Vector a -> Int
V.length
    genericTake :: a -> Vector a -> Vector a
genericTake a
i = Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
V.take (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)
    genericDrop :: a -> Vector a -> Vector a
genericDrop a
i = Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
V.drop (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)
    --genericSplitAt i =
    genericReplicate :: a -> a -> Vector a
genericReplicate a
i = Int -> a -> Vector a
forall a. Int -> a -> Vector a
V.replicate (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)

    sequence :: fullinp -> m (Vector a)
sequence  = ([a] -> Vector a) -> m [a] -> m (Vector a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [a] -> Vector a
forall l. IsList l => [Item l] -> l
fromList (m [a] -> m (Vector a))
-> (fullinp -> m [a]) -> fullinp -> m (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [m a] -> m [a]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
P.sequence  ([m a] -> m [a]) -> (fullinp -> [m a]) -> fullinp -> m [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. fullinp -> [m a]
forall l. IsList l => l -> [Item l]
toList
    mapM :: (a -> m item') -> Vector a -> m full'
mapM a -> m item'
func = ([item'] -> full') -> m [item'] -> m full'
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [item'] -> full'
forall l. IsList l => [Item l] -> l
fromList (m [item'] -> m full')
-> (Vector a -> m [item']) -> Vector a -> m full'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m item') -> [a] -> m [item']
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
P.mapM a -> m item'
func ([a] -> m [item']) -> (Vector a -> [a]) -> Vector a -> m [item']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall l. IsList l => l -> [Item l]
toList

instance IsString (V.Vector Char) where
    fromString :: String -> Vector Char
fromString = String -> Vector Char
forall l. IsList l => [Item l] -> l
fromList

instance StringLike (V.Vector Char) where
    toString :: Vector Char -> String
toString = Vector Char -> String
forall l. IsList l => l -> [Item l]
toList
    --words =
    --lines =
    unwords :: full -> Vector Char
unwords = let sp :: Vector Char
sp = Char -> Vector Char
forall a. a -> Vector a
V.singleton Char
' ' in [Vector Char] -> Vector Char
forall a. [Vector a] -> Vector a
V.concat ([Vector Char] -> Vector Char)
-> (full -> [Vector Char]) -> full -> Vector Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Char -> [Vector Char] -> [Vector Char]
forall full item. ListLike full item => item -> full -> full
intersperse Vector Char
sp ([Vector Char] -> [Vector Char])
-> (full -> [Vector Char]) -> full -> [Vector Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. full -> [Vector Char]
forall l. IsList l => l -> [Item l]
toList
    unlines :: full -> Vector Char
unlines = let eol :: Vector Char
eol = Char -> Vector Char
forall a. a -> Vector a
V.singleton Char
'\n' in [Vector Char] -> Vector Char
forall a. [Vector a] -> Vector a
V.concat ([Vector Char] -> Vector Char)
-> (full -> [Vector Char]) -> full -> Vector Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Char -> [Vector Char] -> [Vector Char]
forall full item. ListLike full item => item -> full -> full
intersperse Vector Char
eol ([Vector Char] -> [Vector Char])
-> (full -> [Vector Char]) -> full -> [Vector Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. full -> [Vector Char]
forall l. IsList l => l -> [Item l]
toList

isPrefixOf' :: Eq a => V.Vector a -> V.Vector a -> Bool
isPrefixOf' :: Vector a -> Vector a -> Bool
isPrefixOf' Vector a
needle Vector a
haystack
  | Vector a -> Bool
forall a. Vector a -> Bool
V.null Vector a
needle = Bool
True
  | Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
haystack =
            Vector a
needle Vector a -> Vector a -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Int -> Vector a -> Vector a
forall a. Int -> Int -> Vector a -> Vector a
V.slice Int
0 (Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
needle) Vector a
haystack
  | Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
haystack = Vector a
needle Vector a -> Vector a -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a
haystack
  | Bool
otherwise = Bool
False
isSuffixOf' :: Eq a => V.Vector a -> V.Vector a -> Bool
isSuffixOf' :: Vector a -> Vector a -> Bool
isSuffixOf' Vector a
needle Vector a
haystack
  | Vector a -> Bool
forall a. Vector a -> Bool
V.null Vector a
needle = Bool
True
  | Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
haystack =
        Vector a
needle Vector a -> Vector a -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Int -> Vector a -> Vector a
forall a. Int -> Int -> Vector a -> Vector a
V.slice (Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
haystack Int -> Int -> Int
forall a. Num a => a -> a -> a
- Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
needle)
                          (Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
needle)
                          Vector a
haystack
  | Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
haystack = Vector a
needle Vector a -> Vector a -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a
haystack
  | Bool
otherwise = Bool
False