summaryrefslogtreecommitdiffstats
path: root/src/Control
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-02-07 18:42:36 +0100
committertv <tv@krebsco.de>2019-02-07 18:54:59 +0100
commitfb5636483871fbafe9b286b377c339c8ddf8b4f8 (patch)
tree5016d6b38bff4b13856828ee385aaf7498d8e344 /src/Control
initial commitv1.0.0-rc1
Diffstat (limited to 'src/Control')
-rw-r--r--src/Control/Concurrent/Extended.hs24
-rw-r--r--src/Control/Monad/Extended.hs14
2 files changed, 38 insertions, 0 deletions
diff --git a/src/Control/Concurrent/Extended.hs b/src/Control/Concurrent/Extended.hs
new file mode 100644
index 0000000..933e3a6
--- /dev/null
+++ b/src/Control/Concurrent/Extended.hs
@@ -0,0 +1,24 @@
+module Control.Concurrent.Extended
+ ( module Exports
+ , newChan
+ , newRef
+ , newRelay
+ , newSemaphore
+ ) where
+
+import Control.Arrow
+import Control.Concurrent as Exports hiding (newChan,readChan,writeChan)
+import qualified Control.Concurrent.Chan.Unagi as U
+import Data.IORef
+
+newChan :: IO (a -> IO (), IO a)
+newChan = (U.writeChan *** U.readChan) <$> U.newChan
+
+newRef :: a -> IO (a -> IO (), IO a)
+newRef v0 = (atomicWriteIORef &&& readIORef) <$> newIORef v0
+
+newRelay :: IO (a -> IO (), IO a)
+newRelay = (putMVar &&& takeMVar) <$> newEmptyMVar
+
+newSemaphore :: IO (IO (), IO ())
+newSemaphore = first ($()) <$> newRelay
diff --git a/src/Control/Monad/Extended.hs b/src/Control/Monad/Extended.hs
new file mode 100644
index 0000000..d91b12c
--- /dev/null
+++ b/src/Control/Monad/Extended.hs
@@ -0,0 +1,14 @@
+module Control.Monad.Extended
+ ( module Control.Monad
+ , unlessM_
+ , untilM_
+ ) where
+
+import Control.Monad
+
+
+unlessM_ :: Monad m => m Bool -> m () -> m ()
+unlessM_ p f = p >>= flip unless f
+
+untilM_ :: Monad m => m Bool -> m a -> m ()
+untilM_ p f = unlessM_ p (f >> untilM_ p f)