【发布时间】:2014-01-16 00:48:41
【问题描述】:
假设我正在编写一个程序,它读取一些输入,处理它并写入输出。
假设我也有一个函数def process(input: MyInput): MyOutput
现在我应该使用 Reader monad 作为输入。
def readAndProcess(reader: MyReader[MyInput]): MyReader[MyOutput] = for(in到目前为止,一切都很好,但现在我需要在某处写输出。也就是说,我需要一个
Writermonad 并且可以定义一个函数readProcessAndWritedef readProcessAndWrite(reader: MyReader[MyInput]): MyWriter[MyOutput]假设我有一个函数
def write(out: MyOutput, writer: MyWriter[MyOutput]) : MyWriter[MyOutput]如何定义
def readProcessAndWrite(阅读器:MyReader[MyInput], 作家:MyWriter[MyOutput]):MyWriter[MyOutput] = ... ???readProcessAndWrite?
【问题讨论】:
标签: scala io functional-programming monads