Isaias Barroso (2) [Avatar] Offline
Hi Debasish,

I'm thinking about what would be a better way to pass Context Values between layers, for example: I need to get the logged user information on the Controller of a Web Application and use these informations at Repository to update audit fields of a table. I could add a parameter and manually pass the context for other layers, but I would like to know if you suggest some generic structure in a functional way. I'm thinking about Reader, but I don't know if it is the simpler way.

Debasish Ghosh (116) [Avatar] Offline
You are thinking along right lines - the Reader monad is the way to go. And in case you want to handle reading of context values and using it to update state, there's a more powerful abstraction in scalaz, called ReaderWriterState. has an example. But if you just want to pass context for reading, Reader monad should just be fine.

Isaias Barroso (2) [Avatar] Offline
Hi Debasish,

I'll follow in this line. I think using Reader will be nice because I'll remove some spaghetti code in favour of for comprehension.

Thanks and congrats by the book