mirror of
https://github.com/composewell/streamly.git
synced 2024-09-20 16:08:20 +03:00
25 lines
645 B
Haskell
25 lines
645 B
Haskell
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
-- | This example generates two streams sorted in ascending order and merges
|
|
-- them in ascending order, concurrently.
|
|
--
|
|
-- Compile with '-threaded -with-rtsopts "-N"' GHC options to use the
|
|
-- parallelism.
|
|
|
|
import Data.Word
|
|
import System.Random (getStdGen, randoms)
|
|
import Data.List (sort)
|
|
import Data.Ord (compare)
|
|
|
|
import Streamly
|
|
import qualified Streamly.Prelude as S
|
|
|
|
getSorted :: Serial Word16
|
|
getSorted = do
|
|
g <- S.yieldM getStdGen
|
|
let ls = take 100000 (randoms g) :: [Word16]
|
|
foldMap return (sort ls)
|
|
|
|
main :: IO ()
|
|
main = S.last (S.mergeAsyncBy compare getSorted getSorted) >>= print
|