summaryrefslogtreecommitdiff
path: root/Control
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-12-24 14:24:16 -0500
committerBen Sima <ben@bsima.me>2020-12-24 14:24:16 -0500
commit6eaaf3d8ce6025932990de6fa697d14c9651be76 (patch)
tree65ca4a0dd0393db98d9a6067bbbef789469e8122 /Control
parent6a4a8aa37044d578c95dea145b9605908b8dc28d (diff)
linting fixes and cleanup
Diffstat (limited to 'Control')
-rw-r--r--Control/Concurrent/Go.hs27
-rw-r--r--Control/Concurrent/Sema.hs2
2 files changed, 14 insertions, 15 deletions
diff --git a/Control/Concurrent/Go.hs b/Control/Concurrent/Go.hs
index 69d35b8..92444f4 100644
--- a/Control/Concurrent/Go.hs
+++ b/Control/Concurrent/Go.hs
@@ -30,17 +30,16 @@ import Data.Text (Text)
import qualified System.IO.Unsafe as Unsafe
-- | A standard channel.
-data Channel a
- = Channel
- { _in :: Chan.InChan a,
- _out :: Chan.OutChan a,
- _size :: Int
- }
+data Channel a = Channel
+ { _in :: Chan.InChan a,
+ _out :: Chan.OutChan a,
+ _size :: Int
+ }
instance Aeson.ToJSON (Channel a) where
toJSON c = Aeson.String ("#<channel " <> len c <> ">" :: Text)
where
- len = show . Unsafe.unsafePerformIO . Chan.estimatedLength . _in
+ len = show <. Unsafe.unsafePerformIO <. Chan.estimatedLength <. _in
-- | Starts a background process.
fork :: IO () -> IO Concurrent.ThreadId
@@ -58,26 +57,26 @@ type Mult a = Chan.OutChan a
-- | Duplicates a channel, but then anything written to the source will
-- be available to both. This is like Clojure's `core.async/mult`
mult :: Channel a -> IO (Mult a)
-mult = Chan.dupChan . _in
+mult = Chan.dupChan <. _in
-- | Read a value from a 'Mult'. This is like Clojure's `core.async/tap`.
--
-- You can use this to read from a channel in a background process, e.g.:
--
-- >>> c <- Go.chan
--- >>> Go.fork . forever <| Go.mult c >>= Go.tap >>= print
+-- >>> Go.fork <. forever <| Go.mult c >>= Go.tap >>= print
tap :: Mult a -> IO a
tap = Chan.readChan
-- | Take from a channel. Blocks until a value is received.
read :: Channel a -> IO a
-read = Chan.readChan . _out
+read = Chan.readChan <. _out
-- | Write to a channel. Blocks if the channel is full.
write :: Channel a -> a -> IO Bool
-write = Chan.tryWriteChan . _in
+write = Chan.tryWriteChan <. _in
--- $example
+-- <|example
--
-- A simple example from ghci:
--
@@ -94,9 +93,9 @@ write = Chan.tryWriteChan . _in
-- >>> Go.read c
-- "hi"
-- >>> Go.fork
--- >>> Go.fork $ forever $ Go.mult c >>= Go.tap >>= \t -> print ("one: " <> t)
+-- >>> Go.fork <| forever <| Go.mult c >>= Go.tap >>= \t -> print ("one: " <> t)
-- ThreadId 810
--- >>> Go.fork $ forever $ Go.mult c >>= Go.tap >>= \t -> print ("two: " <> t)
+-- >>> Go.fork <| forever <| Go.mult c >>= Go.tap >>= \t -> print ("two: " <> t)
-- ThreadId 825
-- >>> Go.write c "test"
-- "two: t"eosnte":
diff --git a/Control/Concurrent/Sema.hs b/Control/Concurrent/Sema.hs
index 5b32bab..c105cf8 100644
--- a/Control/Concurrent/Sema.hs
+++ b/Control/Concurrent/Sema.hs
@@ -9,4 +9,4 @@ import qualified Control.Concurrent.MSem as Sem
mapPool :: Traversable t => Int -> (a -> IO b) -> t a -> IO (t b)
mapPool n f xs = do
sima <- Sem.new n
- mapConcurrently (Sem.with sima . f) xs
+ mapConcurrently (Sem.with sima <. f) xs