mirror of
https://github.com/composewell/streamly.git
synced 2024-11-10 02:44:29 +03:00
Change the order of arguments in Unfold.fold
To keep it consistent with Stream.fold.
This commit is contained in:
parent
ca60ffaa88
commit
ae741f1bd8
@ -62,7 +62,7 @@ source n = UF.enumerateFromToIntegral n
|
||||
|
||||
{-# INLINE drainGeneration #-}
|
||||
drainGeneration :: Monad m => Unfold m a b -> a -> m ()
|
||||
drainGeneration unf seed = UF.fold unf FL.drain seed
|
||||
drainGeneration unf seed = UF.fold FL.drain unf seed
|
||||
|
||||
{-# INLINE drainTransformation #-}
|
||||
drainTransformation ::
|
||||
@ -409,7 +409,7 @@ toNullAp value start =
|
||||
let end = start + nthRoot 2 value
|
||||
s = source end
|
||||
-- in UF.fold ((+) <$> s <*> s) FL.drain start
|
||||
in UF.fold ((+) `fmap` s `UF.apply` s) FL.drain start
|
||||
in UF.fold FL.drain ((+) `fmap` s `UF.apply` s) start
|
||||
|
||||
{-# INLINE _apDiscardFst #-}
|
||||
_apDiscardFst :: Int -> Int -> m ()
|
||||
@ -451,7 +451,7 @@ toNull value start =
|
||||
u = src `UF.bind` \x ->
|
||||
src `UF.bind` \y ->
|
||||
UF.yield (x + y)
|
||||
in UF.fold u FL.drain start
|
||||
in UF.fold FL.drain u start
|
||||
|
||||
|
||||
{-# INLINE toNull3 #-}
|
||||
@ -469,7 +469,7 @@ toNull3 value start =
|
||||
u = src `UF.bind` \x ->
|
||||
src `UF.bind` \y ->
|
||||
UF.yield (x + y)
|
||||
in UF.fold u FL.drain start
|
||||
in UF.fold FL.drain u start
|
||||
|
||||
{-# INLINE toList #-}
|
||||
toList :: Monad m => Int -> Int -> m [Int]
|
||||
@ -485,7 +485,7 @@ toList value start = do
|
||||
u = src `UF.bind` \x ->
|
||||
src `UF.bind` \y ->
|
||||
UF.yield (x + y)
|
||||
in UF.fold u FL.toList start
|
||||
in UF.fold FL.toList u start
|
||||
|
||||
{-# INLINE toListSome #-}
|
||||
toListSome :: Monad m => Int -> Int -> m [Int]
|
||||
@ -501,7 +501,7 @@ toListSome value start = do
|
||||
u = src `UF.bind` \x ->
|
||||
src `UF.bind` \y ->
|
||||
UF.yield (x + y)
|
||||
in UF.fold (UF.take 1000 u) FL.toList start
|
||||
in UF.fold FL.toList (UF.take 1000 u) start
|
||||
|
||||
{-# INLINE filterAllOut #-}
|
||||
filterAllOut :: Monad m => Int -> Int -> m ()
|
||||
@ -519,7 +519,7 @@ filterAllOut value start = do
|
||||
in if s < 0
|
||||
then UF.yield s
|
||||
else UF.nilM (return . const ())
|
||||
in UF.fold u FL.drain start
|
||||
in UF.fold FL.drain u start
|
||||
|
||||
{-# INLINE filterAllIn #-}
|
||||
filterAllIn :: Monad m => Int -> Int -> m ()
|
||||
@ -537,7 +537,7 @@ filterAllIn value start = do
|
||||
in if s > 0
|
||||
then UF.yield s
|
||||
else UF.nilM (return . const ())
|
||||
in UF.fold u FL.drain start
|
||||
in UF.fold FL.drain u start
|
||||
|
||||
{-# INLINE filterSome #-}
|
||||
filterSome :: Monad m => Int -> Int -> m ()
|
||||
@ -555,7 +555,7 @@ filterSome value start = do
|
||||
in if s > 1100000
|
||||
then UF.yield s
|
||||
else UF.nilM (return . const ())
|
||||
in UF.fold u FL.drain start
|
||||
in UF.fold FL.drain u start
|
||||
|
||||
{-# INLINE breakAfterSome #-}
|
||||
breakAfterSome :: Int -> Int -> IO ()
|
||||
@ -574,7 +574,7 @@ breakAfterSome value start =
|
||||
then error "break"
|
||||
else UF.yield s
|
||||
in do
|
||||
(_ :: Either ErrorCall ()) <- try $ UF.fold u FL.drain start
|
||||
(_ :: Either ErrorCall ()) <- try $ UF.fold FL.drain u start
|
||||
return ()
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@ -590,9 +590,7 @@ concatCount linearCount =
|
||||
concat :: Monad m => Int -> Int -> m ()
|
||||
concat linearCount start = do
|
||||
let end = start + concatCount linearCount
|
||||
UF.fold
|
||||
(UF.many (source end) (source end))
|
||||
FL.drain start
|
||||
UF.fold FL.drain (UF.many (source end) (source end)) start
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Benchmarks
|
||||
|
@ -132,7 +132,7 @@ inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''D.FoldMany
|
||||
-- | Send the chunk content ('defaultChunkSize') to /dev/null
|
||||
-- Implicitly benchmarked via 'readFromBytesNull'
|
||||
_readChunks :: Handle -> Handle -> IO ()
|
||||
_readChunks inh devNull = IUF.fold unf fld inh
|
||||
_readChunks inh devNull = IUF.fold fld unf inh
|
||||
|
||||
where
|
||||
|
||||
@ -142,7 +142,7 @@ _readChunks inh devNull = IUF.fold unf fld inh
|
||||
-- | Send the chunk content to /dev/null
|
||||
-- Implicitly benchmarked via 'readWithBufferOfFromBytesNull'
|
||||
_readChunksWithBufferOf :: Handle -> Handle -> IO ()
|
||||
_readChunksWithBufferOf inh devNull = IUF.fold unf fld (defaultChunkSize, inh)
|
||||
_readChunksWithBufferOf inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
|
||||
|
||||
where
|
||||
|
||||
@ -163,7 +163,7 @@ o_1_space_copy_fromBytes env =
|
||||
-- | Send the file contents ('defaultChunkSize') to /dev/null
|
||||
{-# NOINLINE writeReadWithBufferOf #-}
|
||||
writeReadWithBufferOf :: Handle -> Handle -> IO ()
|
||||
writeReadWithBufferOf inh devNull = IUF.fold unf fld (defaultChunkSize, inh)
|
||||
writeReadWithBufferOf inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
|
||||
|
||||
where
|
||||
|
||||
@ -181,7 +181,7 @@ inspect $ 'writeReadWithBufferOf `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeN
|
||||
-- | Send the file contents ('AT.defaultChunkSize') to /dev/null
|
||||
{-# NOINLINE writeRead #-}
|
||||
writeRead :: Handle -> Handle -> IO ()
|
||||
writeRead inh devNull = IUF.fold unf fld inh
|
||||
writeRead inh devNull = IUF.fold fld unf inh
|
||||
|
||||
where
|
||||
|
||||
|
@ -135,7 +135,7 @@ o_1_space_copy_stream_exceptions env =
|
||||
readChunksOnException :: Handle -> Handle -> IO ()
|
||||
readChunksOnException inh devNull =
|
||||
let readEx = IUF.onException (\_ -> hClose inh) FH.readChunks
|
||||
in IUF.fold readEx (IFH.writeChunks devNull) inh
|
||||
in IUF.fold (IFH.writeChunks devNull) readEx inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses 'readChunksOnException
|
||||
@ -146,7 +146,7 @@ inspect $ hasNoTypeClasses 'readChunksOnException
|
||||
readChunksBracket_ :: Handle -> Handle -> IO ()
|
||||
readChunksBracket_ inh devNull =
|
||||
let readEx = IUF.bracket_ return (\_ -> hClose inh) FH.readChunks
|
||||
in IUF.fold readEx (IFH.writeChunks devNull) inh
|
||||
in IUF.fold (IFH.writeChunks devNull) readEx inh
|
||||
|
||||
#ifdef INSPECTION
|
||||
inspect $ hasNoTypeClasses 'readChunksBracket_
|
||||
@ -156,7 +156,7 @@ inspect $ hasNoTypeClasses 'readChunksBracket_
|
||||
readChunksBracket :: Handle -> Handle -> IO ()
|
||||
readChunksBracket inh devNull =
|
||||
let readEx = IUF.bracket return (\_ -> hClose inh) FH.readChunks
|
||||
in IUF.fold readEx (IFH.writeChunks devNull) inh
|
||||
in IUF.fold (IFH.writeChunks devNull) readEx inh
|
||||
|
||||
o_1_space_copy_exceptions_readChunks :: BenchEnv -> [Benchmark]
|
||||
o_1_space_copy_exceptions_readChunks env =
|
||||
|
@ -328,8 +328,8 @@ swap = lmap Tuple.swap
|
||||
-- /Pre-release/
|
||||
--
|
||||
{-# INLINE_NORMAL fold #-}
|
||||
fold :: Monad m => Unfold m a b -> Fold m b c -> a -> m c
|
||||
fold (Unfold ustep inject) (Fold fstep initial extract) a = do
|
||||
fold :: Monad m => Fold m b c -> Unfold m a b -> a -> m c
|
||||
fold (Fold fstep initial extract) (Unfold ustep inject) a = do
|
||||
res <- initial
|
||||
case res of
|
||||
FL.Partial x -> inject a >>= go SPEC x
|
||||
|
Loading…
Reference in New Issue
Block a user