generalize first/last for indexed seq