forked from composewell/streamly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchQuery.hs
More file actions
29 lines (24 loc) · 1004 Bytes
/
SearchQuery.hs
File metadata and controls
29 lines (24 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Streamly
import Streamly.Prelude (drain, nil, yieldM, (|:))
import Network.HTTP.Simple
-- | Runs three search engine queries in parallel and prints the search engine
-- names in the fastest first order.
--
-- Does it twice using two different ways.
--
main :: IO ()
main = do
putStrLn "Using parallel stream construction"
drain . parallely $ google |: bing |: duckduckgo |: nil
putStrLn "\nUsing parallel semigroup composition"
drain . parallely $ yieldM google <> yieldM bing <> yieldM duckduckgo
putStrLn "\nUsing parallel applicative zip"
drain . zipAsyncly $
(,,) <$> yieldM google <*> yieldM bing <*> yieldM duckduckgo
where
get :: String -> IO ()
get s = httpNoBody (parseRequest_ s) >> print s
google, bing, duckduckgo :: IO ()
google = get "https://www.google.com/search?q=haskell"
bing = get "https://www.bing.com/search?q=haskell"
duckduckgo = get "https://www.duckduckgo.com/?q=haskell"