on decdf72 help sign in
streamly/examples/SearchQuery.hs
25 lines 878 B history raw
1import Streamly
2import Streamly.Prelude (once)
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 semigroup composition"
13 runStream . parallely $ google <> bing <> duckduckgo
15 putStrLn "\nUsing parallel applicative zip"
16 runStream . zipAsyncly $ (,,) <$> google <*> bing <*> duckduckgo
18 where
19 get :: IsStream t => String -> t IO ()
20 get s = once (httpNoBody (parseRequest_ s) >> putStrLn (show s))
22 google, bing, duckduckgo :: IsStream t => t IO ()
23 google = get "https://www.google.com/search?q=haskell"
24 bing = get "https://www.bing.com/search?q=haskell"
25 duckduckgo = get "https://www.duckduckgo.com/?q=haskell"