winteryoung
12/31/2015, 5:15 AMoperator fun <T> List<T>.get(index: Int) = this.getx(index)
fun <T> List<T>.getx(index: Int): T {
val i = xindex(index)
return this[i]
}
private fun <T> List<T>.xindex(index: Int): Int {
val i = if (index < 0) {
this.size + index
} else {
index
}
return i
}
fun <T> MutableList<T>.setx(index: Int, value: T) {
this[xindex(index)] = value
}
If define List.get like above, code like list[-1]
still won't work