1{-# LANGUAGE FlexibleContexts #-}
3module Streamly.Examples.MergeSortedStreams where
6import System.Random (getStdGen, randoms)
9import qualified Streamly.Prelude as A
11getSorted :: MonadIO m => StreamT m Word16
14 let ls = take 100000 (randoms g) :: [Word16]
15 foldMapWith (<>) return (sort ls)
17mergeAsync :: (Ord a, MonadAsync m)
18 => StreamT m a -> StreamT m a -> StreamT m a
24merge :: (Ord a, MonadAsync m) => StreamT m a -> StreamT m a -> StreamT m a
26 a1 <- lift $ A.uncons a
30 b1 <- lift $ A.uncons b
32 Nothing -> return x <> ma
35 then (return y) <> merge (return x <> ma) mb
36 else (return x) <> merge ma (return y <> mb)
38mergeSortedStreams :: IO ()
39mergeSortedStreams = do
40 xs <- A.toList $ mergeAsync getSorted getSorted
41 putStrLn $ show $ length xs
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list