The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

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