| | 21 | |
| | 22 | A coroutine parameterized by this functor is a generator which yields a value every time it suspends. For example, the following function generates the program's command-line arguments: |
| | 23 | |
| | 24 | {{{ |
| | 25 | genArgs :: Coroutine (Yield String) IO () |
| | 26 | genArgs = getArgs >>= mapM_ yield |
| | 27 | }}} |
| | 28 | |
| | 29 | The `Await` functor is dual to `Yield`; a coroutine that suspends using this functor is a consumer coroutine that on every suspension expects to be given a value before it resumes. The following example is a consumer coroutine that prints every received value to standard output: |
| | 30 | |
| | 31 | {{{ |
| | 32 | printer :: Show x => Coroutine (Await x) IO () |
| | 33 | printer = await >>= print >> printer |
| | 34 | }}} |