{-# LANGUAGE MultiParamTypeClasses
,TypeFamilies
,FlexibleInstances #-}
{-# OPTIONS -fno-warn-orphans #-}
module Data.ListLike.Vector.Storable ()
where
import Prelude as P
import Control.Monad
import qualified Data.Vector.Storable as V
import Data.Vector.Storable ((!))
import Data.ListLike.Base
import Data.ListLike.FoldableLL
import Data.ListLike.String
import Data.String (IsString)
import Foreign.Storable (Storable)
instance Storable 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. Storable 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. Storable 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. Storable 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. Storable 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. Storable 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. Storable a => (a -> a -> a) -> Vector a -> a
V.foldr1
instance Storable a => ListLike (V.Vector a) a where
empty :: Vector a
empty = Vector a
forall a. Storable a => Vector a
V.empty
singleton :: a -> Vector a
singleton = a -> Vector a
forall a. Storable a => a -> Vector a
V.singleton
cons :: a -> Vector a -> Vector a
cons = a -> Vector a -> Vector a
forall a. Storable a => a -> Vector a -> Vector a
V.cons
snoc :: Vector a -> a -> Vector a
snoc = Vector a -> a -> Vector a
forall a. Storable 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. Storable a => Vector a -> a
V.head
last :: Vector a -> a
last = Vector a -> a
forall a. Storable a => Vector a -> a
V.last
tail :: Vector a -> Vector a
tail = Vector a -> Vector a
forall a. Storable a => Vector a -> Vector a
V.tail
init :: Vector a -> Vector a
init = Vector a -> Vector a
forall a. Storable a => Vector a -> Vector a
V.init
null :: Vector a -> Bool
null = Vector a -> Bool
forall a. Storable a => Vector a -> Bool
V.null
length :: Vector a -> Int
length = Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length
rigidMap :: (a -> a) -> Vector a -> Vector a
rigidMap = (a -> a) -> Vector a -> Vector a
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
V.map
reverse :: Vector a -> Vector a
reverse = Vector a -> Vector a
forall a. Storable a => Vector a -> Vector a
V.reverse
concat :: forall full'. ListLike full' (Vector a) => full' -> Vector a
concat = [Vector a] -> Vector a
forall a. Storable 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.
(Storable a, Storable b) =>
(a -> Vector b) -> Vector a -> Vector b
V.concatMap
any :: (a -> Bool) -> Vector a -> Bool
any = (a -> Bool) -> Vector a -> Bool
forall a. Storable a => (a -> Bool) -> Vector a -> Bool
V.any
all :: (a -> Bool) -> Vector a -> Bool
all = (a -> Bool) -> Vector a -> Bool
forall a. Storable a => (a -> Bool) -> Vector a -> Bool
V.all
maximum :: Ord a => Vector a -> a
maximum = Vector a -> a
forall a. (Storable a, Ord a) => Vector a -> a
V.maximum
minimum :: Ord a => Vector a -> a
minimum = Vector a -> a
forall a. (Storable a, Ord a) => Vector a -> a
V.minimum
replicate :: Int -> a -> Vector a
replicate = Int -> a -> Vector a
forall a. Storable a => Int -> a -> Vector a
V.replicate
take :: Int -> Vector a -> Vector a
take = Int -> Vector a -> Vector a
forall a. Storable a => Int -> Vector a -> Vector a
V.take
drop :: Int -> Vector a -> Vector a
drop = Int -> Vector a -> Vector a
forall a. Storable a => Int -> Vector a -> Vector a
V.drop
takeWhile :: (a -> Bool) -> Vector a -> Vector a
takeWhile = (a -> Bool) -> Vector a -> Vector a
forall a. Storable 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. Storable 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.
Storable 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.
Storable 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. (Storable 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. (Storable a, Eq a) => Vector a -> Vector a -> Bool
isSuffixOf'
elem :: Eq a => a -> Vector a -> Bool
elem = a -> Vector a -> Bool
forall a. (Storable 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. Storable 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. Storable a => (a -> Bool) -> Vector a -> Vector a
V.filter
index :: Vector a -> Int -> a
index = Vector a -> Int -> a
forall a. Storable a => Vector a -> Int -> a
(!)
findIndex :: (a -> Bool) -> Vector a -> Maybe Int
findIndex = (a -> Bool) -> Vector a -> Maybe Int
forall a. Storable 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. Storable 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. Storable 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. Storable 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. Storable 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.
(Monad m, ListLike fullinp (m a)) =>
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 :: forall (m :: * -> *) full' item'.
(Monad m, ListLike full' item') =>
(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
unwords :: forall full. ListLike full (Vector Char) => full -> Vector Char
unwords = let sp :: Vector Char
sp = Char -> Vector Char
forall a. Storable a => a -> Vector a
V.singleton Char
' ' in [Vector Char] -> Vector Char
forall a. Storable 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 :: forall full. ListLike full (Vector Char) => full -> Vector Char
unlines = let eol :: Vector Char
eol = Char -> Vector Char
forall a. Storable a => a -> Vector a
V.singleton Char
'\n' in [Vector Char] -> Vector Char
forall a. Storable 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' :: (Storable a, Eq a) => V.Vector a -> V.Vector a -> Bool
isPrefixOf' :: forall a. (Storable a, Eq a) => Vector a -> Vector a -> Bool
isPrefixOf' Vector a
needle Vector a
haystack
| Vector a -> Bool
forall a. Storable a => Vector a -> Bool
V.null Vector a
needle = Bool
True
| Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Vector a -> Int
forall a. Storable 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. Storable a => Int -> Int -> Vector a -> Vector a
V.slice Int
0 (Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
needle) Vector a
haystack
| Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a -> Int
forall a. Storable 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' :: (Storable a, Eq a) => V.Vector a -> V.Vector a -> Bool
isSuffixOf' :: forall a. (Storable a, Eq a) => Vector a -> Vector a -> Bool
isSuffixOf' Vector a
needle Vector a
haystack
| Vector a -> Bool
forall a. Storable a => Vector a -> Bool
V.null Vector a
needle = Bool
True
| Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Vector a -> Int
forall a. Storable 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. Storable a => Int -> Int -> Vector a -> Vector a
V.slice (Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
haystack Int -> Int -> Int
forall a. Num a => a -> a -> a
- Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
needle)
(Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
needle)
Vector a
haystack
| Vector a -> Int
forall a. Storable a => Vector a -> Int
V.length Vector a
needle Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Vector a -> Int
forall a. Storable 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