Variance in functions/properties removed from stdlib

This commit is contained in:
Andrey Breslav
2012-11-22 13:58:27 +04:00
parent 12fd07af08
commit 5b93ae2d08
40 changed files with 103 additions and 103 deletions
+2 -2
View File
@@ -26,12 +26,12 @@ public object Collections {
public fun <K,V> emptyMap(): Map<K,V> = emptyMap as Map<K,V> public fun <K,V> emptyMap(): Map<K,V> = emptyMap as Map<K,V>
library library
public fun <in T> sort(list: List<T>): Unit { public fun <T> sort(list: MutableList<T>): Unit {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
library("sortWithComp") library("sortWithComp")
public fun <in T> sort(list: List<T>, comparator: java.util.Comparator<T>): Unit { public fun <T> sort(list: MutableList<T>, comparator: java.util.Comparator<T>): Unit {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
@@ -248,7 +248,7 @@ public inline fun <T, C: MutableCollection<in T>> Array<T>.takeWhileTo(result: C
} }
/** Copies all elements into the given collection */ /** Copies all elements into the given collection */
public inline fun <in T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C { public inline fun <T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C {
for (element in this) result.add(element) for (element in this) result.add(element)
return result return result
} }
@@ -265,16 +265,16 @@ public inline fun <T> Array<T>.reverse() : List<T> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun <in T> Array<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>()) public inline fun <T> Array<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun <in T> Array<T>.toList() : List<T> = toCollection(ArrayList<T>()) public inline fun <T> Array<T>.toList() : List<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun <in T> Array<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>()) public inline fun <T> Array<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun <in T> Array<T>.toSet() : Set<T> = toCollection(HashSet<T>()) public inline fun <T> Array<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun <in T> Array<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>()) public inline fun <T> Array<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -51,7 +51,7 @@ public inline fun <T, R> Array<T>.flatMap(transform: (T)-> Collection<R>) : Coll
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun <in T> Array<T>.plus(element: T): List<in T> { public inline fun <T> Array<T>.plus(element: T): List<T> {
val list = toCollection(ArrayList<T>()) val list = toCollection(ArrayList<T>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun <in T> Array<T>.plus(element: T): List<in T> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun <in T> Array<T>.plus(elements: Array<T>): List<T> { public inline fun <T> Array<T>.plus(elements: Array<T>): List<T> {
val list = toCollection(ArrayList<T>()) val list = toCollection(ArrayList<T>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun <in T> Array<T>.plus(elements: Array<T>): List<T> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun <in T> Array<T?>.requireNoNulls() : List<T> { public inline fun <T> Array<T?>.requireNoNulls() : List<T> {
val list = ArrayList<T>() val list = ArrayList<T>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -265,16 +265,16 @@ public inline fun BooleanArray.reverse() : List<Boolean> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun BooleanArray.toLinkedList() : LinkedList<Boolean> = toCollection(LinkedList<Boolean>()) public inline fun BooleanArray.toLinkedList() : LinkedList<Boolean> = toCollection(LinkedList<Boolean>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun BooleanArray.toList() : List<Boolean> = toCollection(ArrayList<Boolean>()) public inline fun BooleanArray.toList() : List<Boolean> = toCollection(ArrayList<Boolean>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun BooleanArray.toCollection() : Collection<Boolean> = toCollection(ArrayList<Boolean>()) public inline fun BooleanArray.toCollection() : Collection<Boolean> = toCollection(ArrayList<Boolean>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun BooleanArray.toSet() : Set<Boolean> = toCollection(HashSet<Boolean>()) public inline fun BooleanArray.toSet() : Set<Boolean> = toCollection(HashSet<Boolean>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun BooleanArray.toSortedSet() : SortedSet<Boolean> = toCollection(TreeSet<Boolean>()) public inline fun BooleanArray.toSortedSet() : SortedSet<Boolean> = toCollection(TreeSet<Boolean>())
@@ -51,7 +51,7 @@ public inline fun <R> BooleanArray.flatMap(transform: (Boolean)-> Collection<R>)
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun BooleanArray.plus(element: Boolean): List<Boolean> { public inline fun BooleanArray.plus(element: Boolean): List<Boolean> {
val list = toCollection(ArrayList<Boolean>()) val list = toCollection(ArrayList<Boolean>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun BooleanArray.plus(element: Boolean): List<Boolean> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun BooleanArray.plus(elements: BooleanArray): List<Boolean> { public inline fun BooleanArray.plus(elements: BooleanArray): List<Boolean> {
val list = toCollection(ArrayList<Boolean>()) val list = toCollection(ArrayList<Boolean>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun BooleanArray.plus(elements: BooleanArray): List<Boolean> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun BooleanArray.requireNoNulls() : List<Boolean> { public inline fun BooleanArray.requireNoNulls() : List<Boolean> {
val list = ArrayList<Boolean>() val list = ArrayList<Boolean>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -265,16 +265,16 @@ public inline fun ByteArray.reverse() : List<Byte> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun ByteArray.toLinkedList() : LinkedList<Byte> = toCollection(LinkedList<Byte>()) public inline fun ByteArray.toLinkedList() : LinkedList<Byte> = toCollection(LinkedList<Byte>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun ByteArray.toList() : List<Byte> = toCollection(ArrayList<Byte>()) public inline fun ByteArray.toList() : List<Byte> = toCollection(ArrayList<Byte>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun ByteArray.toCollection() : Collection<Byte> = toCollection(ArrayList<Byte>()) public inline fun ByteArray.toCollection() : Collection<Byte> = toCollection(ArrayList<Byte>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun ByteArray.toSet() : Set<Byte> = toCollection(HashSet<Byte>()) public inline fun ByteArray.toSet() : Set<Byte> = toCollection(HashSet<Byte>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun ByteArray.toSortedSet() : SortedSet<Byte> = toCollection(TreeSet<Byte>()) public inline fun ByteArray.toSortedSet() : SortedSet<Byte> = toCollection(TreeSet<Byte>())
@@ -51,7 +51,7 @@ public inline fun <R> ByteArray.flatMap(transform: (Byte)-> Collection<R>) : Col
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun ByteArray.plus(element: Byte): List<Byte> { public inline fun ByteArray.plus(element: Byte): List<Byte> {
val list = toCollection(ArrayList<Byte>()) val list = toCollection(ArrayList<Byte>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun ByteArray.plus(element: Byte): List<Byte> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun ByteArray.plus(elements: ByteArray): List<Byte> { public inline fun ByteArray.plus(elements: ByteArray): List<Byte> {
val list = toCollection(ArrayList<Byte>()) val list = toCollection(ArrayList<Byte>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun ByteArray.plus(elements: ByteArray): List<Byte> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun ByteArray.requireNoNulls() : List<Byte> { public inline fun ByteArray.requireNoNulls() : List<Byte> {
val list = ArrayList<Byte>() val list = ArrayList<Byte>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -265,16 +265,16 @@ public inline fun CharArray.reverse() : List<Char> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun CharArray.toLinkedList() : LinkedList<Char> = toCollection(LinkedList<Char>()) public inline fun CharArray.toLinkedList() : LinkedList<Char> = toCollection(LinkedList<Char>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun CharArray.toList() : List<Char> = toCollection(ArrayList<Char>()) public inline fun CharArray.toList() : List<Char> = toCollection(ArrayList<Char>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun CharArray.toCollection() : Collection<Char> = toCollection(ArrayList<Char>()) public inline fun CharArray.toCollection() : Collection<Char> = toCollection(ArrayList<Char>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun CharArray.toSet() : Set<Char> = toCollection(HashSet<Char>()) public inline fun CharArray.toSet() : Set<Char> = toCollection(HashSet<Char>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun CharArray.toSortedSet() : SortedSet<Char> = toCollection(TreeSet<Char>()) public inline fun CharArray.toSortedSet() : SortedSet<Char> = toCollection(TreeSet<Char>())
@@ -51,7 +51,7 @@ public inline fun <R> CharArray.flatMap(transform: (Char)-> Collection<R>) : Col
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun CharArray.plus(element: Char): List<Char> { public inline fun CharArray.plus(element: Char): List<Char> {
val list = toCollection(ArrayList<Char>()) val list = toCollection(ArrayList<Char>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun CharArray.plus(element: Char): List<Char> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun CharArray.plus(elements: CharArray): List<Char> { public inline fun CharArray.plus(elements: CharArray): List<Char> {
val list = toCollection(ArrayList<Char>()) val list = toCollection(ArrayList<Char>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun CharArray.plus(elements: CharArray): List<Char> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun CharArray.requireNoNulls() : List<Char> { public inline fun CharArray.requireNoNulls() : List<Char> {
val list = ArrayList<Char>() val list = ArrayList<Char>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -265,16 +265,16 @@ public inline fun DoubleArray.reverse() : List<Double> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun DoubleArray.toLinkedList() : LinkedList<Double> = toCollection(LinkedList<Double>()) public inline fun DoubleArray.toLinkedList() : LinkedList<Double> = toCollection(LinkedList<Double>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun DoubleArray.toList() : List<Double> = toCollection(ArrayList<Double>()) public inline fun DoubleArray.toList() : List<Double> = toCollection(ArrayList<Double>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun DoubleArray.toCollection() : Collection<Double> = toCollection(ArrayList<Double>()) public inline fun DoubleArray.toCollection() : Collection<Double> = toCollection(ArrayList<Double>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun DoubleArray.toSet() : Set<Double> = toCollection(HashSet<Double>()) public inline fun DoubleArray.toSet() : Set<Double> = toCollection(HashSet<Double>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun DoubleArray.toSortedSet() : SortedSet<Double> = toCollection(TreeSet<Double>()) public inline fun DoubleArray.toSortedSet() : SortedSet<Double> = toCollection(TreeSet<Double>())
@@ -51,7 +51,7 @@ public inline fun <R> DoubleArray.flatMap(transform: (Double)-> Collection<R>) :
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun DoubleArray.plus(element: Double): List<Double> { public inline fun DoubleArray.plus(element: Double): List<Double> {
val list = toCollection(ArrayList<Double>()) val list = toCollection(ArrayList<Double>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun DoubleArray.plus(element: Double): List<Double> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun DoubleArray.plus(elements: DoubleArray): List<Double> { public inline fun DoubleArray.plus(elements: DoubleArray): List<Double> {
val list = toCollection(ArrayList<Double>()) val list = toCollection(ArrayList<Double>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun DoubleArray.plus(elements: DoubleArray): List<Double> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun DoubleArray.requireNoNulls() : List<Double> { public inline fun DoubleArray.requireNoNulls() : List<Double> {
val list = ArrayList<Double>() val list = ArrayList<Double>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -265,16 +265,16 @@ public inline fun FloatArray.reverse() : List<Float> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun FloatArray.toLinkedList() : LinkedList<Float> = toCollection(LinkedList<Float>()) public inline fun FloatArray.toLinkedList() : LinkedList<Float> = toCollection(LinkedList<Float>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun FloatArray.toList() : List<Float> = toCollection(ArrayList<Float>()) public inline fun FloatArray.toList() : List<Float> = toCollection(ArrayList<Float>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun FloatArray.toCollection() : Collection<Float> = toCollection(ArrayList<Float>()) public inline fun FloatArray.toCollection() : Collection<Float> = toCollection(ArrayList<Float>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun FloatArray.toSet() : Set<Float> = toCollection(HashSet<Float>()) public inline fun FloatArray.toSet() : Set<Float> = toCollection(HashSet<Float>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun FloatArray.toSortedSet() : SortedSet<Float> = toCollection(TreeSet<Float>()) public inline fun FloatArray.toSortedSet() : SortedSet<Float> = toCollection(TreeSet<Float>())
@@ -51,7 +51,7 @@ public inline fun <R> FloatArray.flatMap(transform: (Float)-> Collection<R>) : C
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun FloatArray.plus(element: Float): List<Float> { public inline fun FloatArray.plus(element: Float): List<Float> {
val list = toCollection(ArrayList<Float>()) val list = toCollection(ArrayList<Float>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun FloatArray.plus(element: Float): List<Float> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun FloatArray.plus(elements: FloatArray): List<Float> { public inline fun FloatArray.plus(elements: FloatArray): List<Float> {
val list = toCollection(ArrayList<Float>()) val list = toCollection(ArrayList<Float>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun FloatArray.plus(elements: FloatArray): List<Float> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun FloatArray.requireNoNulls() : List<Float> { public inline fun FloatArray.requireNoNulls() : List<Float> {
val list = ArrayList<Float>() val list = ArrayList<Float>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -265,16 +265,16 @@ public inline fun IntArray.reverse() : List<Int> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun IntArray.toLinkedList() : LinkedList<Int> = toCollection(LinkedList<Int>()) public inline fun IntArray.toLinkedList() : LinkedList<Int> = toCollection(LinkedList<Int>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun IntArray.toList() : List<Int> = toCollection(ArrayList<Int>()) public inline fun IntArray.toList() : List<Int> = toCollection(ArrayList<Int>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun IntArray.toCollection() : Collection<Int> = toCollection(ArrayList<Int>()) public inline fun IntArray.toCollection() : Collection<Int> = toCollection(ArrayList<Int>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun IntArray.toSet() : Set<Int> = toCollection(HashSet<Int>()) public inline fun IntArray.toSet() : Set<Int> = toCollection(HashSet<Int>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun IntArray.toSortedSet() : SortedSet<Int> = toCollection(TreeSet<Int>()) public inline fun IntArray.toSortedSet() : SortedSet<Int> = toCollection(TreeSet<Int>())
@@ -51,7 +51,7 @@ public inline fun <R> IntArray.flatMap(transform: (Int)-> Collection<R>) : Colle
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun IntArray.plus(element: Int): List<Int> { public inline fun IntArray.plus(element: Int): List<Int> {
val list = toCollection(ArrayList<Int>()) val list = toCollection(ArrayList<Int>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun IntArray.plus(element: Int): List<Int> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun IntArray.plus(elements: IntArray): List<Int> { public inline fun IntArray.plus(elements: IntArray): List<Int> {
val list = toCollection(ArrayList<Int>()) val list = toCollection(ArrayList<Int>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun IntArray.plus(elements: IntArray): List<Int> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun IntArray.requireNoNulls() : List<Int> { public inline fun IntArray.requireNoNulls() : List<Int> {
val list = ArrayList<Int>() val list = ArrayList<Int>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -247,7 +247,7 @@ public inline fun <T, C: MutableCollection<in T>> Iterator<T>.takeWhileTo(result
} }
/** Copies all elements into the given collection */ /** Copies all elements into the given collection */
public inline fun <in T, C: MutableCollection<in T>> Iterator<T>.toCollection(result: C) : C { public inline fun <T, C: MutableCollection<in T>> Iterator<T>.toCollection(result: C) : C {
for (element in this) result.add(element) for (element in this) result.add(element)
return result return result
} }
@@ -264,16 +264,16 @@ public inline fun <T> Iterator<T>.reverse() : List<T> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun <in T> Iterator<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>()) public inline fun <T> Iterator<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun <in T> Iterator<T>.toList() : List<T> = toCollection(ArrayList<T>()) public inline fun <T> Iterator<T>.toList() : List<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun <in T> Iterator<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>()) public inline fun <T> Iterator<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun <in T> Iterator<T>.toSet() : Set<T> = toCollection(HashSet<T>()) public inline fun <T> Iterator<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -11,5 +11,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun <in T> Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>()) public inline fun <T> Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -265,16 +265,16 @@ public inline fun LongArray.reverse() : List<Long> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun LongArray.toLinkedList() : LinkedList<Long> = toCollection(LinkedList<Long>()) public inline fun LongArray.toLinkedList() : LinkedList<Long> = toCollection(LinkedList<Long>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun LongArray.toList() : List<Long> = toCollection(ArrayList<Long>()) public inline fun LongArray.toList() : List<Long> = toCollection(ArrayList<Long>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun LongArray.toCollection() : Collection<Long> = toCollection(ArrayList<Long>()) public inline fun LongArray.toCollection() : Collection<Long> = toCollection(ArrayList<Long>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun LongArray.toSet() : Set<Long> = toCollection(HashSet<Long>()) public inline fun LongArray.toSet() : Set<Long> = toCollection(HashSet<Long>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun LongArray.toSortedSet() : SortedSet<Long> = toCollection(TreeSet<Long>()) public inline fun LongArray.toSortedSet() : SortedSet<Long> = toCollection(TreeSet<Long>())
@@ -51,7 +51,7 @@ public inline fun <R> LongArray.flatMap(transform: (Long)-> Collection<R>) : Col
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun LongArray.plus(element: Long): List<Long> { public inline fun LongArray.plus(element: Long): List<Long> {
val list = toCollection(ArrayList<Long>()) val list = toCollection(ArrayList<Long>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun LongArray.plus(element: Long): List<Long> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun LongArray.plus(elements: LongArray): List<Long> { public inline fun LongArray.plus(elements: LongArray): List<Long> {
val list = toCollection(ArrayList<Long>()) val list = toCollection(ArrayList<Long>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun LongArray.plus(elements: LongArray): List<Long> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun LongArray.requireNoNulls() : List<Long> { public inline fun LongArray.requireNoNulls() : List<Long> {
val list = ArrayList<Long>() val list = ArrayList<Long>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -265,16 +265,16 @@ public inline fun ShortArray.reverse() : List<Short> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun ShortArray.toLinkedList() : LinkedList<Short> = toCollection(LinkedList<Short>()) public inline fun ShortArray.toLinkedList() : LinkedList<Short> = toCollection(LinkedList<Short>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun ShortArray.toList() : List<Short> = toCollection(ArrayList<Short>()) public inline fun ShortArray.toList() : List<Short> = toCollection(ArrayList<Short>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun ShortArray.toCollection() : Collection<Short> = toCollection(ArrayList<Short>()) public inline fun ShortArray.toCollection() : Collection<Short> = toCollection(ArrayList<Short>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun ShortArray.toSet() : Set<Short> = toCollection(HashSet<Short>()) public inline fun ShortArray.toSet() : Set<Short> = toCollection(HashSet<Short>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
@@ -12,5 +12,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun ShortArray.toSortedSet() : SortedSet<Short> = toCollection(TreeSet<Short>()) public inline fun ShortArray.toSortedSet() : SortedSet<Short> = toCollection(TreeSet<Short>())
@@ -51,7 +51,7 @@ public inline fun <R> ShortArray.flatMap(transform: (Short)-> Collection<R>) : C
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun ShortArray.plus(element: Short): List<Short> { public inline fun ShortArray.plus(element: Short): List<Short> {
val list = toCollection(ArrayList<Short>()) val list = toCollection(ArrayList<Short>())
list.add(element) list.add(element)
return list return list
@@ -63,7 +63,7 @@ public inline fun ShortArray.plus(element: Short): List<Short> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun ShortArray.plus(elements: ShortArray): List<Short> { public inline fun ShortArray.plus(elements: ShortArray): List<Short> {
val list = toCollection(ArrayList<Short>()) val list = toCollection(ArrayList<Short>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -74,7 +74,7 @@ public inline fun ShortArray.plus(elements: ShortArray): List<Short> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun ShortArray.requireNoNulls() : List<Short> { public inline fun ShortArray.requireNoNulls() : List<Short> {
val list = ArrayList<Short>() val list = ArrayList<Short>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
+1 -1
View File
@@ -33,5 +33,5 @@ public inline val DoubleArray.lastIndex : Int
public inline val CharArray.lastIndex : Int public inline val CharArray.lastIndex : Int
get() = this.size - 1 get() = this.size - 1
public inline val <in T: Any?> Array<T>.lastIndex : Int public inline val <T: Any?> Array<T>.lastIndex : Int
get() = this.size - 1 get() = this.size - 1
+1 -1
View File
@@ -57,7 +57,7 @@ public inline fun FloatArray.fill(value: Float) : Unit = Arrays.fill(this,
public inline fun DoubleArray.fill(value: Double) : Unit = Arrays.fill(this, value) public inline fun DoubleArray.fill(value: Double) : Unit = Arrays.fill(this, value)
public inline fun CharArray.fill(value: Char) : Unit = Arrays.fill(this, value) public inline fun CharArray.fill(value: Char) : Unit = Arrays.fill(this, value)
public inline fun <in T: Any?> Array<T>.fill(value: T) : Unit = Arrays.fill(this, value) public inline fun <T: Any?> Array<T>.fill(value: T) : Unit = Arrays.fill(this, value)
public inline fun ByteArray.sort() : Unit = Arrays.sort(this) public inline fun ByteArray.sort() : Unit = Arrays.sort(this)
public inline fun ShortArray.sort() : Unit = Arrays.sort(this) public inline fun ShortArray.sort() : Unit = Arrays.sort(this)
+5 -5
View File
@@ -239,7 +239,7 @@ public inline fun <T, C: MutableCollection<in T>> Iterable<T>.takeWhileTo(result
} }
/** Copies all elements into the given collection */ /** Copies all elements into the given collection */
public inline fun <in T, C: MutableCollection<in T>> Iterable<T>.toCollection(result: C) : C { public inline fun <T, C: MutableCollection<in T>> Iterable<T>.toCollection(result: C) : C {
for (element in this) result.add(element) for (element in this) result.add(element)
return result return result
} }
@@ -256,16 +256,16 @@ public inline fun <T> Iterable<T>.reverse() : List<T> {
} }
/** Copies all elements into a [[LinkedList]] */ /** Copies all elements into a [[LinkedList]] */
public inline fun <in T> Iterable<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>()) public inline fun <T> Iterable<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>())
/** Copies all elements into a [[List]] */ /** Copies all elements into a [[List]] */
public inline fun <in T> Iterable<T>.toList() : List<T> = toCollection(ArrayList<T>()) public inline fun <T> Iterable<T>.toList() : List<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[List] */ /** Copies all elements into a [[List] */
public inline fun <in T> Iterable<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>()) public inline fun <T> Iterable<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[Set]] */ /** Copies all elements into a [[Set]] */
public inline fun <in T> Iterable<T>.toSet() : Set<T> = toCollection(HashSet<T>()) public inline fun <T> Iterable<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/** /**
TODO figure out necessary variance/generics ninja stuff... :) TODO figure out necessary variance/generics ninja stuff... :)
+1 -1
View File
@@ -3,5 +3,5 @@ package kotlin
import java.util.* import java.util.*
/** Copies all elements into a [[SortedSet]] */ /** Copies all elements into a [[SortedSet]] */
public inline fun <in T> Iterable<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>()) public inline fun <T> Iterable<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
+3 -3
View File
@@ -42,7 +42,7 @@ public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Collection<R>) : C
* *
* @includeFunctionBody ../../test/CollectionTest.kt plus * @includeFunctionBody ../../test/CollectionTest.kt plus
*/ */
public inline fun <in T> Iterable<T>.plus(element: T): List<T> { public inline fun <T> Iterable<T>.plus(element: T): List<T> {
val list = toCollection(ArrayList<T>()) val list = toCollection(ArrayList<T>())
list.add(element) list.add(element)
return list return list
@@ -54,7 +54,7 @@ public inline fun <in T> Iterable<T>.plus(element: T): List<T> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection * @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/ */
public inline fun <in T> Iterable<T>.plus(elements: Iterable<T>): List<T> { public inline fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> {
val list = toCollection(ArrayList<T>()) val list = toCollection(ArrayList<T>())
list.addAll(elements.toCollection()) list.addAll(elements.toCollection())
return list return list
@@ -65,7 +65,7 @@ public inline fun <in T> Iterable<T>.plus(elements: Iterable<T>): List<T> {
* *
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls * @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/ */
public inline fun <in T> Iterable<T?>.requireNoNulls() : List<T> { public inline fun <T> Iterable<T?>.requireNoNulls() : List<T> {
val list = ArrayList<T>() val list = ArrayList<T>()
for (element in this) { for (element in this) {
if (element == null) { if (element == null) {
@@ -106,13 +106,13 @@ public fun <T> Iterable<T>.withIndices(): List<Pair<Int, T>> {
return answer return answer
} }
public inline fun <in T: Comparable<T>> MutableIterable<T>.sort() : List<T> { public inline fun <T: Comparable<T>> MutableIterable<T>.sort() : List<T> {
val list = toCollection(ArrayList<T>()) val list = toCollection(ArrayList<T>())
java.util.Collections.sort(list) java.util.Collections.sort(list)
return list return list
} }
public inline fun <in T> Iterable<T>.sort(comparator: java.util.Comparator<T>) : List<T> { public inline fun <T> Iterable<T>.sort(comparator: java.util.Comparator<T>) : List<T> {
val list = toCollection(ArrayList<T>()) val list = toCollection(ArrayList<T>())
java.util.Collections.sort(list, comparator) java.util.Collections.sort(list, comparator)
return list return list
@@ -13,7 +13,7 @@ import java.util.ArrayList
* *
* @includeFunctionBody ../../test/CollectionTest.kt sortBy * @includeFunctionBody ../../test/CollectionTest.kt sortBy
*/ */
public inline fun <in T, R: Comparable<in R>> Iterable<T>.sortBy(f: (T) -> R): List<T> { public inline fun <T, R: Comparable<in R>> Iterable<T>.sortBy(f: (T) -> R): List<T> {
val sortedList = toCollection(ArrayList<T>()) val sortedList = toCollection(ArrayList<T>())
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
val xr = f(x) val xr = f(x)
+4 -4
View File
@@ -99,7 +99,7 @@ private class FlatMapIterator<T, R>(val iterator : Iterator<T>, val transform: (
* *
* @includeFunctionBody ../../test/iterators/IteratorsTest.kt plus * @includeFunctionBody ../../test/iterators/IteratorsTest.kt plus
*/ */
public inline fun <in T> Iterator<T>.plus(element: T): Iterator<T> { public inline fun <T> Iterator<T>.plus(element: T): Iterator<T> {
return CompositeIterator<T>(this, SingleIterator(element)) return CompositeIterator<T>(this, SingleIterator(element))
} }
@@ -109,7 +109,7 @@ public inline fun <in T> Iterator<T>.plus(element: T): Iterator<T> {
* *
* @includeFunctionBody ../../test/iterators/IteratorsTest.kt plusCollection * @includeFunctionBody ../../test/iterators/IteratorsTest.kt plusCollection
*/ */
public inline fun <in T> Iterator<T>.plus(iterator: Iterator<T>): Iterator<T> { public inline fun <T> Iterator<T>.plus(iterator: Iterator<T>): Iterator<T> {
return CompositeIterator<T>(this, iterator) return CompositeIterator<T>(this, iterator)
} }
@@ -118,7 +118,7 @@ public inline fun <in T> Iterator<T>.plus(iterator: Iterator<T>): Iterator<T> {
* *
* @includeFunctionBody ../../test/iterators/IteratorsTest.kt plusCollection * @includeFunctionBody ../../test/iterators/IteratorsTest.kt plusCollection
*/ */
public inline fun <in T> Iterator<T>.plus(collection: Iterable<T>): Iterator<T> = plus(collection.iterator()) public inline fun <T> Iterator<T>.plus(collection: Iterable<T>): Iterator<T> = plus(collection.iterator())
/** /**
* Returns an iterator containing all the non-*null* elements, lazily throwing an [[IllegalArgumentException]] * Returns an iterator containing all the non-*null* elements, lazily throwing an [[IllegalArgumentException]]
@@ -126,7 +126,7 @@ public inline fun <in T> Iterator<T>.plus(collection: Iterable<T>): Iterator<T>
* *
* @includeFunctionBody ../../test/iterators/IteratorsTest.kt requireNoNulls * @includeFunctionBody ../../test/iterators/IteratorsTest.kt requireNoNulls
*/ */
public inline fun <in T> Iterator<T?>.requireNoNulls(): Iterator<T> { public inline fun <T> Iterator<T?>.requireNoNulls(): Iterator<T> {
return map<T?, T>{ return map<T?, T>{
if (it == null) throw IllegalArgumentException("null element in iterator $this") else it if (it == null) throw IllegalArgumentException("null element in iterator $this") else it
} }
+2 -2
View File
@@ -5,10 +5,10 @@ import java.lang.Object
import jet.runtime.Intrinsic import jet.runtime.Intrinsic
public val <out T> T.javaClass : Class<T> public val <T> T.javaClass : Class<T>
[Intrinsic("kotlin.javaClass.property")] get() = (this as java.lang.Object).getClass() as Class<T> [Intrinsic("kotlin.javaClass.property")] get() = (this as java.lang.Object).getClass() as Class<T>
[Intrinsic("kotlin.javaClass.function")] fun <out T> javaClass() : Class<T> = null as Class<T> [Intrinsic("kotlin.javaClass.function")] fun <T> javaClass() : Class<T> = null as Class<T>
/** /**
+2 -2
View File
@@ -36,9 +36,9 @@ public inline fun <T> Collection<T>?.orEmpty() : Collection<T>
/** TODO these functions don't work when they generate the Array<T> versions when they are in JLIterables */ /** TODO these functions don't work when they generate the Array<T> versions when they are in JLIterables */
public inline fun <in T: Comparable<T>> Iterable<T>.toSortedList() : List<T> = toCollection(ArrayList<T>()).sort() public inline fun <T: Comparable<T>> Iterable<T>.toSortedList() : List<T> = toCollection(ArrayList<T>()).sort()
public inline fun <in T: Comparable<T>> Iterable<T>.toSortedList(comparator: java.util.Comparator<T>) : List<T> = toList().sort(comparator) public inline fun <T: Comparable<T>> Iterable<T>.toSortedList(comparator: java.util.Comparator<T>) : List<T> = toList().sort(comparator)
// List APIs // List APIs