The first case is canonical and often pointed to, but I find it problematic in many cases.
Mentoring is always a good goal but I think that for real development work, if there is a large disparity between the skillsets it can lead to the more experienced engineer becoming frustrated and essentially feeling less productive (as the mentoree is not contributing much in the way of actual implementation). Similarly, it can be like drinking from a fire hose or the less experienced person.
So while it is an effective technique in some cases, it is (in my experience) quite domain and problem specific, and if the gap in skills is too large, it simply does not work well.
The second example you give is where it really can stand out though, in the spirit of the first example as well; bringing a second experienced dev up to speed in the first dev's domain.