TupleN classes and their usages replaced by Pair and Triple
(KT-2358 Drop tuples) #KT-2358 In Progress
This commit is contained in:
@@ -96,11 +96,11 @@ public fun <T> Iterable<T>.contains(item : T) : Boolean {
|
||||
*
|
||||
* @includeFunctionBody ../../test/ListTest.kt withIndices
|
||||
*/
|
||||
public fun <T> Iterable<T>.withIndices(): List<#(Int, T)> {
|
||||
val answer = ArrayList<#(Int, T)>()
|
||||
public fun <T> Iterable<T>.withIndices(): List<Pair<Int, T>> {
|
||||
val answer = ArrayList<Pair<Int, T>>()
|
||||
var nextIndex = 0
|
||||
for (e in this) {
|
||||
answer.add(#(nextIndex, e))
|
||||
answer.add(Pair(nextIndex, e))
|
||||
nextIndex++
|
||||
}
|
||||
return answer
|
||||
|
||||
@@ -24,14 +24,14 @@ public inline fun sortedSet<T>(comparator: Comparator<T>, vararg values: T) : Tr
|
||||
*
|
||||
* @includeFunctionBody ../../test/MapTest.kt createUsingTuples
|
||||
*/
|
||||
public inline fun <K,V> hashMap(vararg values: #(K,V)): HashMap<K,V> {
|
||||
public inline fun <K,V> hashMap(vararg values: Pair<K,V>): HashMap<K,V> {
|
||||
val answer = HashMap<K,V>(values.size)
|
||||
/**
|
||||
TODO replace by this simpler call when we can pass vararg values into other methods
|
||||
answer.putAll(values)
|
||||
*/
|
||||
for (v in values) {
|
||||
answer.put(v._1, v._2)
|
||||
answer.put(v.first, v.second)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
@@ -42,14 +42,14 @@ public inline fun <K,V> hashMap(vararg values: #(K,V)): HashMap<K,V> {
|
||||
*
|
||||
* @includeFunctionBody ../../test/MapTest.kt createSortedMap
|
||||
*/
|
||||
public inline fun <K,V> sortedMap(vararg values: #(K,V)): SortedMap<K,V> {
|
||||
public inline fun <K,V> sortedMap(vararg values: Pair<K, V>): SortedMap<K,V> {
|
||||
val answer = TreeMap<K,V>()
|
||||
/**
|
||||
TODO replace by this simpler call when we can pass vararg values into other methods
|
||||
answer.putAll(values)
|
||||
*/
|
||||
for (v in values) {
|
||||
answer.put(v._1, v._2)
|
||||
answer.put(v.first, v.second)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
@@ -61,14 +61,14 @@ public inline fun <K,V> sortedMap(vararg values: #(K,V)): SortedMap<K,V> {
|
||||
*
|
||||
* @includeFunctionBody ../../test/MapTest.kt createLinkedMap
|
||||
*/
|
||||
public inline fun <K,V> linkedMap(vararg values: #(K,V)): LinkedHashMap<K,V> {
|
||||
public inline fun <K,V> linkedMap(vararg values: Pair<K, V>): LinkedHashMap<K,V> {
|
||||
val answer = LinkedHashMap<K,V>(values.size)
|
||||
/**
|
||||
TODO replace by this simpler call when we can pass vararg values into other methods
|
||||
answer.putAll(values)
|
||||
*/
|
||||
for (v in values) {
|
||||
answer.put(v._1, v._2)
|
||||
answer.put(v.first, v.second)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ public inline fun <K,V,R,C: MutableMap<K,R>> MutableMap<K,V>.mapValuesTo(result:
|
||||
/**
|
||||
* Puts all the entries into the map with the first value in the tuple being the key and the second the value
|
||||
*/
|
||||
public inline fun <K,V> MutableMap<K,V>.putAll(vararg values: #(K,V)): Unit {
|
||||
public inline fun <K,V> MutableMap<K,V>.putAll(vararg values: Pair<K, V>): Unit {
|
||||
for (v in values) {
|
||||
put(v._1, v._2)
|
||||
put(v.first, v.second)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,12 +40,12 @@ public inline fun <T> Iterator<T>.toHashSet() : HashSet<T> = toCollection(HashSe
|
||||
|
||||
|
||||
/**
|
||||
* Creates a tuple of type [[#(A,B)]] from this and *that* which can be useful for creating [[Map]] literals
|
||||
* Creates a tuple of type [[Pair<A,B>]] from this and *that* which can be useful for creating [[Map]] literals
|
||||
* with less noise, for example
|
||||
|
||||
* @includeFunctionBody ../../test/MapTest.kt createUsingTo
|
||||
*/
|
||||
public inline fun <A,B> A.to(that: B): #(A, B) = #(this, that)
|
||||
public inline fun <A,B> A.to(that: B): Pair<A, B> = Pair(this, that)
|
||||
|
||||
/**
|
||||
Run function f
|
||||
@@ -61,5 +61,4 @@ public inline fun runnable(action: ()-> Unit): Runnable {
|
||||
action()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class FunctionalQueue<T> (
|
||||
|
||||
public fun addFirst(element: T) : FunctionalQueue<T> = FunctionalQueue<T>(input, output add element)
|
||||
|
||||
public fun removeFirst() : #(T,FunctionalQueue<T>) =
|
||||
public fun removeFirst() : Pair<T, FunctionalQueue<T>> =
|
||||
if(output.empty) {
|
||||
if(input.empty)
|
||||
throw java.util.NoSuchElementException()
|
||||
@@ -24,6 +24,6 @@ class FunctionalQueue<T> (
|
||||
FunctionalQueue<T>(FunctionalList.emptyList<T>(), input.reversed()).removeFirst()
|
||||
}
|
||||
else {
|
||||
#(output.head, FunctionalQueue<T>(input, output.tail))
|
||||
Pair(output.head, FunctionalQueue<T>(input, output.tail))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user