1# Frequently Asked Questions
3This document provides idioms or examples to solve common programming
4problems using streamly. To start with please go through [Streamly Quick
5Overview](/docs/User/Tutorials/Introduction.md) and [`Streamly examples repository`][streamly-examples].
6This document provides additional examples.
8## Distribute and Zip Concurrently
10Say, you have an input stream, and each element of the input stream is to be
11transformed in multiple ways using monadic functions. Then you want to zip the
12results together and consume the resulting stream concurrently.
14First, distribute an item to multiple effectful consumer concurrently, for
18import Data.Function ((&))
19import qualified Streamly.Prelude as Stream
22 Prelude.map ($ x) [return . (+ 1), return . (+ 2)]
28Alternatively, if you want to concurrently zip different types of outputs, you
29can use `Applicative` composition:
32import Data.Maybe (fromJust)
35 <$> Stream.fromEffect (return $ show x)
36 <*> Stream.fromEffect (return $ x + 1)
37 <*> Stream.fromEffect (return $ fromIntegral x / 2)
43Then 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)]
65 Stream.fromList [1,2,3,4,5::Int]
66& Stream.scan (Array.writeLastN 2)
69[[],[1],[1,2],[2,3],[3,4],[4,5]]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list