From c6f65c94aa534065377cbd9900a8c74ce32fdaf4 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Sun, 1 Dec 2024 20:17:42 +0530 Subject: [PATCH] Rename write APIs and fix warnings for streamly-0.3.0 --- src/Streamly/External/Text.hs | 24 ++++++++++++++++-------- src/Streamly/External/Text/Lazy.hs | 10 +++++++++- streamly-text.cabal | 2 +- test/Main.hs | 8 ++++---- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Streamly/External/Text.hs b/src/Streamly/External/Text.hs index b19d80a..610a783 100644 --- a/src/Streamly/External/Text.hs +++ b/src/Streamly/External/Text.hs @@ -9,8 +9,8 @@ module Streamly.External.Text , reader - , unsafeWriteN - , unsafeWrite + , unsafeCreateOf + , unsafeCreate ) where @@ -42,6 +42,14 @@ import Prelude hiding (read) #define EMPTY MBArr.nil #endif +#if MIN_VERSION_streamly_core(0,3,0) +#define CREATE_OF Array.createOf +#define CREATE Array.create +#else +#define CREATE_OF Array.writeN +#define CREATE Array.write +#endif + -- | Convert a 'Text' to an array of 'Word8'. It can be done in constant time. {-# INLINE toArray #-} toArray :: Text -> Array Word8 @@ -72,11 +80,11 @@ reader :: Monad m => Unfold m Text Word8 reader = lmap toArray Array.reader -- | Fold a stream of Word8 to a 'Text' of given size in bytes. -{-# INLINE unsafeWriteN #-} -unsafeWriteN :: MonadIO m => Int -> Fold m Word8 Text -unsafeWriteN i = unsafeFromArray <$> Array.writeN i +{-# INLINE unsafeCreateOf #-} +unsafeCreateOf :: MonadIO m => Int -> Fold m Word8 Text +unsafeCreateOf i = unsafeFromArray <$> CREATE_OF i -- | Fold a stream of Word8 to a 'Text' of appropriate size. -{-# INLINE unsafeWrite #-} -unsafeWrite :: MonadIO m => Fold m Word8 Text -unsafeWrite = unsafeFromArray <$> Array.write +{-# INLINE unsafeCreate #-} +unsafeCreate :: MonadIO m => Fold m Word8 Text +unsafeCreate = unsafeFromArray <$> CREATE diff --git a/src/Streamly/External/Text/Lazy.hs b/src/Streamly/External/Text/Lazy.hs index 31d03d7..6053c31 100644 --- a/src/Streamly/External/Text/Lazy.hs +++ b/src/Streamly/External/Text/Lazy.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + module Streamly.External.Text.Lazy ( chunkReader , reader @@ -25,6 +27,12 @@ import qualified Streamly.Data.Stream as Stream import Prelude hiding (read) +#if MIN_VERSION_streamly_core(0,3,0) +#define UNFOLD_EACH Unfold.unfoldEach +#else +#define UNFOLD_EACH Unfold.many +#endif + -- | Unfold a lazy 'Text' to a stream of 'Array' 'Words'. {-# INLINE chunkReader #-} chunkReader :: Monad m => Unfold m Text (Array Word8) @@ -37,7 +45,7 @@ chunkReader = Unfold step seed -- | Unfold a lazy 'Text' to a stream of Word8 {-# INLINE reader #-} reader :: Monad m => Unfold m Text Word8 -reader = Unfold.many Array.reader chunkReader +reader = UNFOLD_EACH Array.reader chunkReader -- XXX Should this be called readChunks? -- | Convert a lazy 'Text' to a serial stream of 'Array' 'Word8'. diff --git a/streamly-text.cabal b/streamly-text.cabal index 1e3504e..c63ebf8 100644 --- a/streamly-text.cabal +++ b/streamly-text.cabal @@ -29,7 +29,7 @@ library exposed-modules: Streamly.External.Text , Streamly.External.Text.Lazy build-depends: base >=4.7 && <5 - , streamly-core >=0.2.0 && <0.2.3 + , streamly-core >=0.2.0 && <0.3.1 , text >=2.0 && <2.1.2 hs-source-dirs: src default-language: Haskell2010 diff --git a/test/Main.hs b/test/Main.hs index da8c8e4..472f2c5 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -75,9 +75,9 @@ main = do (pure . Strict.unsafeFromArray) (pure . runIdentity) pipelinePropStrict - "Strict.unsafeWrite . Strict.reader" + "Strict.unsafeCreate . Strict.reader" (Stream.unfold Strict.reader) - (Stream.fold Strict.unsafeWrite) + (Stream.fold Strict.unsafeCreate) id pipelinePropLazy "Lazy.unsafeFromChunks . Lazy.toChunks" @@ -95,7 +95,7 @@ main = do Lazy.unsafeFromChunks (pure . runIdentity) pipelinePropLazy - "fmap Text.fromStrict . Strict.unsafeWrite . Lazy.reader" + "fmap Text.fromStrict . Strict.unsafeCreate . Lazy.reader" (Stream.unfold Lazy.reader) - (fmap BSL.fromStrict . Stream.fold Strict.unsafeWrite) + (fmap BSL.fromStrict . Stream.fold Strict.unsafeCreate) id