@@ -0,0 +1,59 @@
1+# Frequently Asked Questions
3+This document provides idioms or examples to solve common programming
4+problems using streamly. To start with please go through [Streamly Quick
5+Overview](README.md) and [`Streamly examples repository`][streamly-examples].
6+This document provides additional examples.
8+## Distribute and Zip Concurrently
10+Say, you have an input stream, and each element of the input stream is to be
11+transformed in multiple ways using monadic functions. Then you want to zip the
12+results together and consume the resulting stream concurrently.
14+First, distribute an item to multiple effectful consumer concurrently, for
18+import Data.Function ((&))
19+import qualified Streamly.Prelude as Stream
22+ Prelude.map ($ x) [return . (+ 1), return . (+ 2)]
28+Alternatively, if you want to concurrently zip different types of outputs, you
29+can use `Applicative` composition:
32+import Data.Maybe (fromJust)
35+ <$> Stream.fromEffect (return $ show x)
36+ <*> Stream.fromEffect (return $ x + 1)
37+ <*> Stream.fromEffect (return $ fromIntegral x / 2)
43+Then apply the function `f` concurrently to your input stream:
54+>>> g f1 [1,2,3,4::Int]
55+[[2,3],[3,4],[4,5],[5,6]]
57+>>> g f2 [1,2,3,4::Int]
58+[("1",2,0.5),("2",3,1.0),("3",4,1.5),("4",5,2.0)]