{-# LANGUAGE CPP #-}
module Streamly.Internal.Data.Array.Type
(
Array (..)
, unsafeFreeze
, unsafeFreezeWithShrink
, unsafeThaw
, pin
, unpin
, isPinned
, unsafePinnedAsPtr
, empty
, clone
, pinnedClone
, splitAt
, breakOn
, unsafeMakePure
, createOf
, pinnedCreateOf
, unsafeCreateOf
, unsafePinnedCreateOf
, create
, pinnedCreate
, createWith
, fromListN
, pinnedFromListN
, fromList
, pinnedFromList
, fromListRevN
, fromListRev
, fromStreamN
, fromStream
, fromPureStreamN
, fromPureStream
, fromByteStr#
, fromByteStr
, fromPtrN
, fromChunks
, fromChunksK
, unsafeIndexIO
, getIndexUnsafe
, read
, readRev
, toStreamK
, toStreamKRev
, toList
, producer
, readerUnsafe
, reader
, readerRev
, length
, byteLength
, foldl'
, foldr
, byteCmp
, byteEq
, splice
, chunksOf
, pinnedChunksOf
, buildChunks
, concat
, concatRev
, fCompactGE
, fPinnedCompactGE
, lCompactGE
, lPinnedCompactGE
, compactGE
, asPtrUnsafe
, unsafeIndex
, bufferChunks
, flattenArrays
, flattenArraysRev
, fromArrayStreamK
, fromStreamDN
, fromStreamD
, toStreamD
, toStreamDRev
, toStream
, toStreamRev
, nil
, writeWith
, writeN
, pinnedWriteN
, writeNUnsafe
, pinnedWriteNUnsafe
, pinnedWriteNAligned
, write
, pinnedWrite
)
where
#include "ArrayMacros.h"
#include "inline.hs"
import Control.Exception (assert)
import Control.Monad (replicateM, when)
import Control.Monad.IO.Class (MonadIO(..))
import Data.Functor.Identity (Identity(..))
import Data.Int (Int8, Int16, Int32, Int64)
import Data.Proxy (Proxy(..))
import Data.Word (Word8, Word16, Word32, Word64)
import GHC.Base (build)
import GHC.Exts (IsList, IsString(..), Addr#)
import GHC.IO (unsafePerformIO)
import GHC.Ptr (Ptr(..))
import Streamly.Internal.Data.Producer.Type (Producer(..))
import Streamly.Internal.Data.MutArray.Type (MutArray(..))
import Streamly.Internal.Data.MutByteArray.Type (MutByteArray)
import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.Stream.Type (Stream)
import Streamly.Internal.Data.StreamK.Type (StreamK)
import Streamly.Internal.Data.Unbox (Unbox(..))
import Streamly.Internal.Data.Unfold.Type (Unfold(..))
import Text.Read (readPrec)
import Prelude hiding (Foldable(..), concat, read, unlines, splitAt)
import qualified GHC.Exts as Exts
import qualified Streamly.Internal.Data.Fold.Type as Fold
import qualified Streamly.Internal.Data.MutArray.Type as MA
import qualified Streamly.Internal.Data.Stream.Type as D
import qualified Streamly.Internal.Data.StreamK.Type as K
import qualified Streamly.Internal.Data.MutByteArray.Type as Unboxed
import qualified Streamly.Internal.Data.Producer as Producer
import qualified Streamly.Internal.Data.Unfold.Type as Unfold
import qualified Text.ParserCombinators.ReadPrec as ReadPrec
import Streamly.Internal.System.IO (unsafeInlineIO, defaultChunkSize)
#include "DocTestDataArray.hs"
data Array a =
#ifdef DEVBUILD
Unbox a =>
#endif
Array
{ forall a. Array a -> MutByteArray
arrContents :: {-# UNPACK #-} !MutByteArray
, forall a. Array a -> Int
arrStart :: {-# UNPACK #-} !Int
, forall a. Array a -> Int
arrEnd :: {-# UNPACK #-} !Int
}
{-# INLINE unsafePinnedAsPtr #-}
unsafePinnedAsPtr :: MonadIO m => Array a -> (Ptr a -> m b) -> m b
unsafePinnedAsPtr :: forall (m :: * -> *) a b.
MonadIO m =>
Array a -> (Ptr a -> m b) -> m b
unsafePinnedAsPtr Array a
arr = MutArray a -> (Ptr a -> m b) -> m b
forall (m :: * -> *) a b.
MonadIO m =>
MutArray a -> (Ptr a -> m b) -> m b
MA.unsafePinnedAsPtr (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# DEPRECATED asPtrUnsafe "Please use unsafePinnedAsPtr instead." #-}
{-# INLINE asPtrUnsafe #-}
asPtrUnsafe :: MonadIO m => Array a -> (Ptr a -> m b) -> m b
asPtrUnsafe :: forall (m :: * -> *) a b.
MonadIO m =>
Array a -> (Ptr a -> m b) -> m b
asPtrUnsafe = Array a -> (Ptr a -> m b) -> m b
forall (m :: * -> *) a b.
MonadIO m =>
Array a -> (Ptr a -> m b) -> m b
unsafePinnedAsPtr
{-# INLINE unsafeFreeze #-}
unsafeFreeze :: MutArray a -> Array a
unsafeFreeze :: forall a. MutArray a -> Array a
unsafeFreeze (MutArray MutByteArray
ac Int
as Int
ae Int
_) = MutByteArray -> Int -> Int -> Array a
forall a. MutByteArray -> Int -> Int -> Array a
Array MutByteArray
ac Int
as Int
ae
{-# INLINE unsafeFreezeWithShrink #-}
unsafeFreezeWithShrink :: Unbox a => MutArray a -> Array a
unsafeFreezeWithShrink :: forall a. Unbox a => MutArray a -> Array a
unsafeFreezeWithShrink MutArray a
arr = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ do
MutArray MutByteArray
ac Int
as Int
ae Int
_ <- MutArray a -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
MutArray a -> m (MutArray a)
MA.rightSize MutArray a
arr
Array a -> IO (Array a)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Array a -> IO (Array a)) -> Array a -> IO (Array a)
forall a b. (a -> b) -> a -> b
$ MutByteArray -> Int -> Int -> Array a
forall a. MutByteArray -> Int -> Int -> Array a
Array MutByteArray
ac Int
as Int
ae
{-# INLINE unsafeThaw #-}
unsafeThaw :: Array a -> MutArray a
unsafeThaw :: forall a. Array a -> MutArray a
unsafeThaw (Array MutByteArray
ac Int
as Int
ae) = MutByteArray -> Int -> Int -> Int -> MutArray a
forall a. MutByteArray -> Int -> Int -> Int -> MutArray a
MutArray MutByteArray
ac Int
as Int
ae Int
ae
{-# INLINE pin #-}
pin :: Array a -> IO (Array a)
pin :: forall a. Array a -> IO (Array a)
pin = (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (IO (MutArray a) -> IO (Array a))
-> (Array a -> IO (MutArray a)) -> Array a -> IO (Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutArray a -> IO (MutArray a)
forall a. MutArray a -> IO (MutArray a)
MA.pin (MutArray a -> IO (MutArray a))
-> (Array a -> MutArray a) -> Array a -> IO (MutArray a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# INLINE unpin #-}
unpin :: Array a -> IO (Array a)
unpin :: forall a. Array a -> IO (Array a)
unpin = (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (IO (MutArray a) -> IO (Array a))
-> (Array a -> IO (MutArray a)) -> Array a -> IO (Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutArray a -> IO (MutArray a)
forall a. MutArray a -> IO (MutArray a)
MA.unpin (MutArray a -> IO (MutArray a))
-> (Array a -> MutArray a) -> Array a -> IO (MutArray a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# INLINE isPinned #-}
isPinned :: Array a -> Bool
isPinned :: forall a. Array a -> Bool
isPinned = MutArray a -> Bool
forall a. MutArray a -> Bool
MA.isPinned (MutArray a -> Bool) -> (Array a -> MutArray a) -> Array a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# INLINE splice #-}
splice :: MonadIO m => Array a -> Array a -> m (Array a)
splice :: forall (m :: * -> *) a.
MonadIO m =>
Array a -> Array a -> m (Array a)
splice Array a
arr1 Array a
arr2 =
MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> m (MutArray a) -> m (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MutArray a -> MutArray a -> m (MutArray a)
forall (m :: * -> *) a.
MonadIO m =>
MutArray a -> MutArray a -> m (MutArray a)
MA.spliceCopy (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr1) (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr2)
{-# INLINABLE fromListN #-}
fromListN :: Unbox a => Int -> [a] -> Array a
fromListN :: forall a. Unbox a => Int -> [a] -> Array a
fromListN Int
n [a]
xs = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> [a] -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> [a] -> m (MutArray a)
MA.fromListN Int
n [a]
xs
{-# INLINABLE pinnedFromListN #-}
pinnedFromListN :: Unbox a => Int -> [a] -> Array a
pinnedFromListN :: forall a. Unbox a => Int -> [a] -> Array a
pinnedFromListN Int
n [a]
xs =
IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> [a] -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> [a] -> m (MutArray a)
MA.pinnedFromListN Int
n [a]
xs
{-# INLINABLE fromListRevN #-}
fromListRevN :: Unbox a => Int -> [a] -> Array a
fromListRevN :: forall a. Unbox a => Int -> [a] -> Array a
fromListRevN Int
n [a]
xs = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> [a] -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> [a] -> m (MutArray a)
MA.fromListRevN Int
n [a]
xs
{-# INLINE fromList #-}
fromList :: Unbox a => [a] -> Array a
fromList :: forall a. Unbox a => [a] -> Array a
fromList [a]
xs = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
[a] -> m (MutArray a)
MA.fromList [a]
xs
{-# INLINE pinnedFromList #-}
pinnedFromList :: Unbox a => [a] -> Array a
pinnedFromList :: forall a. Unbox a => [a] -> Array a
pinnedFromList [a]
xs = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
[a] -> m (MutArray a)
MA.pinnedFromList [a]
xs
{-# INLINABLE fromListRev #-}
fromListRev :: Unbox a => [a] -> Array a
fromListRev :: forall a. Unbox a => [a] -> Array a
fromListRev [a]
xs = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
[a] -> m (MutArray a)
MA.fromListRev [a]
xs
{-# INLINE_NORMAL fromStreamN #-}
fromStreamN :: (MonadIO m, Unbox a) => Int -> Stream m a -> m (Array a)
fromStreamN :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> m (Array a)
fromStreamN Int
n Stream m a
m = do
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ [Char] -> m ()
forall a. HasCallStack => [Char] -> a
error [Char]
"writeN: negative write count specified"
MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a) -> m (MutArray a) -> m (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Stream m a -> m (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> m (MutArray a)
MA.fromStreamN Int
n Stream m a
m
{-# DEPRECATED fromStreamDN "Please use fromStreamN instead." #-}
fromStreamDN :: forall m a. (MonadIO m, Unbox a)
=> Int -> D.Stream m a -> m (Array a)
fromStreamDN :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> m (Array a)
fromStreamDN = Int -> Stream m a -> m (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> m (Array a)
fromStreamN
{-# INLINE_NORMAL fromStreamD #-}
fromStream :: (MonadIO m, Unbox a) => Stream m a -> m (Array a)
fromStream :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m a -> m (Array a)
fromStream = Fold m a (Array a) -> Stream m a -> m (Array a)
forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> m b
D.fold Fold m a (Array a)
forall (m :: * -> *) a. (MonadIO m, Unbox a) => Fold m a (Array a)
write
{-# DEPRECATED fromStreamD "Please use fromStream instead." #-}
fromStreamD :: forall m a. (MonadIO m, Unbox a)
=> D.Stream m a -> m (Array a)
fromStreamD :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m a -> m (Array a)
fromStreamD = Stream m a -> m (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m a -> m (Array a)
fromStream
{-# INLINE clone #-}
clone ::
( MonadIO m
#ifdef DEVBUILD
, Unbox a
#endif
)
=> Array a -> m (Array a)
clone :: forall (m :: * -> *) a. MonadIO m => Array a -> m (Array a)
clone = (MutArray a -> Array a) -> m (MutArray a) -> m (Array a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (m (MutArray a) -> m (Array a))
-> (Array a -> m (MutArray a)) -> Array a -> m (Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutArray a -> m (MutArray a)
forall (m :: * -> *) a. MonadIO m => MutArray a -> m (MutArray a)
MA.clone (MutArray a -> m (MutArray a))
-> (Array a -> MutArray a) -> Array a -> m (MutArray a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# INLINE pinnedClone #-}
pinnedClone ::
( MonadIO m
#ifdef DEVBUILD
, Unbox a
#endif
)
=> Array a -> m (Array a)
pinnedClone :: forall (m :: * -> *) a. MonadIO m => Array a -> m (Array a)
pinnedClone = (MutArray a -> Array a) -> m (MutArray a) -> m (Array a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (m (MutArray a) -> m (Array a))
-> (Array a -> m (MutArray a)) -> Array a -> m (Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutArray a -> m (MutArray a)
forall (m :: * -> *) a. MonadIO m => MutArray a -> m (MutArray a)
MA.pinnedClone (MutArray a -> m (MutArray a))
-> (Array a -> MutArray a) -> Array a -> m (MutArray a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# INLINE buildChunks #-}
buildChunks :: (MonadIO m, Unbox a) =>
D.Stream m a -> m (K.StreamK m (Array a))
buildChunks :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m a -> m (StreamK m (Array a))
buildChunks Stream m a
m = (Array a -> StreamK m (Array a) -> StreamK m (Array a))
-> StreamK m (Array a)
-> Stream m (Array a)
-> m (StreamK m (Array a))
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> b) -> b -> Stream m a -> m b
D.foldr Array a -> StreamK m (Array a) -> StreamK m (Array a)
forall a (m :: * -> *). a -> StreamK m a -> StreamK m a
K.cons StreamK m (Array a)
forall (m :: * -> *) a. StreamK m a
K.nil (Stream m (Array a) -> m (StreamK m (Array a)))
-> Stream m (Array a) -> m (StreamK m (Array a))
forall a b. (a -> b) -> a -> b
$ Int -> Stream m a -> Stream m (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> Stream m (Array a)
chunksOf Int
defaultChunkSize Stream m a
m
{-# DEPRECATED bufferChunks "Please use buildChunks instead." #-}
bufferChunks :: (MonadIO m, Unbox a) =>
D.Stream m a -> m (K.StreamK m (Array a))
bufferChunks :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m a -> m (StreamK m (Array a))
bufferChunks = Stream m a -> m (StreamK m (Array a))
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m a -> m (StreamK m (Array a))
buildChunks
{-# INLINE_NORMAL chunksOf #-}
chunksOf :: forall m a. (MonadIO m, Unbox a)
=> Int -> D.Stream m a -> D.Stream m (Array a)
chunksOf :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> Stream m (Array a)
chunksOf Int
n Stream m a
str = (MutArray a -> Array a)
-> Stream m (MutArray a) -> Stream m (Array a)
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
D.map MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Stream m (MutArray a) -> Stream m (Array a))
-> Stream m (MutArray a) -> Stream m (Array a)
forall a b. (a -> b) -> a -> b
$ Int -> Stream m a -> Stream m (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> Stream m (MutArray a)
MA.chunksOf Int
n Stream m a
str
{-# INLINE_NORMAL pinnedChunksOf #-}
pinnedChunksOf :: forall m a. (MonadIO m, Unbox a)
=> Int -> D.Stream m a -> D.Stream m (Array a)
pinnedChunksOf :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> Stream m (Array a)
pinnedChunksOf Int
n Stream m a
str = (MutArray a -> Array a)
-> Stream m (MutArray a) -> Stream m (Array a)
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
D.map MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Stream m (MutArray a) -> Stream m (Array a))
-> Stream m (MutArray a) -> Stream m (Array a)
forall a b. (a -> b) -> a -> b
$ Int -> Stream m a -> Stream m (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> Stream m (MutArray a)
MA.pinnedChunksOf Int
n Stream m a
str
{-# INLINE_NORMAL concat #-}
concat :: (Monad m, Unbox a) => Stream m (Array a) -> Stream m a
concat :: forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Stream m (Array a) -> Stream m a
concat = (forall b. IO b -> m b) -> Stream m (MutArray a) -> Stream m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> Stream m (MutArray a) -> Stream m a
MA.concatWith (b -> m b
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO) (Stream m (MutArray a) -> Stream m a)
-> (Stream m (Array a) -> Stream m (MutArray a))
-> Stream m (Array a)
-> Stream m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Array a -> MutArray a)
-> Stream m (Array a) -> Stream m (MutArray a)
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
D.map Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# DEPRECATED flattenArrays "Please use \"unfoldMany reader\" instead." #-}
{-# INLINE flattenArrays #-}
flattenArrays :: forall m a. (MonadIO m, Unbox a)
=> D.Stream m (Array a) -> D.Stream m a
flattenArrays :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m (Array a) -> Stream m a
flattenArrays = Stream m (Array a) -> Stream m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Stream m (Array a) -> Stream m a
concat
{-# INLINE_NORMAL concatRev #-}
concatRev :: forall m a. (Monad m, Unbox a)
=> D.Stream m (Array a) -> D.Stream m a
concatRev :: forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Stream m (Array a) -> Stream m a
concatRev = (forall b. IO b -> m b) -> Stream m (MutArray a) -> Stream m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> Stream m (MutArray a) -> Stream m a
MA.concatRevWith (b -> m b
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO) (Stream m (MutArray a) -> Stream m a)
-> (Stream m (Array a) -> Stream m (MutArray a))
-> Stream m (Array a)
-> Stream m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Array a -> MutArray a)
-> Stream m (Array a) -> Stream m (MutArray a)
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
D.map Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# DEPRECATED flattenArraysRev "Please use \"unfoldMany readerRev\" instead." #-}
{-# INLINE flattenArraysRev #-}
flattenArraysRev :: forall m a. (MonadIO m, Unbox a)
=> D.Stream m (Array a) -> D.Stream m a
flattenArraysRev :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m (Array a) -> Stream m a
flattenArraysRev = Stream m (Array a) -> Stream m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Stream m (Array a) -> Stream m a
concatRev
{-# INLINE_NORMAL fCompactGE #-}
fCompactGE :: (MonadIO m, Unbox a) => Int -> Fold m (Array a) (Array a)
fCompactGE :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (Array a) (Array a)
fCompactGE Int
n = (MutArray a -> Array a)
-> Fold m (Array a) (MutArray a) -> Fold m (Array a) (Array a)
forall a b. (a -> b) -> Fold m (Array a) a -> Fold m (Array a) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Fold m (Array a) (MutArray a) -> Fold m (Array a) (Array a))
-> Fold m (Array a) (MutArray a) -> Fold m (Array a) (Array a)
forall a b. (a -> b) -> a -> b
$ (Array a -> MutArray a)
-> Fold m (MutArray a) (MutArray a)
-> Fold m (Array a) (MutArray a)
forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
Fold.lmap Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw (Fold m (MutArray a) (MutArray a) -> Fold m (Array a) (MutArray a))
-> Fold m (MutArray a) (MutArray a)
-> Fold m (Array a) (MutArray a)
forall a b. (a -> b) -> a -> b
$ Int -> Fold m (MutArray a) (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (MutArray a) (MutArray a)
MA.fCompactGE Int
n
{-# INLINE_NORMAL fPinnedCompactGE #-}
fPinnedCompactGE :: (MonadIO m, Unbox a) => Int -> Fold m (Array a) (Array a)
fPinnedCompactGE :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (Array a) (Array a)
fPinnedCompactGE Int
n =
(MutArray a -> Array a)
-> Fold m (Array a) (MutArray a) -> Fold m (Array a) (Array a)
forall a b. (a -> b) -> Fold m (Array a) a -> Fold m (Array a) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Fold m (Array a) (MutArray a) -> Fold m (Array a) (Array a))
-> Fold m (Array a) (MutArray a) -> Fold m (Array a) (Array a)
forall a b. (a -> b) -> a -> b
$ (Array a -> MutArray a)
-> Fold m (MutArray a) (MutArray a)
-> Fold m (Array a) (MutArray a)
forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
Fold.lmap Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw (Fold m (MutArray a) (MutArray a) -> Fold m (Array a) (MutArray a))
-> Fold m (MutArray a) (MutArray a)
-> Fold m (Array a) (MutArray a)
forall a b. (a -> b) -> a -> b
$ Int -> Fold m (MutArray a) (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (MutArray a) (MutArray a)
MA.fPinnedCompactGE Int
n
{-# INLINE compactGE #-}
compactGE ::
(MonadIO m, Unbox a)
=> Int -> Stream m (Array a) -> Stream m (Array a)
compactGE :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m (Array a) -> Stream m (Array a)
compactGE Int
n Stream m (Array a)
stream =
(MutArray a -> Array a)
-> Stream m (MutArray a) -> Stream m (Array a)
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
D.map MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Stream m (MutArray a) -> Stream m (Array a))
-> Stream m (MutArray a) -> Stream m (Array a)
forall a b. (a -> b) -> a -> b
$ Int -> Stream m (MutArray a) -> Stream m (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m (MutArray a) -> Stream m (MutArray a)
MA.compactGE Int
n (Stream m (MutArray a) -> Stream m (MutArray a))
-> Stream m (MutArray a) -> Stream m (MutArray a)
forall a b. (a -> b) -> a -> b
$ (Array a -> MutArray a)
-> Stream m (Array a) -> Stream m (MutArray a)
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
D.map Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Stream m (Array a)
stream
{-# INLINE_NORMAL lCompactGE #-}
lCompactGE :: (MonadIO m, Unbox a)
=> Int -> Fold m (Array a) () -> Fold m (Array a) ()
lCompactGE :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (Array a) () -> Fold m (Array a) ()
lCompactGE Int
n Fold m (Array a) ()
fld =
(Array a -> MutArray a)
-> Fold m (MutArray a) () -> Fold m (Array a) ()
forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
Fold.lmap Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw (Fold m (MutArray a) () -> Fold m (Array a) ())
-> Fold m (MutArray a) () -> Fold m (Array a) ()
forall a b. (a -> b) -> a -> b
$ Int -> Fold m (MutArray a) () -> Fold m (MutArray a) ()
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (MutArray a) () -> Fold m (MutArray a) ()
MA.lCompactGE Int
n ((MutArray a -> Array a)
-> Fold m (Array a) () -> Fold m (MutArray a) ()
forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
Fold.lmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze Fold m (Array a) ()
fld)
{-# INLINE_NORMAL lPinnedCompactGE #-}
lPinnedCompactGE :: (MonadIO m, Unbox a)
=> Int -> Fold m (Array a) () -> Fold m (Array a) ()
lPinnedCompactGE :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (Array a) () -> Fold m (Array a) ()
lPinnedCompactGE Int
n Fold m (Array a) ()
fld =
(Array a -> MutArray a)
-> Fold m (MutArray a) () -> Fold m (Array a) ()
forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
Fold.lmap Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw (Fold m (MutArray a) () -> Fold m (Array a) ())
-> Fold m (MutArray a) () -> Fold m (Array a) ()
forall a b. (a -> b) -> a -> b
$ Int -> Fold m (MutArray a) () -> Fold m (MutArray a) ()
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m (MutArray a) () -> Fold m (MutArray a) ()
MA.lPinnedCompactGE Int
n ((MutArray a -> Array a)
-> Fold m (Array a) () -> Fold m (MutArray a) ()
forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
Fold.lmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze Fold m (Array a) ()
fld)
{-# INLINE breakOn #-}
breakOn :: MonadIO m
=> Word8 -> Array Word8 -> m (Array Word8, Maybe (Array Word8))
breakOn :: forall (m :: * -> *).
MonadIO m =>
Word8 -> Array Word8 -> m (Array Word8, Maybe (Array Word8))
breakOn Word8
sep Array Word8
arr = do
(MutArray Word8
a, Maybe (MutArray Word8)
b) <- Word8
-> MutArray Word8 -> m (MutArray Word8, Maybe (MutArray Word8))
forall (m :: * -> *).
MonadIO m =>
Word8
-> MutArray Word8 -> m (MutArray Word8, Maybe (MutArray Word8))
MA.breakOn Word8
sep (Array Word8 -> MutArray Word8
forall a. Array a -> MutArray a
unsafeThaw Array Word8
arr)
(Array Word8, Maybe (Array Word8))
-> m (Array Word8, Maybe (Array Word8))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (MutArray Word8 -> Array Word8
forall a. MutArray a -> Array a
unsafeFreeze MutArray Word8
a, MutArray Word8 -> Array Word8
forall a. MutArray a -> Array a
unsafeFreeze (MutArray Word8 -> Array Word8)
-> Maybe (MutArray Word8) -> Maybe (Array Word8)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (MutArray Word8)
b)
{-# INLINE_NORMAL unsafeIndexIO #-}
unsafeIndexIO :: forall a. Unbox a => Int -> Array a -> IO a
unsafeIndexIO :: forall a. Unbox a => Int -> Array a -> IO a
unsafeIndexIO Int
i Array a
arr = Int -> MutArray a -> IO a
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> MutArray a -> m a
MA.getIndexUnsafe Int
i (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# INLINE_NORMAL getIndexUnsafe #-}
getIndexUnsafe :: forall a. Unbox a => Int -> Array a -> a
getIndexUnsafe :: forall a. Unbox a => Int -> Array a -> a
getIndexUnsafe Int
i Array a
arr = let !r :: a
r = IO a -> a
forall a. IO a -> a
unsafeInlineIO (IO a -> a) -> IO a -> a
forall a b. (a -> b) -> a -> b
$ Int -> Array a -> IO a
forall a. Unbox a => Int -> Array a -> IO a
unsafeIndexIO Int
i Array a
arr in a
r
{-# DEPRECATED unsafeIndex "Please use 'getIndexUnsafe' instead" #-}
{-# INLINE_NORMAL unsafeIndex #-}
unsafeIndex :: forall a. Unbox a => Int -> Array a -> a
unsafeIndex :: forall a. Unbox a => Int -> Array a -> a
unsafeIndex = Int -> Array a -> a
forall a. Unbox a => Int -> Array a -> a
getIndexUnsafe
{-# INLINE byteLength #-}
byteLength :: Array a -> Int
byteLength :: forall a. Array a -> Int
byteLength = MutArray a -> Int
forall a. MutArray a -> Int
MA.byteLength (MutArray a -> Int) -> (Array a -> MutArray a) -> Array a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw
{-# INLINE length #-}
length :: Unbox a => Array a -> Int
length :: forall a. Unbox a => Array a -> Int
length Array a
arr = MutArray a -> Int
forall a. Unbox a => MutArray a -> Int
MA.length (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# INLINE_NORMAL producer #-}
producer :: forall m a. (Monad m, Unbox a) => Producer m (Array a) a
producer :: forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Producer m (Array a) a
producer =
(Array a -> MutArray a)
-> (MutArray a -> Array a)
-> Producer m (MutArray a) a
-> Producer m (Array a) a
forall (m :: * -> *) a c b.
Functor m =>
(a -> c) -> (c -> a) -> Producer m c b -> Producer m a b
Producer.translate Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze
(Producer m (MutArray a) a -> Producer m (Array a) a)
-> Producer m (MutArray a) a -> Producer m (Array a) a
forall a b. (a -> b) -> a -> b
$ (forall b. IO b -> m b) -> Producer m (MutArray a) a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> Producer m (MutArray a) a
MA.producerWith (b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO)
{-# INLINE_NORMAL reader #-}
reader :: forall m a. (Monad m, Unbox a) => Unfold m (Array a) a
reader :: forall (m :: * -> *) a. (Monad m, Unbox a) => Unfold m (Array a) a
reader = Producer m (Array a) a -> Unfold m (Array a) a
forall (m :: * -> *) a b. Producer m a b -> Unfold m a b
Producer.simplify Producer m (Array a) a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Producer m (Array a) a
producer
{-# INLINE_NORMAL readerUnsafe #-}
readerUnsafe :: forall m a. (Monad m, Unbox a) => Unfold m (Array a) a
readerUnsafe :: forall (m :: * -> *) a. (Monad m, Unbox a) => Unfold m (Array a) a
readerUnsafe = (ArrayUnsafe Any -> m (Step (ArrayUnsafe Any) a))
-> (Array a -> m (ArrayUnsafe Any)) -> Unfold m (Array a) a
forall (m :: * -> *) a b s.
(s -> m (Step s b)) -> (a -> m s) -> Unfold m a b
Unfold ArrayUnsafe Any -> m (Step (ArrayUnsafe Any) a)
forall {m :: * -> *} {a} {a} {a}.
(Monad m, Unbox a) =>
ArrayUnsafe a -> m (Step (ArrayUnsafe a) a)
step Array a -> m (ArrayUnsafe Any)
forall {m :: * -> *} {a} {a}.
Monad m =>
Array a -> m (ArrayUnsafe a)
inject
where
inject :: Array a -> m (ArrayUnsafe a)
inject (Array MutByteArray
contents Int
start Int
end) =
ArrayUnsafe a -> m (ArrayUnsafe a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (MutByteArray -> Int -> Int -> ArrayUnsafe a
forall a. MutByteArray -> Int -> Int -> ArrayUnsafe a
MA.ArrayUnsafe MutByteArray
contents Int
end Int
start)
{-# INLINE_LATE step #-}
step :: ArrayUnsafe a -> m (Step (ArrayUnsafe a) a)
step (MA.ArrayUnsafe MutByteArray
contents Int
end Int
p) = do
let !x :: a
x = IO a -> a
forall a. IO a -> a
unsafeInlineIO (IO a -> a) -> IO a -> a
forall a b. (a -> b) -> a -> b
$ Int -> MutByteArray -> IO a
forall a. Unbox a => Int -> MutByteArray -> IO a
peekAt Int
p MutByteArray
contents
let !p1 :: Int
p1 = INDEX_NEXT(p,a)
Step (ArrayUnsafe a) a -> m (Step (ArrayUnsafe a) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ArrayUnsafe a) a -> m (Step (ArrayUnsafe a) a))
-> Step (ArrayUnsafe a) a -> m (Step (ArrayUnsafe a) a)
forall a b. (a -> b) -> a -> b
$ a -> ArrayUnsafe a -> Step (ArrayUnsafe a) a
forall s a. a -> s -> Step s a
D.Yield a
x (MutByteArray -> Int -> Int -> ArrayUnsafe a
forall a. MutByteArray -> Int -> Int -> ArrayUnsafe a
MA.ArrayUnsafe MutByteArray
contents Int
end Int
p1)
{-# INLINE_NORMAL readerRev #-}
readerRev :: forall m a. (Monad m, Unbox a) => Unfold m (Array a) a
readerRev :: forall (m :: * -> *) a. (Monad m, Unbox a) => Unfold m (Array a) a
readerRev = (Array a -> MutArray a)
-> Unfold m (MutArray a) a -> Unfold m (Array a) a
forall a c (m :: * -> *) b.
(a -> c) -> Unfold m c b -> Unfold m a b
Unfold.lmap Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw (Unfold m (MutArray a) a -> Unfold m (Array a) a)
-> Unfold m (MutArray a) a -> Unfold m (Array a) a
forall a b. (a -> b) -> a -> b
$ (forall b. IO b -> m b) -> Unfold m (MutArray a) a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> Unfold m (MutArray a) a
MA.readerRevWith (b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO)
{-# DEPRECATED toStreamD "Please use 'read' instead." #-}
{-# INLINE_NORMAL toStreamD #-}
toStreamD :: forall m a. (Monad m, Unbox a) => Array a -> D.Stream m a
toStreamD :: forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamD = Array a -> Stream m a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
read
{-# INLINE toStreamK #-}
toStreamK :: forall m a. (Monad m, Unbox a) => Array a -> K.StreamK m a
toStreamK :: forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Array a -> StreamK m a
toStreamK Array a
arr = (forall b. IO b -> m b) -> MutArray a -> StreamK m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> MutArray a -> StreamK m a
MA.toStreamKWith (b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO) (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# DEPRECATED toStreamDRev "Please use 'readRev' instead." #-}
{-# INLINE_NORMAL toStreamDRev #-}
toStreamDRev :: forall m a. (Monad m, Unbox a) => Array a -> D.Stream m a
toStreamDRev :: forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamDRev = Array a -> Stream m a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
readRev
{-# INLINE toStreamKRev #-}
toStreamKRev :: forall m a. (Monad m, Unbox a) => Array a -> K.StreamK m a
toStreamKRev :: forall (m :: * -> *) a.
(Monad m, Unbox a) =>
Array a -> StreamK m a
toStreamKRev Array a
arr =
(forall b. IO b -> m b) -> MutArray a -> StreamK m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> MutArray a -> StreamK m a
MA.toStreamKRevWith (b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO) (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# INLINE_EARLY read #-}
read :: (Monad m, Unbox a) => Array a -> Stream m a
read :: forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
read Array a
arr = (forall b. IO b -> m b) -> MutArray a -> Stream m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> MutArray a -> Stream m a
MA.toStreamWith (b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO) (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# DEPRECATED toStream "Please use 'read' instead." #-}
{-# INLINE_EARLY toStream #-}
toStream :: (Monad m, Unbox a) => Array a -> Stream m a
toStream :: forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStream = Array a -> Stream m a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
read
{-# INLINE_EARLY readRev #-}
readRev :: (Monad m, Unbox a) => Array a -> Stream m a
readRev :: forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
readRev Array a
arr = (forall b. IO b -> m b) -> MutArray a -> Stream m a
forall (m :: * -> *) a.
(Monad m, Unbox a) =>
(forall b. IO b -> m b) -> MutArray a -> Stream m a
MA.toStreamRevWith (b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (IO b -> b) -> IO b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> b
forall a. IO a -> a
unsafeInlineIO) (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# DEPRECATED toStreamRev "Please use 'readRev' instead." #-}
{-# INLINE_EARLY toStreamRev #-}
toStreamRev :: (Monad m, Unbox a) => Array a -> Stream m a
toStreamRev :: forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamRev = Array a -> Stream m a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
readRev
{-# INLINE_NORMAL foldl' #-}
foldl' :: forall a b. Unbox a => (b -> a -> b) -> b -> Array a -> b
foldl' :: forall a b. Unbox a => (b -> a -> b) -> b -> Array a -> b
foldl' b -> a -> b
f b
z Array a
arr = Identity b -> b
forall a. Identity a -> a
runIdentity (Identity b -> b) -> Identity b -> b
forall a b. (a -> b) -> a -> b
$ (b -> a -> b) -> b -> Stream Identity a -> Identity b
forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Stream m a -> m b
D.foldl' b -> a -> b
f b
z (Stream Identity a -> Identity b)
-> Stream Identity a -> Identity b
forall a b. (a -> b) -> a -> b
$ Array a -> Stream Identity a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamD Array a
arr
{-# INLINE_NORMAL foldr #-}
foldr :: Unbox a => (a -> b -> b) -> b -> Array a -> b
foldr :: forall a b. Unbox a => (a -> b -> b) -> b -> Array a -> b
foldr a -> b -> b
f b
z Array a
arr = Identity b -> b
forall a. Identity a -> a
runIdentity (Identity b -> b) -> Identity b -> b
forall a b. (a -> b) -> a -> b
$ (a -> b -> b) -> b -> Stream Identity a -> Identity b
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> b) -> b -> Stream m a -> m b
D.foldr a -> b -> b
f b
z (Stream Identity a -> Identity b)
-> Stream Identity a -> Identity b
forall a b. (a -> b) -> a -> b
$ Array a -> Stream Identity a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamD Array a
arr
{-# INLINE splitAt #-}
splitAt :: Unbox a => Int -> Array a -> (Array a, Array a)
splitAt :: forall a. Unbox a => Int -> Array a -> (Array a, Array a)
splitAt Int
i Array a
arr = (MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze MutArray a
a, MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze MutArray a
b)
where
(MutArray a
a, MutArray a
b) = Int -> MutArray a -> (MutArray a, MutArray a)
forall a. Unbox a => Int -> MutArray a -> (MutArray a, MutArray a)
MA.splitAt Int
i (Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr)
{-# INLINE_LATE toListFB #-}
toListFB :: forall a b. Unbox a => (a -> b -> b) -> b -> Array a -> b
toListFB :: forall a b. Unbox a => (a -> b -> b) -> b -> Array a -> b
toListFB a -> b -> b
c b
n Array{Int
MutByteArray
arrContents :: forall a. Array a -> MutByteArray
arrStart :: forall a. Array a -> Int
arrEnd :: forall a. Array a -> Int
arrContents :: MutByteArray
arrStart :: Int
arrEnd :: Int
..} = Int -> b
go Int
arrStart
where
go :: Int -> b
go Int
p | Bool -> Bool -> Bool
forall a. HasCallStack => Bool -> a -> a
assert (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
arrEnd) (Int
p Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
arrEnd) = b
n
go Int
p =
let !x :: a
x = IO a -> a
forall a. IO a -> a
unsafeInlineIO (IO a -> a) -> IO a -> a
forall a b. (a -> b) -> a -> b
$ Int -> MutByteArray -> IO a
forall a. Unbox a => Int -> MutByteArray -> IO a
peekAt Int
p MutByteArray
arrContents
in a -> b -> b
c a
x (Int -> b
go (INDEX_NEXT(p,a)))
{-# INLINE toList #-}
toList :: Unbox a => Array a -> [a]
toList :: forall a. Unbox a => Array a -> [a]
toList Array a
s = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\a -> b -> b
c b
n -> (a -> b -> b) -> b -> Array a -> b
forall a b. Unbox a => (a -> b -> b) -> b -> Array a -> b
toListFB a -> b -> b
c b
n Array a
s)
{-# INLINE_NORMAL createOf #-}
createOf :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
createOf :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
createOf = (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall a b. (a -> b) -> Fold m a a -> Fold m a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Fold m a (MutArray a) -> Fold m a (Array a))
-> (Int -> Fold m a (MutArray a)) -> Int -> Fold m a (Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (MutArray a)
MA.createOf
{-# INLINE writeN #-}
writeN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
writeN :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
writeN = Int -> Fold m a (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
createOf
{-# INLINE_NORMAL pinnedCreateOf #-}
pinnedCreateOf :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
pinnedCreateOf :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
pinnedCreateOf = (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall a b. (a -> b) -> Fold m a a -> Fold m a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Fold m a (MutArray a) -> Fold m a (Array a))
-> (Int -> Fold m a (MutArray a)) -> Int -> Fold m a (Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (MutArray a)
MA.pinnedCreateOf
{-# DEPRECATED pinnedWriteN "Please use pinnedCreateOf instead." #-}
{-# INLINE pinnedWriteN #-}
pinnedWriteN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
pinnedWriteN :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
pinnedWriteN = Int -> Fold m a (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
pinnedCreateOf
{-# INLINE_NORMAL pinnedWriteNAligned #-}
{-# DEPRECATED pinnedWriteNAligned "To be removed." #-}
pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
=> Int -> Int -> Fold m a (Array a)
pinnedWriteNAligned :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Int -> Fold m a (Array a)
pinnedWriteNAligned Int
alignSize = (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall a b. (a -> b) -> Fold m a a -> Fold m a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Fold m a (MutArray a) -> Fold m a (Array a))
-> (Int -> Fold m a (MutArray a)) -> Int -> Fold m a (Array a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Int -> Fold m a (MutArray a)
MA.pinnedWriteNAligned Int
alignSize
{-# INLINE_NORMAL unsafeCreateOf #-}
unsafeCreateOf :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
unsafeCreateOf :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
unsafeCreateOf Int
n = MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (MutArray a)
MA.unsafeCreateOf Int
n
{-# DEPRECATED writeNUnsafe "Please use unsafeCreateOf instead." #-}
{-# INLINE writeNUnsafe #-}
writeNUnsafe :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
writeNUnsafe :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
writeNUnsafe = Int -> Fold m a (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
unsafeCreateOf
{-# INLINE_NORMAL unsafePinnedCreateOf #-}
unsafePinnedCreateOf :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
unsafePinnedCreateOf :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
unsafePinnedCreateOf Int
n = MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (MutArray a)
MA.unsafePinnedCreateOf Int
n
{-# DEPRECATED pinnedWriteNUnsafe "Please use unsafePinnedCreateOf instead." #-}
{-# INLINE pinnedWriteNUnsafe #-}
pinnedWriteNUnsafe :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
pinnedWriteNUnsafe :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
pinnedWriteNUnsafe = Int -> Fold m a (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
unsafePinnedCreateOf
{-# INLINE_NORMAL createWith #-}
createWith :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
createWith :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
createWith Int
elemCount = MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (MutArray a)
MA.createWith Int
elemCount
{-# DEPRECATED writeWith "Please use createWith instead." #-}
{-# INLINE writeWith #-}
writeWith :: forall m a. (MonadIO m, Unbox a)
=> Int -> Fold m a (Array a)
writeWith :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
writeWith = Int -> Fold m a (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Fold m a (Array a)
createWith
{-# INLINE create #-}
create :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
create :: forall (m :: * -> *) a. (MonadIO m, Unbox a) => Fold m a (Array a)
create = (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall a b. (a -> b) -> Fold m a a -> Fold m a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Fold m a (MutArray a)
MA.create
{-# INLINE write #-}
write :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
write :: forall (m :: * -> *) a. (MonadIO m, Unbox a) => Fold m a (Array a)
write = Fold m a (Array a)
forall (m :: * -> *) a. (MonadIO m, Unbox a) => Fold m a (Array a)
create
{-# INLINE pinnedCreate #-}
pinnedCreate :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
pinnedCreate :: forall (m :: * -> *) a. (MonadIO m, Unbox a) => Fold m a (Array a)
pinnedCreate = (MutArray a -> Array a)
-> Fold m a (MutArray a) -> Fold m a (Array a)
forall a b. (a -> b) -> Fold m a a -> Fold m a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze Fold m a (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Fold m a (MutArray a)
MA.pinnedCreate
{-# DEPRECATED pinnedWrite "Please use pinnedCreate instead." #-}
{-# INLINE pinnedWrite #-}
pinnedWrite :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
pinnedWrite :: forall (m :: * -> *) a. (MonadIO m, Unbox a) => Fold m a (Array a)
pinnedWrite = Fold m a (Array a)
forall (m :: * -> *) a. (MonadIO m, Unbox a) => Fold m a (Array a)
pinnedCreate
{-# INLINE unsafeMakePure #-}
unsafeMakePure :: Monad m => Fold IO a b -> Fold m a b
unsafeMakePure :: forall (m :: * -> *) a b. Monad m => Fold IO a b -> Fold m a b
unsafeMakePure (Fold s -> a -> IO (Step s b)
step IO (Step s b)
initial s -> IO b
extract s -> IO b
final) =
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> (s -> m b) -> Fold m a b
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> (s -> m b) -> Fold m a b
Fold (\s
x a
a -> Step s b -> m (Step s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$! IO (Step s b) -> Step s b
forall a. IO a -> a
unsafeInlineIO (s -> a -> IO (Step s b)
step s
x a
a))
(Step s b -> m (Step s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$! IO (Step s b) -> Step s b
forall a. IO a -> a
unsafePerformIO IO (Step s b)
initial)
(\s
s -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$! IO b -> b
forall a. IO a -> a
unsafeInlineIO (IO b -> b) -> IO b -> b
forall a b. (a -> b) -> a -> b
$ s -> IO b
extract s
s)
(\s
s -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$! IO b -> b
forall a. IO a -> a
unsafeInlineIO (IO b -> b) -> IO b -> b
forall a b. (a -> b) -> a -> b
$ s -> IO b
final s
s)
{-# INLINE fromPureStreamN #-}
fromPureStreamN :: Unbox a => Int -> Stream Identity a -> Array a
fromPureStreamN :: forall a. Unbox a => Int -> Stream Identity a -> Array a
fromPureStreamN Int
n Stream Identity a
x =
IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (Int -> Stream Identity a -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream Identity a -> m (MutArray a)
MA.fromPureStreamN Int
n Stream Identity a
x)
fromPureStream :: Unbox a => Stream Identity a -> Array a
fromPureStream :: forall a. Unbox a => Stream Identity a -> Array a
fromPureStream Stream Identity a
x = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ (MutArray a -> Array a) -> IO (MutArray a) -> IO (Array a)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze) (Stream Identity a -> IO (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream Identity a -> m (MutArray a)
MA.fromPureStream Stream Identity a
x)
fromPtrN :: Int -> Ptr Word8 -> Array Word8
fromPtrN :: Int -> Ptr Word8 -> Array Word8
fromPtrN Int
n Ptr Word8
addr = IO (Array Word8) -> Array Word8
forall a. IO a -> a
unsafePerformIO (IO (Array Word8) -> Array Word8)
-> IO (Array Word8) -> Array Word8
forall a b. (a -> b) -> a -> b
$ (MutArray Word8 -> Array Word8)
-> IO (MutArray Word8) -> IO (Array Word8)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray Word8 -> Array Word8
forall a. MutArray a -> Array a
unsafeFreeze (Int -> Ptr Word8 -> IO (MutArray Word8)
forall (m :: * -> *).
MonadIO m =>
Int -> Ptr Word8 -> m (MutArray Word8)
MA.fromPtrN Int
n Ptr Word8
addr)
fromByteStr# :: Addr# -> Array Word8
fromByteStr# :: Addr# -> Array Word8
fromByteStr# Addr#
addr = IO (Array Word8) -> Array Word8
forall a. IO a -> a
unsafePerformIO (IO (Array Word8) -> Array Word8)
-> IO (Array Word8) -> Array Word8
forall a b. (a -> b) -> a -> b
$ (MutArray Word8 -> Array Word8)
-> IO (MutArray Word8) -> IO (Array Word8)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray Word8 -> Array Word8
forall a. MutArray a -> Array a
unsafeFreeze (Addr# -> IO (MutArray Word8)
forall (m :: * -> *). MonadIO m => Addr# -> m (MutArray Word8)
MA.fromByteStr# Addr#
addr)
fromByteStr :: Ptr Word8 -> Array Word8
fromByteStr :: Ptr Word8 -> Array Word8
fromByteStr (Ptr Addr#
addr#) = Addr# -> Array Word8
fromByteStr# Addr#
addr#
{-# INLINE fromChunksK #-}
fromChunksK :: (MonadIO m, Unbox a) => StreamK m (Array a) -> m (Array a)
fromChunksK :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
StreamK m (Array a) -> m (Array a)
fromChunksK StreamK m (Array a)
stream =
(MutArray a -> Array a) -> m (MutArray a) -> m (Array a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (m (MutArray a) -> m (Array a)) -> m (MutArray a) -> m (Array a)
forall a b. (a -> b) -> a -> b
$ StreamK m (MutArray a) -> m (MutArray a)
forall a (m :: * -> *).
(Unbox a, MonadIO m) =>
StreamK m (MutArray a) -> m (MutArray a)
MA.fromChunksK (StreamK m (MutArray a) -> m (MutArray a))
-> StreamK m (MutArray a) -> m (MutArray a)
forall a b. (a -> b) -> a -> b
$ (Array a -> MutArray a)
-> StreamK m (Array a) -> StreamK m (MutArray a)
forall a b. (a -> b) -> StreamK m a -> StreamK m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw StreamK m (Array a)
stream
{-# DEPRECATED fromArrayStreamK "Please use fromChunksK instead." #-}
fromArrayStreamK :: (Unbox a, MonadIO m) => StreamK m (Array a) -> m (Array a)
fromArrayStreamK :: forall a (m :: * -> *).
(Unbox a, MonadIO m) =>
StreamK m (Array a) -> m (Array a)
fromArrayStreamK = StreamK m (Array a) -> m (Array a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
StreamK m (Array a) -> m (Array a)
fromChunksK
{-# INLINE fromChunks #-}
fromChunks :: (MonadIO m, Unbox a) => Stream m (Array a) -> m (Array a)
fromChunks :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m (Array a) -> m (Array a)
fromChunks Stream m (Array a)
s =
(MutArray a -> Array a) -> m (MutArray a) -> m (Array a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutArray a -> Array a
forall a. MutArray a -> Array a
unsafeFreeze (m (MutArray a) -> m (Array a)) -> m (MutArray a) -> m (Array a)
forall a b. (a -> b) -> a -> b
$ Stream m (MutArray a) -> m (MutArray a)
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m (MutArray a) -> m (MutArray a)
MA.fromChunksRealloced ((Array a -> MutArray a)
-> Stream m (Array a) -> Stream m (MutArray a)
forall a b. (a -> b) -> Stream m a -> Stream m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Stream m (Array a)
s)
instance (Show a, Unbox a) => Show (Array a) where
{-# INLINE show #-}
show :: Array a -> [Char]
show Array a
arr = [Char]
"fromList " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [a] -> [Char]
forall a. Show a => a -> [Char]
show (Array a -> [a]
forall a. Unbox a => Array a -> [a]
toList Array a
arr)
instance (Unbox a, Read a, Show a) => Read (Array a) where
{-# INLINE readPrec #-}
readPrec :: ReadPrec (Array a)
readPrec = do
[Char]
fromListWord <- Int -> ReadPrec Char -> ReadPrec [Char]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
9 ReadPrec Char
ReadPrec.get
if [Char]
fromListWord [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"fromList "
then [a] -> Array a
forall a. Unbox a => [a] -> Array a
fromList ([a] -> Array a) -> ReadPrec [a] -> ReadPrec (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadPrec [a]
forall a. Read a => ReadPrec a
readPrec
else ReadPrec (Array a)
forall a. ReadPrec a
ReadPrec.pfail
instance (a ~ Char) => IsString (Array a) where
{-# INLINE fromString #-}
fromString :: [Char] -> Array a
fromString = [Char] -> Array a
[Char] -> Array Char
forall a. Unbox a => [a] -> Array a
fromList
instance Unbox a => IsList (Array a) where
type (Item (Array a)) = a
{-# INLINE fromList #-}
fromList :: [Item (Array a)] -> Array a
fromList = [a] -> Array a
[Item (Array a)] -> Array a
forall a. Unbox a => [a] -> Array a
fromList
{-# INLINE fromListN #-}
fromListN :: Int -> [Item (Array a)] -> Array a
fromListN = Int -> [a] -> Array a
Int -> [Item (Array a)] -> Array a
forall a. Unbox a => Int -> [a] -> Array a
fromListN
{-# INLINE toList #-}
toList :: Array a -> [Item (Array a)]
toList = Array a -> [a]
Array a -> [Item (Array a)]
forall a. Unbox a => Array a -> [a]
toList
{-# INLINE byteCmp #-}
byteCmp :: Array a -> Array a -> Ordering
byteCmp :: forall a. Array a -> Array a -> Ordering
byteCmp Array a
arr1 Array a
arr2 =
IO Ordering -> Ordering
forall a. IO a -> a
unsafeInlineIO (IO Ordering -> Ordering) -> IO Ordering -> Ordering
forall a b. (a -> b) -> a -> b
$! Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr1 MutArray a -> MutArray a -> IO Ordering
forall (m :: * -> *) a.
MonadIO m =>
MutArray a -> MutArray a -> m Ordering
`MA.byteCmp` Array a -> MutArray a
forall a. Array a -> MutArray a
unsafeThaw Array a
arr2
{-# INLINE byteEq #-}
byteEq :: Array a -> Array a -> Bool
byteEq :: forall a. Array a -> Array a -> Bool
byteEq Array a
arr1 Array a
arr2 = Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
(==) Ordering
EQ (Ordering -> Bool) -> Ordering -> Bool
forall a b. (a -> b) -> a -> b
$ Array a -> Array a -> Ordering
forall a. Array a -> Array a -> Ordering
byteCmp Array a
arr1 Array a
arr2
#define MK_EQ_INSTANCE(typ) \
instance {-# OVERLAPPING #-} Eq (Array typ) where { \
; {-# INLINE (==) #-} \
; (==) = byteEq \
}
MK_EQ_INSTANCE(Char)
MK_EQ_INSTANCE(Word8)
MK_EQ_INSTANCE(Word16)
MK_EQ_INSTANCE(Word32)
MK_EQ_INSTANCE(Word64)
MK_EQ_INSTANCE(Int)
MK_EQ_INSTANCE(Int8)
MK_EQ_INSTANCE(Int16)
MK_EQ_INSTANCE(Int32)
MK_EQ_INSTANCE(Int64)
instance {-# OVERLAPPABLE #-} (Unbox a, Eq a) => Eq (Array a) where
{-# INLINE (==) #-}
Array a
arr1 == :: Array a -> Array a -> Bool
== Array a
arr2 =
(Array a -> Stream Identity a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamD Array a
arr1 :: Stream Identity a) Stream Identity a -> Stream Identity a -> Bool
forall a. Eq a => a -> a -> Bool
== Array a -> Stream Identity a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamD Array a
arr2
instance (Unbox a, Ord a) => Ord (Array a) where
{-# INLINE compare #-}
compare :: Array a -> Array a -> Ordering
compare Array a
arr1 Array a
arr2 = Identity Ordering -> Ordering
forall a. Identity a -> a
runIdentity (Identity Ordering -> Ordering) -> Identity Ordering -> Ordering
forall a b. (a -> b) -> a -> b
$
(a -> a -> Ordering)
-> Stream Identity a -> Stream Identity a -> Identity Ordering
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> Ordering) -> Stream m a -> Stream m b -> m Ordering
D.cmpBy a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Array a -> Stream Identity a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamD Array a
arr1) (Array a -> Stream Identity a
forall (m :: * -> *) a. (Monad m, Unbox a) => Array a -> Stream m a
toStreamD Array a
arr2)
{-# INLINE (<) #-}
Array a
x < :: Array a -> Array a -> Bool
< Array a
y = case Array a -> Array a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Array a
x Array a
y of { Ordering
LT -> Bool
True; Ordering
_ -> Bool
False }
{-# INLINE (<=) #-}
Array a
x <= :: Array a -> Array a -> Bool
<= Array a
y = case Array a -> Array a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Array a
x Array a
y of { Ordering
GT -> Bool
False; Ordering
_ -> Bool
True }
{-# INLINE (>) #-}
Array a
x > :: Array a -> Array a -> Bool
> Array a
y = case Array a -> Array a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Array a
x Array a
y of { Ordering
GT -> Bool
True; Ordering
_ -> Bool
False }
{-# INLINE (>=) #-}
Array a
x >= :: Array a -> Array a -> Bool
>= Array a
y = case Array a -> Array a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Array a
x Array a
y of { Ordering
LT -> Bool
False; Ordering
_ -> Bool
True }
{-# INLINE max #-}
max :: Array a -> Array a -> Array a
max Array a
x Array a
y = if Array a
x Array a -> Array a -> Bool
forall a. Ord a => a -> a -> Bool
<= Array a
y then Array a
y else Array a
x
{-# INLINE min #-}
min :: Array a -> Array a -> Array a
min Array a
x Array a
y = if Array a
x Array a -> Array a -> Bool
forall a. Ord a => a -> a -> Bool
<= Array a
y then Array a
x else Array a
y
#ifdef DEVBUILD
{-# INLINE_NORMAL _toStreamD_ #-}
_toStreamD_ :: forall m a. MonadIO m => Int -> Array a -> D.Stream m a
_toStreamD_ size Array{..} = D.Stream step arrStart
where
{-# INLINE_LATE step #-}
step _ p | p == arrEnd = return D.Stop
step _ p = liftIO $ do
x <- peekAt p arrContents
return $ D.Yield x (p + size)
#endif
instance Unbox a => Semigroup (Array a) where
Array a
arr1 <> :: Array a -> Array a -> Array a
<> Array a
arr2 = IO (Array a) -> Array a
forall a. IO a -> a
unsafePerformIO (IO (Array a) -> Array a) -> IO (Array a) -> Array a
forall a b. (a -> b) -> a -> b
$ Array a -> Array a -> IO (Array a)
forall (m :: * -> *) a.
MonadIO m =>
Array a -> Array a -> m (Array a)
splice Array a
arr1 Array a
arr2
empty ::
#ifdef DEVBUILD
Unbox a =>
#endif
Array a
empty :: forall a. Array a
empty = MutByteArray -> Int -> Int -> Array a
forall a. MutByteArray -> Int -> Int -> Array a
Array MutByteArray
Unboxed.empty Int
0 Int
0
{-# DEPRECATED nil "Please use empty instead." #-}
nil ::
#ifdef DEVBUILD
Unbox a =>
#endif
Array a
nil :: forall a. Array a
nil = Array a
forall a. Array a
empty
instance Unbox a => Monoid (Array a) where
mempty :: Array a
mempty = Array a
forall a. Array a
nil
mappend :: Array a -> Array a -> Array a
mappend = Array a -> Array a -> Array a
forall a. Semigroup a => a -> a -> a
(<>)