not generate methods for java Iterable/Iterator

in standard library
This commit is contained in:
Svetlana Isakova
2012-08-14 15:24:58 +04:00
parent ca6d7e643e
commit 266cd5d4e7
7 changed files with 29 additions and 489 deletions
@@ -1,28 +0,0 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JUtilCollections.kt
//
import java.util.*
//
// This file contains methods which are optimised for working on Collection / Array collections where the size
// could be used to implement a more optimal solution
//
// See [[GenerateStandardLib.kt]] for more details
//
/**
* 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))
return result
}
@@ -1,27 +0,0 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JUtilCollectionsJVM.kt
//
import java.util.*
//
// This file contains methods which are optimised for working on Collection / Array collections where the size
// could be used to implement a more optimal solution
//
// See [[GenerateStandardLib.kt]] for more details
//
/**
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
*
* @includeFunctionBody ../../test/CollectionTest.kt map
*/
public inline fun <T, R> java.lang.Iterable<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(), transform)
}
@@ -9,13 +9,14 @@ package kotlin
import java.util.*
import jet.Iterator
/**
* Returns *true* if all elements match the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt all
*/
public inline fun <T> java.util.Iterator<T>.all(predicate: (T) -> Boolean) : Boolean {
public inline fun <T> Iterator<T>.all(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (!predicate(element)) return false
return true
}
@@ -25,7 +26,7 @@ public inline fun <T> java.util.Iterator<T>.all(predicate: (T) -> Boolean) : Boo
*
* @includeFunctionBody ../../test/CollectionTest.kt any
*/
public inline fun <T> java.util.Iterator<T>.any(predicate: (T) -> Boolean) : Boolean {
public inline fun <T> Iterator<T>.any(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (predicate(element)) return true
return false
}
@@ -38,7 +39,7 @@ public inline fun <T> java.util.Iterator<T>.any(predicate: (T) -> Boolean) : Boo
*
* @includeFunctionBody ../../test/CollectionTest.kt appendString
*/
public inline fun <T> java.util.Iterator<T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit {
public inline fun <T> Iterator<T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit {
buffer.append(prefix)
var count = 0
for (element in this) {
@@ -57,7 +58,7 @@ public inline fun <T> java.util.Iterator<T>.appendString(buffer: Appendable, sep
*
* @includeFunctionBody ../../test/CollectionTest.kt count
*/
public inline fun <T> java.util.Iterator<T>.count(predicate: (T) -> Boolean) : Int {
public inline fun <T> Iterator<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0
for (element in this) if (predicate(element)) count++
return count
@@ -68,7 +69,7 @@ public inline fun <T> java.util.Iterator<T>.count(predicate: (T) -> Boolean) : I
*
* @includeFunctionBody ../../test/CollectionTest.kt find
*/
public inline fun <T> java.util.Iterator<T>.find(predicate: (T) -> Boolean) : T? {
public inline fun <T> Iterator<T>.find(predicate: (T) -> Boolean) : T? {
for (element in this) if (predicate(element)) return element
return null
}
@@ -78,7 +79,7 @@ public inline fun <T> java.util.Iterator<T>.find(predicate: (T) -> Boolean) : T?
*
* @includeFunctionBody ../../test/CollectionTest.kt filterIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> java.util.Iterator<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
public inline fun <T, C: Collection<in T>> Iterator<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element)
return result
}
@@ -88,7 +89,7 @@ public inline fun <T, C: Collection<in T>> java.util.Iterator<T>.filterTo(result
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNotIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> java.util.Iterator<T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
public inline fun <T, C: Collection<in T>> Iterator<T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (!predicate(element)) result.add(element)
return result
}
@@ -98,7 +99,7 @@ public inline fun <T, C: Collection<in T>> java.util.Iterator<T>.filterNotTo(res
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> java.util.Iterator<T?>?.filterNotNullTo(result: C) : C {
public inline fun <T, C: Collection<in T>> Iterator<T?>?.filterNotNullTo(result: C) : C {
if (this != null) {
for (element in this) if (element != null) result.add(element)
}
@@ -110,7 +111,7 @@ public inline fun <T, C: Collection<in T>> java.util.Iterator<T?>?.filterNotNull
*
* @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/
public inline fun <T, R> java.util.Iterator<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
public inline fun <T, R> Iterator<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
for (element in this) {
val list = transform(element)
if (list != null) {
@@ -125,14 +126,14 @@ public inline fun <T, R> java.util.Iterator<T>.flatMapTo(result: Collection<R>,
*
* @includeFunctionBody ../../test/CollectionTest.kt forEach
*/
public inline fun <T> java.util.Iterator<T>.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element)
public inline fun <T> Iterator<T>.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element)
/**
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
*
* @includeFunctionBody ../../test/CollectionTest.kt fold
*/
public inline fun <T> java.util.Iterator<T>.fold(initial: T, operation: (T, T) -> T): T {
public inline fun <T> Iterator<T>.fold(initial: T, operation: (T, T) -> T): T {
var answer = initial
for (element in this) answer = operation(answer, element)
return answer
@@ -143,7 +144,7 @@ public inline fun <T> java.util.Iterator<T>.fold(initial: T, operation: (T, T) -
*
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
*/
public inline fun <T> java.util.Iterator<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, {x, y -> operation(y, x)})
public inline fun <T> Iterator<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, {x, y -> operation(y, x)})
/**
@@ -152,7 +153,7 @@ public inline fun <T> java.util.Iterator<T>.foldRight(initial: T, operation: (T,
*
* @includeFunctionBody ../../test/CollectionTest.kt reduce
*/
public inline fun <T> java.util.Iterator<T>.reduce(operation: (T, T) -> T): T {
public inline fun <T> Iterator<T>.reduce(operation: (T, T) -> T): T {
val iterator = this.iterator().sure()
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
@@ -172,7 +173,7 @@ public inline fun <T> java.util.Iterator<T>.reduce(operation: (T, T) -> T): T {
*
* @includeFunctionBody ../../test/CollectionTest.kt reduceRight
*/
public inline fun <T> java.util.Iterator<T>.reduceRight(operation: (T, T) -> T): T = reverse().reduce { x, y -> operation(y, x) }
public inline fun <T> Iterator<T>.reduceRight(operation: (T, T) -> T): T = reverse().reduce { x, y -> operation(y, x) }
/**
@@ -180,14 +181,14 @@ public inline fun <T> java.util.Iterator<T>.reduceRight(operation: (T, T) -> T):
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> java.util.Iterator<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> = groupByTo<T,K>(HashMap<K, List<T>>(), toKey)
public inline fun <T, K> Iterator<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> = groupByTo<T,K>(HashMap<K, List<T>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> java.util.Iterator<T>.groupByTo(result: Map<K, List<T>>, toKey: (T) -> K) : Map<K, List<T>> {
public inline fun <T, K> Iterator<T>.groupByTo(result: Map<K, List<T>>, toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
@@ -204,14 +205,14 @@ public inline fun <T, K> java.util.Iterator<T>.groupByTo(result: Map<K, List<T>>
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun <T> java.util.Iterator<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
public inline fun <T> Iterator<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
appendString(buffer, separator, prefix, postfix, limit, truncated)
return buffer.toString().sure()
}
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
public inline fun <T, L: List<in T>> java.util.Iterator<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
public inline fun <T, L: List<in T>> Iterator<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
var start = true
for (element in this) {
if (start && predicate(element)) {
@@ -225,13 +226,13 @@ public inline fun <T, L: List<in T>> java.util.Iterator<T>.dropWhileTo(result: L
}
/** Returns a list containing the first elements that satisfy the given *predicate* */
public inline fun <T, C: Collection<in T>> java.util.Iterator<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
public inline fun <T, C: Collection<in T>> Iterator<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element) else break
return result
}
/** Copies all elements into the given collection */
public inline fun <in T, C: Collection<in T>> java.util.Iterator<T>.toCollection(result: C) : C {
public inline fun <in T, C: Collection<in T>> Iterator<T>.toCollection(result: C) : C {
for (element in this) result.add(element)
return result
}
@@ -241,27 +242,27 @@ public inline fun <in T, C: Collection<in T>> java.util.Iterator<T>.toCollection
*
* @includeFunctionBody ../../test/CollectionTest.kt reverse
*/
public inline fun <T> java.util.Iterator<T>.reverse() : List<T> {
public inline fun <T> Iterator<T>.reverse() : List<T> {
val list = toList()
Collections.reverse(list)
return list
}
/** Copies all elements into a [[LinkedList]] */
public inline fun <in T> java.util.Iterator<T>.toLinkedList() : LinkedList<T> = toCollection(LinkedList<T>())
public inline fun <in T> 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> = toCollection(ArrayList<T>())
public inline fun <in T> 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> = toCollection(ArrayList<T>())
public inline fun <in T> 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> = toCollection(HashSet<T>())
public inline fun <in T> Iterator<T>.toSet() : Set<T> = toCollection(HashSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
public inline fun <in T> java.util.Iterator<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
public inline fun <in T> Iterator<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
val answer = this.toList()
answer.sort(transform)
return answer
@@ -9,7 +9,8 @@ package kotlin
import java.util.*
import jet.Iterator
/** Copies all elements into a [[SortedSet]] */
public inline fun <in T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
public inline fun <in T> Iterator<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -1,270 +0,0 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JLangIterables.kt
//
import java.util.*
/**
* Returns *true* if all elements match the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt all
*/
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (!predicate(element)) return false
return true
}
/**
* Returns *true* if any elements match the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt any
*/
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (predicate(element)) return true
return false
}
/**
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt appendString
*/
public inline fun <T> Iterable<T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit {
buffer.append(prefix)
var count = 0
for (element in this) {
if (++count > 1) buffer.append(separator)
if (limit < 0 || count <= limit) {
val text = if (element == null) "null" else element.toString()
buffer.append(text)
} else break
}
if (limit >= 0 && count > limit) buffer.append(truncated)
buffer.append(postfix)
}
/**
* Returns the number of elements which match the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt count
*/
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0
for (element in this) if (predicate(element)) count++
return count
}
/**
* Returns the first element which matches the given *predicate* or *null* if none matched
*
* @includeFunctionBody ../../test/CollectionTest.kt find
*/
public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean) : T? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Filters all elements which match the given predicate into the given list
*
* @includeFunctionBody ../../test/CollectionTest.kt filterIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element)
return result
}
/**
* Returns a list containing all elements which do not match the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNotIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> Iterable<T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (!predicate(element)) result.add(element)
return result
}
/**
* Filters all non-*null* elements into the given list
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/
public inline fun <T, C: Collection<in T>> Iterable<T?>?.filterNotNullTo(result: C) : C {
if (this != null) {
for (element in this) if (element != null) result.add(element)
}
return result
}
/**
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
*
* @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/
public inline fun <T, R> Iterable<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
for (element in this) {
val list = transform(element)
if (list != null) {
for (r in list) result.add(r)
}
}
return result
}
/**
* Performs the given *operation* on each element
*
* @includeFunctionBody ../../test/CollectionTest.kt forEach
*/
public inline fun <T> Iterable<T>.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element)
/**
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
*
* @includeFunctionBody ../../test/CollectionTest.kt fold
*/
public inline fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {
var answer = initial
for (element in this) answer = operation(answer, element)
return answer
}
/**
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
*
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
*/
public inline fun <T> Iterable<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, {x, y -> operation(y, x)})
/**
* Applies binary operation to all elements of iterable, going from left to right.
* Similar to fold function, but uses the first element as initial value
*
* @includeFunctionBody ../../test/CollectionTest.kt reduce
*/
public inline fun <T> Iterable<T>.reduce(operation: (T, T) -> T): T {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: T = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
result = operation(result, iterator.next())
}
return result
}
/**
* Applies binary operation to all elements of iterable, going from right to left.
* Similar to foldRight function, but uses the last element as initial value
*
* @includeFunctionBody ../../test/CollectionTest.kt reduceRight
*/
public inline fun <T> Iterable<T>.reduceRight(operation: (T, T) -> T): T = reverse().reduce { x, y -> operation(y, x) }
/**
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> Iterable<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> = groupByTo<T,K>(HashMap<K, List<T>>(), toKey)
/**
* Groups the elements in the collection into the given [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
*
* @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/
public inline fun <T, K> Iterable<T>.groupByTo(result: Map<K, List<T>>, toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
list.add(element)
}
return result
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
*
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
* a special *truncated* separator (which defaults to "..."
*
* @includeFunctionBody ../../test/CollectionTest.kt makeString
*/
public inline fun <T> Iterable<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
appendString(buffer, separator, prefix, postfix, limit, truncated)
return buffer.toString().sure()
}
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
public inline fun <T, L: List<in T>> Iterable<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
var start = true
for (element in this) {
if (start && predicate(element)) {
// ignore
} else {
start = false
result.add(element)
}
}
return result
}
/** Returns a list containing the first elements that satisfy the given *predicate* */
public inline fun <T, C: Collection<in T>> Iterable<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element) else break
return result
}
/** Copies all elements into the given collection */
public inline fun <in T, C: Collection<in T>> Iterable<T>.toCollection(result: C) : C {
for (element in this) result.add(element)
return result
}
/**
* Reverses the order the elements into a list
*
* @includeFunctionBody ../../test/CollectionTest.kt reverse
*/
public inline fun <T> Iterable<T>.reverse() : List<T> {
val list = toList()
Collections.reverse(list)
return list
}
/** Copies all elements into a [[LinkedList]] */
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> = toCollection(ArrayList<T>())
/** Copies all elements into a [[List] */
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> = 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> {
val answer = this.toList()
answer.sort(transform)
return answer
}
*/
@@ -1,16 +0,0 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JLangIterablesJVM.kt
//
import java.util.*
/** Copies all elements into a [[SortedSet]] */
public inline fun <in T> Iterable<T>.toSortedSet() : SortedSet<T> = toCollection(TreeSet<T>())
@@ -1,121 +0,0 @@
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
// Generated from input file: src/kotlin/JLangIterablesLazy.kt
//
import java.util.ArrayList
import java.util.Collection
import java.util.List
//
// This file contains methods which could have a lazy implementation for things like
// Iterator<T> or java.util.Iterator<T>
//
// See [[GenerateStandardLib.kt]] for more details
//
/**
* Returns a list containing all elements which match the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt filter
*/
public inline fun <T> Iterable<T>.filter(predicate: (T) -> Boolean) : List<T> = filterTo(ArrayList<T>(), predicate)
/**
* Returns a list containing all elements which do not match the given predicate
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNot
*/
public inline fun <T> Iterable<T>.filterNot(predicate: (T)-> Boolean) : List<T> = filterNotTo(ArrayList<T>(), predicate)
/**
* Returns a list containing all the non-*null* elements
*
* @includeFunctionBody ../../test/CollectionTest.kt filterNotNull
*/
public inline fun <T> Iterable<T?>?.filterNotNull() : List<T> = filterNotNullTo<T, ArrayList<T>>(java.util.ArrayList<T>())
/**
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
*
* @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/
public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Collection<R>) : Collection<R> = flatMapTo(ArrayList<R>(), transform)
/**
* Creates a copy of this collection as a [[List]] with the element added at the end
*
* @includeFunctionBody ../../test/CollectionTest.kt plus
*/
public inline fun <in T> Iterable<T>.plus(element: T): List<in T> {
val list = toCollection(ArrayList<T>())
list.add(element)
return list
}
/**
* Creates a copy of this collection as a [[List]] with all the elements added at the end
*
* @includeFunctionBody ../../test/CollectionTest.kt plusCollection
*/
public inline fun <in T> Iterable<T>.plus(elements: Iterable<T>): List<T> {
val list = toCollection(ArrayList<T>())
list.addAll(elements.toCollection())
return list
}
/**
* Returns a list containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
*
* @includeFunctionBody ../../test/CollectionTest.kt requireNoNulls
*/
public inline fun <in T> Iterable<T?>?.requireNoNulls() : List<T> {
val list = ArrayList<T>()
for (element in this) {
if (element == null) {
throw IllegalArgumentException("null element found in $this")
} else {
list.add(element)
}
}
return list
}
/**
* Returns a list containing everything but the first *n* elements
*
* @includeFunctionBody ../../test/CollectionTest.kt drop
*/
public inline fun <T> Iterable<T>.drop(n: Int): List<T> {
return dropWhile(countTo(n))
}
/**
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
*/
public inline fun <T> Iterable<T>.dropWhile(predicate: (T) -> Boolean): List<T> = dropWhileTo(ArrayList<T>(), predicate)
/**
* Returns a list containing the first *n* elements
*
* @includeFunctionBody ../../test/CollectionTest.kt take
*/
public inline fun <T> Iterable<T>.take(n: Int): List<T> {
return takeWhile(countTo(n))
}
/**
* Returns a list containing the first elements that satisfy the given *predicate*
*
* @includeFunctionBody ../../test/CollectionTest.kt takeWhile
*/
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)