on bbfffe8 help sign in
streamly/examples/MergeSort.hs
24 lines 645 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)
12import Data.Ord (compare)
14import Streamly
15import qualified Streamly.Prelude as S
17getSorted :: Serial Word16
18getSorted = do
19 g <- S.yieldM getStdGen
20 let ls = take 100000 (randoms g) :: [Word16]
21 foldMap return (sort ls)
23main :: IO ()
24main = S.last (S.mergeAsyncBy compare getSorted getSorted) >>= print