Skip to content

Commit 53424f8

Browse files
committed
Remove the use of deprecated APIs
1 parent fe5e1d3 commit 53424f8

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

src/Streamly/Internal/System/Process.hs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ import qualified Streamly.Internal.Unicode.Stream as Unicode (lines)
176176

177177
#include "DocTestProcess.hs"
178178

179+
-------------------------------------------------------------------------------
180+
-- Compatibility
181+
-------------------------------------------------------------------------------
182+
183+
#if MIN_VERSION_streamly_core(0,3,0)
184+
#define UNFOLD_EACH Stream.unfoldEach
185+
#define CHUNKS_OF Array.chunksOf
186+
#else
187+
#define UNFOLD_EACH Stream.unfoldMany
188+
#define CHUNKS_OF Stream.chunksOf
189+
#endif
190+
179191
-------------------------------------------------------------------------------
180192
-- Config
181193
-------------------------------------------------------------------------------
@@ -686,11 +698,11 @@ pipeBytesEither ::
686698
-> Stream m Word8 -- ^ Input Stream
687699
-> Stream m (Either Word8 Word8) -- ^ Output Stream
688700
pipeBytesEither path args input =
689-
let input1 = Stream.chunksOf defaultChunkSize input
701+
let input1 = CHUNKS_OF defaultChunkSize input
690702
output = pipeChunksEither path args input1
691703
leftRdr = fmap Left Array.reader
692704
rightRdr = fmap Right Array.reader
693-
in Stream.unfoldMany (Unfold.either leftRdr rightRdr) output
705+
in UNFOLD_EACH (Unfold.either leftRdr rightRdr) output
694706

695707
-- | Like 'pipeChunks' but use the specified configuration to run the process.
696708
{-# INLINE pipeChunksWith #-}
@@ -784,9 +796,9 @@ pipeBytes ::
784796
-> Stream m Word8 -- ^ Input Stream
785797
-> Stream m Word8 -- ^ Output Stream
786798
pipeBytes path args input = -- rights . pipeBytesEither path args
787-
let input1 = Stream.chunksOf defaultChunkSize input
799+
let input1 = CHUNKS_OF defaultChunkSize input
788800
output = pipeChunks path args input1
789-
in Stream.unfoldMany Array.reader output
801+
in UNFOLD_EACH Array.reader output
790802

791803
{-# DEPRECATED processBytes "Please use pipeBytes instead." #-}
792804
{-# INLINE processBytes #-}
@@ -906,7 +918,7 @@ toBytesEither path args =
906918
let output = toChunksEither path args
907919
leftRdr = fmap Left Array.reader
908920
rightRdr = fmap Right Array.reader
909-
in Stream.unfoldMany (Unfold.either leftRdr rightRdr) output
921+
in UNFOLD_EACH (Unfold.either leftRdr rightRdr) output
910922

911923
-- | @toBytes path args@ runs the executable specified by @path@ using @args@
912924
-- as arguments and returns the output of the process as a stream of bytes.
@@ -930,7 +942,7 @@ toBytes ::
930942
-> Stream m Word8 -- ^ Output Stream
931943
toBytes path args =
932944
let output = toChunks path args
933-
in Stream.unfoldMany Array.reader output
945+
in UNFOLD_EACH Array.reader output
934946

935947
-- | Like 'toBytesEither' but generates a stream of @Array Word8@ instead of a stream
936948
-- of @Word8@.

test/Streamly/System/Process.hs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
module Main (main) where
44

5+
-------------------------------------------------------------------------------
6+
-- Imports
7+
-------------------------------------------------------------------------------
8+
59
import Data.Function ((&))
610
import Data.List ((\\))
711
import Data.Maybe (fromMaybe)
@@ -36,6 +40,22 @@ import qualified Streamly.Data.Stream as Stream
3640
import qualified Streamly.Internal.FileSystem.Handle as FH (putBytes, read)
3741
import qualified Streamly.Internal.System.Command as Cmd (quotedWord)
3842

43+
-------------------------------------------------------------------------------
44+
-- Compatibility
45+
-------------------------------------------------------------------------------
46+
47+
#if MIN_VERSION_streamly_core(0,3,0)
48+
#define UNFOLD_EACH Stream.unfoldEach
49+
#define CHUNKS_OF Array.chunksOf
50+
#else
51+
#define UNFOLD_EACH Stream.unfoldMany
52+
#define CHUNKS_OF Stream.chunksOf
53+
#endif
54+
55+
-------------------------------------------------------------------------------
56+
-- Tests
57+
-------------------------------------------------------------------------------
58+
3959
newtype SimpleError = SimpleError String
4060
deriving Show
4161

@@ -172,7 +192,7 @@ toBytes2 = monadicIO $ run checkFailAction
172192

173193
{-# INLINE concatArr #-}
174194
concatArr :: (Monad m, Unbox a) => Stream m (Array a) -> Stream m a
175-
concatArr = S.unfoldMany Array.reader
195+
concatArr = UNFOLD_EACH Array.reader
176196

177197
toChunks1 :: Property
178198
toChunks1 =
@@ -270,7 +290,7 @@ processChunksConsumeAllInput =
270290
Proc.pipeChunks
271291
trBinary
272292
["[a-z]", "[A-Z]"]
273-
(S.chunksOf arrayChunkSize inputStream)
293+
(CHUNKS_OF arrayChunkSize inputStream)
274294

275295
charUpperStrm = fmap toUpper inputStream
276296

@@ -290,7 +310,7 @@ processChunksConsumePartialInput =
290310
Proc.pipeChunks
291311
path
292312
["-n", "1"]
293-
(S.chunksOf arrayChunkSize inputStream)
313+
(CHUNKS_OF arrayChunkSize inputStream)
294314

295315
headLine =
296316
S.foldMany
@@ -409,7 +429,7 @@ pipeChunksEither1 =
409429
Proc.pipeChunksEither
410430
trBinary
411431
["[a-z]", "[A-Z]"]
412-
(S.chunksOf arrayChunkSize inputStream)
432+
(CHUNKS_OF arrayChunkSize inputStream)
413433

414434
charUpperStrm = fmap toUpper inputStream
415435

@@ -427,7 +447,7 @@ pipeChunksEither2 =
427447
Proc.pipeChunksEither
428448
interpreterFile
429449
[interpreterArg, executableFile, "[a-z]", "[A-Z]"]
430-
(S.chunksOf arrayChunkSize inputStream)
450+
(CHUNKS_OF arrayChunkSize inputStream)
431451

432452
charUpperStrm = fmap toUpper inputStream
433453

0 commit comments

Comments
 (0)