on master help sign in
Move Fold2 to a separate "Consumer" module
3cda01fHarendra Kumar
src/Streamly/Internal/Data/Consumer/Type.hsnew file+28
@@ -0,0 +1,28 @@
1+-- |
2+-- Module : Streamly.Internal.Data.Consumer.Type
3+-- Copyright : (c) 2019 Composewell Technologies
4+-- License : BSD-3-Clause
5+-- Maintainer : streamly@composewell.com
6+-- Stability : experimental
7+-- Portability : GHC
8+--
9+-- Consumer is to Fold as Unfold is to Stream.
10+--
11+module Streamly.Internal.Data.Consumer.Type
12+ (
13+ -- * Types
14+ Fold2 (..)
15+ )
16+where
17+
18+-- All folds in the Fold module should be implemented as Refolds.
19+--
20+-- | Experimental type to provide a side input to the fold for generating the
21+-- initial state. For example, if we have to fold chunks of a stream and write
22+-- each chunk to a different file, then we can generate the file name using a
23+-- monadic action. This is a generalized version of 'Fold'.
24+--
25+-- /Internal/
26+data Fold2 m c a b =
27+ -- | @Fold @ @ step @ @ inject @ @ extract@
28+ forall s. Fold2 (s -> a -> m s) (c -> m s) (s -> m b)
src/Streamly/Internal/Data/Fold/Type.hs+3−9
@@ -272,6 +272,7 @@ import Data.Maybe (isJust, fromJust)
272import Fusion.Plugin.Types (Fuse(..))
272import Fusion.Plugin.Types (Fuse(..))
273import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
273import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
274import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
274import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
275+import Streamly.Internal.Data.Consumer.Type (Fold2(..))
275
276
276import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
277import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
277
278
@@ -570,16 +571,9 @@ mkFoldM_ step initial = mkFoldM step initial return
570-- Fold2
571-- Fold2
571------------------------------------------------------------------------------
572------------------------------------------------------------------------------
572
573
573−-- | Experimental type to provide a side input to the fold for generating the
574+-- This is similar to how we run an Unfold to generate a Stream. A Fold is like
574−-- initial state. For example, if we have to fold chunks of a stream and write
575+-- a Stream and a Fold2 is like an Unfold.
575−-- each chunk to a different file, then we can generate the file name using a
576−-- monadic action. This is a generalized version of 'Fold'.
577--
576--
578−-- /Internal/
579−data Fold2 m c a b =
580− -- | @Fold @ @ step @ @ inject @ @ extract@
581− forall s. Fold2 (s -> a -> m s) (c -> m s) (s -> m b)
582−
583-- | Convert more general type 'Fold2' into a simpler type 'Fold'
577-- | Convert more general type 'Fold2' into a simpler type 'Fold'
584--
578--
585-- /Internal/
579-- /Internal/
streamly.cabal+1
@@ -385,6 +385,7 @@ library
385 , Streamly.Internal.Data.SVar.Pull
385 , Streamly.Internal.Data.SVar.Pull
386 , Streamly.Internal.Data.SVar
386 , Streamly.Internal.Data.SVar
387 , Streamly.Internal.Data.Stream.StreamK.Type
387 , Streamly.Internal.Data.Stream.StreamK.Type
388+ , Streamly.Internal.Data.Consumer.Type
388 , Streamly.Internal.Data.Fold.Type
389 , Streamly.Internal.Data.Fold.Type
389 , Streamly.Internal.Data.Stream.StreamD.Step
390 , Streamly.Internal.Data.Stream.StreamD.Step
390 , Streamly.Internal.Data.Stream.StreamD.Type
391 , Streamly.Internal.Data.Stream.StreamD.Type