Transform *Array.size to properties
This commit is contained in:
@@ -4,6 +4,6 @@ fun main(args : Array<String>) {
|
||||
var ints : Array<Int?> = arrayOfNulls<Int>(31)
|
||||
|
||||
ints[0] = 4; ints[11] = 5; ints[2] =7
|
||||
for(i in 0..ints.size())
|
||||
for(i in 0..ints.size)
|
||||
ints[i<!SYNTAX!><!>
|
||||
}
|
||||
+2
-2
@@ -2,9 +2,9 @@ package c
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
fun Array<Int>.toIntArray(): IntArray = this.<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>mapTo<!>(IntArray(size()), {it})
|
||||
fun Array<Int>.toIntArray(): IntArray = this.<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>mapTo<!>(IntArray(size), {it})
|
||||
|
||||
fun Array<Int>.toArrayList(): ArrayList<Int> = this.mapTo(ArrayList<Int>(size()), {it})
|
||||
fun Array<Int>.toArrayList(): ArrayList<Int> = this.mapTo(ArrayList<Int>(size), {it})
|
||||
|
||||
public fun <T, R, C: MutableCollection<in R>> Array<out T>.mapTo(result: C, transform : (T) -> R) : C =
|
||||
throw Exception("$result $transform")
|
||||
|
||||
@@ -22,7 +22,7 @@ fun test() {
|
||||
// ---------------------
|
||||
// copy from kotlin util
|
||||
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size))
|
||||
|
||||
fun <T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
|
||||
@@ -25,7 +25,7 @@ fun test() {
|
||||
|
||||
//------------
|
||||
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size))
|
||||
|
||||
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {
|
||||
return mapTo(java.util.ArrayList<R>(this.size), transform)
|
||||
|
||||
@@ -27,7 +27,7 @@ fun testSomeFunction() {
|
||||
fun assertEquals(<!UNUSED_PARAMETER!>expected<!>: Any?, <!UNUSED_PARAMETER!>actual<!>: Any?, <!UNUSED_PARAMETER!>message<!>: String = "") {
|
||||
}
|
||||
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size))
|
||||
|
||||
fun <T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
|
||||
@@ -4,7 +4,7 @@ public inline fun <reified T> Array(n: Int, block: (Int) -> T): Array<T> = null!
|
||||
// KT-312 Nullability problem when a nullable version of a generic type is returned
|
||||
|
||||
fun <T> Array<out T>.safeGet(index : Int) : T? {
|
||||
return if (index < size()) this[index] else null
|
||||
return if (index < size) this[index] else null
|
||||
}
|
||||
|
||||
val args : Array<String> = Array<String>(1, {""})
|
||||
|
||||
@@ -17,6 +17,6 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Array<T>.lastIndex() = size() - 1
|
||||
val <T> Array<T>.lastIndex : Int get() = size() - 1
|
||||
fun <T> Array<T>.lastIndex() = size - 1
|
||||
val <T> Array<T>.lastIndex : Int get() = size - 1
|
||||
val <T> Array<T>.indices : IntRange get() = IntRange(0, lastIndex)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// See also KT-7186
|
||||
|
||||
fun IntArray.forEachIndexed( op: (i: Int, value: Int) -> Unit) {
|
||||
for (i in 0..this.size()-1)
|
||||
for (i in 0..this.size)
|
||||
op(i, this[i])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user