Transform sync, async or generator function to Stream. Correctly handle errors and optional arguments.