on master help sign in
Move Fold2 to a separate "Consumer" module
commit3cda01f5da11895e38c68df6f6b7d4655922fbb8 authorHarendra Kumar <harendra@composewell.com> dateFri 8 Oct 2021, 16:06 (5 years ago) parent726d356
3 files changed+32−9
src/Streamly/Internal/Data/Consumer/Type.hs+28 src/Streamly/Internal/Data/Fold/Type.hs+3−9 streamly.cabal+1
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)
272272import Fusion.Plugin.Types (Fuse(..))
273273import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
274274import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
275+import Streamly.Internal.Data.Consumer.Type (Fold2(..))
275276
276277import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
277278
@@ -570,16 +571,9 @@ mkFoldM_ step initial = mkFoldM step initial return
570571-- Fold2
571572------------------------------------------------------------------------------
572573
573−-- | Experimental type to provide a side input to the fold for generating the
574−-- initial state. For example, if we have to fold chunks of a stream and write
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'.
574+-- This is similar to how we run an Unfold to generate a Stream. A Fold is like
575+-- a Stream and a Fold2 is like an Unfold.
577576--
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−
583577-- | Convert more general type 'Fold2' into a simpler type 'Fold'
584578--
585579-- /Internal/
streamly.cabal+1
@@ -385,6 +385,7 @@ library
385385 , Streamly.Internal.Data.SVar.Pull
386386 , Streamly.Internal.Data.SVar
387387 , Streamly.Internal.Data.Stream.StreamK.Type
388+ , Streamly.Internal.Data.Consumer.Type
388389 , Streamly.Internal.Data.Fold.Type
389390 , Streamly.Internal.Data.Stream.StreamD.Step
390391 , Streamly.Internal.Data.Stream.StreamD.Type