select!(v, a:b): manually CSE the calls to first(r) and last(r).

Our compiler may or may not be smart enough to eliminate all these
calls, but this also makes the code a little easier to read.