added toMutableList, toMutableCollection, toMutableSet

methods to standard library
This commit is contained in:
Svetlana Isakova
2012-09-04 19:07:41 +04:00
parent fedf080a59
commit ce23fe7941
11 changed files with 110 additions and 11 deletions
+10 -1
View File
@@ -234,7 +234,7 @@ public inline fun <in T, C: MutableCollection<in T>> Iterable<T>.toCollection(re
* @includeFunctionBody ../../test/CollectionTest.kt reverse
*/
public inline fun <T> Iterable<T>.reverse() : List<T> {
val list = toList()
val list = toMutableList()
Collections.reverse(list)
return list
}
@@ -251,6 +251,15 @@ public inline fun <in T> Iterable<T>.toCollection() : Collection<T> = toCollecti
/** Copies all elements into a [[Set]] */
public inline fun <in T> Iterable<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/** Copies all elements into a [[MutableList]] */
public inline fun <in T> Iterable<T>.toMutableList() : MutableList<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[List] */
public inline fun <in T> Iterable<T>.toMutableCollection() : MutableCollection<T> = toCollection(ArrayList<T>())
/** Copies all elements into a [[Set]] */
public inline fun <in T> Iterable<T>.toMutableSet() : MutableSet<T> = toCollection(HashSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun <in T> Iterable<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {