box-0.9.0: boxes
Safe HaskellSafe-Inferred
LanguageHaskell2010

Box.IO

Description

IO effects

Synopsis

Documentation

fromStdin :: Emitter IO Text Source #

Emit text from stdin

λ> emit fromStdin
hello
Just "hello"

toStdout :: Committer IO Text Source #

Commit to stdout

>>> commit toStdout ("I'm committed!" :: Text)
I'm committed!
True

fromStdinN :: Int -> CoEmitter IO Text Source #

Finite console emitter

λ> toListM <$|> fromStdinN 2
hello
hello again
["hello","hello again"]

toStdoutN :: Int -> CoCommitter IO Text Source #

Finite console committer

glue <$> contramap (pack . show) <$> (toStdoutN 2) <*|> qList [1..3]

1 2

readStdin :: Read a => Emitter IO a Source #

Read from console, throwing away read errors

λ> glueN 2 showStdout (readStdin :: Emitter IO Int) 1 1 hippo 2 2

showStdout :: Show a => Committer IO a Source #

Show to stdout

>>> glue showStdout <$|> qList [1..3]
1
2
3

refCommitter :: IO (Committer IO a, IO [a]) Source #

Commit to an IORef

>>> (c1,l1) <- refCommitter :: IO (Committer IO Int, IO [Int])
>>> glue c1 <$|> qList [1..3]
>>> l1
[1,2,3]

refEmitter :: [a] -> IO (Emitter IO a) Source #

Emit from a list IORef

>>> e <- refEmitter [1..3]
>>> toListM e
[1,2,3]

handleE :: (IsString a, Eq a) => (Handle -> IO a) -> Handle -> Emitter IO a Source #

Emits lines of Text from a handle. handleEText = handleE Text.hGetLine

Emits lines of Text from a handle.

handleC :: (Handle -> a -> IO ()) -> Handle -> Committer IO a Source #

Commit lines of Text to a handle.

fileE :: FilePath -> BufferMode -> IOMode -> (Handle -> Emitter IO a) -> CoEmitter IO a Source #

Commit lines of Text to a handle. handleCBS = handleC Char8.hPutStrLn

Emits lines of Text from a handle. handleCText = handleC Text.hPutStrLn

Emit lines of Text from a file.

fileC :: FilePath -> IOMode -> BufferMode -> (Handle -> Committer IO a) -> CoCommitter IO a Source #

Commit lines of Text to a file.

logConsoleC :: Show a => String -> Committer IO a -> Committer IO a Source #

simple console logger for rough testing

logConsoleE :: Show a => String -> Emitter IO a -> Emitter IO a Source #

simple console logger for rough testing

pauser :: Emitter IO Bool -> Emitter IO a -> Emitter IO a Source #

Pause an emitter based on a Bool emitter

changer :: Eq a => a -> Emitter IO a -> CoEmitter IO Bool Source #

Create an emitter that indicates when another emitter has changed.

quit :: Emitter IO Bool -> IO a -> IO (Either Bool a) Source #

quit a process based on a Bool emitter

quit <$> speedEffect (pure 2) <$> (resetGap 5) <*|> pure io

0 1 2 3 4 Left True

restart :: Emitter IO Bool -> IO a -> IO (Either Bool a) Source #

restart a process if flagged by a Bool emitter