@@ -7,6 +7,7 @@ import Control.Monad.IO.Class (liftIO)
7-- import Data.List (nub)
7-- import Data.List (nub)
8import Data.List (sort)
8import Data.List (sort)
9import Data.Monoid ((<>))
9import Data.Monoid ((<>))
10+import Prelude hiding (take, drop)
10import Test.Hspec
11import Test.Hspec
12import Asyncly
13import Asyncly
@@ -42,6 +43,8 @@ main = hspec $ do
42 describe "Left Biased parallel loops (<|)" $ loops (<|) sort sort
43 describe "Left Biased parallel loops (<|)" $ loops (<|) sort sort
43 describe "Fair parallel loops (<|>)" $ loops (<|>) sort sort
44 describe "Fair parallel loops (<|>)" $ loops (<|>) sort sort
46+ describe "Transformation" $ transformOps (<>)
45bind :: Spec
48bind :: Spec
47 it "Simple runAsyncly and 'then' with IO" $
50 it "Simple runAsyncly and 'then' with IO" $
@@ -122,6 +125,28 @@ loops f tsrt hsrt = do
122 liftIO $ putStrLn "LoopTail..."
125 liftIO $ putStrLn "LoopTail..."
123 return x `f` (if x < 3 then loopTail (x + 1) else empty)
126 return x `f` (if x < 3 then loopTail (x + 1) else empty)
128+transformOps :: (AsyncT IO Int -> AsyncT IO Int -> AsyncT IO Int) -> Spec
131+ (toList $ take 10 $ foldMapWith f return [1..10])
132+ `shouldReturn` [1..10]
134+ (toList $ take 0 $ foldMapWith f return [1..10])
137+ (toList $ take 5 $ foldMapWith f return [1..10])
138+ `shouldReturn` [1..5]
141+ (toList $ drop 10 $ foldMapWith f return [1..10])
144+ (toList $ drop 0 $ foldMapWith f return [1..10])
145+ `shouldReturn` [1..10]
147+ (toList $ drop 5 $ foldMapWith f return [1..10])
148+ `shouldReturn` [6..10]
126 it "Alternative composition of async and sync tasks" $
151 it "Alternative composition of async and sync tasks" $
127 ((wait (threads 0 ((async (return 0) <|> return 1)))) >>= return . sort)
152 ((wait (threads 0 ((async (return 0) <|> return 1)))) >>= return . sort)