interact package:base

interact f takes the entire input from stdin and applies f to it. The resulting string is written to the stdout device. Note that this operation is lazy, which allows to produce output even before all input has been consumed. This operation may fail with the same errors as getContents and putStr.

Examples

>>> interact (\str -> str ++ str)
> hi :)
hi :)
> ^D
hi :)
>>> interact (const ":D")
:D
>>> interact (show . words)
> hello world!
> I hope you have a great day
> ^D
["hello","world!","I","hope","you","have","a","great","day"]