on fa8a2cf help sign in
streamly/examples/SearchQuery.hs
29 lines 1.0 kB history raw
1import Streamly
2import Streamly.Prelude (drain, nil, yieldM, (|:))
3import Network.HTTP.Simple
5-- | Runs three search engine queries in parallel and prints the search engine
6-- names in the fastest first order.
7--
8-- Does it twice using two different ways.
9--
10main :: IO ()
11main = do
12 putStrLn "Using parallel stream construction"
13 drain . parallely $ google |: bing |: duckduckgo |: nil
15 putStrLn "\nUsing parallel semigroup composition"
16 drain . parallely $ yieldM google <> yieldM bing <> yieldM duckduckgo
18 putStrLn "\nUsing parallel applicative zip"
19 drain . zipAsyncly $
20 (,,) <$> yieldM google <*> yieldM bing <*> yieldM duckduckgo
22 where
23 get :: String -> IO ()
24 get s = httpNoBody (parseRequest_ s) >> print s
26 google, bing, duckduckgo :: IO ()
27 google = get "https://www.google.com/search?q=haskell"
28 bing = get "https://www.bing.com/search?q=haskell"
29 duckduckgo = get "https://www.duckduckgo.com/?q=haskell"