on beabbcc help sign in
streamly/examples/SearchQuery.hs
35 lines 1.1 kB history raw
1{-# LANGUAGE CPP #-}
3#if !(MIN_VERSION_base(4,11,0))
4import Data.Semigroup ((<>))
5#endif
6import Streamly.Prelude (drain, nil, yieldM, (|:))
7import Network.HTTP.Simple
9import qualified Streamly.Prelude as S
11-- | Runs three search engine queries in parallel and prints the search engine
12-- names in the fastest first order.
13--
14-- Does it twice using two different ways.
15--
16main :: IO ()
17main = do
18 putStrLn "Using parallel stream construction"
19 drain . S.parallely $ google |: bing |: duckduckgo |: nil
21 putStrLn "\nUsing parallel semigroup composition"
22 drain . S.parallely $ yieldM google <> yieldM bing <> yieldM duckduckgo
24 putStrLn "\nUsing parallel applicative zip"
25 drain . S.zipAsyncly $
26 (,,) <$> yieldM google <*> yieldM bing <*> yieldM duckduckgo
28 where
29 get :: String -> IO ()
30 get s = httpNoBody (parseRequest_ s) >> print s
32 google, bing, duckduckgo :: IO ()
33 google = get "https://www.google.com/search?q=haskell"
34 bing = get "https://www.bing.com/search?q=haskell"
35 duckduckgo = get "https://www.duckduckgo.com/?q=haskell"