Variance in functions/properties removed from stdlib
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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>())
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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... :)
|
||||||
|
|||||||
@@ -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>())
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user