mirror of
https://github.com/composewell/streamly.git
synced 2024-10-27 20:18:55 +03:00
Move Fold2 to a separate "Consumer" module
This commit is contained in:
parent
726d356bf7
commit
3cda01f5da
28
src/Streamly/Internal/Data/Consumer/Type.hs
Normal file
28
src/Streamly/Internal/Data/Consumer/Type.hs
Normal file
@ -0,0 +1,28 @@
|
||||
-- |
|
||||
-- Module : Streamly.Internal.Data.Consumer.Type
|
||||
-- Copyright : (c) 2019 Composewell Technologies
|
||||
-- License : BSD-3-Clause
|
||||
-- Maintainer : streamly@composewell.com
|
||||
-- Stability : experimental
|
||||
-- Portability : GHC
|
||||
--
|
||||
-- Consumer is to Fold as Unfold is to Stream.
|
||||
--
|
||||
module Streamly.Internal.Data.Consumer.Type
|
||||
(
|
||||
-- * Types
|
||||
Fold2 (..)
|
||||
)
|
||||
where
|
||||
|
||||
-- All folds in the Fold module should be implemented as Refolds.
|
||||
--
|
||||
-- | Experimental type to provide a side input to the fold for generating the
|
||||
-- initial state. For example, if we have to fold chunks of a stream and write
|
||||
-- each chunk to a different file, then we can generate the file name using a
|
||||
-- monadic action. This is a generalized version of 'Fold'.
|
||||
--
|
||||
-- /Internal/
|
||||
data Fold2 m c a b =
|
||||
-- | @Fold @ @ step @ @ inject @ @ extract@
|
||||
forall s. Fold2 (s -> a -> m s) (c -> m s) (s -> m b)
|
@ -272,6 +272,7 @@ import Data.Maybe (isJust, fromJust)
|
||||
import Fusion.Plugin.Types (Fuse(..))
|
||||
import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
|
||||
import Streamly.Internal.Data.Tuple.Strict (Tuple'(..), Tuple3'(..))
|
||||
import Streamly.Internal.Data.Consumer.Type (Fold2(..))
|
||||
|
||||
import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
|
||||
|
||||
@ -570,16 +571,9 @@ mkFoldM_ step initial = mkFoldM step initial return
|
||||
-- Fold2
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- | Experimental type to provide a side input to the fold for generating the
|
||||
-- initial state. For example, if we have to fold chunks of a stream and write
|
||||
-- each chunk to a different file, then we can generate the file name using a
|
||||
-- monadic action. This is a generalized version of 'Fold'.
|
||||
-- This is similar to how we run an Unfold to generate a Stream. A Fold is like
|
||||
-- a Stream and a Fold2 is like an Unfold.
|
||||
--
|
||||
-- /Internal/
|
||||
data Fold2 m c a b =
|
||||
-- | @Fold @ @ step @ @ inject @ @ extract@
|
||||
forall s. Fold2 (s -> a -> m s) (c -> m s) (s -> m b)
|
||||
|
||||
-- | Convert more general type 'Fold2' into a simpler type 'Fold'
|
||||
--
|
||||
-- /Internal/
|
||||
|
@ -385,6 +385,7 @@ library
|
||||
, Streamly.Internal.Data.SVar.Pull
|
||||
, Streamly.Internal.Data.SVar
|
||||
, Streamly.Internal.Data.Stream.StreamK.Type
|
||||
, Streamly.Internal.Data.Consumer.Type
|
||||
, Streamly.Internal.Data.Fold.Type
|
||||
, Streamly.Internal.Data.Stream.StreamD.Step
|
||||
, Streamly.Internal.Data.Stream.StreamD.Type
|
||||
|
Loading…
Reference in New Issue
Block a user