File: Extended.hs

package info (click to toggle)
patat 0.15.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,196 kB
  • sloc: haskell: 4,120; makefile: 86; xml: 22; sh: 17
file content (15 lines) | stat: -rw-r--r-- 464 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Control.Concurrent.Chan.Extended
    ( module Control.Concurrent.Chan
    , withMapChan
    ) where

import qualified Control.Concurrent.Async as Async
import           Control.Concurrent.Chan
import           Control.Monad            (forever)

withMapChan :: (a -> b) -> Chan a -> (Chan b -> IO r) -> IO r
withMapChan f chan cont = do
    new <- newChan
    Async.withAsync
        (forever $ readChan chan >>= writeChan new . f)
        (\_ -> cont new)