Skip to content

Instantly share code, notes, and snippets.

@MgaMPKAy
Created June 16, 2012 13:18
Show Gist options
  • Save MgaMPKAy/2941316 to your computer and use it in GitHub Desktop.
Save MgaMPKAy/2941316 to your computer and use it in GitHub Desktop.
import Control.Monad
type Reciver a = [a] -> IO ()
type Sender a = [a]
sender :: Int -> Sender Int
sender n = n : sender (n + 1)
printer :: Show a => Reciver a
printer = mapM_ print
ignore :: Reciver a
ignore _ = return ()
growth :: Show a => Reciver a
growth = mapM_ (putStrLn . concat . (replicate 2) . show)
split :: [Reciver a] -> Sender a -> IO ()
split recvers [] = return ()
split recvers (x:xs) = forM_ recvers (\r -> r [x]) >> split recvers xs
main = sender 1 |> take 10 |> split [printer, ignore, growth]
x |> f = f x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment