Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That only works if you're ranging from 0 to n-1, though.

A popular way to partition an array at i and j is to do:

    arr[0..<i], arr[i..<j], arr[j...-1]


  a0,a1,a2 = arr.splitat({i,j})
maybe? It avoids repeating i and j twice and arr thrice, at least. Admittedly, there probably are cases where you really do want a range [x..^y] for arbitrary x and y, but it seems like most cases aren't.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: