Variance in functions/properties removed from stdlib
This commit is contained in:
@@ -33,5 +33,5 @@ public inline val DoubleArray.lastIndex : Int
|
||||
public inline val CharArray.lastIndex : Int
|
||||
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
|
||||
|
||||
@@ -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 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 ShortArray.sort() : Unit = Arrays.sort(this)
|
||||
|
||||
@@ -239,7 +239,7 @@ public inline fun <T, C: MutableCollection<in T>> Iterable<T>.takeWhileTo(result
|
||||
}
|
||||
|
||||
/** 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)
|
||||
return result
|
||||
}
|
||||
@@ -256,16 +256,16 @@ public inline fun <T> Iterable<T>.reverse() : List<T> {
|
||||
}
|
||||
|
||||
/** 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]] */
|
||||
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] */
|
||||
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]] */
|
||||
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... :)
|
||||
|
||||
@@ -3,5 +3,5 @@ package kotlin
|
||||
import java.util.*
|
||||
|
||||
/** 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>())
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Collection<R>) : C
|
||||
*
|
||||
* @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>())
|
||||
list.add(element)
|
||||
return list
|
||||
@@ -54,7 +54,7 @@ public inline fun <in T> Iterable<T>.plus(element: T): List<T> {
|
||||
*
|
||||
* @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>())
|
||||
list.addAll(elements.toCollection())
|
||||
return list
|
||||
@@ -65,7 +65,7 @@ public inline fun <in T> Iterable<T>.plus(elements: Iterable<T>): List<T> {
|
||||
*
|
||||
* @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>()
|
||||
for (element in this) {
|
||||
if (element == null) {
|
||||
|
||||
@@ -106,13 +106,13 @@ public fun <T> Iterable<T>.withIndices(): List<Pair<Int, T>> {
|
||||
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>())
|
||||
java.util.Collections.sort(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>())
|
||||
java.util.Collections.sort(list, comparator)
|
||||
return list
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.ArrayList
|
||||
*
|
||||
* @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 sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
|
||||
val xr = f(x)
|
||||
|
||||
@@ -99,7 +99,7 @@ private class FlatMapIterator<T, R>(val iterator : Iterator<T>, val transform: (
|
||||
*
|
||||
* @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))
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public inline fun <in T> Iterator<T>.plus(element: T): Iterator<T> {
|
||||
*
|
||||
* @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)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public inline fun <in T> Iterator<T>.plus(iterator: Iterator<T>): Iterator<T> {
|
||||
*
|
||||
* @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]]
|
||||
@@ -126,7 +126,7 @@ public inline fun <in T> Iterator<T>.plus(collection: Iterable<T>): Iterator<T>
|
||||
*
|
||||
* @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>{
|
||||
if (it == null) throw IllegalArgumentException("null element in iterator $this") else it
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.lang.Object
|
||||
|
||||
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.function")] fun <out T> javaClass() : Class<T> = null as Class<T>
|
||||
[Intrinsic("kotlin.javaClass.function")] fun <T> javaClass() : Class<T> = null as Class<T>
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 */
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user