Compositional zooming for StateT and ReaderT using lens

Posted on September 4, 2018

Consider writing updates in a state monad where the state contains deeply nested structures. As our running example we will consider a state containing multiple “wallets”, where each wallet has multiple “accounts”, and each account has multiple “addresses”. Suppose we want to write an update that changes one of the fields in a particular address. If the address cannot be found, we want a precise error message that distinguishes between the address itself not being found, or one of its parents (the account, or the wallet) not being found. In this blog post we will show how we can develop some composable abstractions that will help with writing code like this in a concise manner.

Read more at well-typed.com