The closest thing to what you are asking is probably Haskell's do notation, which lets you write code that resembles sequences of imperative steps, then translates them internally to a monadic expression. If you use a free monad, you can then create an interpreter for that expression that does what you want with it.
Another idea that comes very close to what you are asking, especially the deep nesting part, is lenses. Lenses are difficult to explain concisely, but have the same semantics of creating something that resembles an imperative mutation to the programmer, but that performs a pure operation under the hood.