Copyright | (c) 2020 Composewell Technologies |
---|---|
License | BSD-3-Clause |
Maintainer | streamly@composewell.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data Array a = Array ByteArray# Int Int
- unsafeFreeze :: (Prim a, MonadIO m) => Array a -> m (Array a)
- unsafeFreezeWithShrink :: (Prim a, MonadIO m) => Array a -> Int -> m (Array a)
- defaultChunkSize :: Int
- nil :: Prim a => Array a
- spliceTwo :: (MonadIO m, Prim a) => Array a -> Array a -> m (Array a)
- fromList :: Prim a => [a] -> Array a
- fromListN :: Prim a => Int -> [a] -> Array a
- fromStreamDN :: (MonadIO m, Prim a) => Int -> Stream m a -> m (Array a)
- fromStreamD :: (MonadIO m, Prim a) => Stream m a -> m (Array a)
- fromStreamDArraysOf :: (MonadIO m, Prim a) => Int -> Stream m a -> Stream m (Array a)
- data FlattenState s a
- flattenArrays :: (MonadIO m, Prim a) => Stream m (Array a) -> Stream m a
- flattenArraysRev :: (MonadIO m, Prim a) => Stream m (Array a) -> Stream m a
- data SpliceState s arr1 arr2
- = SpliceInitial s
- | SpliceBuffering s arr2
- | SpliceYielding arr1 (SpliceState s arr1 arr2)
- | SpliceFinish
- packArraysChunksOf :: forall m a. (MonadIO m, Prim a) => Int -> Stream m (Array a) -> Stream m (Array a)
- lpackArraysChunksOf :: forall m a. (MonadIO m, Prim a) => Int -> Fold m (Array a) () -> Fold m (Array a) ()
- splitOn :: MonadIO m => Word8 -> Stream m (Array Word8) -> Stream m (Array Word8)
- breakOn :: MonadIO m => Word8 -> Array Word8 -> m (Array Word8, Maybe (Array Word8))
- unsafeIndex :: Prim a => Array a -> Int -> a
- byteLength :: forall a. Prim a => Array a -> Int
- length :: Array a -> Int
- foldl' :: Prim a => (b -> a -> b) -> b -> Array a -> b
- foldr :: Prim a => (a -> b -> b) -> b -> Array a -> b
- foldr' :: Prim a => (a -> b -> b) -> b -> Array a -> b
- foldlM' :: (Prim a, Monad m) => (b -> a -> m b) -> b -> Array a -> m b
- splitAt :: Int -> [a] -> ([a], [a])
- toStreamD :: (Prim a, Monad m) => Array a -> Stream m a
- toStreamDRev :: (Prim a, Monad m) => Array a -> Stream m a
- toStreamK :: Prim a => Array a -> Stream m a
- toStreamKRev :: Prim a => Array a -> Stream m a
- toList :: Prim a => Array a -> [a]
- writeN :: (MonadIO m, Prim a) => Int -> Fold m a (Array a)
- data ArrayUnsafe a = ArrayUnsafe !(Array a) !Int
- writeNUnsafe :: (MonadIO m, Prim a) => Int -> Fold m a (Array a)
- write :: (MonadIO m, Prim a) => Fold m a (Array a)
- unlines :: (MonadIO m, Prim a) => a -> Stream m (Array a) -> Stream m a
- toPtr :: Array a -> Ptr a
- touchArray :: Array a -> IO ()
- withArrayAsPtr :: Array a -> (Ptr a -> IO b) -> IO b
Documentation
Instances
a ~ Char => IsString (Array a) Source # | |
Defined in Streamly.Internal.Data.Array.Prim.Pinned.Type fromString :: String -> Array a # | |
Prim a => Monoid (Array a) Source # | |
Prim a => Semigroup (Array a) Source # | |
Prim a => IsList (Array a) Source # | |
(Prim a, Read a, Show a) => Read (Array a) Source # | |
(Show a, Prim a) => Show (Array a) Source # | |
NFData (Array a) Source # | |
(Eq a, Prim a) => Eq (Array a) Source # | |
(Ord a, Prim a) => Ord (Array a) Source # | Lexicographic ordering. Subject to change between major versions. |
type Item (Array a) Source # | |
defaultChunkSize :: Int Source #
Default maximum buffer size in bytes, for reading from and writing to IO devices, the value is 32KB minus GHC allocation overhead, which is a few bytes, so that the actual allocation is 32KB.
Construction
spliceTwo :: (MonadIO m, Prim a) => Array a -> Array a -> m (Array a) Source #
Splice two immutable arrays creating a new immutable array.
Streams of arrays
fromStreamDArraysOf :: (MonadIO m, Prim a) => Int -> Stream m a -> Stream m (Array a) Source #
fromStreamArraysOf n stream
groups the input stream into a stream of
arrays of size n.
data SpliceState s arr1 arr2 Source #
SpliceInitial s | |
SpliceBuffering s arr2 | |
SpliceYielding arr1 (SpliceState s arr1 arr2) | |
SpliceFinish |
packArraysChunksOf :: forall m a. (MonadIO m, Prim a) => Int -> Stream m (Array a) -> Stream m (Array a) Source #
Coalesce adjacent arrays in incoming stream to form bigger arrays of a maximum specified size in bytes. Note that if a single array is bigger than the specified size we do not split it to fit. When we coalesce multiple arrays if the size would exceed the specified size we do not coalesce therefore the actual array size may be less than the specified chunk size.
Pre-release
lpackArraysChunksOf :: forall m a. (MonadIO m, Prim a) => Int -> Fold m (Array a) () -> Fold m (Array a) () Source #
splitOn :: MonadIO m => Word8 -> Stream m (Array Word8) -> Stream m (Array Word8) Source #
Split a stream of arrays on a given separator byte, dropping the separator and coalescing all the arrays between two separators into a single array.
Pre-release
Elimination
foldl' :: Prim a => (b -> a -> b) -> b -> Array a -> b Source #
Strict left-associated fold over the elements of an Array
.
foldr' :: Prim a => (a -> b -> b) -> b -> Array a -> b Source #
Strict right-associated fold over the elements of an Array
.
foldlM' :: (Prim a, Monad m) => (b -> a -> m b) -> b -> Array a -> m b Source #
Strict left-associated fold over the elements of an Array
.
splitAt :: Int -> [a] -> ([a], [a]) #
splitAt
n xs
returns a tuple where first element is xs
prefix of
length n
and second element is the remainder of the list:
>>>
splitAt 6 "Hello World!"
("Hello ","World!")>>>
splitAt 3 [1,2,3,4,5]
([1,2,3],[4,5])>>>
splitAt 1 [1,2,3]
([1],[2,3])>>>
splitAt 3 [1,2,3]
([1,2,3],[])>>>
splitAt 4 [1,2,3]
([1,2,3],[])>>>
splitAt 0 [1,2,3]
([],[1,2,3])>>>
splitAt (-1) [1,2,3]
([],[1,2,3])
It is equivalent to (
when take
n xs, drop
n xs)n
is not _|_
(splitAt _|_ xs = _|_
).
splitAt
is an instance of the more general genericSplitAt
,
in which n
may be of any integral type.
writeN :: (MonadIO m, Prim a) => Int -> Fold m a (Array a) Source #
writeN n
folds a maximum of n
elements from the input stream to an
Array
.
Pre-release
data ArrayUnsafe a Source #
ArrayUnsafe !(Array a) !Int |
writeNUnsafe :: (MonadIO m, Prim a) => Int -> Fold m a (Array a) Source #
Like writeN
but does not check the array bounds when writing. The fold
driver must not call the step function more than n
times otherwise it will
corrupt the memory and crash. This function exists mainly because any
conditional in the step function blocks fusion causing 10x performance
slowdown.
Pre-release
write :: (MonadIO m, Prim a) => Fold m a (Array a) Source #
Fold the whole input to a single array.
Caution! Do not use this on infinite streams.
Pre-release
touchArray :: Array a -> IO () Source #