vector-0.12.3.1: Efficient Arrays
Copyright (c) Roman Leshchinskiy 2008-2010
License BSD-style
Maintainer Roman Leshchinskiy <rl@cse.unsw.edu.au>
Stability experimental
Portability non-portable
Safe Haskell None
Language Haskell2010

Data.Vector.Fusion.Bundle

Description

Bundles for stream fusion

Synopsis

Types

data Step s a where Source #

Result of taking a single step in a stream

Constructors

Yield :: a -> s -> Step s a
Skip :: s -> Step s a
Done :: Step s a

Instances

Instances details
Functor ( Step s) Source #
Instance details

Defined in Data.Vector.Fusion.Stream.Monadic

Methods

fmap :: (a -> b) -> Step s a -> Step s b Source #

(<$) :: a -> Step s b -> Step s a Source #

data Chunk v a Source #

Constructors

Chunk Int ( forall m. ( PrimMonad m, Vector v a) => Mutable v ( PrimState m) a -> m ())

type Bundle = Bundle Id Source #

The type of pure streams

type MBundle = Bundle Source #

Alternative name for monadic streams

In-place markers

Size hints

Length information

Construction

cons :: a -> Bundle v a -> Bundle v a Source #

Prepend an element

snoc :: Bundle v a -> a -> Bundle v a Source #

Append an element

replicate :: Int -> a -> Bundle v a Source #

Replicate a value to a given length

generate :: Int -> ( Int -> a) -> Bundle v a Source #

Generate a stream from its indices

(++) :: Bundle v a -> Bundle v a -> Bundle v a infixr 5 Source #

Concatenate two Bundle s

Accessing individual elements

head :: Bundle v a -> a Source #

First element of the Bundle or error if empty

last :: Bundle v a -> a Source #

Last element of the Bundle or error if empty

(!!) :: Bundle v a -> Int -> a infixl 9 Source #

Element at the given position

(!?) :: Bundle v a -> Int -> Maybe a infixl 9 Source #

Element at the given position or Nothing if out of bounds

Substreams

slice Source #

Arguments

:: Int

starting index

-> Int

length

-> Bundle v a
-> Bundle v a

Extract a substream of the given length starting at the given position.

init :: Bundle v a -> Bundle v a Source #

All but the last element

tail :: Bundle v a -> Bundle v a Source #

All but the first element

take :: Int -> Bundle v a -> Bundle v a Source #

The first n elements

drop :: Int -> Bundle v a -> Bundle v a Source #

All but the first n elements

Mapping

map :: (a -> b) -> Bundle v a -> Bundle v b Source #

Map a function over a Bundle

flatten :: (a -> s) -> (s -> Step s b) -> Size -> Bundle v a -> Bundle v b Source #

Create a Bundle of values from a Bundle of streamable things

Zipping

indexed :: Bundle v a -> Bundle v ( Int , a) Source #

Pair each element in a Bundle with its index

indexedR :: Int -> Bundle v a -> Bundle v ( Int , a) Source #

Pair each element in a Bundle with its index, starting from the right and counting down

zipWith :: (a -> b -> c) -> Bundle v a -> Bundle v b -> Bundle v c Source #

Zip two Bundle s with the given function

zipWith3 :: (a -> b -> c -> d) -> Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d Source #

Zip three Bundle s with the given function

zipWith4 :: (a -> b -> c -> d -> e) -> Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d -> Bundle v e Source #

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 Source #

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 Source #

zip4 :: Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d -> Bundle v (a, b, c, d) Source #

zip5 :: Bundle v a -> Bundle v b -> Bundle v c -> Bundle v d -> Bundle v e -> Bundle v (a, b, c, d, e) Source #

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) Source #

Filtering

filter :: (a -> Bool ) -> Bundle v a -> Bundle v a Source #

Drop elements which do not satisfy the predicate

takeWhile :: (a -> Bool ) -> Bundle v a -> Bundle v a Source #

Longest prefix of elements that satisfy the predicate

dropWhile :: (a -> Bool ) -> Bundle v a -> Bundle v a Source #

Drop the longest prefix of elements that satisfy the predicate

Searching

elem :: Eq a => a -> Bundle v a -> Bool infix 4 Source #

Check whether the Bundle contains an element

notElem :: Eq a => a -> Bundle v a -> Bool infix 4 Source #

Inverse of elem

find :: (a -> Bool ) -> Bundle v a -> Maybe a Source #

Yield Just the first element matching the predicate or Nothing if no such element exists.

findIndex :: (a -> Bool ) -> Bundle v a -> Maybe Int Source #

Yield Just the index of the first element matching the predicate or Nothing if no such element exists.

Folding

foldl :: (a -> b -> a) -> a -> Bundle v b -> a Source #

