#KT-537 adds A.to(B) helper method to make easy creation of map literals: hashMap("a" to 3, "b" to 6) etc

This commit is contained in:
James Strachan
2012-04-16 20:37:13 +01:00
parent 87e613a8c2
commit 0007be9377
2 changed files with 16 additions and 0 deletions
+9
View File
@@ -73,6 +73,15 @@ public inline fun <T> Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(Tr
*/
public inline fun <T> Iterator<T>.toSortedSet(comparator: Comparator<T>) : SortedSet<T> = toCollection(TreeSet<T>(comparator))
/**
* Creates a tuple of type [[#(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)
/**
Run function f
*/