@@ -7,6 +7,7 @@ import Control.Monad.IO.Class (liftIO)
77-- import Data.List (nub)
88import Data.List (sort)
99import Data.Monoid ((<>))
10+import Prelude hiding (take, drop)
1011import Test.Hspec
1112
1213import Asyncly
@@ -42,6 +43,8 @@ main = hspec $ do
4243 describe "Left Biased parallel loops (<|)" $ loops (<|) sort sort
4344 describe "Fair parallel loops (<|>)" $ loops (<|>) sort sort
4445
46+ describe "Transformation" $ transformOps (<>)
47+
4548bind :: Spec
4649bind = do
4750 it "Simple runAsyncly and 'then' with IO" $
@@ -122,6 +125,28 @@ loops f tsrt hsrt = do
122125 liftIO $ putStrLn "LoopTail..."
123126 return x `f` (if x < 3 then loopTail (x + 1) else empty)
124127
128+transformOps :: (AsyncT IO Int -> AsyncT IO Int -> AsyncT IO Int) -> Spec
129+transformOps f = do
130+ it "take all" $
131+ (toList $ take 10 $ foldMapWith f return [1..10])
132+ `shouldReturn` [1..10]
133+ it "take none" $
134+ (toList $ take 0 $ foldMapWith f return [1..10])
135+ `shouldReturn` []
136+ it "take 5" $
137+ (toList $ take 5 $ foldMapWith f return [1..10])
138+ `shouldReturn` [1..5]
139+
140+ it "drop all" $
141+ (toList $ drop 10 $ foldMapWith f return [1..10])
142+ `shouldReturn` []
143+ it "drop none" $
144+ (toList $ drop 0 $ foldMapWith f return [1..10])
145+ `shouldReturn` [1..10]
146+ it "drop 5" $
147+ (toList $ drop 5 $ foldMapWith f return [1..10])
148+ `shouldReturn` [6..10]
149+
125150 {-
126151 it "Alternative composition of async and sync tasks" $
127152 ((wait (threads 0 ((async (return 0) <|> return 1)))) >>= return . sort)