{-# LANGUAGE MultiParamTypeClasses
,TypeFamilies
,FlexibleInstances #-}
{-# OPTIONS -fno-warn-orphans #-}
module Data.ListLike.Vector.Unboxed ()
where
import Prelude as P
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed (Unbox, (!))
import Data.ListLike.Base
import Data.ListLike.FoldableLL
import Data.ListLike.String
import Data.String (IsString)
instance Unbox a => FoldableLL (V.Vector a) a where
foldl :: forall a. (a -> a -> a) -> a -> Vector a -> a
foldl = (a -> a -> a) -> a -> Vector a -> a
forall b a. Unbox b => (a -> b -> a) -> a -> Vector b -> a
V.foldl
foldl' :: forall a. (a -> a -> a) -> a -> Vector a -> a
foldl' = (a -> a -> a) -> a -> Vector a -> a
forall b a. Unbox 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. Unbox a => (a -> a -> a) -> Vector a -> a
V.foldl1
foldr :: forall b. (a -> b -> b) -> b -> Vector a -> b
foldr = (a -> b -> b) -> b -> Vector a -> b
forall a b. Unbox a => (a -> b -> b) -> b -> Vector a -> b
V.foldr
foldr' :: forall b. (a -> b -> b) -> b -> Vector a -> b
foldr' = (a -> b -> b) -> b -> Vector a -> b
forall a b. Unbox a => (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. Unbox a => (a -> a -> a) -> Vector a -> a
V.foldr1
instance Unbox a => ListLike (V.Vector a) a where
empty :: Vector a
empty = Vector a
forall a. Unbox a => Vector a
V.empty
singleton :: a -> Vector a
singleton = a -> Vector a
forall a. Unbox a => a -> Vector a
V.singleton
cons :: a -> Vector a -> Vector a
cons = a -> Vector a -> Vector a
forall a. Unbox a => a -> Vector a -> Vector a
V.cons
snoc :: Vector a -> a -> Vector a
snoc = Vector a -> a -> Vector a
forall a. Unbox 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. Unbox a => Vector a -> a
V.head
last :: Vector a -> a
last = Vector a -> a
forall a. Unbox a => Vector a -> a
V.last
tail :: Vector a -> Vector a
tail = Vector a -> Vector a
forall a. Unbox a => Vector a -> Vector a
V.tail
init :: Vector a -> Vector a
init = Vector a -> Vector a
forall a. Unbox a => Vector a -> Vector a
V.init
null :: Vector a -> Bool
null = Vector a -> Bool
forall a. Unbox a => Vector a -> Bool
V.null
length :: Vector a -> Int
length = Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length
rigidMap :: (a -> a) -> Vector a -> Vector a
rigidMap = (a -> a) -> Vector a -> Vector a
forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b
V.map
reverse :: Vector a -> Vector a
reverse = Vector a -> Vector a
forall a. Unbox a => Vector a -> Vector a
V.reverse
concat :: forall full'. ListLike full' (Vector a) => full' -> Vector a
concat = [Vector a] -> Vector a
forall a. Unbox 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' -> [Item full']
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.
(Unbox a, Unbox b) =>
(a -> Vector b) -> Vector a -> Vector b
V.concatMap
any :: (a -> Bool) -> Vector a -> Bool
any = (a -> Bool) -> Vector a -> Bool
forall a. Unbox a => (a -> Bool) -> Vector a -> Bool
V.any
all :: (a -> Bool) -> Vector a -> Bool
all = (a -> Bool) -> Vector a -> Bool
forall a. Unbox a => (a -> Bool) -> Vector a -> Bool
V.all
maximum :: Ord a => Vector a -> a
maximum = Vector a -> a
forall a. (Unbox a, Ord a) => Vector a -> a
V.maximum
minimum :: Ord a => Vector a -> a
minimum = Vector a -> a
forall a. (Unbox a, Ord a) => Vector a -> a
V.minimum
replicate :: Int -> a -> Vector a
replicate = Int -> a -> Vector a
forall a. Unbox a => Int -> a -> Vector a
V.replicate
take :: Int -> Vector a -> Vector a
take = Int -> Vector a -> Vector a
forall a. Unbox a => Int -> Vector a -> Vector a
V.take
drop :: Int -> Vector a -> Vector a
drop = Int -> Vector a -> Vector a
forall a. Unbox a => Int -> Vector a -> Vector a
V.drop
takeWhile :: (a -> Bool) -> Vector a -> Vector a
takeWhile = (a -> Bool) -> Vector a -> Vector a
forall a. Unbox 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. Unbox 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.
Unbox 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.
Unbox a =>
(a -> Bool) -> Vector a -> (Vector a, Vector a)
V.break
isPrefixOf :: Eq a => Vector a -> Vector a -> Bool
isPrefixOf = Vector a -> Vector a -> Bool
forall a. (Unbox a, Eq a) => Vector a -> Vector a -> Bool
isPrefixOf'
isSuffixOf :: Eq a => Vector a -> Vector a -> Bool
isSuffixOf = Vector a -> Vector a -> Bool
forall a. (Unbox a, Eq a) => Vector a -> Vector a -> Bool
isSuffixOf'
elem :: Eq a => a -> Vector a -> Bool
elem = a -> Vector a -> Bool
forall a. (Unbox 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. Unbox 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. Unbox a => (a -> Bool) -> Vector a -> Vector a
V.filter
index :: Vector a -> Int -> a
index = Vector a -> Int -> a
forall a. Unbox a => Vector a -> Int -> a
(!)
findIndex :: (a -> Bool) -> Vector a -> Maybe Int
findIndex = (a -> Bool) -> Vector a -> Maybe Int
forall a. Unbox a => (a -> Bool) -> Vector a -> Maybe Int
V.findIndex
genericLength :: forall a. Num a => 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. Unbox a => Vector a -> Int
V.length
genericTake :: forall a. Integral a => a -> Vector a -> Vector a
genericTake a
i = Int -> Vector a -> Vector a
forall a. Unbox a => Int -> Vector a -> Vector a
V.take (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)
genericDrop :: forall a. Integral a => a -> Vector a -> Vector a
genericDrop a
i = Int -> Vector a -> Vector a
forall a. Unbox a => Int -> Vector a -> Vector a
V.drop (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)
genericReplicate :: forall a. Integral a => a -> a -> Vector a
genericReplicate a
i = Int -> a -> Vector a
forall a. Unbox a => Int -> a -> Vector a
V.replicate (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)
sequence :: forall (m :: * -> *) fullinp.
(Applicative m, ListLike fullinp (m a)) =>
fullinp -> m (Vector a)
sequence = ([a] -> Vector a) -> m [a] -> m (Vector a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> Vector a
[Item (Vector 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 :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
P.sequenceA ([m a] -> m [a]) -> (fullinp -> [m a]) -> fullinp -> m [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. fullinp -> [m a]
fullinp -> [Item fullinp]
forall l. IsList l => l -> [Item l]
toList
mapM :: forall (m :: * -> *) full' item'.
(Applicative m, ListLike full' item') =>
(a -> m item') -> Vector a -> m full'
mapM a -> m item'
func = ([item'] -> full') -> m [item'] -> m full'
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [item'] -> full'
[Item full'] -> 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 :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
P.traverse 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]
Vector a -> [Item (Vector a)]
forall l. IsList l => l -> [Item l]
toList
instance IsString (V.Vector Char) where
fromString :: String -> Vector Char
fromString = String -> Vector Char
[Item (Vector Char)] -> Vector Char
forall l. IsList l => [Item l] -> l
fromList
instance StringLike (V.Vector Char) where
toString :: Vector Char -> String
toString = Vector Char -> String
Vector Char -> [Item (Vector Char)]
forall l. IsList l => l -> [Item l]
toList
unwords :: forall full. ListLike full (Vector Char) => full -> Vector Char
unwords = let sp :: Vector Char
sp = Char -> Vector Char
forall a. Unbox a => a -> Vector a
V.singleton Char
' ' in [Vector Char] -> Vector Char
forall a. Unbox 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 -> [Item full]
full -> [Vector Char]
forall l. IsList l => l -> [Item l]
toList
unlines :: forall full. ListLike full (Vector Char) => full -> Vector Char
unlines = let eol :: Vector Char
eol = Char -> Vector Char
forall a. Unbox a => a -> Vector a
V.singleton Char
'\n' in [Vector Char] -> Vector Char
forall a. Unbox 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 -> [Item full]
full -> [Vector Char]
forall l. IsList l => l -> [Item l]
toList
isPrefixOf' :: (Unbox a, Eq a) => V.Vector a -> V.Vector a -> Bool
isPrefixOf' :: forall a. (Unbox a, Eq a) => Vector a -> Vector a -> Bool
isPrefixOf' Vector a
needle Vector a
haystack
| Vector a -> Bool
forall a. Unbox a => Vector a -> Bool
V.null Vector a
needle = Bool
True
| Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Vector a -> Int
forall a. Unbox 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. Unbox a => Int -> Int -> Vector a -> Vector a
V.slice Int
0 (Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
needle) Vector a
haystack
| Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a -> Int
forall a. Unbox 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' :: (Unbox a, Eq a) => V.Vector a -> V.Vector a -> Bool
isSuffixOf' :: forall a. (Unbox a, Eq a) => Vector a -> Vector a -> Bool
isSuffixOf' Vector a
needle Vector a
haystack
| Vector a -> Bool
forall a. Unbox a => Vector a -> Bool
V.null Vector a
needle = Bool
True
| Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Vector a -> Int
forall a. Unbox 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. Unbox a => Int -> Int -> Vector a -> Vector a
V.slice (Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
haystack Int -> Int -> Int
forall a. Num a => a -> a -> a
- Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
needle)
(Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
needle)
Vector a
haystack
| Vector a -> Int
forall a. Unbox a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a -> Int
forall a. Unbox 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