on master help sign in
Fix example code in Internal.Data.Fold
89edadeRanjeet Kumar Ranjan
src/Streamly/Internal/Data/Fold.hs+11−8
@@ -275,6 +275,7 @@ import Streamly.Internal.Data.Fold.Type
275-- >>> import qualified Streamly.Data.Fold as Fold
275-- >>> import qualified Streamly.Data.Fold as Fold
276-- >>> import qualified Streamly.Internal.Data.Fold as Fold
276-- >>> import qualified Streamly.Internal.Data.Fold as Fold
277-- >>> import qualified Streamly.Internal.Data.Parser as Parser
277-- >>> import qualified Streamly.Internal.Data.Parser as Parser
278+-- >>> import Data.IORef (newIORef, readIORef, writeIORef)
278
279
279------------------------------------------------------------------------------
280------------------------------------------------------------------------------
280-- hoist
281-- hoist
@@ -1128,23 +1129,25 @@ distribute = Prelude.foldr (teeWith (:)) (fromPure [])
1128--
1129--
1129-- Send input to the two folds in a proportion of 2:1:
1130-- Send input to the two folds in a proportion of 2:1:
1130--
1131--
1131−-- @
1132+-- >>> :{
1132−-- import Data.IORef (newIORef, readIORef, writeIORef)
1133-- proportionately m n = do
1133-- proportionately m n = do
1134-- ref <- newIORef $ cycle $ concat [replicate m Left, replicate n Right]
1134-- ref <- newIORef $ cycle $ concat [replicate m Left, replicate n Right]
1135−-- return $ \\a -> do
1135+-- return $ \a -> do
1136-- r <- readIORef ref
1136-- r <- readIORef ref
1137-- writeIORef ref $ tail r
1137-- writeIORef ref $ tail r
1138−-- return $ head r a
1138+-- return $ Prelude.head r a
1139+-- :}
1139--
1140--
1141+-- >>> :{
1140-- main = do
1142-- main = do
1141-- f <- proportionately 2 1
1143-- f <- proportionately 2 1
1142−-- r <- S.fold (FL.partitionByM f FL.length FL.length) (S.enumerateFromTo (1 :: Int) 100)
1144+-- r <- Stream.fold (Fold.partitionByM f Fold.length Fold.length) (Stream.enumerateFromTo (1 :: Int) 100)
1143-- print r
1145-- print r
1144−-- @
1146+-- :}
1145−-- @
1147+--
1148+-- >>> main
1146-- (67,33)
1149-- (67,33)
1147−-- @
1150+--
1148--
1151--
1149-- This is the consumer side dual of the producer side 'mergeBy' operation.
1152-- This is the consumer side dual of the producer side 'mergeBy' operation.
1150--
1153--