added 'public' annotation to library functions

This commit is contained in:
Svetlana Isakova
2012-03-30 13:38:22 +04:00
parent 4f30e12177
commit d4d177c0ed
10 changed files with 118 additions and 118 deletions
@@ -10,7 +10,7 @@ import java.util.*
*
* @includeFunction ../../test/CollectionTest.kt any
*/
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
return false
}
@@ -20,7 +20,7 @@ inline fun <T> Array<T>.any(predicate: (T) -> Boolean) : Boolean {
*
* @includeFunction ../../test/CollectionTest.kt all
*/
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
return true
}
@@ -30,7 +30,7 @@ inline fun <T> Array<T>.all(predicate: (T) -> Boolean) : Boolean {
*
* @includeFunction ../../test/CollectionTest.kt count
*/
inline fun <T> Array<T>.count(predicate: (T) -> Boolean) : Int {
public inline fun <T> Array<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0
for (element in this) if (predicate(element)) count++
return count
@@ -41,7 +41,7 @@ inline fun <T> Array<T>.count(predicate: (T) -> Boolean) : Int {
*
* @includeFunction ../../test/CollectionTest.kt find
*/
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
return null
}
@@ -51,7 +51,7 @@ inline fun <T> Array<T>.find(predicate: (T) -> Boolean) : T? {
*
* @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList
*/
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)
return result
}
@@ -61,7 +61,7 @@ inline fun <T, C: Collection<in T>> Array<T>.filterTo(result: C, predicate: (T)
*
* @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList
*/
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)
return result
}
@@ -71,7 +71,7 @@ inline fun <T, L: List<in T>> Array<T>.filterNotTo(result: L, predicate: (T) ->
*
* @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/
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) {
for (element in this) if (element != null) result.add(element)
}
@@ -83,7 +83,7 @@ inline fun <T, L: List<in T>> Array<T?>?.filterNotNullTo(result: L) : L {
*
* @includeFunction ../../test/CollectionTest.kt flatMap
*/
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) {
val list = transform(element)
if (list != null) {
@@ -98,14 +98,14 @@ inline fun <T, R> Array<T>.flatMapTo(result: Collection<R>, transform: (T) -> Co
*
* @includeFunction ../../test/CollectionTest.kt forEach
*/
inline fun <T> Array<T>.forEach(operation: (T) -> 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
*
* @includeFunction ../../test/CollectionTest.kt fold
*/
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
for (element in this) answer = operation(answer, element)
return answer
@@ -116,14 +116,14 @@ inline fun <T> Array<T>.fold(initial: T, operation: (T, T) -> T): T {
*
* @includeFunction ../../test/CollectionTest.kt foldRight
*/
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
*
* @includeFunction ../../test/CollectionTest.kt groupBy
*/
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) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
@@ -133,7 +133,7 @@ inline fun <T, K> Array<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<T>>
}
/** Returns a list containing the first elements that satisfy the given *predicate* */
inline fun <T, L: List<in T>> Array<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
public inline fun <T, L: List<in T>> Array<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
for (element in this) if (predicate(element)) result.add(element) else break
return result
}
@@ -143,33 +143,33 @@ inline fun <T, L: List<in T>> Array<T>.takeWhileTo(result: L, predicate: (T) ->
*
* @includeFunction ../../test/CollectionTest.kt reverse
*/
inline fun <T> Array<T>.reverse() : List<T> {
public inline fun <T> Array<T>.reverse() : List<T> {
val answer = LinkedList<T>()
for (element in this) answer.addFirst(element)
return answer
}
/** Copies all elements into the given collection */
inline fun <T, C: Collection<T>> Array<T>.to(result: C) : C {
public inline fun <T, C: Collection<T>> Array<T>.to(result: C) : C {
for (element in this) result.add(element)
return result
}
/** Copies all elements into a [[LinkedList]] */
inline fun <T> Array<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
public inline fun <T> Array<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
/** Copies all elements into a [[List]] */
inline fun <T> Array<T>.toList() : List<T> = to(ArrayList<T>())
public inline fun <T> Array<T>.toList() : List<T> = to(ArrayList<T>())
/** Copies all elements into a [[Set]] */
inline fun <T> Array<T>.toSet() : Set<T> = to(HashSet<T>())
public inline fun <T> Array<T>.toSet() : Set<T> = to(HashSet<T>())
/** Copies all elements into a [[SortedSet]] */
inline fun <T> Array<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
public inline fun <T> Array<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
inline fun <in T> Array<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
public inline fun <in T> Array<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
val answer = this.toList()
answer.sort(transform)
return answer
@@ -19,35 +19,35 @@ import java.util.List
*
* @includeFunction ../../test/CollectionTest.kt filter
*/
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
*
* @includeFunction ../../test/CollectionTest.kt filterNot
*/
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
*
* @includeFunction ../../test/CollectionTest.kt filterNotNull
*/
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
*
* @includeFunction ../../test/CollectionTest.kt flatMap
*/
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
*
* @includeFunction ../../test/CollectionTest.kt take
*/
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 {
var count = 0
return { ++count; count <= n }
@@ -60,14 +60,14 @@ inline fun <T> Array<T>.take(n: Int): List<T> {
*
* @includeFunction ../../test/CollectionTest.kt takeWhile
*/
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
*
* @includeFunction ../../test/CollectionTest.kt join
*/
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)
var first = true
for (element in this) {
@@ -8,7 +8,7 @@ import java.util.*
*
* @includeFunction ../../test/CollectionTest.kt any
*/
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
return false
}
@@ -18,7 +18,7 @@ inline fun <T> java.util.Iterator<T>.any(predicate: (T) -> Boolean) : Boolean {
*
* @includeFunction ../../test/CollectionTest.kt all
*/
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
return true
}
@@ -28,7 +28,7 @@ inline fun <T> java.util.Iterator<T>.all(predicate: (T) -> Boolean) : Boolean {
*
* @includeFunction ../../test/CollectionTest.kt count
*/
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
for (element in this) if (predicate(element)) count++
return count
@@ -39,7 +39,7 @@ inline fun <T> java.util.Iterator<T>.count(predicate: (T) -> Boolean) : Int {
*
* @includeFunction ../../test/CollectionTest.kt find
*/
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
return null
}
@@ -49,7 +49,7 @@ inline fun <T> java.util.Iterator<T>.find(predicate: (T) -> Boolean) : T? {
*
* @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList
*/
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)
return result
}
@@ -59,7 +59,7 @@ inline fun <T, C: Collection<in T>> java.util.Iterator<T>.filterTo(result: C, pr
*
* @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList
*/
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)
return result
}
@@ -69,7 +69,7 @@ inline fun <T, L: List<in T>> java.util.Iterator<T>.filterNotTo(result: L, predi
*
* @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/
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) {
for (element in this) if (element != null) result.add(element)
}
@@ -81,7 +81,7 @@ inline fun <T, L: List<in T>> java.util.Iterator<T?>?.filterNotNullTo(result: L)
*
* @includeFunction ../../test/CollectionTest.kt flatMap
*/
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) {
val list = transform(element)
if (list != null) {
@@ -96,14 +96,14 @@ inline fun <T, R> java.util.Iterator<T>.flatMapTo(result: Collection<R>, transfo
*
* @includeFunction ../../test/CollectionTest.kt forEach
*/
inline fun <T> java.util.Iterator<T>.forEach(operation: (T) -> 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
*
* @includeFunction ../../test/CollectionTest.kt fold
*/
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
for (element in this) answer = operation(answer, element)
return answer
@@ -114,14 +114,14 @@ inline fun <T> java.util.Iterator<T>.fold(initial: T, operation: (T, T) -> T): T
*
* @includeFunction ../../test/CollectionTest.kt foldRight
*/
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
*
* @includeFunction ../../test/CollectionTest.kt groupBy
*/
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) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
@@ -131,7 +131,7 @@ inline fun <T, K> java.util.Iterator<T>.groupBy(result: Map<K, List<T>> = HashMa
}
/** Returns a list containing the first elements that satisfy the given *predicate* */
inline fun <T, L: List<in T>> java.util.Iterator<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
public inline fun <T, L: List<in T>> java.util.Iterator<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
for (element in this) if (predicate(element)) result.add(element) else break
return result
}
@@ -141,33 +141,33 @@ inline fun <T, L: List<in T>> java.util.Iterator<T>.takeWhileTo(result: L, predi
*
* @includeFunction ../../test/CollectionTest.kt reverse
*/
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>()
for (element in this) answer.addFirst(element)
return answer
}
/** Copies all elements into the given collection */
inline fun <T, C: Collection<T>> java.util.Iterator<T>.to(result: C) : C {
public inline fun <T, C: Collection<T>> java.util.Iterator<T>.to(result: C) : C {
for (element in this) result.add(element)
return result
}
/** Copies all elements into a [[LinkedList]] */
inline fun <T> java.util.Iterator<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
public inline fun <T> java.util.Iterator<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
/** Copies all elements into a [[List]] */
inline fun <T> java.util.Iterator<T>.toList() : List<T> = to(ArrayList<T>())
public inline fun <T> java.util.Iterator<T>.toList() : List<T> = to(ArrayList<T>())
/** Copies all elements into a [[Set]] */
inline fun <T> java.util.Iterator<T>.toSet() : Set<T> = to(HashSet<T>())
public inline fun <T> java.util.Iterator<T>.toSet() : Set<T> = to(HashSet<T>())
/** Copies all elements into a [[SortedSet]] */
inline fun <T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
public inline fun <T> java.util.Iterator<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
inline fun <in T> java.util.Iterator<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
public inline fun <in T> java.util.Iterator<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
val answer = this.toList()
answer.sort(transform)
return answer
@@ -10,7 +10,7 @@ import java.util.*
*
* @includeFunction ../../test/CollectionTest.kt any
*/
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
return false
}
@@ -20,7 +20,7 @@ inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean) : Boolean {
*
* @includeFunction ../../test/CollectionTest.kt all
*/
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
return true
}
@@ -30,7 +30,7 @@ inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean) : Boolean {
*
* @includeFunction ../../test/CollectionTest.kt count
*/
inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int {
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int {
var count = 0
for (element in this) if (predicate(element)) count++
return count
@@ -41,7 +41,7 @@ inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int {
*
* @includeFunction ../../test/CollectionTest.kt find
*/
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
return null
}
@@ -51,7 +51,7 @@ inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean) : T? {
*
* @includeFunction ../../test/CollectionTest.kt filterIntoLinkedList
*/
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)
return result
}
@@ -61,7 +61,7 @@ inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predicate: (
*
* @includeFunction ../../test/CollectionTest.kt filterNotIntoLinkedList
*/
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)
return result
}
@@ -71,7 +71,7 @@ inline fun <T, L: List<in T>> Iterable<T>.filterNotTo(result: L, predicate: (T)
*
* @includeFunction ../../test/CollectionTest.kt filterNotNullIntoLinkedList
*/
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) {
for (element in this) if (element != null) result.add(element)
}
@@ -83,7 +83,7 @@ inline fun <T, L: List<in T>> Iterable<T?>?.filterNotNullTo(result: L) : L {
*
* @includeFunction ../../test/CollectionTest.kt flatMap
*/
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) {
val list = transform(element)
if (list != null) {
@@ -98,14 +98,14 @@ inline fun <T, R> Iterable<T>.flatMapTo(result: Collection<R>, transform: (T) ->
*
* @includeFunction ../../test/CollectionTest.kt forEach
*/
inline fun <T> Iterable<T>.forEach(operation: (T) -> 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
*
* @includeFunction ../../test/CollectionTest.kt fold
*/
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
for (element in this) answer = operation(answer, element)
return answer
@@ -116,14 +116,14 @@ inline fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {
*
* @includeFunction ../../test/CollectionTest.kt foldRight
*/
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
*
* @includeFunction ../../test/CollectionTest.kt groupBy
*/
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) {
val key = toKey(element)
val list = result.getOrPut(key) { ArrayList<T>() }
@@ -133,7 +133,7 @@ inline fun <T, K> Iterable<T>.groupBy(result: Map<K, List<T>> = HashMap<K, List<
}
/** Returns a list containing the first elements that satisfy the given *predicate* */
inline fun <T, L: List<in T>> Iterable<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
public inline fun <T, L: List<in T>> Iterable<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
for (element in this) if (predicate(element)) result.add(element) else break
return result
}
@@ -143,33 +143,33 @@ inline fun <T, L: List<in T>> Iterable<T>.takeWhileTo(result: L, predicate: (T)
*
* @includeFunction ../../test/CollectionTest.kt reverse
*/
inline fun <T> Iterable<T>.reverse() : List<T> {
public inline fun <T> Iterable<T>.reverse() : List<T> {
val answer = LinkedList<T>()
for (element in this) answer.addFirst(element)
return answer
}
/** Copies all elements into the given collection */
inline fun <T, C: Collection<T>> Iterable<T>.to(result: C) : C {
public inline fun <T, C: Collection<T>> Iterable<T>.to(result: C) : C {
for (element in this) result.add(element)
return result
}
/** Copies all elements into a [[LinkedList]] */
inline fun <T> Iterable<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
public inline fun <T> Iterable<T>.toLinkedList() : LinkedList<T> = to(LinkedList<T>())
/** Copies all elements into a [[List]] */
inline fun <T> Iterable<T>.toList() : List<T> = to(ArrayList<T>())
public inline fun <T> Iterable<T>.toList() : List<T> = to(ArrayList<T>())
/** Copies all elements into a [[Set]] */
inline fun <T> Iterable<T>.toSet() : Set<T> = to(HashSet<T>())
public inline fun <T> Iterable<T>.toSet() : Set<T> = to(HashSet<T>())
/** Copies all elements into a [[SortedSet]] */
inline fun <T> Iterable<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
public inline fun <T> Iterable<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
/**
TODO figure out necessary variance/generics ninja stuff... :)
inline fun <in T> Iterable<T>.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List<T> {
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
@@ -19,35 +19,35 @@ import java.util.List
*
* @includeFunction ../../test/CollectionTest.kt filter
*/
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
*
* @includeFunction ../../test/CollectionTest.kt filterNot
*/
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
*
* @includeFunction ../../test/CollectionTest.kt filterNotNull
*/
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
*
* @includeFunction ../../test/CollectionTest.kt flatMap
*/
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
*
* @includeFunction ../../test/CollectionTest.kt take
*/
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 {
var count = 0
return { ++count; count <= n }
@@ -60,14 +60,14 @@ inline fun <T> Iterable<T>.take(n: Int): List<T> {
*
* @includeFunction ../../test/CollectionTest.kt takeWhile
*/
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
*
* @includeFunction ../../test/CollectionTest.kt join
*/
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)
var first = true
for (element in this) {