Suppose I am writing a program, which reads some input, processes it and writes the output.
Suppose also I have a function def process(input: MyInput): MyOutput
Now I should use a Reader
monad for the input.
def readAndProcess(reader: MyReader[MyInput]): MyReader[MyOutput] = for(in <- reader) yield process(in)
So far, so good but now I need to write the output somewhere. That is, I need a Writer
monad and can define a function readProcessAndWrite
def readProcessAndWrite(reader: MyReader[MyInput]): MyWriter[MyOutput]
Suppose I have a function
def write(out: MyOutput, writer: MyWriter[MyOutput]) : MyWriter[MyOutput]
How can I define readProcessAndWrite
?
def readProcessAndWrite(reader: MyReader[MyInput], writer: MyWriter[MyOutput]): MyWriter[MyOutput] = ... ???