Isaias Barroso (2) [Avatar] Offline
#1
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.

Thanks
Debasish Ghosh (113) [Avatar] Offline
#2
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. http://stackoverflow.com/questions/30152019/scalaz-lens-to-readerwriterstate/30153427#30153427 has an example. But if you just want to pass context for reading, Reader monad should just be fine.

Thanks.
Isaias Barroso (2) [Avatar] Offline
#3
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