From fe9d5ddf894a7107d0fa312bd09a846ac091572e Mon Sep 17 00:00:00 2001 From: James Strachan Date: Tue, 27 Mar 2012 12:48:37 +0100 Subject: [PATCH] fixed up the code generator after moving stuff around and updated with the latest/greatest documentation and function includes --- .../generated/ArraysFromJavaCollections.kt | 8 +- .../src/generated/ArraysFromJavaIterables.kt | 89 +++++++++++++++---- .../generated/ArraysFromJavaIterablesLazy.kt | 28 ++++-- .../JavaUtilIterablesFromJavaCollections.kt | 8 +- .../JavaUtilIteratorsFromJavaIterables.kt | 89 +++++++++++++++---- .../generated/StandardFromJavaCollections.kt | 8 +- .../generated/StandardFromJavaIterables.kt | 89 +++++++++++++++---- .../StandardFromJavaIterablesLazy.kt | 28 ++++-- libraries/stdlib/test/GenerateStandardLib.kt | 8 +- 9 files changed, 274 insertions(+), 81 deletions(-) diff --git a/libraries/stdlib/src/generated/ArraysFromJavaCollections.kt b/libraries/stdlib/src/generated/ArraysFromJavaCollections.kt index a572e6198c2..ee25a60503e 100644 --- a/libraries/stdlib/src/generated/ArraysFromJavaCollections.kt +++ b/libraries/stdlib/src/generated/ArraysFromJavaCollections.kt @@ -1,9 +1,13 @@ -// NOTE this file is auto-generated from src/JavaCollections.kt +// NOTE this file is auto-generated from src/kotlin/JavaCollections.kt package kotlin 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 + */ inline fun Array.map(transform : (T) -> R) : java.util.List { return mapTo(java.util.ArrayList(this.size), transform) } diff --git a/libraries/stdlib/src/generated/ArraysFromJavaIterables.kt b/libraries/stdlib/src/generated/ArraysFromJavaIterables.kt index 2f3bac7bf3f..d85f43f052c 100644 --- a/libraries/stdlib/src/generated/ArraysFromJavaIterables.kt +++ b/libraries/stdlib/src/generated/ArraysFromJavaIterables.kt @@ -1,11 +1,15 @@ -// NOTE this file is auto-generated from src/JavaIterables.kt +// NOTE this file is auto-generated from src/kotlin/JavaIterables.kt package kotlin import kotlin.util.* import java.util.* -/** Returns true if any elements in the collection match the given predicate */ +/** + * Returns true if any elements in the collection match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt any + */ inline fun Array.any(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (predicate(elem)) { @@ -15,7 +19,11 @@ inline fun Array.any(predicate: (T)-> Boolean) : Boolean { return false } -/** Returns true if all elements in the collection match the given predicate */ +/** + * Returns true if all elements in the collection match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt all + */ inline fun Array.all(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (!predicate(elem)) { @@ -25,7 +33,11 @@ inline fun Array.all(predicate: (T)-> Boolean) : Boolean { return true } -/** Returns the number of items which match the given predicate */ +/** + * Returns the number of items which match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt count + */ inline fun Array.count(predicate: (T)-> Boolean) : Int { var answer = 0 for (elem in this) { @@ -35,7 +47,11 @@ inline fun Array.count(predicate: (T)-> Boolean) : Int { return answer } -/** Returns the first item in the collection which matches the given predicate or null if none matched */ +/** + * Returns the first item in the collection which matches the given predicate or null if none matched + * + * @includeFunction ../../test/CollectionTest.kt find + */ inline fun Array.find(predicate: (T)-> Boolean) : T? { for (elem in this) { if (predicate(elem)) @@ -44,7 +60,11 @@ inline fun Array.find(predicate: (T)-> Boolean) : T? { return null } -/** Filters all elements in this collection which match the given predicate into the given result collection */ +/** + * Filters all elements in this collection which match the given predicate into the given result collection + * + * @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList + */ inline fun > Array.filterTo(result: C, predicate: (T)-> Boolean) : C { for (elem in this) { if (predicate(elem)) @@ -53,18 +73,27 @@ inline fun > Array.filterTo(result: C, predicate: (T)- return result } -/** Filters all the null elements in this collection into the given result collection */ +/** + * Filters all the null elements in this collection into the given result collection + * + * @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList + */ inline fun > Array?.filterNotNullTo(result: C) : C { if (this != null) { for (elem in this) { - if (elem != null) + if (elem != null) { result.add(elem) + } } } return result } -/** Returns a new collection containing all elements in this collection which do not match the given predicate */ +/** + * Returns a new collection containing all elements in this collection which do not match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList + */ inline fun > Array.filterNotTo(result: C, predicate: (T)-> Boolean) : C { for (elem in this) { if (!predicate(elem)) @@ -74,9 +103,10 @@ inline fun > Array.filterNotTo(result: C, predicate: ( } /** - * Returns the result of transforming each item in the collection to a one or more values which - * are concatenated together into a single collection - */ + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + */ +// TODO * @includeFunction ../../test/CollectionTest.kt flatMapTo inline fun Array.flatMapTo(result: Collection, transform: (T)-> Collection) : Collection { for (elem in this) { val coll = transform(elem) @@ -89,7 +119,11 @@ inline fun Array.flatMapTo(result: Collection, transform: (T)-> Col return result } -/** Performs the given operation on each element inside the collection */ +/** + * Performs the given operation on each element inside the collection + * + * @includeFunction ../../test/CollectionTest.kt forEach + */ inline fun Array.forEach(operation: (element: T) -> Unit) { for (elem in this) operation(elem) @@ -98,8 +132,7 @@ inline fun Array.forEach(operation: (element: T) -> Unit) { /** * Folds all the values from from left to right with the initial value to perform the operation on sequential pairs of values * - * For example to sum together all numeric values in a collection of numbers it would be - * {code}val total = numbers.fold(0){(a, b) -> a + b}{code} + * @includeFunction ../../test/CollectionTest.kt fold */ inline fun Array.fold(initial: T, operation: (it: T, it2: T) -> T): T { var answer = initial @@ -111,6 +144,8 @@ inline fun Array.fold(initial: T, operation: (it: T, it2: T) -> T): T { /** * Folds all the values from right to left with the initial value to perform the operation on sequential pairs of values + * + * @includeFunction ../../test/CollectionTest.kt foldRight */ inline fun Array.foldRight(initial: T, operation: (it: T, it2: T) -> T): T { val reversed = this.reverse() @@ -120,6 +155,8 @@ inline fun Array.foldRight(initial: T, operation: (it: T, it2: T) -> T): /** * Iterates through the collection performing the transformation on each element and using the result * as the key in a map to group elements by the result + * + * @includeFunction ../../test/CollectionTest.kt groupBy */ inline fun Array.groupBy(result: Map> = HashMap>(), toKey: (T)-> K) : Map> { for (elem in this) { @@ -131,7 +168,11 @@ inline fun Array.groupBy(result: Map> = HashMap>(), } -/** Creates a String from all the elements in the collection, using the seperator between them and using the given prefix and postfix if supplied */ +/** + * Creates a String from all the elements in the collection, using the seperator between them and using the given prefix and postfix if supplied + * + * @includeFunction ../../test/CollectionTest.kt join + */ inline fun Array.join(separator: String, prefix: String = "", postfix: String = "") : String { val buffer = StringBuilder(prefix) var first = true @@ -146,7 +187,11 @@ inline fun Array.join(separator: String, prefix: String = "", postfix: St return buffer.toString().sure() } -/** Returns a reversed List of this collection */ +/** + * Returns a reversed List of this collection + * + * @includeFunction ../../test/CollectionTest.kt reverse + */ inline fun Array.reverse() : List { val answer = LinkedList() for (elem in this) { @@ -155,14 +200,20 @@ inline fun Array.reverse() : List { return answer } -/** Copies the collection into the given collection */ +/** + * Copies the collection into the given collection + * + * @includeFunction ../../test/CollectionTest.kt reverse + */ inline fun > Array.to(result: C) : C { for (elem in this) result.add(elem) return result } -/** Converts the collection into a LinkedList */ +/** + * Converts the collection into a LinkedList + */ inline fun Array.toLinkedList() : LinkedList = this.to(LinkedList()) /** Converts the collection into a List */ diff --git a/libraries/stdlib/src/generated/ArraysFromJavaIterablesLazy.kt b/libraries/stdlib/src/generated/ArraysFromJavaIterablesLazy.kt index eb1705a05e7..0c2ee079a33 100644 --- a/libraries/stdlib/src/generated/ArraysFromJavaIterablesLazy.kt +++ b/libraries/stdlib/src/generated/ArraysFromJavaIterablesLazy.kt @@ -1,4 +1,4 @@ -// NOTE this file is auto-generated from src/JavaIterablesLazy.kt +// NOTE this file is auto-generated from src/kotlin/JavaIterablesLazy.kt package kotlin import kotlin.util.* @@ -12,19 +12,33 @@ import java.util.* // See [[GenerateStandardLib.kt]] for more details // -/** Returns a new List containing all elements in this collection which match the given predicate */ +/** + * Returns a new List containing all elements in this collection which match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt filter + */ inline fun Array.filter(predicate: (T)-> Boolean) : Collection = filterTo(java.util.ArrayList(), predicate) -/** Returns a List containing all the non null elements in this collection */ +/** + * Returns a List containing all the non null elements in this collection + * + * @includeFunction ../../test/CollectionTest.kt filterNotNull + */ inline fun Array?.filterNotNull() : Collection = filterNotNullTo>(java.util.ArrayList()) -/** Returns a new collection containing all elements in this collection which do not match the given predicate */ +/** + * Returns a new collection containing all elements in this collection which do not match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt filterNot + */ inline fun Array.filterNot(predicate: (T)-> Boolean) : Collection = filterNotTo(ArrayList(), predicate) /** - * Returns the result of transforming each item in the collection to a one or more values which - * are concatenated together into a single collection - */ + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + * + * @includeFunction ../../test/CollectionTest.kt flatMap + */ inline fun Array.flatMap(transform: (T)-> Collection) : Collection { return flatMapTo(ArrayList(), transform) } diff --git a/libraries/stdlib/src/generated/JavaUtilIterablesFromJavaCollections.kt b/libraries/stdlib/src/generated/JavaUtilIterablesFromJavaCollections.kt index 657a412cb25..4f0a3ab224b 100644 --- a/libraries/stdlib/src/generated/JavaUtilIterablesFromJavaCollections.kt +++ b/libraries/stdlib/src/generated/JavaUtilIterablesFromJavaCollections.kt @@ -1,9 +1,13 @@ -// NOTE this file is auto-generated from src/JavaCollections.kt +// NOTE this file is auto-generated from src/kotlin/JavaCollections.kt package kotlin 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 + */ inline fun java.lang.Iterable.map(transform : (T) -> R) : java.util.List { return mapTo(java.util.ArrayList(), transform) } diff --git a/libraries/stdlib/src/generated/JavaUtilIteratorsFromJavaIterables.kt b/libraries/stdlib/src/generated/JavaUtilIteratorsFromJavaIterables.kt index 5810c035ab2..7f0afe3add7 100644 --- a/libraries/stdlib/src/generated/JavaUtilIteratorsFromJavaIterables.kt +++ b/libraries/stdlib/src/generated/JavaUtilIteratorsFromJavaIterables.kt @@ -1,9 +1,13 @@ -// NOTE this file is auto-generated from src/JavaIterables.kt +// NOTE this file is auto-generated from src/kotlin/JavaIterables.kt package kotlin import java.util.* -/** Returns true if any elements in the collection match the given predicate */ +/** + * Returns true if any elements in the collection match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt any + */ inline fun java.util.Iterator.any(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (predicate(elem)) { @@ -13,7 +17,11 @@ inline fun java.util.Iterator.any(predicate: (T)-> Boolean) : Boolean { return false } -/** Returns true if all elements in the collection match the given predicate */ +/** + * Returns true if all elements in the collection match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt all + */ inline fun java.util.Iterator.all(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (!predicate(elem)) { @@ -23,7 +31,11 @@ inline fun java.util.Iterator.all(predicate: (T)-> Boolean) : Boolean { return true } -/** Returns the number of items which match the given predicate */ +/** + * Returns the number of items which match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt count + */ inline fun java.util.Iterator.count(predicate: (T)-> Boolean) : Int { var answer = 0 for (elem in this) { @@ -33,7 +45,11 @@ inline fun java.util.Iterator.count(predicate: (T)-> Boolean) : Int { return answer } -/** Returns the first item in the collection which matches the given predicate or null if none matched */ +/** + * Returns the first item in the collection which matches the given predicate or null if none matched + * + * @includeFunction ../../test/CollectionTest.kt find + */ inline fun java.util.Iterator.find(predicate: (T)-> Boolean) : T? { for (elem in this) { if (predicate(elem)) @@ -42,7 +58,11 @@ inline fun java.util.Iterator.find(predicate: (T)-> Boolean) : T? { return null } -/** Filters all elements in this collection which match the given predicate into the given result collection */ +/** + * Filters all elements in this collection which match the given predicate into the given result collection + * + * @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList + */ inline fun > java.util.Iterator.filterTo(result: C, predicate: (T)-> Boolean) : C { for (elem in this) { if (predicate(elem)) @@ -51,18 +71,27 @@ inline fun > java.util.Iterator.filterTo(result: C, pr return result } -/** Filters all the null elements in this collection into the given result collection */ +/** + * Filters all the null elements in this collection into the given result collection + * + * @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList + */ inline fun > java.util.Iterator?.filterNotNullTo(result: C) : C { if (this != null) { for (elem in this) { - if (elem != null) + if (elem != null) { result.add(elem) + } } } return result } -/** Returns a new collection containing all elements in this collection which do not match the given predicate */ +/** + * Returns a new collection containing all elements in this collection which do not match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList + */ inline fun > java.util.Iterator.filterNotTo(result: C, predicate: (T)-> Boolean) : C { for (elem in this) { if (!predicate(elem)) @@ -72,9 +101,10 @@ inline fun > java.util.Iterator.filterNotTo(result: C, } /** - * Returns the result of transforming each item in the collection to a one or more values which - * are concatenated together into a single collection - */ + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + */ +// TODO * @includeFunction ../../test/CollectionTest.kt flatMapTo inline fun java.util.Iterator.flatMapTo(result: Collection, transform: (T)-> Collection) : Collection { for (elem in this) { val coll = transform(elem) @@ -87,7 +117,11 @@ inline fun java.util.Iterator.flatMapTo(result: Collection, transfo return result } -/** Performs the given operation on each element inside the collection */ +/** + * Performs the given operation on each element inside the collection + * + * @includeFunction ../../test/CollectionTest.kt forEach + */ inline fun java.util.Iterator.forEach(operation: (element: T) -> Unit) { for (elem in this) operation(elem) @@ -96,8 +130,7 @@ inline fun java.util.Iterator.forEach(operation: (element: T) -> Unit) { /** * Folds all the values from from left to right with the initial value to perform the operation on sequential pairs of values * - * For example to sum together all numeric values in a collection of numbers it would be - * {code}val total = numbers.fold(0){(a, b) -> a + b}{code} + * @includeFunction ../../test/CollectionTest.kt fold */ inline fun java.util.Iterator.fold(initial: T, operation: (it: T, it2: T) -> T): T { var answer = initial @@ -109,6 +142,8 @@ inline fun java.util.Iterator.fold(initial: T, operation: (it: T, it2: T) /** * Folds all the values from right to left with the initial value to perform the operation on sequential pairs of values + * + * @includeFunction ../../test/CollectionTest.kt foldRight */ inline fun java.util.Iterator.foldRight(initial: T, operation: (it: T, it2: T) -> T): T { val reversed = this.reverse() @@ -118,6 +153,8 @@ inline fun java.util.Iterator.foldRight(initial: T, operation: (it: T, it /** * Iterates through the collection performing the transformation on each element and using the result * as the key in a map to group elements by the result + * + * @includeFunction ../../test/CollectionTest.kt groupBy */ inline fun java.util.Iterator.groupBy(result: Map> = HashMap>(), toKey: (T)-> K) : Map> { for (elem in this) { @@ -129,7 +166,11 @@ inline fun java.util.Iterator.groupBy(result: Map> = HashMap< } -/** Creates a String from all the elements in the collection, using the seperator between them and using the given prefix and postfix if supplied */ +/** + * Creates a String from all the elements in the collection, using the seperator between them and using the given prefix and postfix if supplied + * + * @includeFunction ../../test/CollectionTest.kt join + */ inline fun java.util.Iterator.join(separator: String, prefix: String = "", postfix: String = "") : String { val buffer = StringBuilder(prefix) var first = true @@ -144,7 +185,11 @@ inline fun java.util.Iterator.join(separator: String, prefix: String = "" return buffer.toString().sure() } -/** Returns a reversed List of this collection */ +/** + * Returns a reversed List of this collection + * + * @includeFunction ../../test/CollectionTest.kt reverse + */ inline fun java.util.Iterator.reverse() : List { val answer = LinkedList() for (elem in this) { @@ -153,14 +198,20 @@ inline fun java.util.Iterator.reverse() : List { return answer } -/** Copies the collection into the given collection */ +/** + * Copies the collection into the given collection + * + * @includeFunction ../../test/CollectionTest.kt reverse + */ inline fun > java.util.Iterator.to(result: C) : C { for (elem in this) result.add(elem) return result } -/** Converts the collection into a LinkedList */ +/** + * Converts the collection into a LinkedList + */ inline fun java.util.Iterator.toLinkedList() : LinkedList = this.to(LinkedList()) /** Converts the collection into a List */ diff --git a/libraries/stdlib/src/generated/StandardFromJavaCollections.kt b/libraries/stdlib/src/generated/StandardFromJavaCollections.kt index 7b05938a752..c12747b7db3 100644 --- a/libraries/stdlib/src/generated/StandardFromJavaCollections.kt +++ b/libraries/stdlib/src/generated/StandardFromJavaCollections.kt @@ -1,9 +1,13 @@ -// NOTE this file is auto-generated from src/JavaCollections.kt +// NOTE this file is auto-generated from src/kotlin/JavaCollections.kt package kotlin 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 + */ inline fun Iterable.map(transform : (T) -> R) : java.util.List { return mapTo(java.util.ArrayList(), transform) } diff --git a/libraries/stdlib/src/generated/StandardFromJavaIterables.kt b/libraries/stdlib/src/generated/StandardFromJavaIterables.kt index 98c85352358..d776f3fed6e 100644 --- a/libraries/stdlib/src/generated/StandardFromJavaIterables.kt +++ b/libraries/stdlib/src/generated/StandardFromJavaIterables.kt @@ -1,11 +1,15 @@ -// NOTE this file is auto-generated from src/JavaIterables.kt +// NOTE this file is auto-generated from src/kotlin/JavaIterables.kt package kotlin import kotlin.util.* import java.util.* -/** Returns true if any elements in the collection match the given predicate */ +/** + * Returns true if any elements in the collection match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt any + */ inline fun Iterable.any(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (predicate(elem)) { @@ -15,7 +19,11 @@ inline fun Iterable.any(predicate: (T)-> Boolean) : Boolean { return false } -/** Returns true if all elements in the collection match the given predicate */ +/** + * Returns true if all elements in the collection match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt all + */ inline fun Iterable.all(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (!predicate(elem)) { @@ -25,7 +33,11 @@ inline fun Iterable.all(predicate: (T)-> Boolean) : Boolean { return true } -/** Returns the number of items which match the given predicate */ +/** + * Returns the number of items which match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt count + */ inline fun Iterable.count(predicate: (T)-> Boolean) : Int { var answer = 0 for (elem in this) { @@ -35,7 +47,11 @@ inline fun Iterable.count(predicate: (T)-> Boolean) : Int { return answer } -/** Returns the first item in the collection which matches the given predicate or null if none matched */ +/** + * Returns the first item in the collection which matches the given predicate or null if none matched + * + * @includeFunction ../../test/CollectionTest.kt find + */ inline fun Iterable.find(predicate: (T)-> Boolean) : T? { for (elem in this) { if (predicate(elem)) @@ -44,7 +60,11 @@ inline fun Iterable.find(predicate: (T)-> Boolean) : T? { return null } -/** Filters all elements in this collection which match the given predicate into the given result collection */ +/** + * Filters all elements in this collection which match the given predicate into the given result collection + * + * @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList + */ inline fun > Iterable.filterTo(result: C, predicate: (T)-> Boolean) : C { for (elem in this) { if (predicate(elem)) @@ -53,18 +73,27 @@ inline fun > Iterable.filterTo(result: C, predicate: ( return result } -/** Filters all the null elements in this collection into the given result collection */ +/** + * Filters all the null elements in this collection into the given result collection + * + * @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList + */ inline fun > Iterable?.filterNotNullTo(result: C) : C { if (this != null) { for (elem in this) { - if (elem != null) + if (elem != null) { result.add(elem) + } } } return result } -/** Returns a new collection containing all elements in this collection which do not match the given predicate */ +/** + * Returns a new collection containing all elements in this collection which do not match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList + */ inline fun > Iterable.filterNotTo(result: C, predicate: (T)-> Boolean) : C { for (elem in this) { if (!predicate(elem)) @@ -74,9 +103,10 @@ inline fun > Iterable.filterNotTo(result: C, predicate } /** - * Returns the result of transforming each item in the collection to a one or more values which - * are concatenated together into a single collection - */ + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + */ +// TODO * @includeFunction ../../test/CollectionTest.kt flatMapTo inline fun Iterable.flatMapTo(result: Collection, transform: (T)-> Collection) : Collection { for (elem in this) { val coll = transform(elem) @@ -89,7 +119,11 @@ inline fun Iterable.flatMapTo(result: Collection, transform: (T)-> return result } -/** Performs the given operation on each element inside the collection */ +/** + * Performs the given operation on each element inside the collection + * + * @includeFunction ../../test/CollectionTest.kt forEach + */ inline fun Iterable.forEach(operation: (element: T) -> Unit) { for (elem in this) operation(elem) @@ -98,8 +132,7 @@ inline fun Iterable.forEach(operation: (element: T) -> Unit) { /** * Folds all the values from from left to right with the initial value to perform the operation on sequential pairs of values * - * For example to sum together all numeric values in a collection of numbers it would be - * {code}val total = numbers.fold(0){(a, b) -> a + b}{code} + * @includeFunction ../../test/CollectionTest.kt fold */ inline fun Iterable.fold(initial: T, operation: (it: T, it2: T) -> T): T { var answer = initial @@ -111,6 +144,8 @@ inline fun Iterable.fold(initial: T, operation: (it: T, it2: T) -> T): T /** * Folds all the values from right to left with the initial value to perform the operation on sequential pairs of values + * + * @includeFunction ../../test/CollectionTest.kt foldRight */ inline fun Iterable.foldRight(initial: T, operation: (it: T, it2: T) -> T): T { val reversed = this.reverse() @@ -120,6 +155,8 @@ inline fun Iterable.foldRight(initial: T, operation: (it: T, it2: T) -> T /** * Iterates through the collection performing the transformation on each element and using the result * as the key in a map to group elements by the result + * + * @includeFunction ../../test/CollectionTest.kt groupBy */ inline fun Iterable.groupBy(result: Map> = HashMap>(), toKey: (T)-> K) : Map> { for (elem in this) { @@ -131,7 +168,11 @@ inline fun Iterable.groupBy(result: Map> = HashMap> } -/** Creates a String from all the elements in the collection, using the seperator between them and using the given prefix and postfix if supplied */ +/** + * Creates a String from all the elements in the collection, using the seperator between them and using the given prefix and postfix if supplied + * + * @includeFunction ../../test/CollectionTest.kt join + */ inline fun Iterable.join(separator: String, prefix: String = "", postfix: String = "") : String { val buffer = StringBuilder(prefix) var first = true @@ -146,7 +187,11 @@ inline fun Iterable.join(separator: String, prefix: String = "", postfix: return buffer.toString().sure() } -/** Returns a reversed List of this collection */ +/** + * Returns a reversed List of this collection + * + * @includeFunction ../../test/CollectionTest.kt reverse + */ inline fun Iterable.reverse() : List { val answer = LinkedList() for (elem in this) { @@ -155,14 +200,20 @@ inline fun Iterable.reverse() : List { return answer } -/** Copies the collection into the given collection */ +/** + * Copies the collection into the given collection + * + * @includeFunction ../../test/CollectionTest.kt reverse + */ inline fun > Iterable.to(result: C) : C { for (elem in this) result.add(elem) return result } -/** Converts the collection into a LinkedList */ +/** + * Converts the collection into a LinkedList + */ inline fun Iterable.toLinkedList() : LinkedList = this.to(LinkedList()) /** Converts the collection into a List */ diff --git a/libraries/stdlib/src/generated/StandardFromJavaIterablesLazy.kt b/libraries/stdlib/src/generated/StandardFromJavaIterablesLazy.kt index b178e5282a1..e9c1c6922a3 100644 --- a/libraries/stdlib/src/generated/StandardFromJavaIterablesLazy.kt +++ b/libraries/stdlib/src/generated/StandardFromJavaIterablesLazy.kt @@ -1,4 +1,4 @@ -// NOTE this file is auto-generated from src/JavaIterablesLazy.kt +// NOTE this file is auto-generated from src/kotlin/JavaIterablesLazy.kt package kotlin import kotlin.util.* @@ -12,19 +12,33 @@ import java.util.* // See [[GenerateStandardLib.kt]] for more details // -/** Returns a new List containing all elements in this collection which match the given predicate */ +/** + * Returns a new List containing all elements in this collection which match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt filter + */ inline fun Iterable.filter(predicate: (T)-> Boolean) : Collection = filterTo(java.util.ArrayList(), predicate) -/** Returns a List containing all the non null elements in this collection */ +/** + * Returns a List containing all the non null elements in this collection + * + * @includeFunction ../../test/CollectionTest.kt filterNotNull + */ inline fun Iterable?.filterNotNull() : Collection = filterNotNullTo>(java.util.ArrayList()) -/** Returns a new collection containing all elements in this collection which do not match the given predicate */ +/** + * Returns a new collection containing all elements in this collection which do not match the given predicate + * + * @includeFunction ../../test/CollectionTest.kt filterNot + */ inline fun Iterable.filterNot(predicate: (T)-> Boolean) : Collection = filterNotTo(ArrayList(), predicate) /** - * Returns the result of transforming each item in the collection to a one or more values which - * are concatenated together into a single collection - */ + * Returns the result of transforming each item in the collection to a one or more values which + * are concatenated together into a single collection + * + * @includeFunction ../../test/CollectionTest.kt flatMap + */ inline fun Iterable.flatMap(transform: (T)-> Collection) : Collection { return flatMapTo(ArrayList(), transform) } diff --git a/libraries/stdlib/test/GenerateStandardLib.kt b/libraries/stdlib/test/GenerateStandardLib.kt index 6086b1c42c2..89b149a3ad0 100644 --- a/libraries/stdlib/test/GenerateStandardLib.kt +++ b/libraries/stdlib/test/GenerateStandardLib.kt @@ -41,12 +41,12 @@ fun generateFile(outFile: File, header: String, inputFile: File, f: (String)-> S * at runtime. */ fun main(args: Array) { - var srcDir = File("src") + var srcDir = File("src/kotlin") if (!srcDir.exists()) { - srcDir = File("stdlib/src") - require(srcDir.exists(), "Could not find the src directory!") + srcDir = File("stdlib/src/kotlin") + require(srcDir.exists(), "Could not find the src/kotlin directory!") } - val outDir = File(srcDir, "generated") + val outDir = File(srcDir, "../generated") // JavaIterables - Generic iterable stuff generateFile(File(outDir, "ArraysFromJavaIterables.kt"), "package kotlin\n\nimport kotlin.util.*", File(srcDir, "JavaIterables.kt")) {