on master help sign in
Add semigroup instance
ccc9655Harendra Kumar
src/Asyncly.hs+2−2
@@ -144,7 +144,7 @@ module Asyncly
144
144
145 -- * Re-exports
145 -- * Re-exports
146 , Monoid (..)
146 , Monoid (..)
147− , (<>)
147+ , Semigroup (..)
148 , Alternative (..)
148 , Alternative (..)
149 , MonadPlus (..)
149 , MonadPlus (..)
150 , MonadIO (..)
150 , MonadIO (..)
@@ -153,7 +153,7 @@ module Asyncly
153where
153where
154
154
155import Asyncly.AsyncT
155import Asyncly.AsyncT
156−import Data.Monoid ((<>))
156+import Data.Semigroup (Semigroup(..))
157import Control.Applicative (Alternative(..))
157import Control.Applicative (Alternative(..))
158import Control.Monad (MonadPlus(..))
158import Control.Monad (MonadPlus(..))
159import Control.Monad.IO.Class (MonadIO (..))
159import Control.Monad.IO.Class (MonadIO (..))
src/Asyncly/AsyncT.hs+8−4
@@ -61,7 +61,7 @@ import Data.IORef (IORef, modifyIORef, newIORef,
61import Data.Atomics (atomicModifyIORefCAS,
61import Data.Atomics (atomicModifyIORefCAS,
62 atomicModifyIORefCAS_)
62 atomicModifyIORefCAS_)
63import Data.Maybe (isNothing)
63import Data.Maybe (isNothing)
64−import Data.Monoid ((<>))
64+import Data.Semigroup (Semigroup(..))
65import Data.Set (Set)
65import Data.Set (Set)
66import qualified Data.Set as S
66import qualified Data.Set as S
67import Prelude hiding (take, drop)
67import Prelude hiding (take, drop)
@@ -118,14 +118,18 @@ type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
118------------------------------------------------------------------------------
118------------------------------------------------------------------------------
119
119
120-- | Appends the results of two AsyncT computations in order.
120-- | Appends the results of two AsyncT computations in order.
121−instance Monad m => Monoid (AsyncT m a) where
121+instance Semigroup (AsyncT m a) where
122− mempty = AsyncT $ \_ stp _ -> stp
123− mappend (AsyncT m1) m2 = AsyncT $ \ctx stp yld ->
122+ (AsyncT m1) <> m2 = AsyncT $ \ctx stp yld ->
124 let stop = (runAsyncT m2) ctx stp yld
123 let stop = (runAsyncT m2) ctx stp yld
125 yield a c Nothing = yld a c (Just m2)
124 yield a c Nothing = yld a c (Just m2)
126 yield a c (Just r) = yld a c (Just (mappend r m2))
125 yield a c (Just r) = yld a c (Just (mappend r m2))
127 in m1 ctx stop yield
126 in m1 ctx stop yield
128
127
128+-- | Appends the results of two AsyncT computations in order.
129+instance Monoid (AsyncT m a) where
130+ mempty = AsyncT $ \_ stp _ -> stp
131+ mappend = (<>)
132+
129-- | Interleaves the results of two 'AsyncT' streams
133-- | Interleaves the results of two 'AsyncT' streams
130interleave :: AsyncT m a -> AsyncT m a -> AsyncT m a
134interleave :: AsyncT m a -> AsyncT m a -> AsyncT m a
131interleave m1 m2 = AsyncT $ \ctx stp yld -> do
135interleave m1 m2 = AsyncT $ \ctx stp yld -> do