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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,13 +93,13 @@ class CollectionJVMTest {
|
||||
|
||||
test fun sortBy() {
|
||||
expect(arrayList("two" to 2, "three" to 3)) {
|
||||
arrayList("three" to 3, "two" to 2).sortBy { it._2 }
|
||||
arrayList("three" to 3, "two" to 2).sortBy { it.second }
|
||||
}
|
||||
expect(arrayList("three" to 3, "two" to 2)) {
|
||||
arrayList("three" to 3, "two" to 2).sortBy { it._1 }
|
||||
arrayList("three" to 3, "two" to 2).sortBy { it.first }
|
||||
}
|
||||
expect(arrayList("two" to 2, "three" to 3)) {
|
||||
arrayList("three" to 3, "two" to 2).sortBy { it._1.length }
|
||||
arrayList("three" to 3, "two" to 2).sortBy { it.first.length }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ class ListTest {
|
||||
val wis = data.withIndices()
|
||||
var index = 0
|
||||
for (withIndex in wis) {
|
||||
assertEquals(withIndex._1, index)
|
||||
assertEquals(withIndex._2, data[index])
|
||||
assertEquals(withIndex.first, index)
|
||||
assertEquals(withIndex.second, data[index])
|
||||
index++
|
||||
}
|
||||
assertEquals(data.size(), index)
|
||||
|
||||
@@ -103,7 +103,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
test fun createUsingTuples() {
|
||||
val map = hashMap(#("a", 1), #("b", 2))
|
||||
val map = hashMap(Pair("a", 1), Pair("b", 2))
|
||||
assertEquals(2, map.size)
|
||||
assertEquals(1, map.get("a"))
|
||||
assertEquals(2, map.get("b"))
|
||||
@@ -117,7 +117,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
test fun createLinkedMap() {
|
||||
val map = linkedMap(#("c", 3), #("b", 2), #("a", 1))
|
||||
val map = linkedMap(Pair("c", 3), Pair("b", 2), Pair("a", 1))
|
||||
assertEquals(1, map.get("a"))
|
||||
assertEquals(2, map.get("b"))
|
||||
assertEquals(3, map.get("c"))
|
||||
@@ -125,7 +125,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
test fun createSortedMap() {
|
||||
val map = sortedMap(#("c", 3), #("b", 2), #("a", 1))
|
||||
val map = sortedMap(Pair("c", 3), Pair("b", 2), Pair("a", 1))
|
||||
assertEquals(1, map.get("a"))
|
||||
assertEquals(2, map.get("b"))
|
||||
assertEquals(3, map.get("c"))
|
||||
@@ -133,7 +133,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
test fun toSortedMap() {
|
||||
val map = hashMap<String,Int>(#("c", 3), #("b", 2), #("a", 1))
|
||||
val map = hashMap<String,Int>(Pair("c", 3), Pair("b", 2), Pair("a", 1))
|
||||
val sorted = map.toSortedMap<String,Int>()
|
||||
assertEquals(1, sorted.get("a"))
|
||||
assertEquals(2, sorted.get("b"))
|
||||
@@ -142,7 +142,7 @@ class MapTest {
|
||||
}
|
||||
|
||||
test fun toSortedMapWithComparator() {
|
||||
val map = hashMap(#("c", 3), #("bc", 2), #("bd", 4), #("abc", 1))
|
||||
val map = hashMap(Pair("c", 3), Pair("bc", 2), Pair("bd", 4), Pair("abc", 1))
|
||||
val c = comparator<String>{ a, b ->
|
||||
val answer = a.length() - b.length()
|
||||
if (answer == 0) a.compareTo(b) else answer
|
||||
|
||||
@@ -15,7 +15,7 @@ class Serial(val a : String) : java.lang.Object(), Serializable {
|
||||
|
||||
class SerialTest() : TestCase() {
|
||||
fun testMe() {
|
||||
val tuple = #("lala", "bbb", Serial("serial"))
|
||||
val tuple = Triple("lala", "bbb", Serial("serial"))
|
||||
val op = { -> tuple.toString() }
|
||||
|
||||
val baos = ByteArrayOutputStream()
|
||||
|
||||
@@ -52,7 +52,7 @@ class MapJsTest {
|
||||
*/
|
||||
|
||||
test fun createUsingTuples() {
|
||||
val map = hashMap(#("a", 1), #("b", 2))
|
||||
val map = hashMap(Pair("a", 1), Pair("b", 2))
|
||||
assertEquals(2, map.size)
|
||||
assertEquals(1, map.get("a"))
|
||||
assertEquals(2, map.get("b"))
|
||||
|
||||
Reference in New Issue
Block a user