From 6eaaf3d8ce6025932990de6fa697d14c9651be76 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Thu, 24 Dec 2020 14:24:16 -0500 Subject: linting fixes and cleanup --- Control/Concurrent/Go.hs | 27 +++++++++++++-------------- Control/Concurrent/Sema.hs | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'Control/Concurrent') 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 ("# 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 -- cgit v1.2.3