on 7d00819 help sign in
streamly/examples/MergeSort.hs
23 lines 619 B history raw
1{-# LANGUAGE FlexibleContexts #-}
3-- | This example generates two streams sorted in ascending order and merges
4-- them in ascending order, concurrently.
5--
6-- Compile with '-threaded -with-rtsopts "-N"' GHC options to use the
7-- parallelism.
9import Data.Word
10import System.Random (getStdGen, randoms)
11import Data.List (sort)
13import Streamly
14import qualified Streamly.Prelude as S
16getSorted :: Serial Word16
17getSorted = do
18 g <- S.yieldM getStdGen
19 let ls = take 100000 (randoms g) :: [Word16]
20 foldMap return (sort ls)
22main :: IO ()
23main = S.last (S.mergeAsyncBy compare getSorted getSorted) >>= print