hi All,
I have been using the scalaz-seven library in a project I am working on, and have often found the need to build up types like Kleisli[IO,Env,Validation[String,StatusMessage]], which to me (who is quite the newbie here!) basically means to read some stuff from the Env, and do a little IO that may result in a success or failure. I don't know if this is a common construct, since I don't have much practice yet using scalaz, but I am finding it tricky to get guys like these to compose the way I would like.
To provide a more concrete example:
def foo: Kleisli[Option,Env,String]
def bar: String => Kleisli[IO,Env,Validation[String,StatusMessage]]
def snaz: StatusMessage => Validation[String,String]
def run: Kleisli[IO,Env,Validation[String,String]] =
// some magic to take foo to bar to snaz
So I would have some run function that would use the above functions to take the resulting String in the Option from foo and pass it to bar, then take the StatusMessage from bar and pass it to snaz, where the return type of this run function would end up as: Kleisli[IO,Env,Validation[String,String]]. Maybe this isn't making a lot of sense, or seems rather contrived, but what I am most curious about is how to properly structure this kind of code so that it can compose together. Because really what I want to achieve is composing foo, bar, and snaz, but be able to do so with the Monads layered over top.
Is the above just incorrect, is there something I am just missing, or would it be more common to do all of the Env reading up-front so that, for instance, the foo and bar functions didn't have to know about the Env? I realize this may completely depend on the context of the program, but I want to get a sense of how to generally tackle problems like these. Any suggestions, feedback, or simple examples would be great! And if there is something that needs clarification, please just let me know.
Thanks!
-Eric