Array#lastIndex property has been added to stdlib

This commit is contained in:
Sergey Lukjanov
2012-04-21 22:22:55 +04:00
parent 75255aebdc
commit 71ef123dc3
2 changed files with 45 additions and 0 deletions
+27
View File
@@ -124,3 +124,30 @@ public inline fun <T> Array<T>.isEmpty() : Boolean = this.size == 0
/** Returns the array if its not null or else returns an empty array */
public inline fun <T> Array<T>?.orEmpty() : Array<T> = if (this != null) this else array<T>()
public inline val BooleanArray.lastIndex : Int
get() = this.size - 1
public inline val ByteArray.lastIndex : Int
get() = this.size - 1
public inline val ShortArray.lastIndex : Int
get() = this.size - 1
public inline val IntArray.lastIndex : Int
get() = this.size - 1
public inline val LongArray.lastIndex : Int
get() = this.size - 1
public inline val FloatArray.lastIndex : Int
get() = this.size - 1
public inline val DoubleArray.lastIndex : Int
get() = this.size - 1
public inline val CharArray.lastIndex : Int
get() = this.size - 1
public inline val <in T: Any?> Array<T>.lastIndex : Int
get() = this.size - 1