refactored the to(Collection) methods to be called toCollection(Collection) to avoid clashing with a potentially new method called to(T) for making a pair/tuple/Map.Entry
This commit is contained in:
@@ -193,25 +193,25 @@ public inline fun <T> Array<T>.reverse() : List<T> {
|
||||
}
|
||||
|
||||
/** Copies all elements into the given collection */
|
||||
public inline fun <in T, C: Collection<in T>> Array<T>.to(result: C) : C {
|
||||
public inline fun <in T, C: Collection<in T>> Array<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
public inline fun <in T> Array<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
|
||||
public inline fun <in T> Array<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>())
|
||||
|
||||
/** Copies all elements into a [[List]] */
|
||||
public inline fun <in T> Array<T>.toList() : List<T> = to(ArrayList<T>())
|
||||
public inline fun <in T> Array<T>.toList() : List<T> = toCollection(ArrayList<T>())
|
||||
|
||||
/** Copies all elements into a [[List] */
|
||||
public inline fun <in T> Array<T>.toCollection() : Collection<T> = to(ArrayList<T>())
|
||||
public inline fun <in T> Array<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
|
||||
|
||||
/** Copies all elements into a [[Set]] */
|
||||
public inline fun <in T> Array<T>.toSet() : Set<T> = to(HashSet<T>())
|
||||
public inline fun <in T> Array<T>.toSet() : Set<T> = toCollection(HashSet<T>())
|
||||
|
||||
/** Copies all elements into a [[SortedSet]] */
|
||||
public inline fun <in T> Array<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
|
||||
public inline fun <in T> Array<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
|
||||
|
||||
/**
|
||||
TODO figure out necessary variance/generics ninja stuff... :)
|
||||
|
||||
@@ -48,7 +48,7 @@ public inline fun <T, R> Array<T>.flatMap(transform: (T)-> Collection<R>) : Coll
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt plus
|
||||
*/
|
||||
public inline fun <in T> Array<T>.plus(element: T): List<in T> {
|
||||
val list = to(ArrayList<T>())
|
||||
val list = toCollection(ArrayList<T>())
|
||||
list.add(element)
|
||||
return list
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public inline fun <in T> Array<T>.plus(element: T): List<in T> {
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection
|
||||
*/
|
||||
public inline fun <in T> Array<T>.plus(elements: Array<T>): List<T> {
|
||||
val list = to(ArrayList<T>())
|
||||
val list = toCollection(ArrayList<T>())
|
||||
list.addAll(elements.toCollection())
|
||||
return list
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given function to each element in this collection
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt map
|
||||
*/
|
||||
@@ -19,7 +19,10 @@ public inline fun <T, R> Array<T>.map(transform : (T) -> R) : java.util.List<R>
|
||||
return mapTo(java.util.ArrayList<R>(this.size), transform)
|
||||
}
|
||||
|
||||
/** Transforms each element of this collection with the given function then adds the results to the given collection */
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <T, R, C: Collection<in R>> Array<T>.mapTo(result: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given function to each element in this collection
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt map
|
||||
*/
|
||||
@@ -19,7 +19,10 @@ public inline fun <T, R> java.lang.Iterable<T>.map(transform : (T) -> R) : java.
|
||||
return mapTo(java.util.ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/** Transforms each element of this collection with the given function then adds the results to the given collection */
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <T, R, C: Collection<in R>> java.lang.Iterable<T>.mapTo(result: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
|
||||
@@ -191,25 +191,25 @@ public inline fun <T> java.util.Iterator<T>.reverse() : List<T> {
|
||||
}
|
||||
|
||||
/** Copies all elements into the given collection */
|
||||
public inline fun <in T, C: Collection<in T>> java.util.Iterator<T>.to(result: C) : C {
|
||||
public inline fun <in T, C: Collection<in T>> java.util.Iterator<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
public inline fun <in T> java.util.Iterator<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
|
||||
public inline fun <in T> java.util.Iterator<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>())
|
||||
|
||||
/** Copies all elements into a [[List]] */
|
||||
public inline fun <in T> java.util.Iterator<T>.toList() : List<T> = to(ArrayList<T>())
|
||||
public inline fun <in T> java.util.Iterator<T>.toList() : List<T> = toCollection(ArrayList<T>())
|
||||
|
||||
/** Copies all elements into a [[List] */
|
||||
public inline fun <in T> java.util.Iterator<T>.toCollection() : Collection<T> = to(ArrayList<T>())
|
||||
public inline fun <in T> java.util.Iterator<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
|
||||
|
||||
/** Copies all elements into a [[Set]] */
|
||||
public inline fun <in T> java.util.Iterator<T>.toSet() : Set<T> = to(HashSet<T>())
|
||||
public inline fun <in T> java.util.Iterator<T>.toSet() : Set<T> = toCollection(HashSet<T>())
|
||||
|
||||
/** Copies all elements into a [[SortedSet]] */
|
||||
public inline fun <in T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
|
||||
public inline fun <in T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
|
||||
|
||||
/**
|
||||
TODO figure out necessary variance/generics ninja stuff... :)
|
||||
|
||||
@@ -193,25 +193,25 @@ public inline fun <T> Iterable<T>.reverse() : List<T> {
|
||||
}
|
||||
|
||||
/** Copies all elements into the given collection */
|
||||
public inline fun <in T, C: Collection<in T>> Iterable<T>.to(result: C) : C {
|
||||
public inline fun <in T, C: Collection<in T>> Iterable<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
public inline fun <in T> Iterable<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
|
||||
public inline fun <in T> Iterable<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>())
|
||||
|
||||
/** Copies all elements into a [[List]] */
|
||||
public inline fun <in T> Iterable<T>.toList() : List<T> = to(ArrayList<T>())
|
||||
public inline fun <in T> Iterable<T>.toList() : List<T> = toCollection(ArrayList<T>())
|
||||
|
||||
/** Copies all elements into a [[List] */
|
||||
public inline fun <in T> Iterable<T>.toCollection() : Collection<T> = to(ArrayList<T>())
|
||||
public inline fun <in T> Iterable<T>.toCollection() : Collection<T> = toCollection(ArrayList<T>())
|
||||
|
||||
/** Copies all elements into a [[Set]] */
|
||||
public inline fun <in T> Iterable<T>.toSet() : Set<T> = to(HashSet<T>())
|
||||
public inline fun <in T> Iterable<T>.toSet() : Set<T> = toCollection(HashSet<T>())
|
||||
|
||||
/** Copies all elements into a [[SortedSet]] */
|
||||
public inline fun <in T> Iterable<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
|
||||
public inline fun <in T> Iterable<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
|
||||
|
||||
/**
|
||||
TODO figure out necessary variance/generics ninja stuff... :)
|
||||
|
||||
@@ -48,7 +48,7 @@ public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Collection<R>) : C
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt plus
|
||||
*/
|
||||
public inline fun <in T> Iterable<T>.plus(element: T): List<in T> {
|
||||
val list = to(ArrayList<T>())
|
||||
val list = toCollection(ArrayList<T>())
|
||||
list.add(element)
|
||||
return list
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public inline fun <in T> Iterable<T>.plus(element: T): List<in T> {
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection
|
||||
*/
|
||||
public inline fun <in T> Iterable<T>.plus(elements: Iterable<T>): List<T> {
|
||||
val list = to(ArrayList<T>())
|
||||
val list = toCollection(ArrayList<T>())
|
||||
list.addAll(elements.toCollection())
|
||||
return list
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given function to each element in this collection
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt map
|
||||
*/
|
||||
@@ -19,7 +19,10 @@ public inline fun <T, R> Iterable<T>.map(transform : (T) -> R) : java.util.List<
|
||||
return mapTo(java.util.ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/** Transforms each element of this collection with the given function then adds the results to the given collection */
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <T, R, C: Collection<in R>> Iterable<T>.mapTo(result: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
|
||||
Reference in New Issue
Block a user