Left fold

foldl1 :: (a -> a -> a) -> Bundle v a -> a Source #

Left fold on non-empty Bundle s

foldl' :: (a -> b -> a) -> a -> Bundle v b -> a Source #

Left fold with strict accumulator

foldl1' :: (a -> a -> a) -> Bundle v a -> a Source #

Left fold on non-empty Bundle s with strict accumulator

foldr :: (a -> b -> b) -> b -> Bundle v a -> b Source #

Right fold

foldr1 :: (a -> a -> a) -> Bundle v a -> a Source #

Right fold on non-empty Bundle s

Specialised folds

Unfolding

unfoldr :: (s -> Maybe (a, s)) -> s -> Bundle v a Source #

Unfold

unfoldrN :: Int -> (s -> Maybe (a, s)) -> s -> Bundle v a Source #

Unfold at most n elements

unfoldrExactN :: Int -> (s -> (a, s)) -> s -> Bundle v a Source #

Unfold exactly n elements

Since: 0.12.2.0

iterateN :: Int -> (a -> a) -> a -> Bundle v a Source #

O(n) Apply function \(\max(n - 1, 0)\) times to an initial value, producing a pure bundle of exact length \(\max(n, 0)\) . Zeroth element will contain the initial value.

Scans

prescanl :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a Source #

Prefix scan

prescanl' :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a Source #

Prefix scan with strict accumulator

postscanl :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a Source #

Suffix scan

postscanl' :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a Source #

Suffix scan with strict accumulator

scanl :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a Source #

Haskell-style scan

scanl' :: (a -> b -> a) -> a -> Bundle v b -> Bundle v a Source #

Haskell-style scan with strict accumulator

scanl1 :: (a -> a -> a) -> Bundle v a -> Bundle v a Source #

Scan over a non-empty Bundle

scanl1' :: (a -> a -> a) -> Bundle v a -> Bundle v a Source #

Scan over a non-empty Bundle with a strict accumulator

Enumerations

enumFromStepN :: Num a => a -> a -> Int -> Bundle v a Source #

Yield a Bundle of the given length containing the values x , x+y , x+y+y etc.

enumFromTo :: Enum a => a -> a -> Bundle v a Source #

Enumerate values

WARNING: This operations can be very inefficient. If at all possible, use enumFromStepN instead.

enumFromThenTo :: Enum a => a -> a -> a -> Bundle v a Source #

Enumerate values with a given step.

WARNING: This operations is very inefficient. If at all possible, use enumFromStepN instead.

Conversions

toList :: Bundle v a -> [a] Source #

Convert a Bundle to a list

fromList :: [a] -> Bundle v a Source #

Create a Bundle from a list

fromListN :: Int -> [a] -> Bundle v a Source #

Create a Bundle from the first n elements of a list

fromListN n xs = fromList (take n xs)

lift :: Monad m => Bundle Id v a -> Bundle m v a Source #

Convert a pure stream to a monadic stream

Monadic combinators

mapM :: Monad m => (a -> m b) -> Bundle v a -> Bundle m v b Source #

Apply a monadic action to each element of the stream, producing a monadic stream of results

mapM_ :: Monad m => (a -> m b) -> Bundle v a -> m () Source #

Apply a monadic action to each element of the stream

zipWithM :: Monad m => (a -> b -> m c) -> Bundle v a -> Bundle v b -> Bundle m v c Source #

zipWithM_ :: Monad m => (a -> b -> m c) -> Bundle v a -> Bundle v b -> m () Source #

filterM :: Monad m => (a -> m Bool ) -> Bundle v a -> Bundle m v a Source #

Yield a monadic stream of elements that satisfy the monadic predicate

mapMaybeM :: Monad m => (a -> m ( Maybe b)) -> Bundle v a -> Bundle m v b Source #

O(n) Apply monadic function to each element of a bundle and discard elements returning Nothing.

Since: 0.12.2.0

foldM :: Monad m => (a -> b -> m a) -> a -> Bundle v b -> m a Source #

Monadic fold

fold1M :: Monad m => (a -> a -> m a) -> Bundle v a -> m a Source #

Monadic fold over non-empty stream

foldM' :: Monad m => (a -> b -> m a) -> a -> Bundle v b -> m a Source #

Monadic fold with strict accumulator

fold1M' :: Monad m => (a -> a -> m a) -> Bundle v a -> m a Source #

Monad fold over non-empty stream with strict accumulator

eq :: Eq a => Bundle v a -> Bundle v a -> Bool Source #

Check if two Bundle s are equal

cmp :: Ord a => Bundle v a -> Bundle v a -> Ordering Source #

Lexicographically compare two Bundle s

Orphan instances