on master help sign in
Make monoid instance append two computations in order

Conflicts: test/Main.hs

commit550eed458fdf6e550534606b4679d1e1a04f23fc authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 14 Aug 2017, 15:44 (9 years ago) parentef006c8
2 files changed+7−3
src/Asyncly/AsyncT.hs+4−3 test/Main.hs+3
src/Asyncly/AsyncT.hs+4−3
@@ -281,9 +281,10 @@ instance MonadAsync m => MonadPlus (AsyncT m) where
281281 mzero = empty
282282 mplus = (<|>)
283283
284−instance (Monoid a, Monad m) => Monoid (AsyncT m a) where
285− mappend x y = mappend <$> x <*> y
286− mempty = return mempty
284+-- | Appends the results of two AsyncT computations in order.
285+instance MonadAsync m => Monoid (AsyncT m a) where
286+ mempty = empty
287+ mappend x y = serially x y
287288
288289------------------------------------------------------------------------------
289290-- Num
test/Main.hs+3
@@ -3,6 +3,7 @@ module Main (main) where
33import Asyncly
44import Control.Applicative ((<|>))
55import Control.Concurrent (myThreadId, threadDelay)
6+import Data.Monoid ((<>))
67import Control.Monad.IO.Class (liftIO)
78import Data.List (nub, sort)
89import Test.Hspec
@@ -23,6 +24,8 @@ main = hspec $ do
2324 toList (return 1 >> return 2) `shouldReturn` ([2] :: [Int])
2425 it "Bind and toList" $
2526 toList (do x <- return 1; y <- return 2; return (x + y)) `shouldReturn` ([3] :: [Int])
27+ it "Monoid composition" $
28+ toList (return 0 <> return 1) `shouldReturn` ([0, 1] :: [Int])
2629 it "Alternative composition" $
2730 ((toList $ (return 0 <|> return 1)) >>= return . sort) `shouldReturn` ([0, 1] :: [Int])
2831 {-