मैं चाहता हूँ एक ही डेटा दो "शाखाओं", अलग से संसाधित करने के लिए फिर "में शामिल हो गए" में विभाजित किया जा करने के लिए ...मैं "ब्रांच" कंडिट कैसे बना सकता हूं?
+----------+
+---------+ -->| doublber |--- +--------+
+--------+ | |-- +----------+ -->| | +------+
| source |-->| splitter| | summer |-->| sink |
+--------+ | |-- +----------+ -->| | +------+
+---------+ -->| delayer |--- +--------+
+----------+
मैं यह कैसे करना चाहिए?
मेरे प्रयास:
import Data.Conduit
import Control.Monad.IO.Class
import qualified Data.Conduit.List as CL
-- import Data.Conduit.Internal (zipSources)
import Control.Arrow ((>>>))
source :: Source IO Int
source = do
x <- liftIO $ getLine
yield (read x)
source
splitter :: Conduit Int IO (Int, Int)
splitter = CL.map $ \x -> (x,x)
doubler = CL.map (* 2)
delayer :: Conduit Int IO Int
delayer = do
yield 0
CL.map id
twoConduitBranches :: Monad m => Conduit a m b -> Conduit c m d -> Conduit (a,b) m (c,d)
twoConduitBranches q w = awaitForever $ \(x, y) -> do
out1 <- undefined q x
out2 <- undefined w y
yield (out1, out2)
summer :: Conduit (Int,Int) IO Int
summer = CL.map $ \(x,y) -> x + y
sink :: Sink Int IO()
sink = CL.mapM_ (show >>> putStrLn)
-- combosrc = zipSources (source $= delayer) (source $= doubler)
main = source $= splitter $= twoConduitBranches doubler delayer $= summer $$ sink
क्या मैं undefined
रों के स्थान पर लिखना चाहिए?