pipes-cliff-0.2.0.0: Streaming to and from subprocesses using Pipes

Safe HaskellSafe-Inferred
LanguageHaskell2010

Pipes.Cliff.Examples

Description

Examples using Pipes.Cliff. You will want to look at the source code itself; viewing just the Haddocks will not help you much. You can view the source using Haddock if you used --hyperlink-source when building the library or if you are viewing this on Hackage; look for the Source link. Or, you can find the source at

https://github.com/massysett/pipes-cliff/blob/master/lib/Pipes/Cliff/Examples.hs

Be sure to use the -threaded option when compiling code that uses Pipes.Cliff, including this code; see the warning in Pipes.Cliff for more details.

Synopsis

Documentation

numsToLess :: IO ExitCode Source

Streams an infinite list of numbers to less. The Effect that streams values to the process is run in the background by using conveyor, even though there is only one subprocess. This is typically what you want. Shows off how you can use Pipes.Cliff even for non-finite Producers. Don't try to go to the end of the input in less, though. When you quit less, you will get broken pipe warnings printed to standard error. This is normal. To suppress them, see the quiet option.

alphaNumbers :: IO ExitCode Source

Streams an infinite list of numbers to tr and then to less. Perfectly useless, but shows how to build pipelines. Notice how the components of the pipeline are run in the background using conveyor; if you run one of them in the foreground, you might get a deadlock.

produceNumbers :: Monad m => Producer ByteString m () Source

Produces a stream of ByteString, where each ByteString is a shown integer.

limitedAlphaNumbers :: IO ExitCode Source

Like alphaNumbers but just sends a limited number of numbers to cat. A useful test to make sure that pipelines shut down automatically.

alphaNumbersByteString :: IO ByteString Source

Produces a finite list of numbers, sends it to tr for some mangling, and then puts the results into a ByteString for further processing. Unlike previous examples, there is no use of waitForProcess or conveyor. This is OK because the Effect that retrieves the results from tr will pull all the data; the tr process will then shut down because its standard input will be closed when the source Producer is exhausted. This example shows how you can use this library to place the results of a pipeline into a simple strict data type.

When the SafeT computation completes, a terminateProcess is automatically sent to the tr process--which does nothing, as tr has already died. Only after the process is waited for is it fully removed from the system process table. A waitForProcess from System.Process is automatically done as well. Therefore, you will not get zombie processes if you use this library.