box-0.9.3.1: A profunctor effect system.
Safe HaskellSafe-Inferred
LanguageGHC2021

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

stdBox :: Text -> Box IO Text Text Source #

A Box to and from std, with an escape phrase.

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.

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 #

Emit from a file.

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

Commit to a file.

fileEText :: FilePath -> BufferMode -> CoEmitter IO Text Source #

Emit lines of Text from a file.

fileEBS :: FilePath -> BufferMode -> CoEmitter IO ByteString Source #

Emit lines of ByteString from a file.

fileCText :: FilePath -> BufferMode -> IOMode -> CoCommitter IO Text Source #

Commit Text to a file, as a line.

fileCBS :: FilePath -> BufferMode -> IOMode -> CoCommitter IO ByteString Source #

Commit ByteString to a file, as a line.

toLineBox :: Text -> Box IO ByteString ByteString -> CoBox IO Text Text Source #

Convert a Box from ByteString to lines of Text.

fromLineBox :: Text -> Box IO Text Text -> Box IO ByteString ByteString Source #

Convert a Box from lines of Text to ByteStrings.

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