Handling multiple IO operations that return optional values
Here's how your pseudocode can be rewritten with bounded indentation using MaybeT.

action state pool (Authenticated _) id = cached &lt;|&gt; retrieve &lt;|!&gt; throwError err404 where
  cached = snd &lt;$&gt; MaybeT (find id &lt;$&gt; fromState state)
  retrieve = do 
    doc &lt;- performOp &lt;$&gt; MaybeT (getDocumentFromId id pool)
    _ &lt;- lift $ saveToState state doc
    return doc

infix 2 &lt;|!&gt;
(&lt;|!&gt;) :: Monad m =&gt; MaybeT m a -&gt; m a -&gt; m a
mx &lt;|!&gt; y = runMaybeT mx &gt;&gt;= maybe y pure