renamed @includeFunction to @includeFunctionBody to be more clear that the function definition itself won't be included into the kdocs

This commit is contained in:
James Strachan
2012-04-02 15:25:15 +01:00
parent 4d37672809
commit 3fb74d3e69
15 changed files with 88 additions and 88 deletions
@@ -392,7 +392,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
// lets check for javadoc style @ tags and macros // lets check for javadoc style @ tags and macros
if (text.startsWith("@")) { if (text.startsWith("@")) {
val remaining = text.substring(1) val remaining = text.substring(1)
val macro = "includeFunction" val macro = "includeFunctionBody"
if (remaining.startsWith(macro)) { if (remaining.startsWith(macro)) {
val next = remaining.substring(macro.length()).trim() val next = remaining.substring(macro.length()).trim()
val words = next.split("\\s") val words = next.split("\\s")
@@ -13,7 +13,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 function to each element in this collection
* *
* @includeFunction ../../test/CollectionTest.kt map * @includeFunctionBody ../../test/CollectionTest.kt map
*/ */
public inline fun <T, R> Array<T>.map(transform : (T) -> R) : java.util.List<R> { public inline fun <T, R> Array<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(this.size), transform) return mapTo(java.util.ArrayList<R>(this.size), transform)
@@ -8,7 +8,7 @@ import java.util.*
/** /**
* Returns *true* if any elements match the given *predicate* * Returns *true* if any elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt any * @includeFunctionBody ../../test/CollectionTest.kt any
*/ */
public inline fun <T> Array<T>.any(predicate: (T) -> Boolean) : Boolean { public inline fun <T> Array<T>.any(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (predicate(element)) return true for (element in this) if (predicate(element)) return true
@@ -18,7 +18,7 @@ public inline fun <T> Array<T>.any(predicate: (T) -> Boolean) : Boolean {
/** /**
* Returns *true* if all elements match the given *predicate* * Returns *true* if all elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt all * @includeFunctionBody ../../test/CollectionTest.kt all
*/ */
public inline fun <T> Array<T>.all(predicate: (T) -> Boolean) : Boolean { public inline fun <T> Array<T>.all(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (!predicate(element)) return false for (element in this) if (!predicate(element)) return false
@@ -28,7 +28,7 @@ public inline fun <T> Array<T>.all(predicate: (T) -> Boolean) : Boolean {
/** /**
* Returns the number of elements which match the given *predicate* * Returns the number of elements which match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt count * @includeFunctionBody ../../test/CollectionTest.kt count
*/ */
public inline fun <T> Array<T>.count(predicate: (T) -> Boolean) : Int { public inline fun <T> Array<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0 var count = 0
@@ -39,7 +39,7 @@ public inline fun <T> Array<T>.count(predicate: (T) -> Boolean) : Int {
/** /**
* Returns the first element which matches the given *predicate* or *null* if none matched * Returns the first element which matches the given *predicate* or *null* if none matched
* *
* @includeFunction ../../test/CollectionTest.kt find * @includeFunctionBody ../../test/CollectionTest.kt find
*/ */
public inline fun <T> Array<T>.find(predicate: (T) -> Boolean) : T? { public inline fun <T> Array<T>.find(predicate: (T) -> Boolean) : T? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -49,7 +49,7 @@ public inline fun <T> Array<T>.find(predicate: (T) -> Boolean) : T? {
/** /**
* Filters all elements which match the given predicate into the given list * Filters all elements which match the given predicate into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterIntoLinkedList
*/ */
public inline fun <T, C: Collection<in T>> Array<T>.filterTo(result: C, predicate: (T) -> Boolean) : C { public inline fun <T, C: Collection<in T>> Array<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element) for (element in this) if (predicate(element)) result.add(element)
@@ -59,7 +59,7 @@ public inline fun <T, C: Collection<in T>> Array<T>.filterTo(result: C, predicat
/** /**
* Returns a list containing all elements which do not match the given *predicate* * Returns a list containing all elements which do not match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> Array<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L { public inline fun <T, L: List<in T>> Array<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L {
for (element in this) if (!predicate(element)) result.add(element) for (element in this) if (!predicate(element)) result.add(element)
@@ -69,7 +69,7 @@ public inline fun <T, L: List<in T>> Array<T>.filterNotTo(result: L, predicate:
/** /**
* Filters all non-*null* elements into the given list * Filters all non-*null* elements into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> Array<T?>?.filterNotNullTo(result: L) : L { public inline fun <T, L: List<in T>> Array<T?>?.filterNotNullTo(result: L) : L {
if (this != null) { if (this != null) {
@@ -81,7 +81,7 @@ public inline fun <T, L: List<in T>> Array<T?>?.filterNotNullTo(result: L) : L {
/** /**
* Returns the result of transforming each element to one or more values which are concatenated together into a single list * Returns the result of transforming each element to one or more values which are concatenated together into a single list
* *
* @includeFunction ../../test/CollectionTest.kt flatMap * @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/ */
public inline fun <T, R> Array<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> { public inline fun <T, R> Array<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
for (element in this) { for (element in this) {
@@ -96,14 +96,14 @@ public inline fun <T, R> Array<T>.flatMapTo(result: Collection<R>, transform: (T
/** /**
* Performs the given *operation* on each element * Performs the given *operation* on each element
* *
* @includeFunction ../../test/CollectionTest.kt forEach * @includeFunctionBody ../../test/CollectionTest.kt forEach
*/ */
public inline fun <T> Array<T>.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element) public inline fun <T> Array<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 * Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt fold * @includeFunctionBody ../../test/CollectionTest.kt fold
*/ */
public inline fun <T> Array<T>.fold(initial: T, operation: (T, T) -> T): T { public inline fun <T> Array<T>.fold(initial: T, operation: (T, T) -> T): T {
var answer = initial var answer = initial
@@ -114,14 +114,14 @@ public inline fun <T> Array<T>.fold(initial: T, operation: (T, T) -> T): T {
/** /**
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements * Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt foldRight * @includeFunctionBody ../../test/CollectionTest.kt foldRight
*/ */
public inline fun <T> Array<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation) public inline fun <T> Array<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation)
/** /**
* Transforms each element using the result as the key in a map to group elements by the result * Transforms each element using the result as the key in a map to group elements by the result
* *
* @includeFunction ../../test/CollectionTest.kt groupBy * @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/ */
public inline fun <T, K> Array<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> { public inline fun <T, K> Array<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) { for (element in this) {
@@ -141,7 +141,7 @@ public inline fun <T, L: List<in T>> Array<T>.takeWhileTo(result: L, predicate:
/** /**
* Reverses the order the elements into a list * Reverses the order the elements into a list
* *
* @includeFunction ../../test/CollectionTest.kt reverse * @includeFunctionBody ../../test/CollectionTest.kt reverse
*/ */
public inline fun <T> Array<T>.reverse() : List<T> { public inline fun <T> Array<T>.reverse() : List<T> {
val answer = LinkedList<T>() val answer = LinkedList<T>()
@@ -17,35 +17,35 @@ import java.util.List
/** /**
* Returns a list containing all elements which match the given *predicate* * Returns a list containing all elements which match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt filter * @includeFunctionBody ../../test/CollectionTest.kt filter
*/ */
public inline fun <T> Array<T>.filter(predicate: (T) -> Boolean) : List<T> = filterTo(ArrayList<T>(), predicate) public inline fun <T> Array<T>.filter(predicate: (T) -> Boolean) : List<T> = filterTo(ArrayList<T>(), predicate)
/** /**
* Returns a list containing all elements which do not match the given predicate * Returns a list containing all elements which do not match the given predicate
* *
* @includeFunction ../../test/CollectionTest.kt filterNot * @includeFunctionBody ../../test/CollectionTest.kt filterNot
*/ */
public inline fun <T> Array<T>.filterNot(predicate: (T)-> Boolean) : List<T> = filterNotTo(ArrayList<T>(), predicate) public inline fun <T> Array<T>.filterNot(predicate: (T)-> Boolean) : List<T> = filterNotTo(ArrayList<T>(), predicate)
/** /**
* Returns a list containing all the non-*null* elements * Returns a list containing all the non-*null* elements
* *
* @includeFunction ../../test/CollectionTest.kt filterNotNull * @includeFunctionBody ../../test/CollectionTest.kt filterNotNull
*/ */
public inline fun <T> Array<T?>?.filterNotNull() : List<T> = filterNotNullTo<T, ArrayList<T>>(java.util.ArrayList<T>()) public inline fun <T> Array<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 * Returns the result of transforming each element to one or more values which are concatenated together into a single collection
* *
* @includeFunction ../../test/CollectionTest.kt flatMap * @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/ */
public inline fun <T, R> Array<T>.flatMap(transform: (T)-> Collection<R>) : Collection<R> = flatMapTo(ArrayList<R>(), transform) public inline fun <T, R> Array<T>.flatMap(transform: (T)-> Collection<R>) : Collection<R> = flatMapTo(ArrayList<R>(), transform)
/** /**
* Returns a list containing the first *n* elements * Returns a list containing the first *n* elements
* *
* @includeFunction ../../test/CollectionTest.kt take * @includeFunctionBody ../../test/CollectionTest.kt take
*/ */
public inline fun <T> Array<T>.take(n: Int): List<T> { public inline fun <T> Array<T>.take(n: Int): List<T> {
fun countTo(n: Int): (T) -> Boolean { fun countTo(n: Int): (T) -> Boolean {
@@ -58,14 +58,14 @@ public inline fun <T> Array<T>.take(n: Int): List<T> {
/** /**
* Returns a list containing the first elements that satisfy the given *predicate* * Returns a list containing the first elements that satisfy the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt takeWhile * @includeFunctionBody ../../test/CollectionTest.kt takeWhile
*/ */
public inline fun <T> Array<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate) public inline fun <T> Array<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)
/** /**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
* *
* @includeFunction ../../test/CollectionTest.kt join * @includeFunctionBody ../../test/CollectionTest.kt join
*/ */
public inline fun <T> Array<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String { public inline fun <T> Array<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
val buffer = StringBuilder(prefix) val buffer = StringBuilder(prefix)
@@ -13,7 +13,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 function to each element in this collection
* *
* @includeFunction ../../test/CollectionTest.kt map * @includeFunctionBody ../../test/CollectionTest.kt map
*/ */
public inline fun <T, R> java.lang.Iterable<T>.map(transform : (T) -> R) : java.util.List<R> { public inline fun <T, R> java.lang.Iterable<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(), transform) return mapTo(java.util.ArrayList<R>(), transform)
@@ -6,7 +6,7 @@ import java.util.*
/** /**
* Returns *true* if any elements match the given *predicate* * Returns *true* if any elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt any * @includeFunctionBody ../../test/CollectionTest.kt any
*/ */
public inline fun <T> java.util.Iterator<T>.any(predicate: (T) -> Boolean) : Boolean { public inline fun <T> java.util.Iterator<T>.any(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (predicate(element)) return true for (element in this) if (predicate(element)) return true
@@ -16,7 +16,7 @@ public inline fun <T> java.util.Iterator<T>.any(predicate: (T) -> Boolean) : Boo
/** /**
* Returns *true* if all elements match the given *predicate* * Returns *true* if all elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt all * @includeFunctionBody ../../test/CollectionTest.kt all
*/ */
public inline fun <T> java.util.Iterator<T>.all(predicate: (T) -> Boolean) : Boolean { public inline fun <T> java.util.Iterator<T>.all(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (!predicate(element)) return false for (element in this) if (!predicate(element)) return false
@@ -26,7 +26,7 @@ public inline fun <T> java.util.Iterator<T>.all(predicate: (T) -> Boolean) : Boo
/** /**
* Returns the number of elements which match the given *predicate* * Returns the number of elements which match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt count * @includeFunctionBody ../../test/CollectionTest.kt count
*/ */
public inline fun <T> java.util.Iterator<T>.count(predicate: (T) -> Boolean) : Int { public inline fun <T> java.util.Iterator<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0 var count = 0
@@ -37,7 +37,7 @@ public inline fun <T> java.util.Iterator<T>.count(predicate: (T) -> Boolean) : I
/** /**
* Returns the first element which matches the given *predicate* or *null* if none matched * Returns the first element which matches the given *predicate* or *null* if none matched
* *
* @includeFunction ../../test/CollectionTest.kt find * @includeFunctionBody ../../test/CollectionTest.kt find
*/ */
public inline fun <T> java.util.Iterator<T>.find(predicate: (T) -> Boolean) : T? { public inline fun <T> java.util.Iterator<T>.find(predicate: (T) -> Boolean) : T? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -47,7 +47,7 @@ public inline fun <T> java.util.Iterator<T>.find(predicate: (T) -> Boolean) : T?
/** /**
* Filters all elements which match the given predicate into the given list * Filters all elements which match the given predicate into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList * @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>> java.util.Iterator<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element) for (element in this) if (predicate(element)) result.add(element)
@@ -57,7 +57,7 @@ public inline fun <T, C: Collection<in T>> java.util.Iterator<T>.filterTo(result
/** /**
* Returns a list containing all elements which do not match the given *predicate* * Returns a list containing all elements which do not match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> java.util.Iterator<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L { public inline fun <T, L: List<in T>> java.util.Iterator<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L {
for (element in this) if (!predicate(element)) result.add(element) for (element in this) if (!predicate(element)) result.add(element)
@@ -67,7 +67,7 @@ public inline fun <T, L: List<in T>> java.util.Iterator<T>.filterNotTo(result: L
/** /**
* Filters all non-*null* elements into the given list * Filters all non-*null* elements into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> java.util.Iterator<T?>?.filterNotNullTo(result: L) : L { public inline fun <T, L: List<in T>> java.util.Iterator<T?>?.filterNotNullTo(result: L) : L {
if (this != null) { if (this != null) {
@@ -79,7 +79,7 @@ public inline fun <T, L: List<in T>> java.util.Iterator<T?>?.filterNotNullTo(res
/** /**
* Returns the result of transforming each element to one or more values which are concatenated together into a single list * Returns the result of transforming each element to one or more values which are concatenated together into a single list
* *
* @includeFunction ../../test/CollectionTest.kt flatMap * @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> java.util.Iterator<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
for (element in this) { for (element in this) {
@@ -94,14 +94,14 @@ public inline fun <T, R> java.util.Iterator<T>.flatMapTo(result: Collection<R>,
/** /**
* Performs the given *operation* on each element * Performs the given *operation* on each element
* *
* @includeFunction ../../test/CollectionTest.kt forEach * @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> java.util.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 * Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt fold * @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> java.util.Iterator<T>.fold(initial: T, operation: (T, T) -> T): T {
var answer = initial var answer = initial
@@ -112,14 +112,14 @@ public inline fun <T> java.util.Iterator<T>.fold(initial: T, operation: (T, T) -
/** /**
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements * Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt foldRight * @includeFunctionBody ../../test/CollectionTest.kt foldRight
*/ */
public inline fun <T> java.util.Iterator<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation) public inline fun <T> java.util.Iterator<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation)
/** /**
* Transforms each element using the result as the key in a map to group elements by the result * Transforms each element using the result as the key in a map to group elements by the result
* *
* @includeFunction ../../test/CollectionTest.kt groupBy * @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/ */
public inline fun <T, K> java.util.Iterator<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> { public inline fun <T, K> java.util.Iterator<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) { for (element in this) {
@@ -139,7 +139,7 @@ public inline fun <T, L: List<in T>> java.util.Iterator<T>.takeWhileTo(result: L
/** /**
* Reverses the order the elements into a list * Reverses the order the elements into a list
* *
* @includeFunction ../../test/CollectionTest.kt reverse * @includeFunctionBody ../../test/CollectionTest.kt reverse
*/ */
public inline fun <T> java.util.Iterator<T>.reverse() : List<T> { public inline fun <T> java.util.Iterator<T>.reverse() : List<T> {
val answer = LinkedList<T>() val answer = LinkedList<T>()
@@ -13,7 +13,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 function to each element in this collection
* *
* @includeFunction ../../test/CollectionTest.kt map * @includeFunctionBody ../../test/CollectionTest.kt map
*/ */
public inline fun <T, R> Iterable<T>.map(transform : (T) -> R) : java.util.List<R> { public inline fun <T, R> Iterable<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(), transform) return mapTo(java.util.ArrayList<R>(), transform)
@@ -8,7 +8,7 @@ import java.util.*
/** /**
* Returns *true* if any elements match the given *predicate* * Returns *true* if any elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt any * @includeFunctionBody ../../test/CollectionTest.kt any
*/ */
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean) : Boolean { public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (predicate(element)) return true for (element in this) if (predicate(element)) return true
@@ -18,7 +18,7 @@ public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean) : Boolean {
/** /**
* Returns *true* if all elements match the given *predicate* * Returns *true* if all elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt all * @includeFunctionBody ../../test/CollectionTest.kt all
*/ */
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean) : Boolean { public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (!predicate(element)) return false for (element in this) if (!predicate(element)) return false
@@ -28,7 +28,7 @@ public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean) : Boolean {
/** /**
* Returns the number of elements which match the given *predicate* * Returns the number of elements which match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt count * @includeFunctionBody ../../test/CollectionTest.kt count
*/ */
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int { public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0 var count = 0
@@ -39,7 +39,7 @@ public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int {
/** /**
* Returns the first element which matches the given *predicate* or *null* if none matched * Returns the first element which matches the given *predicate* or *null* if none matched
* *
* @includeFunction ../../test/CollectionTest.kt find * @includeFunctionBody ../../test/CollectionTest.kt find
*/ */
public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean) : T? { public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean) : T? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -49,7 +49,7 @@ public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean) : T? {
/** /**
* Filters all elements which match the given predicate into the given list * Filters all elements which match the given predicate into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterIntoLinkedList
*/ */
public inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predicate: (T) -> Boolean) : C { 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) for (element in this) if (predicate(element)) result.add(element)
@@ -59,7 +59,7 @@ public inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predi
/** /**
* Returns a list containing all elements which do not match the given *predicate* * Returns a list containing all elements which do not match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> Iterable<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L { public inline fun <T, L: List<in T>> Iterable<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L {
for (element in this) if (!predicate(element)) result.add(element) for (element in this) if (!predicate(element)) result.add(element)
@@ -69,7 +69,7 @@ public inline fun <T, L: List<in T>> Iterable<T>.filterNotTo(result: L, predicat
/** /**
* Filters all non-*null* elements into the given list * Filters all non-*null* elements into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> Iterable<T?>?.filterNotNullTo(result: L) : L { public inline fun <T, L: List<in T>> Iterable<T?>?.filterNotNullTo(result: L) : L {
if (this != null) { if (this != null) {
@@ -81,7 +81,7 @@ public inline fun <T, L: List<in T>> Iterable<T?>?.filterNotNullTo(result: L) :
/** /**
* Returns the result of transforming each element to one or more values which are concatenated together into a single list * Returns the result of transforming each element to one or more values which are concatenated together into a single list
* *
* @includeFunction ../../test/CollectionTest.kt flatMap * @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/ */
public inline fun <T, R> Iterable<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> { public inline fun <T, R> Iterable<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
for (element in this) { for (element in this) {
@@ -96,14 +96,14 @@ public inline fun <T, R> Iterable<T>.flatMapTo(result: Collection<R>, transform:
/** /**
* Performs the given *operation* on each element * Performs the given *operation* on each element
* *
* @includeFunction ../../test/CollectionTest.kt forEach * @includeFunctionBody ../../test/CollectionTest.kt forEach
*/ */
public inline fun <T> Iterable<T>.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element) 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 * Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt fold * @includeFunctionBody ../../test/CollectionTest.kt fold
*/ */
public inline fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T { public inline fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {
var answer = initial var answer = initial
@@ -114,14 +114,14 @@ public inline fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {
/** /**
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements * Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt foldRight * @includeFunctionBody ../../test/CollectionTest.kt foldRight
*/ */
public inline fun <T> Iterable<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation) public inline fun <T> Iterable<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation)
/** /**
* Transforms each element using the result as the key in a map to group elements by the result * Transforms each element using the result as the key in a map to group elements by the result
* *
* @includeFunction ../../test/CollectionTest.kt groupBy * @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/ */
public inline fun <T, K> Iterable<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> { public inline fun <T, K> Iterable<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) { for (element in this) {
@@ -141,7 +141,7 @@ public inline fun <T, L: List<in T>> Iterable<T>.takeWhileTo(result: L, predicat
/** /**
* Reverses the order the elements into a list * Reverses the order the elements into a list
* *
* @includeFunction ../../test/CollectionTest.kt reverse * @includeFunctionBody ../../test/CollectionTest.kt reverse
*/ */
public inline fun <T> Iterable<T>.reverse() : List<T> { public inline fun <T> Iterable<T>.reverse() : List<T> {
val answer = LinkedList<T>() val answer = LinkedList<T>()
@@ -17,35 +17,35 @@ import java.util.List
/** /**
* Returns a list containing all elements which match the given *predicate* * Returns a list containing all elements which match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt filter * @includeFunctionBody ../../test/CollectionTest.kt filter
*/ */
public inline fun <T> Iterable<T>.filter(predicate: (T) -> Boolean) : List<T> = filterTo(ArrayList<T>(), predicate) 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 * Returns a list containing all elements which do not match the given predicate
* *
* @includeFunction ../../test/CollectionTest.kt filterNot * @includeFunctionBody ../../test/CollectionTest.kt filterNot
*/ */
public inline fun <T> Iterable<T>.filterNot(predicate: (T)-> Boolean) : List<T> = filterNotTo(ArrayList<T>(), predicate) 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 * Returns a list containing all the non-*null* elements
* *
* @includeFunction ../../test/CollectionTest.kt filterNotNull * @includeFunctionBody ../../test/CollectionTest.kt filterNotNull
*/ */
public inline fun <T> Iterable<T?>?.filterNotNull() : List<T> = filterNotNullTo<T, ArrayList<T>>(java.util.ArrayList<T>()) 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 * Returns the result of transforming each element to one or more values which are concatenated together into a single collection
* *
* @includeFunction ../../test/CollectionTest.kt flatMap * @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/ */
public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Collection<R>) : Collection<R> = flatMapTo(ArrayList<R>(), transform) public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Collection<R>) : Collection<R> = flatMapTo(ArrayList<R>(), transform)
/** /**
* Returns a list containing the first *n* elements * Returns a list containing the first *n* elements
* *
* @includeFunction ../../test/CollectionTest.kt take * @includeFunctionBody ../../test/CollectionTest.kt take
*/ */
public inline fun <T> Iterable<T>.take(n: Int): List<T> { public inline fun <T> Iterable<T>.take(n: Int): List<T> {
fun countTo(n: Int): (T) -> Boolean { fun countTo(n: Int): (T) -> Boolean {
@@ -58,14 +58,14 @@ public inline fun <T> Iterable<T>.take(n: Int): List<T> {
/** /**
* Returns a list containing the first elements that satisfy the given *predicate* * Returns a list containing the first elements that satisfy the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt takeWhile * @includeFunctionBody ../../test/CollectionTest.kt takeWhile
*/ */
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate) public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)
/** /**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
* *
* @includeFunction ../../test/CollectionTest.kt join * @includeFunctionBody ../../test/CollectionTest.kt join
*/ */
public inline fun <T> Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String { public inline fun <T> Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
val buffer = StringBuilder(prefix) val buffer = StringBuilder(prefix)
+7 -7
View File
@@ -6,7 +6,7 @@ import kotlin.support.FunctionIterator
/** /**
* Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns *null* * Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns *null*
* *
* @includeFunction ../../test/iterators/IteratorsTest.kt fibonacci * @includeFunctionBody ../../test/iterators/IteratorsTest.kt fibonacci
*/ */
public inline fun <T> iterate(nextFunction: () -> T?) : java.util.Iterator<T> = FunctionIterator(nextFunction) public inline fun <T> iterate(nextFunction: () -> T?) : java.util.Iterator<T> = FunctionIterator(nextFunction)
@@ -29,7 +29,7 @@ private class FilterIsIterator<T, R :T>(val iterator : java.util.Iterator<T>, va
/** /**
* Returns an iterator over elements which match the given *predicate* * Returns an iterator over elements which match the given *predicate*
* *
* @includeFunction ../../test/iterators/IteratorsTest.kt filterAndTakeWhileExtractTheElementsWithinRange * @includeFunctionBody ../../test/iterators/IteratorsTest.kt filterAndTakeWhileExtractTheElementsWithinRange
*/ */
public inline fun <T> java.util.Iterator<T>.filter(predicate: (T) -> Boolean) : java.util.Iterator<T> = FilterIterator<T>(this, predicate) public inline fun <T> java.util.Iterator<T>.filter(predicate: (T) -> Boolean) : java.util.Iterator<T> = FilterIterator<T>(this, predicate)
@@ -70,7 +70,7 @@ private class FilterNotNullIterator<T>(val iterator : java.util.Iterator<T?>?) :
/** /**
* Returns an iterator obtained by applying *transform*, a function transforming an object of type *T* into an object of type *R* * Returns an iterator obtained by applying *transform*, a function transforming an object of type *T* into an object of type *R*
* *
* @includeFunction ../../test/iterators/IteratorsTest.kt mapAndTakeWhileExtractTheTransformedElements * @includeFunctionBody ../../test/iterators/IteratorsTest.kt mapAndTakeWhileExtractTheTransformedElements
*/ */
public inline fun <T, R> java.util.Iterator<T>.map(transform: (T) -> R): java.util.Iterator<R> = MapIterator<T, R>(this, transform) public inline fun <T, R> java.util.Iterator<T>.map(transform: (T) -> R): java.util.Iterator<R> = MapIterator<T, R>(this, transform)
@@ -87,7 +87,7 @@ private class MapIterator<T, R>(val iterator : java.util.Iterator<T>, val transf
/** /**
* Returns an iterator over the concatenated results of transforming each element to one or more values * Returns an iterator over the concatenated results of transforming each element to one or more values
* *
* @includeFunction ../../test/iterators/IteratorsTest.kt flatMapAndTakeExtractTheTransformedElements * @includeFunctionBody ../../test/iterators/IteratorsTest.kt flatMapAndTakeExtractTheTransformedElements
*/ */
public inline fun <T, R> java.util.Iterator<T>.flatMap(transform: (T) -> java.util.Iterator<R>): java.util.Iterator<R> = FlatMapIterator<T, R>(this, transform) public inline fun <T, R> java.util.Iterator<T>.flatMap(transform: (T) -> java.util.Iterator<R>): java.util.Iterator<R> = FlatMapIterator<T, R>(this, transform)
@@ -113,7 +113,7 @@ private class FlatMapIterator<T, R>(val iterator : java.util.Iterator<T>, val tr
/** /**
* Returns an iterator restricted to the first *n* elements * Returns an iterator restricted to the first *n* elements
* *
* @includeFunction ../../test/iterators/IteratorsTest.kt takeExtractsTheFirstNElements * @includeFunctionBody ../../test/iterators/IteratorsTest.kt takeExtractsTheFirstNElements
*/ */
public inline fun <T> java.util.Iterator<T>.take(n: Int): java.util.Iterator<T> { public inline fun <T> java.util.Iterator<T>.take(n: Int): java.util.Iterator<T> {
fun countTo(n: Int): (T) -> Boolean { fun countTo(n: Int): (T) -> Boolean {
@@ -126,7 +126,7 @@ public inline fun <T> java.util.Iterator<T>.take(n: Int): java.util.Iterator<T>
/** /**
* Returns an iterator restricted to the first elements that match the given *predicate* * Returns an iterator restricted to the first elements that match the given *predicate*
* *
* @includeFunction ../../test/iterators/IteratorsTest.kt filterAndTakeWhileExtractTheElementsWithinRange * @includeFunctionBody ../../test/iterators/IteratorsTest.kt filterAndTakeWhileExtractTheElementsWithinRange
*/ */
public inline fun <T> java.util.Iterator<T>.takeWhile(predicate: (T) -> Boolean): java.util.Iterator<T> = TakeWhileIterator<T>(this, predicate) public inline fun <T> java.util.Iterator<T>.takeWhile(predicate: (T) -> Boolean): java.util.Iterator<T> = TakeWhileIterator<T>(this, predicate)
@@ -146,7 +146,7 @@ private class TakeWhileIterator<T>(val iterator: java.util.Iterator<T>, val pred
/** /**
* Creates a string from the first *n (= limit)* elements separated using the *separator* and using the given *prefix* and *postfix* if supplied * Creates a string from the first *n (= limit)* elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
* *
* @includeFunction ../../test/iterators/IteratorsTest.kt joinConcatenatesTheFirstNElementsAboveAThreshold * @includeFunctionBody ../../test/iterators/IteratorsTest.kt joinConcatenatesTheFirstNElementsAboveAThreshold
*/ */
public inline fun <T> java.util.Iterator<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int? = null) : String { public inline fun <T> java.util.Iterator<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int? = null) : String {
val buffer = StringBuilder(prefix) val buffer = StringBuilder(prefix)
+2 -2
View File
@@ -38,7 +38,7 @@ public inline fun <K,V> java.util.Map<K,V>?.orEmpty() : java.util.Map<K,V>
/** /**
* Returns the value for the given key or returns the result of the defaultValue function if there was no entry for the given key * Returns the value for the given key or returns the result of the defaultValue function if there was no entry for the given key
* *
* @includeFunction ../../test/MapTest.kt getOrElse * @includeFunctionBody ../../test/MapTest.kt getOrElse
*/ */
public inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V { public inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V {
val current = this.get(key) val current = this.get(key)
@@ -52,7 +52,7 @@ public inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()->
/** /**
* Returns the value for the given key or the result of the defaultValue function is put into the map for the given value and returned * Returns the value for the given key or the result of the defaultValue function is put into the map for the given value and returned
* *
* @includeFunction ../../test/MapTest.kt getOrElse * @includeFunctionBody ../../test/MapTest.kt getOrElse
*/ */
public inline fun <K,V> java.util.Map<K,V>.getOrPut(key: K, defaultValue: ()-> V) : V { public inline fun <K,V> java.util.Map<K,V>.getOrPut(key: K, defaultValue: ()-> V) : V {
val current = this.get(key) val current = this.get(key)
@@ -12,7 +12,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 function to each element in this collection
* *
* @includeFunction ../../test/CollectionTest.kt map * @includeFunctionBody ../../test/CollectionTest.kt map
*/ */
public inline fun <T, R> java.util.Collection<T>.map(transform : (T) -> R) : java.util.List<R> { public inline fun <T, R> java.util.Collection<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(this.size), transform) return mapTo(java.util.ArrayList<R>(this.size), transform)
+13 -13
View File
@@ -5,7 +5,7 @@ import java.util.*
/** /**
* Returns *true* if any elements match the given *predicate* * Returns *true* if any elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt any * @includeFunctionBody ../../test/CollectionTest.kt any
*/ */
public inline fun <T> java.lang.Iterable<T>.any(predicate: (T) -> Boolean) : Boolean { public inline fun <T> java.lang.Iterable<T>.any(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (predicate(element)) return true for (element in this) if (predicate(element)) return true
@@ -15,7 +15,7 @@ public inline fun <T> java.lang.Iterable<T>.any(predicate: (T) -> Boolean) : Boo
/** /**
* Returns *true* if all elements match the given *predicate* * Returns *true* if all elements match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt all * @includeFunctionBody ../../test/CollectionTest.kt all
*/ */
public inline fun <T> java.lang.Iterable<T>.all(predicate: (T) -> Boolean) : Boolean { public inline fun <T> java.lang.Iterable<T>.all(predicate: (T) -> Boolean) : Boolean {
for (element in this) if (!predicate(element)) return false for (element in this) if (!predicate(element)) return false
@@ -25,7 +25,7 @@ public inline fun <T> java.lang.Iterable<T>.all(predicate: (T) -> Boolean) : Boo
/** /**
* Returns the number of elements which match the given *predicate* * Returns the number of elements which match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt count * @includeFunctionBody ../../test/CollectionTest.kt count
*/ */
public inline fun <T> java.lang.Iterable<T>.count(predicate: (T) -> Boolean) : Int { public inline fun <T> java.lang.Iterable<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0 var count = 0
@@ -36,7 +36,7 @@ public inline fun <T> java.lang.Iterable<T>.count(predicate: (T) -> Boolean) : I
/** /**
* Returns the first element which matches the given *predicate* or *null* if none matched * Returns the first element which matches the given *predicate* or *null* if none matched
* *
* @includeFunction ../../test/CollectionTest.kt find * @includeFunctionBody ../../test/CollectionTest.kt find
*/ */
public inline fun <T> java.lang.Iterable<T>.find(predicate: (T) -> Boolean) : T? { public inline fun <T> java.lang.Iterable<T>.find(predicate: (T) -> Boolean) : T? {
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -46,7 +46,7 @@ public inline fun <T> java.lang.Iterable<T>.find(predicate: (T) -> Boolean) : T?
/** /**
* Filters all elements which match the given predicate into the given list * Filters all elements which match the given predicate into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterIntoLinkedList
*/ */
public inline fun <T, C: Collection<in T>> java.lang.Iterable<T>.filterTo(result: C, predicate: (T) -> Boolean) : C { public inline fun <T, C: Collection<in T>> java.lang.Iterable<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
for (element in this) if (predicate(element)) result.add(element) for (element in this) if (predicate(element)) result.add(element)
@@ -56,7 +56,7 @@ public inline fun <T, C: Collection<in T>> java.lang.Iterable<T>.filterTo(result
/** /**
* Returns a list containing all elements which do not match the given *predicate* * Returns a list containing all elements which do not match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> java.lang.Iterable<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L { public inline fun <T, L: List<in T>> java.lang.Iterable<T>.filterNotTo(result: L, predicate: (T) -> Boolean) : L {
for (element in this) if (!predicate(element)) result.add(element) for (element in this) if (!predicate(element)) result.add(element)
@@ -66,7 +66,7 @@ public inline fun <T, L: List<in T>> java.lang.Iterable<T>.filterNotTo(result: L
/** /**
* Filters all non-*null* elements into the given list * Filters all non-*null* elements into the given list
* *
* @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList * @includeFunctionBody ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/ */
public inline fun <T, L: List<in T>> java.lang.Iterable<T?>?.filterNotNullTo(result: L) : L { public inline fun <T, L: List<in T>> java.lang.Iterable<T?>?.filterNotNullTo(result: L) : L {
if (this != null) { if (this != null) {
@@ -78,7 +78,7 @@ public inline fun <T, L: List<in T>> java.lang.Iterable<T?>?.filterNotNullTo(res
/** /**
* Returns the result of transforming each element to one or more values which are concatenated together into a single list * Returns the result of transforming each element to one or more values which are concatenated together into a single list
* *
* @includeFunction ../../test/CollectionTest.kt flatMap * @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/ */
public inline fun <T, R> java.lang.Iterable<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> { public inline fun <T, R> java.lang.Iterable<T>.flatMapTo(result: Collection<R>, transform: (T) -> Collection<R>) : Collection<R> {
for (element in this) { for (element in this) {
@@ -93,14 +93,14 @@ public inline fun <T, R> java.lang.Iterable<T>.flatMapTo(result: Collection<R>,
/** /**
* Performs the given *operation* on each element * Performs the given *operation* on each element
* *
* @includeFunction ../../test/CollectionTest.kt forEach * @includeFunctionBody ../../test/CollectionTest.kt forEach
*/ */
public inline fun <T> java.lang.Iterable<T>.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element) public inline fun <T> java.lang.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 * Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt fold * @includeFunctionBody ../../test/CollectionTest.kt fold
*/ */
public inline fun <T> java.lang.Iterable<T>.fold(initial: T, operation: (T, T) -> T): T { public inline fun <T> java.lang.Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {
var answer = initial var answer = initial
@@ -111,14 +111,14 @@ public inline fun <T> java.lang.Iterable<T>.fold(initial: T, operation: (T, T) -
/** /**
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements * Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
* *
* @includeFunction ../../test/CollectionTest.kt foldRight * @includeFunctionBody ../../test/CollectionTest.kt foldRight
*/ */
public inline fun <T> java.lang.Iterable<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation) public inline fun <T> java.lang.Iterable<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, operation)
/** /**
* Transforms each element using the result as the key in a map to group elements by the result * Transforms each element using the result as the key in a map to group elements by the result
* *
* @includeFunction ../../test/CollectionTest.kt groupBy * @includeFunctionBody ../../test/CollectionTest.kt groupBy
*/ */
public inline fun <T, K> java.lang.Iterable<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> { public inline fun <T, K> java.lang.Iterable<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>(), toKey: (T) -> K) : Map<K, List<T>> {
for (element in this) { for (element in this) {
@@ -138,7 +138,7 @@ public inline fun <T, L: List<in T>> java.lang.Iterable<T>.takeWhileTo(result: L
/** /**
* Reverses the order the elements into a list * Reverses the order the elements into a list
* *
* @includeFunction ../../test/CollectionTest.kt reverse * @includeFunctionBody ../../test/CollectionTest.kt reverse
*/ */
public inline fun <T> java.lang.Iterable<T>.reverse() : List<T> { public inline fun <T> java.lang.Iterable<T>.reverse() : List<T> {
val answer = LinkedList<T>() val answer = LinkedList<T>()
@@ -14,35 +14,35 @@ import java.util.List
/** /**
* Returns a list containing all elements which match the given *predicate* * Returns a list containing all elements which match the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt filter * @includeFunctionBody ../../test/CollectionTest.kt filter
*/ */
public inline fun <T> java.lang.Iterable<T>.filter(predicate: (T) -> Boolean) : List<T> = filterTo(ArrayList<T>(), predicate) public inline fun <T> java.lang.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 * Returns a list containing all elements which do not match the given predicate
* *
* @includeFunction ../../test/CollectionTest.kt filterNot * @includeFunctionBody ../../test/CollectionTest.kt filterNot
*/ */
public inline fun <T> java.lang.Iterable<T>.filterNot(predicate: (T)-> Boolean) : List<T> = filterNotTo(ArrayList<T>(), predicate) public inline fun <T> java.lang.Iterable<T>.filterNot(predicate: (T)-> Boolean) : List<T> = filterNotTo(ArrayList<T>(), predicate)
/** /**
* Returns a list containing all the non-*null* elements * Returns a list containing all the non-*null* elements
* *
* @includeFunction ../../test/CollectionTest.kt filterNotNull * @includeFunctionBody ../../test/CollectionTest.kt filterNotNull
*/ */
public inline fun <T> java.lang.Iterable<T?>?.filterNotNull() : List<T> = filterNotNullTo<T, ArrayList<T>>(java.util.ArrayList<T>()) public inline fun <T> java.lang.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 * Returns the result of transforming each element to one or more values which are concatenated together into a single collection
* *
* @includeFunction ../../test/CollectionTest.kt flatMap * @includeFunctionBody ../../test/CollectionTest.kt flatMap
*/ */
public inline fun <T, R> java.lang.Iterable<T>.flatMap(transform: (T)-> Collection<R>) : Collection<R> = flatMapTo(ArrayList<R>(), transform) public inline fun <T, R> java.lang.Iterable<T>.flatMap(transform: (T)-> Collection<R>) : Collection<R> = flatMapTo(ArrayList<R>(), transform)
/** /**
* Returns a list containing the first *n* elements * Returns a list containing the first *n* elements
* *
* @includeFunction ../../test/CollectionTest.kt take * @includeFunctionBody ../../test/CollectionTest.kt take
*/ */
public inline fun <T> java.lang.Iterable<T>.take(n: Int): List<T> { public inline fun <T> java.lang.Iterable<T>.take(n: Int): List<T> {
fun countTo(n: Int): (T) -> Boolean { fun countTo(n: Int): (T) -> Boolean {
@@ -55,14 +55,14 @@ public inline fun <T> java.lang.Iterable<T>.take(n: Int): List<T> {
/** /**
* Returns a list containing the first elements that satisfy the given *predicate* * Returns a list containing the first elements that satisfy the given *predicate*
* *
* @includeFunction ../../test/CollectionTest.kt takeWhile * @includeFunctionBody ../../test/CollectionTest.kt takeWhile
*/ */
public inline fun <T> java.lang.Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate) public inline fun <T> java.lang.Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)
/** /**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied * Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
* *
* @includeFunction ../../test/CollectionTest.kt join * @includeFunctionBody ../../test/CollectionTest.kt join
*/ */
public inline fun <T> java.lang.Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String { public inline fun <T> java.lang.Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
val buffer = StringBuilder(prefix) val buffer = StringBuilder(prefix)
@@ -47,7 +47,7 @@ public inline fun <T> java.lang.Iterable<T>.first() : T {
* *
* Will throw an exception if there are no elements. * Will throw an exception if there are no elements.
* *
* @includeFunction ../../test/CollectionTest.kt last * @includeFunctionBody ../../test/CollectionTest.kt last
*/ */
// TODO: Specify type of the exception // TODO: Specify type of the exception
public fun <T> java.lang.Iterable<T>.last() : T { public fun <T> java.lang.Iterable<T>.last() : T {