on master help sign in
Add semigroup instance
commitccc96551a4d39db2ce6a59ea2607203328b8c1e2 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 7 Sep 2017, 20:32 (9 years ago) parent8213fe2
2 files changed+10−6
src/Asyncly.hs+2−2 src/Asyncly/AsyncT.hs+8−4
src/Asyncly.hs+2−2
@@ -144,7 +144,7 @@ module Asyncly
144144
145145 -- * Re-exports
146146 , Monoid (..)
147− , (<>)
147+ , Semigroup (..)
148148 , Alternative (..)
149149 , MonadPlus (..)
150150 , MonadIO (..)
@@ -153,7 +153,7 @@ module Asyncly
153153where
154154
155155import Asyncly.AsyncT
156−import Data.Monoid ((<>))
156+import Data.Semigroup (Semigroup(..))
157157import Control.Applicative (Alternative(..))
158158import Control.Monad (MonadPlus(..))
159159import Control.Monad.IO.Class (MonadIO (..))
src/Asyncly/AsyncT.hs+8−4
@@ -61,7 +61,7 @@ import Data.IORef (IORef, modifyIORef, newIORef,
6161import Data.Atomics (atomicModifyIORefCAS,
6262 atomicModifyIORefCAS_)
6363import Data.Maybe (isNothing)
64−import Data.Monoid ((<>))
64+import Data.Semigroup (Semigroup(..))
6565import Data.Set (Set)
6666import qualified Data.Set as S
6767import Prelude hiding (take, drop)
@@ -118,14 +118,18 @@ type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
118118------------------------------------------------------------------------------
119119
120120-- | Appends the results of two AsyncT computations in order.
121−instance Monad m => Monoid (AsyncT m a) where
122− mempty = AsyncT $ \_ stp _ -> stp
123− mappend (AsyncT m1) m2 = AsyncT $ \ctx stp yld ->
121+instance Semigroup (AsyncT m a) where
122+ (AsyncT m1) <> m2 = AsyncT $ \ctx stp yld ->
124123 let stop = (runAsyncT m2) ctx stp yld
125124 yield a c Nothing = yld a c (Just m2)
126125 yield a c (Just r) = yld a c (Just (mappend r m2))
127126 in m1 ctx stop yield
128127
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+
129133-- | Interleaves the results of two 'AsyncT' streams
130134interleave :: AsyncT m a -> AsyncT m a -> AsyncT m a
131135interleave m1 m2 = AsyncT $ \ctx stp yld -> do