module Data.Vector.Fusion.Bundle (
Step(..), Chunk(..), Bundle, MBundle,
inplace,
size, sized,
length, null,
empty, singleton, cons, snoc, replicate, generate, (++),
head, last, (!!), (!?),
slice, init, tail, take, drop,
map, concatMap, flatten, unbox,
indexed, indexedR,
zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
zip, zip3, zip4, zip5, zip6,
filter, takeWhile, dropWhile,
elem, notElem, find, findIndex,
foldl, foldl1, foldl', foldl1', foldr, foldr1,
and, or,
unfoldr, unfoldrN, iterateN,
prescanl, prescanl',
postscanl, postscanl',
scanl, scanl',
scanl1, scanl1',
enumFromStepN, enumFromTo, enumFromThenTo,
toList, fromList, fromListN, unsafeFromList, lift,
fromVector, reVector, fromVectors, concatVectors,
mapM, mapM_, zipWithM, zipWithM_, filterM, foldM, fold1M, foldM', fold1M',
eq, cmp
) where
import Data.Vector.Generic.Base ( Vector )
import Data.Vector.Fusion.Bundle.Size
import Data.Vector.Fusion.Util
import Data.Vector.Fusion.Stream.Monadic ( Stream(..), Step(..), SPEC(..) )
import Data.Vector.Fusion.Bundle.Monadic ( Chunk(..) )
import qualified Data.Vector.Fusion.Bundle.Monadic as M
import qualified Data.Vector.Fusion.Stream.Monadic as S
import Prelude hiding ( length, null,
replicate, (++),
head, last, (!!),
init, tail, take, drop,
map, concatMap,
zipWith, zipWith3, zip, zip3,
filter, takeWhile, dropWhile,
elem, notElem,
foldl, foldl1, foldr, foldr1,
and, or,
scanl, scanl1,
enumFromTo, enumFromThenTo,
mapM, mapM_ )
import GHC.Base ( build )
#include "vector.h"
type Bundle = M.Bundle Id
type MBundle = M.Bundle
inplace :: (forall m. Monad m => S.Stream m a -> S.Stream m b)
-> (Size -> Size) -> Bundle v a -> Bundle v b
inplace f g b = b `seq` M.fromStream (f (M.elements b)) (g (M.size b))
lift :: Monad m => Bundle v a -> M.Bundle m v a
lift (M.Bundle (Stream step s) (Stream vstep t) v sz)
= M.Bundle (Stream (return . unId . step) s)
(Stream (return . unId . vstep) t) v sz
size :: Bundle v a -> Size
size = M.size
sized :: Bundle v a -> Size -> Bundle v a
sized = M.sized
length :: Bundle v a -> Int
length = unId . M.length
null :: Bundle v a -> Bool
null = unId . M.null
empty :: Bundle v a
empty = M.empty
singleton :: a -> Bundle v a
singleton = M.singleton
replicate :: Int -> a -> Bundle v a
replicate = M.replicate
generate :: Int -> (Int -> a) -> Bundle v a
generate = M.generate
cons :: a -> Bundle v a -> Bundle v a
cons = M.cons
snoc :: Bundle v a -> a -> Bundle v a
snoc = M.snoc
infixr 5 ++
(++) :: Bundle v a -> Bundle v a -> Bundle v a
(++) = (M.++)
head :: Bundle v a -> a
head = unId . M.head
last :: Bundle v a -> a
last = unId . M.last
infixl 9 !!
(!!) :: Bundle v a -> Int -> a
s !! i = unId (s M.!! i)
infixl 9 !?
(!?) :: Bundle v a -> Int -> Maybe a
s !? i = unId (s M.!? i)
slice :: Int
-> Int
-> Bundle v a
-> Bundle v a
slice = M.slice
init :: Bundle v a -> Bundle v a
init = M.init
tail :: Bundle v a -> Bundle v a
tail = M.tail
take :: Int -> Bundle v a -> Bundle v a
take = M.take
drop :: Int -> Bundle v a -> Bundle v a
drop = M.drop
map :: (a -> b) -> Bundle v a -> Bundle v b
map = M.map
unbox :: Bundle v (Box a) -> Bundle v a
unbox = M.unbox
concatMap :: (a -> Bundle v b) -> Bundle v a -> Bundle v b
concatMap = M.concatMap
indexed :: Bundle v a -> Bundle v (Int,a)
indexed = M.indexed
indexedR :: Int -> Bundle v a -> Bundle v (Int,a)
indexedR = M.indexedR
zipWith :: (a -> b -> c) -> Bundle v a -> Bundle v b -> Bundle v c
zipWith = M.zipWith
zipWith3 :: (a -> b -> c -> d) -> Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d
zipWith3 = M.zipWith3
zipWith4 :: (a -> b -> c -> d -> e)
-> Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d
-> Bundle v e
zipWith4 = M.zipWith4
zipWith5 :: (a -> b -> c -> d -> e -> f)
-> Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d
-> Bundle v e -> Bundle v f
zipWith5 = M.zipWith5
zipWith6 :: (a -> b -> c -> d -> e -> f -> g)
-> Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d
-> Bundle v e -> Bundle v f -> Bundle v g
zipWith6 = M.zipWith6
zip :: Bundle v a -> Bundle v b -> Bundle v (a,b)
zip = M.zip
zip3 :: Bundle v a -> Bundle v b -> Bundle v c -> Bundle v (a,b,c)
zip3 = M.zip3
zip4 :: Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d
-> Bundle v (a,b,c,d)
zip4 = M.zip4
zip5 :: Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d
-> Bundle v e -> Bundle v (a,b,c,d,e)
zip5 = M.zip5
zip6 :: Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d
-> Bundle v e -> Bundle v f -> Bundle v (a,b,c,d,e,f)
zip6 = M.zip6
filter :: (a -> Bool) -> Bundle v a -> Bundle v a
filter = M.filter
takeWhile :: (a -> Bool) -> Bundle v a -> Bundle v a
takeWhile = M.takeWhile
dropWhile :: (a -> Bool) -> Bundle v a -> Bundle v a
dropWhile = M.dropWhile
infix 4 `elem`
elem :: Eq a => a -> Bundle v a -> Bool
elem x = unId . M.elem x
infix 4 `notElem`
notElem :: Eq a => a -> Bundle v a -> Bool
notElem x = unId . M.notElem x
find :: (a -> Bool) -> Bundle v a -> Maybe a
find f = unId . M.find f
findIndex :: (a -> Bool) -> Bundle v a -> Maybe Int
findIndex f = unId . M.findIndex f
foldl :: (a -> b -> a) -> a -> Bundle v b -> a
foldl f z = unId . M.foldl f z
foldl1 :: (a -> a -> a) -> Bundle v a -> a
foldl1 f = unId . M.foldl1 f
foldl' :: (a -> b -> a) -> a -> Bundle v b -> a
foldl' f z = unId . M.foldl' f z
foldl1' :: (a -> a -> a) -> Bundle v a -> a
foldl1' f = unId . M.foldl1' f
foldr :: (a -> b -> b) -> b -> Bundle v a -> b
foldr f z = unId . M.foldr f z
foldr1 :: (a -> a -> a) -> Bundle v a -> a
foldr1 f = unId . M.foldr1 f
and :: Bundle v Bool -> Bool
and = unId . M.and
or :: Bundle v Bool -> Bool
or = unId . M.or
unfoldr :: (s -> Maybe (a, s)) -> s -> Bundle v a
unfoldr = M.unfoldr
unfoldrN :: Int -> (s -> Maybe (a, s)) -> s -> Bundle v a
unfoldrN = M.unfoldrN
iterateN :: Int -> (a -> a) -> a -> Bundle v a
iterateN = M.iterateN
prescanl :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a
prescanl = M.prescanl
prescanl' :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a
prescanl' = M.prescanl'
postscanl :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a
postscanl = M.postscanl
postscanl' :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a
postscanl' = M.postscanl'
scanl :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a
scanl = M.scanl
scanl' :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a
scanl' = M.scanl'
scanl1 :: (a -> a -> a) -> Bundle v a -> Bundle v a
scanl1 = M.scanl1
scanl1' :: (a -> a -> a) -> Bundle v a -> Bundle v a
scanl1' = M.scanl1'
eq :: Eq a => Bundle v a -> Bundle v a -> Bool
eq x y = unId (M.eq x y)
cmp :: Ord a => Bundle v a -> Bundle v a -> Ordering
cmp x y = unId (M.cmp x y)
instance Eq a => Eq (M.Bundle Id v a) where
(==) = eq
instance Ord a => Ord (M.Bundle Id v a) where
compare = cmp
mapM :: Monad m => (a -> m b) -> Bundle v a -> M.Bundle m v b
mapM f = M.mapM f . lift
mapM_ :: Monad m => (a -> m b) -> Bundle v a -> m ()
mapM_ f = M.mapM_ f . lift
zipWithM :: Monad m => (a -> b -> m c) -> Bundle v a -> Bundle v b -> M.Bundle m v c
zipWithM f as bs = M.zipWithM f (lift as) (lift bs)
zipWithM_ :: Monad m => (a -> b -> m c) -> Bundle v a -> Bundle v b -> m ()
zipWithM_ f as bs = M.zipWithM_ f (lift as) (lift bs)
filterM :: Monad m => (a -> m Bool) -> Bundle v a -> M.Bundle m v a
filterM f = M.filterM f . lift
foldM :: Monad m => (a -> b -> m a) -> a -> Bundle v b -> m a
foldM m z = M.foldM m z . lift
fold1M :: Monad m => (a -> a -> m a) -> Bundle v a -> m a
fold1M m = M.fold1M m . lift
foldM' :: Monad m => (a -> b -> m a) -> a -> Bundle v b -> m a
foldM' m z = M.foldM' m z . lift
fold1M' :: Monad m => (a -> a -> m a) -> Bundle v a -> m a
fold1M' m = M.fold1M' m . lift
enumFromStepN :: Num a => a -> a -> Int -> Bundle v a
enumFromStepN = M.enumFromStepN
enumFromTo :: Enum a => a -> a -> Bundle v a
enumFromTo = M.enumFromTo
enumFromThenTo :: Enum a => a -> a -> a -> Bundle v a
enumFromThenTo = M.enumFromThenTo
toList :: Bundle v a -> [a]
toList s = build (\c n -> toListFB c n s)
toListFB :: (a -> b -> b) -> b -> Bundle v a -> b
toListFB c n M.Bundle{M.sElems = Stream step s} = go s
where
go s = case unId (step s) of
Yield x s' -> x `c` go s'
Skip s' -> go s'
Done -> n
fromList :: [a] -> Bundle v a
fromList = M.fromList
fromListN :: Int -> [a] -> Bundle v a
fromListN = M.fromListN
unsafeFromList :: Size -> [a] -> Bundle v a
unsafeFromList = M.unsafeFromList
fromVector :: Vector v a => v a -> Bundle v a
fromVector = M.fromVector
reVector :: Bundle u a -> Bundle v a
reVector = M.reVector
fromVectors :: Vector v a => [v a] -> Bundle v a
fromVectors = M.fromVectors
concatVectors :: Vector v a => Bundle u (v a) -> Bundle v a
concatVectors = M.concatVectors
flatten :: (a -> s) -> (s -> Step s b) -> Size -> Bundle v a -> Bundle v b
flatten mk istep sz = M.flatten (return . mk) (return . istep) sz . lift