New stdlib generators
This commit is contained in:
committed by
Andrey Breslav
parent
0980f5e40a
commit
e37d8174c3
File diff suppressed because it is too large
Load Diff
@@ -8,531 +8,128 @@ package kotlin
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public inline fun <T> Array<out T>.all(predicate: (T) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
public fun <T> Array<out T>.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public inline fun <T> Array<out T>.any(predicate: (T) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
public fun BooleanArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun <T> Array<out T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
public fun ByteArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public inline fun <T> Array<out T>.count(predicate: (T) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
public fun CharArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun <T> Array<out T>.drop(n: Int) : List<T> {
|
||||
return dropWhile(countTo(n))
|
||||
public fun DoubleArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public inline fun <T> Array<out T>.dropWhile(predicate: (T) -> Boolean) : List<T> {
|
||||
return dropWhileTo(ArrayList<T>(), predicate)
|
||||
public fun FloatArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public inline fun <T, L: MutableList<in T>> Array<out T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
public fun IntArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public inline fun <T> Array<out T>.filter(predicate: (T) -> Boolean) : List<T> {
|
||||
return filterTo(ArrayList<T>(), predicate)
|
||||
public fun LongArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public inline fun <T> Array<out T>.filterNot(predicate: (T) -> Boolean) : List<T> {
|
||||
return filterNotTo(ArrayList<T>(), predicate)
|
||||
public fun ShortArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all the non-*null* elements
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public fun <T:Any> Array<out T?>.filterNotNull() : List<T> {
|
||||
return filterNotNullTo<T, ArrayList<T>>(ArrayList<T>())
|
||||
public fun <T> Array<out T>.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all non-*null* elements into the given list
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public fun <T:Any, C: MutableCollection<in T>> Array<out T?>.filterNotNullTo(result: C) : C {
|
||||
for (element in this) if (element != null) result.add(element)
|
||||
return result
|
||||
public fun BooleanArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Array<out T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
public fun ByteArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Array<out T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
public fun CharArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public inline fun <T:Any> Array<out T>.find(predicate: (T) -> Boolean) : T? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
public fun DoubleArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public inline fun <T, R> Array<out T>.flatMap(transform: (T)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
public fun FloatArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Array<out T>.flatMapTo(result: C, transform: (T) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
public fun IntArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public inline fun <T, R> Array<out T>.fold(initial: R, operation: (R, T) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
public fun LongArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
* Returns true if the array is not empty
|
||||
*/
|
||||
public inline fun <T, R> Array<out T>.foldRight(initial: R, operation: (T, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun <T> Array<out T>.forEach(operation: (T) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <T, K> Array<out T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> {
|
||||
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <T, K> Array<out T>.groupByTo(result: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<T>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun <T> Array<out T>.indexOf(item: T) : Int {
|
||||
if (item == null) {
|
||||
for (i in indices) {
|
||||
if (this[i] == null) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Array<out T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <T, R> Array<out T>.map(transform : (T) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Array<out T>.mapTo(result: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Array<out T>.max() : T? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>, T: Any> Array<out T>.maxBy(f: (T) -> R) : T? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Array<out T>.min() : T? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>, T: Any> Array<out T>.minBy(f: (T) -> R) : T? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun <T> Array<out T>.partition(predicate: (T) -> Boolean) : Pair<List<T>, List<T>> {
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun <T> Array<out T>.plus(collection: Iterable<T>) : List<T> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun <T> Array<out T>.plus(element: T) : List<T> {
|
||||
val answer = ArrayList<T>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun <T> Array<out T>.plus(iterator: Iterator<T>) : List<T> {
|
||||
val answer = ArrayList<T>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun <T> Array<out T>.reduce(operation: (T, T) -> T) : T {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: T = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun <T> Array<out T>.reduceRight(operation: (T, T) -> T) : T {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a original Iterable containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> Array<out T?>.requireNoNulls() : Array<out T> {
|
||||
for (element in this) {
|
||||
if (element == null) {
|
||||
throw IllegalArgumentException("null element found in $this")
|
||||
}
|
||||
}
|
||||
return this as Array<out T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun <T> Array<out T>.reverse() : List<T> {
|
||||
val list = toCollection(ArrayList<T>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <T, R: Comparable<R>> Array<out T>.sortBy(f: (T) -> R) : List<T> {
|
||||
val sortedList = toCollection(ArrayList<T>())
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun <T> Array<out T>.take(n: Int) : List<T> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Array<out T>.takeWhile(predicate: (T) -> Boolean) : List<T> {
|
||||
return takeWhileTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Array<out T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <T, C: MutableCollection<in T>> Array<out T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun <T> Array<out T>.toLinkedList() : LinkedList<T> {
|
||||
return toCollection(LinkedList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun <T> Array<out T>.toList() : List<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun <T> Array<out T>.toSet() : Set<T> {
|
||||
return toCollection(LinkedHashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun <T> Array<out T>.toSortedSet() : SortedSet<T> {
|
||||
return toCollection(TreeSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun <T> Array<out T>.withIndices() : Iterator<Pair<Int, T>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Array<Byte>.sum() : Int {
|
||||
return fold(0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Array<Short>.sum() : Int {
|
||||
return fold(0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Array<Int>.sum() : Int {
|
||||
return fold(0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Array<Long>.sum() : Long {
|
||||
return fold(0.toLong(), {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Array<Float>.sum() : Float {
|
||||
return fold(0.toFloat(), {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Array<Double>.sum() : Double {
|
||||
return fold(0.0, {a,b -> a+b})
|
||||
public fun ShortArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,447 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun BooleanArray.any(predicate: (Boolean) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun BooleanArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun BooleanArray.count(predicate: (Boolean) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun BooleanArray.drop(n: Int) : List<Boolean> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean) : List<Boolean> {
|
||||
return dropWhileTo(ArrayList<Boolean>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Boolean>> BooleanArray.dropWhileTo(result: L, predicate: (Boolean) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun BooleanArray.filter(predicate: (Boolean) -> Boolean) : List<Boolean> {
|
||||
return filterTo(ArrayList<Boolean>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun BooleanArray.filterNot(predicate: (Boolean) -> Boolean) : List<Boolean> {
|
||||
return filterNotTo(ArrayList<Boolean>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Boolean>> BooleanArray.filterNotTo(result: C, predicate: (Boolean) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Boolean>> BooleanArray.filterTo(result: C, predicate: (Boolean) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun BooleanArray.find(predicate: (Boolean) -> Boolean) : Boolean? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> BooleanArray.flatMap(transform: (Boolean)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> BooleanArray.flatMapTo(result: C, transform: (Boolean) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> BooleanArray.fold(initial: R, operation: (R, Boolean) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> BooleanArray.foldRight(initial: R, operation: (Boolean, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun BooleanArray.forEach(operation: (Boolean) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> BooleanArray.groupBy(toKey: (Boolean) -> K) : Map<K, List<Boolean>> {
|
||||
return groupByTo(HashMap<K, MutableList<Boolean>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> BooleanArray.groupByTo(result: MutableMap<K, MutableList<Boolean>>, toKey: (Boolean) -> K) : Map<K, MutableList<Boolean>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Boolean>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun BooleanArray.indexOf(item: Boolean) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun BooleanArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun BooleanArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun BooleanArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> BooleanArray.map(transform : (Boolean) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> BooleanArray.mapTo(result: C, transform : (Boolean) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> BooleanArray.maxBy(f: (Boolean) -> R) : Boolean? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> BooleanArray.minBy(f: (Boolean) -> R) : Boolean? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun BooleanArray.partition(predicate: (Boolean) -> Boolean) : Pair<List<Boolean>, List<Boolean>> {
|
||||
val first = ArrayList<Boolean>()
|
||||
val second = ArrayList<Boolean>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun BooleanArray.plus(collection: Iterable<Boolean>) : List<Boolean> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun BooleanArray.plus(element: Boolean) : List<Boolean> {
|
||||
val answer = ArrayList<Boolean>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun BooleanArray.plus(iterator: Iterator<Boolean>) : List<Boolean> {
|
||||
val answer = ArrayList<Boolean>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun BooleanArray.reduce(operation: (Boolean, Boolean) -> Boolean) : Boolean {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Boolean = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun BooleanArray.reduceRight(operation: (Boolean, Boolean) -> Boolean) : Boolean {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun BooleanArray.reverse() : List<Boolean> {
|
||||
val list = toCollection(ArrayList<Boolean>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> BooleanArray.sortBy(f: (Boolean) -> R) : List<Boolean> {
|
||||
val sortedList = toCollection(ArrayList<Boolean>())
|
||||
val sortBy: Comparator<Boolean> = comparator<Boolean> {(x: Boolean, y: Boolean) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun BooleanArray.take(n: Int) : List<Boolean> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun BooleanArray.takeWhile(predicate: (Boolean) -> Boolean) : List<Boolean> {
|
||||
return takeWhileTo(ArrayList<Boolean>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Boolean>> BooleanArray.takeWhileTo(result: C, predicate: (Boolean) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Boolean>> BooleanArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun BooleanArray.toLinkedList() : LinkedList<Boolean> {
|
||||
return toCollection(LinkedList<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun BooleanArray.toList() : List<Boolean> {
|
||||
return toCollection(ArrayList<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun BooleanArray.toSet() : Set<Boolean> {
|
||||
return toCollection(LinkedHashSet<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun BooleanArray.toSortedSet() : SortedSet<Boolean> {
|
||||
return toCollection(TreeSet<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun BooleanArray.withIndices() : Iterator<Pair<Int, Boolean>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
@@ -1,482 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun ByteArray.all(predicate: (Byte) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun ByteArray.any(predicate: (Byte) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ByteArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun ByteArray.count(predicate: (Byte) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun ByteArray.drop(n: Int) : List<Byte> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean) : List<Byte> {
|
||||
return dropWhileTo(ArrayList<Byte>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Byte>> ByteArray.dropWhileTo(result: L, predicate: (Byte) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun ByteArray.filter(predicate: (Byte) -> Boolean) : List<Byte> {
|
||||
return filterTo(ArrayList<Byte>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun ByteArray.filterNot(predicate: (Byte) -> Boolean) : List<Byte> {
|
||||
return filterNotTo(ArrayList<Byte>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Byte>> ByteArray.filterNotTo(result: C, predicate: (Byte) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Byte>> ByteArray.filterTo(result: C, predicate: (Byte) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun ByteArray.find(predicate: (Byte) -> Boolean) : Byte? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> ByteArray.flatMap(transform: (Byte)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ByteArray.flatMapTo(result: C, transform: (Byte) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> ByteArray.fold(initial: R, operation: (R, Byte) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> ByteArray.foldRight(initial: R, operation: (Byte, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun ByteArray.forEach(operation: (Byte) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> ByteArray.groupBy(toKey: (Byte) -> K) : Map<K, List<Byte>> {
|
||||
return groupByTo(HashMap<K, MutableList<Byte>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> ByteArray.groupByTo(result: MutableMap<K, MutableList<Byte>>, toKey: (Byte) -> K) : Map<K, MutableList<Byte>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Byte>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun ByteArray.indexOf(item: Byte) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun ByteArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun ByteArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ByteArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> ByteArray.map(transform : (Byte) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ByteArray.mapTo(result: C, transform : (Byte) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun ByteArray.max() : Byte? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> ByteArray.maxBy(f: (Byte) -> R) : Byte? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun ByteArray.min() : Byte? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> ByteArray.minBy(f: (Byte) -> R) : Byte? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun ByteArray.partition(predicate: (Byte) -> Boolean) : Pair<List<Byte>, List<Byte>> {
|
||||
val first = ArrayList<Byte>()
|
||||
val second = ArrayList<Byte>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun ByteArray.plus(collection: Iterable<Byte>) : List<Byte> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun ByteArray.plus(element: Byte) : List<Byte> {
|
||||
val answer = ArrayList<Byte>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun ByteArray.plus(iterator: Iterator<Byte>) : List<Byte> {
|
||||
val answer = ArrayList<Byte>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun ByteArray.reduce(operation: (Byte, Byte) -> Byte) : Byte {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Byte = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun ByteArray.reduceRight(operation: (Byte, Byte) -> Byte) : Byte {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun ByteArray.reverse() : List<Byte> {
|
||||
val list = toCollection(ArrayList<Byte>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> ByteArray.sortBy(f: (Byte) -> R) : List<Byte> {
|
||||
val sortedList = toCollection(ArrayList<Byte>())
|
||||
val sortBy: Comparator<Byte> = comparator<Byte> {(x: Byte, y: Byte) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun ByteArray.take(n: Int) : List<Byte> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean) : List<Byte> {
|
||||
return takeWhileTo(ArrayList<Byte>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Byte>> ByteArray.takeWhileTo(result: C, predicate: (Byte) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Byte>> ByteArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun ByteArray.toLinkedList() : LinkedList<Byte> {
|
||||
return toCollection(LinkedList<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun ByteArray.toList() : List<Byte> {
|
||||
return toCollection(ArrayList<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun ByteArray.toSet() : Set<Byte> {
|
||||
return toCollection(LinkedHashSet<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun ByteArray.toSortedSet() : SortedSet<Byte> {
|
||||
return toCollection(TreeSet<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun ByteArray.withIndices() : Iterator<Pair<Int, Byte>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun ByteArray.sum() : Int {
|
||||
return fold(0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
@@ -1,475 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun CharArray.all(predicate: (Char) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun CharArray.any(predicate: (Char) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun CharArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun CharArray.count(predicate: (Char) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun CharArray.drop(n: Int) : List<Char> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun CharArray.dropWhile(predicate: (Char) -> Boolean) : List<Char> {
|
||||
return dropWhileTo(ArrayList<Char>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Char>> CharArray.dropWhileTo(result: L, predicate: (Char) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun CharArray.filter(predicate: (Char) -> Boolean) : List<Char> {
|
||||
return filterTo(ArrayList<Char>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun CharArray.filterNot(predicate: (Char) -> Boolean) : List<Char> {
|
||||
return filterNotTo(ArrayList<Char>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Char>> CharArray.filterNotTo(result: C, predicate: (Char) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Char>> CharArray.filterTo(result: C, predicate: (Char) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun CharArray.find(predicate: (Char) -> Boolean) : Char? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> CharArray.flatMap(transform: (Char)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> CharArray.flatMapTo(result: C, transform: (Char) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> CharArray.fold(initial: R, operation: (R, Char) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> CharArray.foldRight(initial: R, operation: (Char, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun CharArray.forEach(operation: (Char) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> CharArray.groupBy(toKey: (Char) -> K) : Map<K, List<Char>> {
|
||||
return groupByTo(HashMap<K, MutableList<Char>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> CharArray.groupByTo(result: MutableMap<K, MutableList<Char>>, toKey: (Char) -> K) : Map<K, MutableList<Char>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Char>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun CharArray.indexOf(item: Char) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun CharArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun CharArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun CharArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> CharArray.map(transform : (Char) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> CharArray.mapTo(result: C, transform : (Char) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun CharArray.max() : Char? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> CharArray.maxBy(f: (Char) -> R) : Char? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun CharArray.min() : Char? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> CharArray.minBy(f: (Char) -> R) : Char? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun CharArray.partition(predicate: (Char) -> Boolean) : Pair<List<Char>, List<Char>> {
|
||||
val first = ArrayList<Char>()
|
||||
val second = ArrayList<Char>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun CharArray.plus(collection: Iterable<Char>) : List<Char> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun CharArray.plus(element: Char) : List<Char> {
|
||||
val answer = ArrayList<Char>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun CharArray.plus(iterator: Iterator<Char>) : List<Char> {
|
||||
val answer = ArrayList<Char>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun CharArray.reduce(operation: (Char, Char) -> Char) : Char {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Char = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun CharArray.reduceRight(operation: (Char, Char) -> Char) : Char {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun CharArray.reverse() : List<Char> {
|
||||
val list = toCollection(ArrayList<Char>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> CharArray.sortBy(f: (Char) -> R) : List<Char> {
|
||||
val sortedList = toCollection(ArrayList<Char>())
|
||||
val sortBy: Comparator<Char> = comparator<Char> {(x: Char, y: Char) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun CharArray.take(n: Int) : List<Char> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun CharArray.takeWhile(predicate: (Char) -> Boolean) : List<Char> {
|
||||
return takeWhileTo(ArrayList<Char>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Char>> CharArray.takeWhileTo(result: C, predicate: (Char) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Char>> CharArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun CharArray.toLinkedList() : LinkedList<Char> {
|
||||
return toCollection(LinkedList<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun CharArray.toList() : List<Char> {
|
||||
return toCollection(ArrayList<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun CharArray.toSet() : Set<Char> {
|
||||
return toCollection(LinkedHashSet<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun CharArray.toSortedSet() : SortedSet<Char> {
|
||||
return toCollection(TreeSet<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun CharArray.withIndices() : Iterator<Pair<Int, Char>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns a original Iterable containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> Collection<T?>.requireNoNulls() : Collection<T> {
|
||||
for (element in this) {
|
||||
if (element == null) {
|
||||
throw IllegalArgumentException("null element found in $this")
|
||||
}
|
||||
}
|
||||
return this as Collection<T>
|
||||
}
|
||||
|
||||
@@ -1,482 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun DoubleArray.all(predicate: (Double) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun DoubleArray.any(predicate: (Double) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun DoubleArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun DoubleArray.count(predicate: (Double) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun DoubleArray.drop(n: Int) : List<Double> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean) : List<Double> {
|
||||
return dropWhileTo(ArrayList<Double>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Double>> DoubleArray.dropWhileTo(result: L, predicate: (Double) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun DoubleArray.filter(predicate: (Double) -> Boolean) : List<Double> {
|
||||
return filterTo(ArrayList<Double>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun DoubleArray.filterNot(predicate: (Double) -> Boolean) : List<Double> {
|
||||
return filterNotTo(ArrayList<Double>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Double>> DoubleArray.filterNotTo(result: C, predicate: (Double) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Double>> DoubleArray.filterTo(result: C, predicate: (Double) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun DoubleArray.find(predicate: (Double) -> Boolean) : Double? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> DoubleArray.flatMap(transform: (Double)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> DoubleArray.flatMapTo(result: C, transform: (Double) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> DoubleArray.fold(initial: R, operation: (R, Double) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> DoubleArray.foldRight(initial: R, operation: (Double, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun DoubleArray.forEach(operation: (Double) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> DoubleArray.groupBy(toKey: (Double) -> K) : Map<K, List<Double>> {
|
||||
return groupByTo(HashMap<K, MutableList<Double>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> DoubleArray.groupByTo(result: MutableMap<K, MutableList<Double>>, toKey: (Double) -> K) : Map<K, MutableList<Double>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Double>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun DoubleArray.indexOf(item: Double) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun DoubleArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun DoubleArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun DoubleArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> DoubleArray.map(transform : (Double) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> DoubleArray.mapTo(result: C, transform : (Double) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun DoubleArray.max() : Double? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> DoubleArray.maxBy(f: (Double) -> R) : Double? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun DoubleArray.min() : Double? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> DoubleArray.minBy(f: (Double) -> R) : Double? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun DoubleArray.partition(predicate: (Double) -> Boolean) : Pair<List<Double>, List<Double>> {
|
||||
val first = ArrayList<Double>()
|
||||
val second = ArrayList<Double>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun DoubleArray.plus(collection: Iterable<Double>) : List<Double> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun DoubleArray.plus(element: Double) : List<Double> {
|
||||
val answer = ArrayList<Double>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun DoubleArray.plus(iterator: Iterator<Double>) : List<Double> {
|
||||
val answer = ArrayList<Double>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun DoubleArray.reduce(operation: (Double, Double) -> Double) : Double {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Double = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun DoubleArray.reduceRight(operation: (Double, Double) -> Double) : Double {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun DoubleArray.reverse() : List<Double> {
|
||||
val list = toCollection(ArrayList<Double>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> DoubleArray.sortBy(f: (Double) -> R) : List<Double> {
|
||||
val sortedList = toCollection(ArrayList<Double>())
|
||||
val sortBy: Comparator<Double> = comparator<Double> {(x: Double, y: Double) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun DoubleArray.take(n: Int) : List<Double> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean) : List<Double> {
|
||||
return takeWhileTo(ArrayList<Double>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Double>> DoubleArray.takeWhileTo(result: C, predicate: (Double) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Double>> DoubleArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun DoubleArray.toLinkedList() : LinkedList<Double> {
|
||||
return toCollection(LinkedList<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun DoubleArray.toList() : List<Double> {
|
||||
return toCollection(ArrayList<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun DoubleArray.toSet() : Set<Double> {
|
||||
return toCollection(LinkedHashSet<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun DoubleArray.toSortedSet() : SortedSet<Double> {
|
||||
return toCollection(TreeSet<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun DoubleArray.withIndices() : Iterator<Pair<Int, Double>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun DoubleArray.sum() : Double {
|
||||
return fold(0.0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,482 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun FloatArray.all(predicate: (Float) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun FloatArray.any(predicate: (Float) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun FloatArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun FloatArray.count(predicate: (Float) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun FloatArray.drop(n: Int) : List<Float> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean) : List<Float> {
|
||||
return dropWhileTo(ArrayList<Float>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Float>> FloatArray.dropWhileTo(result: L, predicate: (Float) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun FloatArray.filter(predicate: (Float) -> Boolean) : List<Float> {
|
||||
return filterTo(ArrayList<Float>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun FloatArray.filterNot(predicate: (Float) -> Boolean) : List<Float> {
|
||||
return filterNotTo(ArrayList<Float>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Float>> FloatArray.filterNotTo(result: C, predicate: (Float) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Float>> FloatArray.filterTo(result: C, predicate: (Float) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun FloatArray.find(predicate: (Float) -> Boolean) : Float? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> FloatArray.flatMap(transform: (Float)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> FloatArray.flatMapTo(result: C, transform: (Float) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> FloatArray.fold(initial: R, operation: (R, Float) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> FloatArray.foldRight(initial: R, operation: (Float, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun FloatArray.forEach(operation: (Float) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> FloatArray.groupBy(toKey: (Float) -> K) : Map<K, List<Float>> {
|
||||
return groupByTo(HashMap<K, MutableList<Float>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> FloatArray.groupByTo(result: MutableMap<K, MutableList<Float>>, toKey: (Float) -> K) : Map<K, MutableList<Float>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Float>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun FloatArray.indexOf(item: Float) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun FloatArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun FloatArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun FloatArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> FloatArray.map(transform : (Float) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> FloatArray.mapTo(result: C, transform : (Float) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun FloatArray.max() : Float? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> FloatArray.maxBy(f: (Float) -> R) : Float? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun FloatArray.min() : Float? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> FloatArray.minBy(f: (Float) -> R) : Float? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun FloatArray.partition(predicate: (Float) -> Boolean) : Pair<List<Float>, List<Float>> {
|
||||
val first = ArrayList<Float>()
|
||||
val second = ArrayList<Float>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun FloatArray.plus(collection: Iterable<Float>) : List<Float> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun FloatArray.plus(element: Float) : List<Float> {
|
||||
val answer = ArrayList<Float>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun FloatArray.plus(iterator: Iterator<Float>) : List<Float> {
|
||||
val answer = ArrayList<Float>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun FloatArray.reduce(operation: (Float, Float) -> Float) : Float {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Float = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun FloatArray.reduceRight(operation: (Float, Float) -> Float) : Float {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun FloatArray.reverse() : List<Float> {
|
||||
val list = toCollection(ArrayList<Float>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> FloatArray.sortBy(f: (Float) -> R) : List<Float> {
|
||||
val sortedList = toCollection(ArrayList<Float>())
|
||||
val sortBy: Comparator<Float> = comparator<Float> {(x: Float, y: Float) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun FloatArray.take(n: Int) : List<Float> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean) : List<Float> {
|
||||
return takeWhileTo(ArrayList<Float>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Float>> FloatArray.takeWhileTo(result: C, predicate: (Float) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Float>> FloatArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun FloatArray.toLinkedList() : LinkedList<Float> {
|
||||
return toCollection(LinkedList<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun FloatArray.toList() : List<Float> {
|
||||
return toCollection(ArrayList<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun FloatArray.toSet() : Set<Float> {
|
||||
return toCollection(LinkedHashSet<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun FloatArray.toSortedSet() : SortedSet<Float> {
|
||||
return toCollection(TreeSet<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun FloatArray.withIndices() : Iterator<Pair<Int, Float>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun FloatArray.sum() : Float {
|
||||
return fold(0.toFloat(), {a,b -> a+b})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,836 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun <T> Array<out T>.partition(predicate: (T) -> Boolean) : Pair<List<T>, List<T>> {
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun BooleanArray.partition(predicate: (Boolean) -> Boolean) : Pair<List<Boolean>, List<Boolean>> {
|
||||
val first = ArrayList<Boolean>()
|
||||
val second = ArrayList<Boolean>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun ByteArray.partition(predicate: (Byte) -> Boolean) : Pair<List<Byte>, List<Byte>> {
|
||||
val first = ArrayList<Byte>()
|
||||
val second = ArrayList<Byte>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun CharArray.partition(predicate: (Char) -> Boolean) : Pair<List<Char>, List<Char>> {
|
||||
val first = ArrayList<Char>()
|
||||
val second = ArrayList<Char>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun DoubleArray.partition(predicate: (Double) -> Boolean) : Pair<List<Double>, List<Double>> {
|
||||
val first = ArrayList<Double>()
|
||||
val second = ArrayList<Double>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun FloatArray.partition(predicate: (Float) -> Boolean) : Pair<List<Float>, List<Float>> {
|
||||
val first = ArrayList<Float>()
|
||||
val second = ArrayList<Float>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun IntArray.partition(predicate: (Int) -> Boolean) : Pair<List<Int>, List<Int>> {
|
||||
val first = ArrayList<Int>()
|
||||
val second = ArrayList<Int>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun LongArray.partition(predicate: (Long) -> Boolean) : Pair<List<Long>, List<Long>> {
|
||||
val first = ArrayList<Long>()
|
||||
val second = ArrayList<Long>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun ShortArray.partition(predicate: (Short) -> Boolean) : Pair<List<Short>, List<Short>> {
|
||||
val first = ArrayList<Short>()
|
||||
val second = ArrayList<Short>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.partition(predicate: (T) -> Boolean) : Pair<List<T>, List<T>> {
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits original collection into pair of collections,
|
||||
* where *first* collection contains elements for which predicate yielded *true*,
|
||||
* while *second* collection contains elements for which predicate yielded *false*
|
||||
*/
|
||||
public inline fun <T> Stream<T>.partition(predicate: (T) -> Boolean) : Pair<List<T>, List<T>> {
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun <T> Array<out T>.plus(array: Array<T>) : List<T> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun BooleanArray.plus(array: Array<Boolean>) : List<Boolean> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun ByteArray.plus(array: Array<Byte>) : List<Byte> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun CharArray.plus(array: Array<Char>) : List<Char> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun DoubleArray.plus(array: Array<Double>) : List<Double> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun FloatArray.plus(array: Array<Float>) : List<Float> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun IntArray.plus(array: Array<Int>) : List<Int> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun LongArray.plus(array: Array<Long>) : List<Long> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun ShortArray.plus(array: Array<Short>) : List<Short> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun <T> Iterable<T>.plus(array: Array<T>) : List<T> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun <T> Array<out T>.plus(collection: Iterable<T>) : List<T> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun BooleanArray.plus(collection: Iterable<Boolean>) : List<Boolean> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun ByteArray.plus(collection: Iterable<Byte>) : List<Byte> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun CharArray.plus(collection: Iterable<Char>) : List<Char> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun DoubleArray.plus(collection: Iterable<Double>) : List<Double> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun FloatArray.plus(collection: Iterable<Float>) : List<Float> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun IntArray.plus(collection: Iterable<Int>) : List<Int> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun LongArray.plus(collection: Iterable<Long>) : List<Long> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun ShortArray.plus(collection: Iterable<Short>) : List<Short> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then all elements of the given *collection*
|
||||
*/
|
||||
public fun <T> Iterable<T>.plus(collection: Iterable<T>) : List<T> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream containing all elements of original stream and then all elements of the given *collection*
|
||||
*/
|
||||
public fun <T> Stream<T>.plus(collection: Iterable<T>) : Stream<T> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer.stream()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun <T> Array<out T>.plus(element: T) : List<T> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun BooleanArray.plus(element: Boolean) : List<Boolean> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun ByteArray.plus(element: Byte) : List<Byte> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun CharArray.plus(element: Char) : List<Char> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun DoubleArray.plus(element: Double) : List<Double> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun FloatArray.plus(element: Float) : List<Float> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun IntArray.plus(element: Int) : List<Int> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun LongArray.plus(element: Long) : List<Long> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun ShortArray.plus(element: Short) : List<Short> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of original collection and then the given element
|
||||
*/
|
||||
public fun <T> Iterable<T>.plus(element: T) : List<T> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream containing all elements of original stream and then the given element
|
||||
*/
|
||||
public fun <T> Stream<T>.plus(element: T) : Stream<T> {
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer.stream()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream containing all elements of original stream and then all elements of the given *stream*
|
||||
*/
|
||||
public fun <T> Stream<T>.plus(stream: Stream<T>) : Stream<T> {
|
||||
val answer = toArrayList()
|
||||
answer.addAll(stream)
|
||||
return answer.stream()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <T, R> Array<out T>.zip(array: Array<R>) : List<Pair<T,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<T,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> BooleanArray.zip(array: Array<R>) : List<Pair<Boolean,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Boolean,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> ByteArray.zip(array: Array<R>) : List<Pair<Byte,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Byte,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> CharArray.zip(array: Array<R>) : List<Pair<Char,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Char,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> DoubleArray.zip(array: Array<R>) : List<Pair<Double,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Double,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> FloatArray.zip(array: Array<R>) : List<Pair<Float,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Float,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> IntArray.zip(array: Array<R>) : List<Pair<Int,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Int,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> LongArray.zip(array: Array<R>) : List<Pair<Long,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Long,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> ShortArray.zip(array: Array<R>) : List<Pair<Short,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<Short,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <T, R> Iterable<T>.zip(array: Array<R>) : List<Pair<T,R>> {
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<T,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <T, R> Array<out T>.zip(collection: Iterable<R>) : List<Pair<T,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<T,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> BooleanArray.zip(collection: Iterable<R>) : List<Pair<Boolean,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Boolean,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> ByteArray.zip(collection: Iterable<R>) : List<Pair<Byte,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Byte,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> CharArray.zip(collection: Iterable<R>) : List<Pair<Char,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Char,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> DoubleArray.zip(collection: Iterable<R>) : List<Pair<Double,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Double,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> FloatArray.zip(collection: Iterable<R>) : List<Pair<Float,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Float,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> IntArray.zip(collection: Iterable<R>) : List<Pair<Int,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Int,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> LongArray.zip(collection: Iterable<R>) : List<Pair<Long,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Long,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <R> ShortArray.zip(collection: Iterable<R>) : List<Pair<Short,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<Short,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <T, R> Iterable<T>.zip(collection: Iterable<R>) : List<Pair<T,R>> {
|
||||
val first = iterator()
|
||||
val second = collection.iterator()
|
||||
val list = ArrayList<Pair<T,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
public fun <T, R> Stream<T>.zip(stream: Stream<R>) : Stream<Pair<T,R>> {
|
||||
return ZippingStream(this, stream)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns an original collection containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> Array<T?>.requireNoNulls() : Array<T> {
|
||||
for (element in this) {
|
||||
if (element == null) {
|
||||
throw IllegalArgumentException("null element found in $this")
|
||||
}
|
||||
}
|
||||
return this as Array<T>
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an original collection containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> Iterable<T?>.requireNoNulls() : Iterable<T> {
|
||||
for (element in this) {
|
||||
if (element == null) {
|
||||
throw IllegalArgumentException("null element found in $this")
|
||||
}
|
||||
}
|
||||
return this as Iterable<T>
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an original collection containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> List<T?>.requireNoNulls() : List<T> {
|
||||
for (element in this) {
|
||||
if (element == null) {
|
||||
throw IllegalArgumentException("null element found in $this")
|
||||
}
|
||||
}
|
||||
return this as List<T>
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an original collection containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> Stream<T?>.requireNoNulls() : Stream<T> {
|
||||
return FilteringStream(this) {
|
||||
if (it == null) {
|
||||
throw IllegalArgumentException("null element found in $this")
|
||||
}
|
||||
true
|
||||
} as Stream<T>
|
||||
|
||||
}
|
||||
|
||||
@@ -1,482 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun IntArray.all(predicate: (Int) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun IntArray.any(predicate: (Int) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun IntArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun IntArray.count(predicate: (Int) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun IntArray.drop(n: Int) : List<Int> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean) : List<Int> {
|
||||
return dropWhileTo(ArrayList<Int>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Int>> IntArray.dropWhileTo(result: L, predicate: (Int) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun IntArray.filter(predicate: (Int) -> Boolean) : List<Int> {
|
||||
return filterTo(ArrayList<Int>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun IntArray.filterNot(predicate: (Int) -> Boolean) : List<Int> {
|
||||
return filterNotTo(ArrayList<Int>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Int>> IntArray.filterNotTo(result: C, predicate: (Int) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Int>> IntArray.filterTo(result: C, predicate: (Int) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun IntArray.find(predicate: (Int) -> Boolean) : Int? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> IntArray.flatMap(transform: (Int)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> IntArray.flatMapTo(result: C, transform: (Int) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> IntArray.fold(initial: R, operation: (R, Int) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> IntArray.foldRight(initial: R, operation: (Int, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun IntArray.forEach(operation: (Int) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> IntArray.groupBy(toKey: (Int) -> K) : Map<K, List<Int>> {
|
||||
return groupByTo(HashMap<K, MutableList<Int>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> IntArray.groupByTo(result: MutableMap<K, MutableList<Int>>, toKey: (Int) -> K) : Map<K, MutableList<Int>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Int>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun IntArray.indexOf(item: Int) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun IntArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun IntArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun IntArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> IntArray.map(transform : (Int) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> IntArray.mapTo(result: C, transform : (Int) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun IntArray.max() : Int? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> IntArray.maxBy(f: (Int) -> R) : Int? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun IntArray.min() : Int? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> IntArray.minBy(f: (Int) -> R) : Int? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun IntArray.partition(predicate: (Int) -> Boolean) : Pair<List<Int>, List<Int>> {
|
||||
val first = ArrayList<Int>()
|
||||
val second = ArrayList<Int>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun IntArray.plus(collection: Iterable<Int>) : List<Int> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun IntArray.plus(element: Int) : List<Int> {
|
||||
val answer = ArrayList<Int>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun IntArray.plus(iterator: Iterator<Int>) : List<Int> {
|
||||
val answer = ArrayList<Int>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun IntArray.reduce(operation: (Int, Int) -> Int) : Int {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Int = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun IntArray.reduceRight(operation: (Int, Int) -> Int) : Int {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun IntArray.reverse() : List<Int> {
|
||||
val list = toCollection(ArrayList<Int>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> IntArray.sortBy(f: (Int) -> R) : List<Int> {
|
||||
val sortedList = toCollection(ArrayList<Int>())
|
||||
val sortBy: Comparator<Int> = comparator<Int> {(x: Int, y: Int) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun IntArray.take(n: Int) : List<Int> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun IntArray.takeWhile(predicate: (Int) -> Boolean) : List<Int> {
|
||||
return takeWhileTo(ArrayList<Int>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Int>> IntArray.takeWhileTo(result: C, predicate: (Int) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Int>> IntArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun IntArray.toLinkedList() : LinkedList<Int> {
|
||||
return toCollection(LinkedList<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun IntArray.toList() : List<Int> {
|
||||
return toCollection(ArrayList<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun IntArray.toSet() : Set<Int> {
|
||||
return toCollection(LinkedHashSet<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun IntArray.toSortedSet() : SortedSet<Int> {
|
||||
return toCollection(TreeSet<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun IntArray.withIndices() : Iterator<Pair<Int, Int>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun IntArray.sum() : Int {
|
||||
return fold(0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
@@ -1,476 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Iterable<T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.drop(n: Int) : List<T> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.dropWhile(predicate: (T) -> Boolean) : List<T> {
|
||||
return dropWhileTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T, L: MutableList<in T>> Iterable<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.filter(predicate: (T) -> Boolean) : List<T> {
|
||||
return filterTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.filterNot(predicate: (T) -> Boolean) : List<T> {
|
||||
return filterNotTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all the non-*null* elements
|
||||
*/
|
||||
public fun <T:Any> Iterable<T?>.filterNotNull() : List<T> {
|
||||
return filterNotNullTo<T, ArrayList<T>>(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all non-*null* elements into the given list
|
||||
*/
|
||||
public fun <T:Any, C: MutableCollection<in T>> Iterable<T?>.filterNotNullTo(result: C) : C {
|
||||
for (element in this) if (element != null) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterable<T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterable<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun <T:Any> Iterable<T>.find(predicate: (T) -> Boolean) : T? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterable<T>.flatMapTo(result: C, transform: (T) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.fold(initial: R, operation: (R, T) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.forEach(operation: (T) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <T, K> Iterable<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> {
|
||||
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <T, K> Iterable<T>.groupByTo(result: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<T>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Iterable<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterable<T>.mapTo(result: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Iterable<T>.max() : T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
|
||||
var max = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
val e = iterator.next()
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>, T: Any> Iterable<T>.maxBy(f: (T) -> R) : T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
|
||||
var maxElem = iterator.next()
|
||||
var maxValue = f(maxElem)
|
||||
while (iterator.hasNext()) {
|
||||
val e = iterator.next()
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Iterable<T>.min() : T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
|
||||
var min = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
val e = iterator.next()
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>, T: Any> Iterable<T>.minBy(f: (T) -> R) : T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
|
||||
var minElem = iterator.next()
|
||||
var minValue = f(minElem)
|
||||
while (iterator.hasNext()) {
|
||||
val e = iterator.next()
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.partition(predicate: (T) -> Boolean) : Pair<List<T>, List<T>> {
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun <T> Iterable<T>.plus(collection: Iterable<T>) : List<T> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun <T> Iterable<T>.plus(element: T) : List<T> {
|
||||
val answer = ArrayList<T>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun <T> Iterable<T>.plus(iterator: Iterator<T>) : List<T> {
|
||||
val answer = ArrayList<T>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.reduce(operation: (T, T) -> T) : T {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: T = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a original Iterable containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> Iterable<T?>.requireNoNulls() : Iterable<T> {
|
||||
for (element in this) {
|
||||
if (element == null) {
|
||||
throw IllegalArgumentException("null element found in $this")
|
||||
}
|
||||
}
|
||||
return this as Iterable<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun <T> Iterable<T>.reverse() : List<T> {
|
||||
val list = toCollection(ArrayList<T>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <T, R: Comparable<R>> Iterable<T>.sortBy(f: (T) -> R) : List<T> {
|
||||
val sortedList = toCollection(ArrayList<T>())
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.take(n: Int) : List<T> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean) : List<T> {
|
||||
return takeWhileTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterable<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <T, C: MutableCollection<in T>> Iterable<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun <T> Iterable<T>.toLinkedList() : LinkedList<T> {
|
||||
return toCollection(LinkedList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun <T> Iterable<T>.toList() : List<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun <T> Iterable<T>.toSet() : Set<T> {
|
||||
return toCollection(LinkedHashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun <T> Iterable<T>.toSortedSet() : SortedSet<T> {
|
||||
return toCollection(TreeSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun <T> Iterable<T>.withIndices() : Iterator<Pair<Int, T>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Iterable<Int>.sum() : Int {
|
||||
return fold(0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Iterable<Long>.sum() : Long {
|
||||
return fold(0.toLong(), {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Iterable<Float>.sum() : Float {
|
||||
return fold(0.toFloat(), {a,b -> a+b})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun Iterable<Double>.sum() : Double {
|
||||
return fold(0.0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
@@ -1,434 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.all(predicate: (T) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.any(predicate: (T) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Iterator<T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.count(predicate: (T) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun <T> Iterator<T>.drop(n: Int) : List<T> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.dropWhile(predicate: (T) -> Boolean) : List<T> {
|
||||
return dropWhileTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T, L: MutableList<in T>> Iterator<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over elements which match the given *predicate*
|
||||
*/
|
||||
public fun <T> Iterator<T>.filter(predicate: (T) -> Boolean) : Iterator<T> {
|
||||
return FilterIterator<T>(this, predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over elements which don't match the given *predicate*
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.filterNot(predicate: (T) -> Boolean) : Iterator<T> {
|
||||
return filter {!predicate(it)}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over non-*null* elements
|
||||
*/
|
||||
public fun <T:Any> Iterator<T?>.filterNotNull() : Iterator<T> {
|
||||
return FilterNotNullIterator(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all non-*null* elements into the given list
|
||||
*/
|
||||
public fun <T:Any, C: MutableCollection<in T>> Iterator<T?>.filterNotNullTo(result: C) : C {
|
||||
for (element in this) if (element != null) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterator<T>.filterNotTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterator<T>.filterTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun <T:Any> Iterator<T>.find(predicate: (T) -> Boolean) : T? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the concatenated results of transforming each element to one or more values
|
||||
*/
|
||||
public fun <T, R> Iterator<T>.flatMap(transform: (T) -> Iterator<R>) : Iterator<R> {
|
||||
return FlatMapIterator<T, R>(this, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterator<T>.flatMapTo(result: C, transform: (T) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <T, R> Iterator<T>.fold(initial: R, operation: (R, T) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.forEach(operation: (T) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <T, K> Iterator<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> {
|
||||
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <T, K> Iterator<T>.groupByTo(result: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<T>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Iterator<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator obtained by applying *transform*, a function transforming an object of type *T* into an object of type *R*
|
||||
*/
|
||||
public fun <T, R> Iterator<T>.map(transform : (T) -> R) : Iterator<R> {
|
||||
return MapIterator<T, R>(this, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterator<T>.mapTo(result: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Iterator<T>.max() : T? {
|
||||
if (!hasNext()) return null
|
||||
|
||||
var max = next()
|
||||
while (hasNext()) {
|
||||
val e = next()
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>, T: Any> Iterator<T>.maxBy(f: (T) -> R) : T? {
|
||||
if (!hasNext()) return null
|
||||
|
||||
var maxElem = next()
|
||||
var maxValue = f(maxElem)
|
||||
while (hasNext()) {
|
||||
val e = next()
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Iterator<T>.min() : T? {
|
||||
if (!hasNext()) return null
|
||||
|
||||
var min = next()
|
||||
while (hasNext()) {
|
||||
val e = next()
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>, T: Any> Iterator<T>.minBy(f: (T) -> R) : T? {
|
||||
if (!hasNext()) return null
|
||||
|
||||
var minElem = next()
|
||||
var minValue = f(minElem)
|
||||
while (hasNext()) {
|
||||
val e = next()
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.partition(predicate: (T) -> Boolean) : Pair<List<T>, List<T>> {
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun <T> Iterator<T>.plus(collection: Iterable<T>) : Iterator<T> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun <T> Iterator<T>.plus(element: T) : Iterator<T> {
|
||||
return CompositeIterator<T>(this, SingleIterator(element))
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun <T> Iterator<T>.plus(iterator: Iterator<T>) : Iterator<T> {
|
||||
return CompositeIterator<T>(this, iterator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.reduce(operation: (T, T) -> T) : T {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: T = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a original Iterable containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements
|
||||
*/
|
||||
public fun <T:Any> Iterator<T?>.requireNoNulls() : Iterator<T> {
|
||||
return map<T?, T>{
|
||||
if (it == null) throw IllegalArgumentException("null element in iterator $this") else it
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun <T> Iterator<T>.reverse() : List<T> {
|
||||
val list = toCollection(ArrayList<T>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <T, R: Comparable<R>> Iterator<T>.sortBy(f: (T) -> R) : List<T> {
|
||||
val sortedList = toCollection(ArrayList<T>())
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator restricted to the first *n* elements
|
||||
*/
|
||||
public fun <T> Iterator<T>.take(n: Int) : Iterator<T> {
|
||||
var count = n
|
||||
return takeWhile{ --count >= 0 }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator restricted to the first elements that match the given *predicate*
|
||||
*/
|
||||
public fun <T> Iterator<T>.takeWhile(predicate: (T) -> Boolean) : Iterator<T> {
|
||||
return TakeWhileIterator<T>(this, predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterator<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <T, C: MutableCollection<in T>> Iterator<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun <T> Iterator<T>.toLinkedList() : LinkedList<T> {
|
||||
return toCollection(LinkedList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun <T> Iterator<T>.toList() : List<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun <T> Iterator<T>.toSet() : Set<T> {
|
||||
return toCollection(LinkedHashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun <T> Iterator<T>.toSortedSet() : SortedSet<T> {
|
||||
return toCollection(TreeSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun <T> Iterator<T>.withIndices() : Iterator<Pair<Int, T>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
@@ -1,482 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun LongArray.all(predicate: (Long) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun LongArray.any(predicate: (Long) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun LongArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun LongArray.count(predicate: (Long) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun LongArray.drop(n: Int) : List<Long> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean) : List<Long> {
|
||||
return dropWhileTo(ArrayList<Long>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Long>> LongArray.dropWhileTo(result: L, predicate: (Long) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun LongArray.filter(predicate: (Long) -> Boolean) : List<Long> {
|
||||
return filterTo(ArrayList<Long>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun LongArray.filterNot(predicate: (Long) -> Boolean) : List<Long> {
|
||||
return filterNotTo(ArrayList<Long>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Long>> LongArray.filterNotTo(result: C, predicate: (Long) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Long>> LongArray.filterTo(result: C, predicate: (Long) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun LongArray.find(predicate: (Long) -> Boolean) : Long? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> LongArray.flatMap(transform: (Long)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> LongArray.flatMapTo(result: C, transform: (Long) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> LongArray.fold(initial: R, operation: (R, Long) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> LongArray.foldRight(initial: R, operation: (Long, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun LongArray.forEach(operation: (Long) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> LongArray.groupBy(toKey: (Long) -> K) : Map<K, List<Long>> {
|
||||
return groupByTo(HashMap<K, MutableList<Long>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> LongArray.groupByTo(result: MutableMap<K, MutableList<Long>>, toKey: (Long) -> K) : Map<K, MutableList<Long>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Long>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun LongArray.indexOf(item: Long) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun LongArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun LongArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun LongArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> LongArray.map(transform : (Long) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> LongArray.mapTo(result: C, transform : (Long) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun LongArray.max() : Long? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> LongArray.maxBy(f: (Long) -> R) : Long? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun LongArray.min() : Long? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> LongArray.minBy(f: (Long) -> R) : Long? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun LongArray.partition(predicate: (Long) -> Boolean) : Pair<List<Long>, List<Long>> {
|
||||
val first = ArrayList<Long>()
|
||||
val second = ArrayList<Long>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun LongArray.plus(collection: Iterable<Long>) : List<Long> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun LongArray.plus(element: Long) : List<Long> {
|
||||
val answer = ArrayList<Long>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun LongArray.plus(iterator: Iterator<Long>) : List<Long> {
|
||||
val answer = ArrayList<Long>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun LongArray.reduce(operation: (Long, Long) -> Long) : Long {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Long = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun LongArray.reduceRight(operation: (Long, Long) -> Long) : Long {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun LongArray.reverse() : List<Long> {
|
||||
val list = toCollection(ArrayList<Long>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> LongArray.sortBy(f: (Long) -> R) : List<Long> {
|
||||
val sortedList = toCollection(ArrayList<Long>())
|
||||
val sortBy: Comparator<Long> = comparator<Long> {(x: Long, y: Long) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun LongArray.take(n: Int) : List<Long> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun LongArray.takeWhile(predicate: (Long) -> Boolean) : List<Long> {
|
||||
return takeWhileTo(ArrayList<Long>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Long>> LongArray.takeWhileTo(result: C, predicate: (Long) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Long>> LongArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun LongArray.toLinkedList() : LinkedList<Long> {
|
||||
return toCollection(LinkedList<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun LongArray.toList() : List<Long> {
|
||||
return toCollection(ArrayList<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun LongArray.toSet() : Set<Long> {
|
||||
return toCollection(LinkedHashSet<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun LongArray.toSortedSet() : SortedSet<Long> {
|
||||
return toCollection(TreeSet<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun LongArray.withIndices() : Iterator<Pair<Int, Long>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun LongArray.sum() : Long {
|
||||
return fold(0.toLong(), {a,b -> a+b})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,858 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <T, R> Array<out T>.flatMap(transform: (T)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> BooleanArray.flatMap(transform: (Boolean)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> ByteArray.flatMap(transform: (Byte)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> CharArray.flatMap(transform: (Char)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> DoubleArray.flatMap(transform: (Double)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> FloatArray.flatMap(transform: (Float)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> IntArray.flatMap(transform: (Int)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> LongArray.flatMap(transform: (Long)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <R> ShortArray.flatMap(transform: (Short)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single list of all elements yielded from results of *transform* function being invoked on each element of original collection
|
||||
*/
|
||||
public inline fun <K, V, R> Map<K,V>.flatMap(transform: (Map.Entry<K,V>)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single stream of all elements streamed from results of *transform* function being invoked on each element of original stream
|
||||
*/
|
||||
public fun <T, R> Stream<T>.flatMap(transform: (T)-> Stream<R>) : Stream<R> {
|
||||
return FlatteningStream(this, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Array<out T>.flatMapTo(collection: C, transform: (T) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> BooleanArray.flatMapTo(collection: C, transform: (Boolean) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ByteArray.flatMapTo(collection: C, transform: (Byte) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> CharArray.flatMapTo(collection: C, transform: (Char) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> DoubleArray.flatMapTo(collection: C, transform: (Double) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> FloatArray.flatMapTo(collection: C, transform: (Float) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> IntArray.flatMapTo(collection: C, transform: (Int) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> LongArray.flatMapTo(collection: C, transform: (Long) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ShortArray.flatMapTo(collection: C, transform: (Short) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterable<T>.flatMapTo(collection: C, transform: (T) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*
|
||||
*/
|
||||
public inline fun <K, V, R, C: MutableCollection<in R>> Map<K,V>.flatMapTo(collection: C, transform: (Map.Entry<K,V>) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements yielded from results of *transform* function being invoked on each element of original stream, to the given *collection*
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Stream<T>.flatMapTo(collection: C, transform: (T) -> Stream<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
collection.addAll(list)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <T, K> Array<out T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> {
|
||||
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> BooleanArray.groupBy(toKey: (Boolean) -> K) : Map<K, List<Boolean>> {
|
||||
return groupByTo(HashMap<K, MutableList<Boolean>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> ByteArray.groupBy(toKey: (Byte) -> K) : Map<K, List<Byte>> {
|
||||
return groupByTo(HashMap<K, MutableList<Byte>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> CharArray.groupBy(toKey: (Char) -> K) : Map<K, List<Char>> {
|
||||
return groupByTo(HashMap<K, MutableList<Char>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> DoubleArray.groupBy(toKey: (Double) -> K) : Map<K, List<Double>> {
|
||||
return groupByTo(HashMap<K, MutableList<Double>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> FloatArray.groupBy(toKey: (Float) -> K) : Map<K, List<Float>> {
|
||||
return groupByTo(HashMap<K, MutableList<Float>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> IntArray.groupBy(toKey: (Int) -> K) : Map<K, List<Int>> {
|
||||
return groupByTo(HashMap<K, MutableList<Int>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> LongArray.groupBy(toKey: (Long) -> K) : Map<K, List<Long>> {
|
||||
return groupByTo(HashMap<K, MutableList<Long>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <K> ShortArray.groupBy(toKey: (Short) -> K) : Map<K, List<Short>> {
|
||||
return groupByTo(HashMap<K, MutableList<Short>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <T, K> Iterable<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> {
|
||||
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <V, K> Map<K,V>.groupBy(toKey: (Map.Entry<K,V>) -> K) : Map<K, List<Map.Entry<K,V>>> {
|
||||
return groupByTo(HashMap<K, MutableList<Map.Entry<K,V>>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the elements in original collection grouped by the result of given *toKey* function
|
||||
*/
|
||||
public inline fun <T, K> Stream<T>.groupBy(toKey: (T) -> K) : Map<K, List<T>> {
|
||||
return groupByTo(HashMap<K, MutableList<T>>(), toKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <T, K> Array<out T>.groupByTo(map: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<T>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> BooleanArray.groupByTo(map: MutableMap<K, MutableList<Boolean>>, toKey: (Boolean) -> K) : Map<K, MutableList<Boolean>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Boolean>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> ByteArray.groupByTo(map: MutableMap<K, MutableList<Byte>>, toKey: (Byte) -> K) : Map<K, MutableList<Byte>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Byte>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> CharArray.groupByTo(map: MutableMap<K, MutableList<Char>>, toKey: (Char) -> K) : Map<K, MutableList<Char>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Char>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> DoubleArray.groupByTo(map: MutableMap<K, MutableList<Double>>, toKey: (Double) -> K) : Map<K, MutableList<Double>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Double>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> FloatArray.groupByTo(map: MutableMap<K, MutableList<Float>>, toKey: (Float) -> K) : Map<K, MutableList<Float>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Float>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> IntArray.groupByTo(map: MutableMap<K, MutableList<Int>>, toKey: (Int) -> K) : Map<K, MutableList<Int>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Int>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> LongArray.groupByTo(map: MutableMap<K, MutableList<Long>>, toKey: (Long) -> K) : Map<K, MutableList<Long>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Long>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <K> ShortArray.groupByTo(map: MutableMap<K, MutableList<Short>>, toKey: (Short) -> K) : Map<K, MutableList<Short>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Short>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <T, K> Iterable<T>.groupByTo(map: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<T>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <V, K> Map<K,V>.groupByTo(map: MutableMap<K, MutableList<Map.Entry<K,V>>>, toKey: (Map.Entry<K,V>) -> K) : Map<K, MutableList<Map.Entry<K,V>>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<Map.Entry<K,V>>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends elements from original collection grouped by the result of given *toKey* function to the given *map*
|
||||
*/
|
||||
public inline fun <T, K> Stream<T>.groupByTo(map: MutableMap<K, MutableList<T>>, toKey: (T) -> K) : Map<K, MutableList<T>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = map.getOrPut(key) { ArrayList<T>() }
|
||||
list.add(element)
|
||||
}
|
||||
return map
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <T, R> Array<out T>.map(transform : (T) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> BooleanArray.map(transform : (Boolean) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> ByteArray.map(transform : (Byte) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> CharArray.map(transform : (Char) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> DoubleArray.map(transform : (Double) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> FloatArray.map(transform : (Float) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> IntArray.map(transform : (Int) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> LongArray.map(transform : (Long) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <R> ShortArray.map(transform : (Short) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.map(transform : (T) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each element of the original collection
|
||||
*/
|
||||
public inline fun <K, V, R> Map<K,V>.map(transform : (Map.Entry<K,V>) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream containing the results of applying the given *transform* function to each element of the original stream
|
||||
*/
|
||||
public fun <T, R> Stream<T>.map(transform : (T) -> R) : Stream<R> {
|
||||
return TransformingStream(this, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each non-null element of the original collection
|
||||
*/
|
||||
public fun <T: Any, R> Array<T?>.mapNotNull(transform : (T) -> R) : List<R> {
|
||||
return mapNotNullTo(ArrayList<R>(), transform)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the results of applying the given *transform* function to each non-null element of the original collection
|
||||
*/
|
||||
public fun <T: Any, R> Iterable<T?>.mapNotNull(transform : (T) -> R) : List<R> {
|
||||
return mapNotNullTo(ArrayList<R>(), transform)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream containing the results of applying the given *transform* function to each non-null element of the original stream
|
||||
*/
|
||||
public fun <T: Any, R> Stream<T?>.mapNotNull(transform : (T) -> R) : Stream<R> {
|
||||
return TransformingStream(FilteringStream(this, false, { it != null }) as Stream<T>, transform)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed non-null elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <T: Any, R, C: MutableCollection<in R>> Array<T?>.mapNotNullTo(collection: C, transform : (T) -> R) : C {
|
||||
for (element in this) {
|
||||
if (element != null) {
|
||||
collection.add(transform(element))
|
||||
}
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed non-null elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <T: Any, R, C: MutableCollection<in R>> Iterable<T?>.mapNotNullTo(collection: C, transform : (T) -> R) : C {
|
||||
for (element in this) {
|
||||
if (element != null) {
|
||||
collection.add(transform(element))
|
||||
}
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed non-null elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <T: Any, R, C: MutableCollection<in R>> Stream<T?>.mapNotNullTo(collection: C, transform : (T) -> R) : C {
|
||||
for (element in this) {
|
||||
if (element != null) {
|
||||
collection.add(transform(element))
|
||||
}
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Array<out T>.mapTo(collection: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> BooleanArray.mapTo(collection: C, transform : (Boolean) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ByteArray.mapTo(collection: C, transform : (Byte) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> CharArray.mapTo(collection: C, transform : (Char) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> DoubleArray.mapTo(collection: C, transform : (Double) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> FloatArray.mapTo(collection: C, transform : (Float) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> IntArray.mapTo(collection: C, transform : (Int) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> LongArray.mapTo(collection: C, transform : (Long) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ShortArray.mapTo(collection: C, transform : (Short) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Iterable<T>.mapTo(collection: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <K, V, R, C: MutableCollection<in R>> Map<K,V>.mapTo(collection: C, transform : (Map.Entry<K,V>) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends transformed elements of original collection using the given *transform* function
|
||||
* to the given *collection*
|
||||
*/
|
||||
public inline fun <T, R, C: MutableCollection<in R>> Stream<T>.mapTo(collection: C, transform : (T) -> R) : C {
|
||||
for (item in this)
|
||||
collection.add(transform(item))
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun <T> Array<out T>.withIndices() : List<Pair<Int, T>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, T>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun BooleanArray.withIndices() : List<Pair<Int, Boolean>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Boolean>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun ByteArray.withIndices() : List<Pair<Int, Byte>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Byte>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun CharArray.withIndices() : List<Pair<Int, Char>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Char>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun DoubleArray.withIndices() : List<Pair<Int, Double>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Double>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun FloatArray.withIndices() : List<Pair<Int, Float>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Float>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun IntArray.withIndices() : List<Pair<Int, Int>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Int>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun LongArray.withIndices() : List<Pair<Int, Long>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Long>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun ShortArray.withIndices() : List<Pair<Int, Short>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, Short>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun <T> Iterable<T>.withIndices() : List<Pair<Int, T>> {
|
||||
var index = 0
|
||||
return mapTo(ArrayList<Pair<Int, T>>(), { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream containing pairs of each element of the original collection and their index
|
||||
*/
|
||||
public fun <T> Stream<T>.withIndices() : Stream<Pair<Int, T>> {
|
||||
var index = 0
|
||||
return TransformingStream(this, { index++ to it })
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Iterable<Int>.sum() : Int {
|
||||
val iterator = iterator()
|
||||
var sum : Int = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Iterable<Long>.sum() : Long {
|
||||
val iterator = iterator()
|
||||
var sum : Long = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Iterable<Double>.sum() : Double {
|
||||
val iterator = iterator()
|
||||
var sum : Double = 0.0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Iterable<Float>.sum() : Float {
|
||||
val iterator = iterator()
|
||||
var sum : Float = 0.0f
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Array<out Int>.sum() : Int {
|
||||
val iterator = iterator()
|
||||
var sum : Int = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun IntArray.sum() : Int {
|
||||
val iterator = iterator()
|
||||
var sum : Int = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Array<out Long>.sum() : Long {
|
||||
val iterator = iterator()
|
||||
var sum : Long = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun LongArray.sum() : Long {
|
||||
val iterator = iterator()
|
||||
var sum : Long = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Array<out Byte>.sum() : Int {
|
||||
val iterator = iterator()
|
||||
var sum : Int = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun ByteArray.sum() : Int {
|
||||
val iterator = iterator()
|
||||
var sum : Int = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Array<out Short>.sum() : Int {
|
||||
val iterator = iterator()
|
||||
var sum : Int = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun ShortArray.sum() : Int {
|
||||
val iterator = iterator()
|
||||
var sum : Int = 0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Array<out Double>.sum() : Double {
|
||||
val iterator = iterator()
|
||||
var sum : Double = 0.0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun DoubleArray.sum() : Double {
|
||||
val iterator = iterator()
|
||||
var sum : Double = 0.0
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Array<out Float>.sum() : Float {
|
||||
val iterator = iterator()
|
||||
var sum : Float = 0.0f
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun FloatArray.sum() : Float {
|
||||
val iterator = iterator()
|
||||
var sum : Float = 0.0f
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun <T> Array<out T>.reverse() : List<T> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun BooleanArray.reverse() : List<Boolean> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun ByteArray.reverse() : List<Byte> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun CharArray.reverse() : List<Char> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun DoubleArray.reverse() : List<Double> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun FloatArray.reverse() : List<Float> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun IntArray.reverse() : List<Int> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun LongArray.reverse() : List<Long> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun ShortArray.reverse() : List<Short> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with elements in reversed order
|
||||
*/
|
||||
public fun <T> Iterable<T>.reverse() : List<T> {
|
||||
val list = toArrayList()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Iterable<T>.sort() : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
java.util.Collections.sort(sortedList)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements, sorted by the specified *comparator*
|
||||
*/
|
||||
public fun <T> Array<out T>.sortBy(comparator : Comparator<T>) : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
java.util.Collections.sort(sortedList, comparator)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements, sorted by the specified *comparator*
|
||||
*/
|
||||
public fun <T> Iterable<T>.sortBy(comparator : Comparator<T>) : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
java.util.Collections.sort(sortedList, comparator)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements, sorted by results of specified *order* function.
|
||||
*/
|
||||
public inline fun <T, R: Comparable<R>> Array<out T>.sortBy(order: (T) -> R) : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(x).compareTo(order(y))}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements, sorted by results of specified *order* function.
|
||||
*/
|
||||
public inline fun <T, R: Comparable<R>> Iterable<T>.sortBy(order: (T) -> R) : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(x).compareTo(order(y))}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Iterable<T>.sortDescending() : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -x.compareTo(y)}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements, sorted by results of specified *order* function.
|
||||
*/
|
||||
public inline fun <T, R: Comparable<R>> Array<out T>.sortDescendingBy(order: (T) -> R) : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y))}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all elements, sorted by results of specified *order* function.
|
||||
*/
|
||||
public inline fun <T, R: Comparable<R>> Iterable<T>.sortDescendingBy(order: (T) -> R) : List<T> {
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y))}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
|
||||
}
|
||||
|
||||
@@ -1,482 +0,0 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns *true* if all elements match the given *predicate*
|
||||
*/
|
||||
public inline fun ShortArray.all(predicate: (Short) -> Boolean) : Boolean {
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns *true* if any elements match the given *predicate*
|
||||
*/
|
||||
public inline fun ShortArray.any(predicate: (Short) -> Boolean) : Boolean {
|
||||
for (element in this) if (predicate(element)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ShortArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun ShortArray.count(predicate: (Short) -> Boolean) : Int {
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*/
|
||||
public fun ShortArray.drop(n: Int) : List<Short> {
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean) : List<Short> {
|
||||
return dropWhileTo(ArrayList<Short>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <L: MutableList<in Short>> ShortArray.dropWhileTo(result: L, predicate: (Short) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which match the given *predicate*
|
||||
*/
|
||||
public inline fun ShortArray.filter(predicate: (Short) -> Boolean) : List<Short> {
|
||||
return filterTo(ArrayList<Short>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun ShortArray.filterNot(predicate: (Short) -> Boolean) : List<Short> {
|
||||
return filterNotTo(ArrayList<Short>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements which do not match the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Short>> ShortArray.filterNotTo(result: C, predicate: (Short) -> Boolean) : C {
|
||||
for (element in this) if (!predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all elements which match the given predicate into the given list
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Short>> ShortArray.filterTo(result: C, predicate: (Short) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element which matches the given *predicate* or *null* if none matched
|
||||
*/
|
||||
public inline fun ShortArray.find(predicate: (Short) -> Boolean) : Short? {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <R> ShortArray.flatMap(transform: (Short)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ShortArray.flatMapTo(result: C, transform: (Short) -> Iterable<R>) : C {
|
||||
for (element in this) {
|
||||
val list = transform(element)
|
||||
for (r in list) result.add(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from from left to right with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> ShortArray.fold(initial: R, operation: (R, Short) -> R) : R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds all elements from right to left with the *initial* value to perform the operation on sequential pairs of elements
|
||||
*/
|
||||
public inline fun <R> ShortArray.foldRight(initial: R, operation: (Short, R) -> R) : R {
|
||||
var r = initial
|
||||
var index = size - 1
|
||||
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given *operation* on each element
|
||||
*/
|
||||
public inline fun ShortArray.forEach(operation: (Short) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the elements in the collection into a new [[Map]] using the supplied *toKey* function to calculate the key to group the elements by
|
||||
*/
|
||||
public inline fun <K> ShortArray.groupBy(toKey: (Short) -> K) : Map<K, List<Short>> {
|
||||
return groupByTo(HashMap<K, MutableList<Short>>(), toKey)
|
||||
}
|
||||
|
||||
public inline fun <K> ShortArray.groupByTo(result: MutableMap<K, MutableList<Short>>, toKey: (Short) -> K) : Map<K, MutableList<Short>> {
|
||||
for (element in this) {
|
||||
val key = toKey(element)
|
||||
val list = result.getOrPut(key) { ArrayList<Short>() }
|
||||
list.add(element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of item, or -1 if the array does not contain item
|
||||
*/
|
||||
public fun ShortArray.indexOf(item: Short) : Int {
|
||||
for (i in indices) {
|
||||
if (item == this[i]) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun ShortArray.isEmpty() : Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun ShortArray.isNotEmpty() : Boolean {
|
||||
return !isEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ShortArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new List containing the results of applying the given *transform* function to each element in this collection
|
||||
*/
|
||||
public inline fun <R> ShortArray.map(transform : (Short) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms each element of this collection with the given *transform* function and
|
||||
* adds each return value to the given *results* collection
|
||||
*/
|
||||
public inline fun <R, C: MutableCollection<in R>> ShortArray.mapTo(result: C, transform : (Short) -> R) : C {
|
||||
for (item in this)
|
||||
result.add(transform(item))
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest element or null if there are no elements
|
||||
*/
|
||||
public fun ShortArray.max() : Short? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var max = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (max < e) max = e
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the largest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> ShortArray.maxBy(f: (Short) -> R) : Short? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var maxElem = this[0]
|
||||
var maxValue = f(maxElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest element or null if there are no elements
|
||||
*/
|
||||
public fun ShortArray.min() : Short? {
|
||||
if (isEmpty()) return null
|
||||
|
||||
var min = this[0]
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
if (min > e) min = e
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> ShortArray.minBy(f: (Short) -> R) : Short? {
|
||||
if (size == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions this collection into a pair of collections
|
||||
*/
|
||||
public inline fun ShortArray.partition(predicate: (Short) -> Boolean) : Pair<List<Short>, List<Short>> {
|
||||
val first = ArrayList<Short>()
|
||||
val second = ArrayList<Short>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following collection
|
||||
*/
|
||||
public fun ShortArray.plus(collection: Iterable<Short>) : List<Short> {
|
||||
return plus(collection.iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the given element at the end
|
||||
*/
|
||||
public fun ShortArray.plus(element: Short) : List<Short> {
|
||||
val answer = ArrayList<Short>()
|
||||
toCollection(answer)
|
||||
answer.add(element)
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [[Iterator]] which iterates over this iterator then the following iterator
|
||||
*/
|
||||
public fun ShortArray.plus(iterator: Iterator<Short>) : List<Short> {
|
||||
val answer = ArrayList<Short>()
|
||||
toCollection(answer)
|
||||
for (element in iterator) {
|
||||
answer.add(element)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from left to right.
|
||||
* Similar to fold function, but uses the first element as initial value
|
||||
*/
|
||||
public inline fun ShortArray.reduce(operation: (Short, Short) -> Short) : Short {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var result: Short = iterator.next() //compiler doesn't understand that result will initialized anyway
|
||||
while (iterator.hasNext()) {
|
||||
result = operation(result, iterator.next())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies binary operation to all elements of iterable, going from right to left.
|
||||
* Similar to foldRight function, but uses the last element as initial value
|
||||
*/
|
||||
public inline fun ShortArray.reduceRight(operation: (Short, Short) -> Short) : Short {
|
||||
var index = size - 1
|
||||
if (index < 0) {
|
||||
throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
}
|
||||
|
||||
var r = get(index--)
|
||||
while (index >= 0) {
|
||||
r = operation(get(index--), r)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*/
|
||||
public fun ShortArray.reverse() : List<Short> {
|
||||
val list = toCollection(ArrayList<Short>())
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]] and sorts it by value of compare_function(element)
|
||||
* E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair
|
||||
*/
|
||||
public inline fun <R: Comparable<R>> ShortArray.sortBy(f: (Short) -> R) : List<Short> {
|
||||
val sortedList = toCollection(ArrayList<Short>())
|
||||
val sortBy: Comparator<Short> = comparator<Short> {(x: Short, y: Short) ->
|
||||
val xr = f(x)
|
||||
val yr = f(y)
|
||||
xr.compareTo(yr)
|
||||
}
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
public fun ShortArray.take(n: Int) : List<Short> {
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean) : List<Short> {
|
||||
return takeWhileTo(ArrayList<Short>(), predicate)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first elements that satisfy the given *predicate*
|
||||
*/
|
||||
public inline fun <C: MutableCollection<in Short>> ShortArray.takeWhileTo(result: C, predicate: (Short) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into the given collection
|
||||
*/
|
||||
public fun <C: MutableCollection<in Short>> ShortArray.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[LinkedList]]
|
||||
*/
|
||||
public fun ShortArray.toLinkedList() : LinkedList<Short> {
|
||||
return toCollection(LinkedList<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[List]]
|
||||
*/
|
||||
public fun ShortArray.toList() : List<Short> {
|
||||
return toCollection(ArrayList<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[Set]]
|
||||
*/
|
||||
public fun ShortArray.toSet() : Set<Short> {
|
||||
return toCollection(LinkedHashSet<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all elements into a [[SortedSet]]
|
||||
*/
|
||||
public fun ShortArray.toSortedSet() : SortedSet<Short> {
|
||||
return toCollection(TreeSet<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator of Pairs(index, data)
|
||||
*/
|
||||
public fun ShortArray.withIndices() : Iterator<Pair<Int, Short>> {
|
||||
return IndexIterator(iterator())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums up the elements
|
||||
*/
|
||||
public fun ShortArray.sum() : Int {
|
||||
return fold(0, {a,b -> a+b})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,720 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun <T> Array<out T>.toArrayList() : ArrayList<T> {
|
||||
val list = ArrayList<T>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun BooleanArray.toArrayList() : ArrayList<Boolean> {
|
||||
val list = ArrayList<Boolean>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun ByteArray.toArrayList() : ArrayList<Byte> {
|
||||
val list = ArrayList<Byte>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun CharArray.toArrayList() : ArrayList<Char> {
|
||||
val list = ArrayList<Char>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun DoubleArray.toArrayList() : ArrayList<Double> {
|
||||
val list = ArrayList<Double>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun FloatArray.toArrayList() : ArrayList<Float> {
|
||||
val list = ArrayList<Float>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun IntArray.toArrayList() : ArrayList<Int> {
|
||||
val list = ArrayList<Int>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun LongArray.toArrayList() : ArrayList<Long> {
|
||||
val list = ArrayList<Long>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun ShortArray.toArrayList() : ArrayList<Short> {
|
||||
val list = ArrayList<Short>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.toArrayList() : ArrayList<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun <T> Stream<T>.toArrayList() : ArrayList<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <T, C : MutableCollection<in T>> Array<out T>.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Boolean>> BooleanArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Byte>> ByteArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Char>> CharArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Double>> DoubleArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Float>> FloatArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Int>> IntArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Long>> LongArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <C : MutableCollection<in Short>> ShortArray.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <T, C : MutableCollection<in T>> Iterable<T>.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements to the given *collection*
|
||||
*/
|
||||
public fun <T, C : MutableCollection<in T>> Stream<T>.toCollection(collection : C) : C {
|
||||
for (item in this) {
|
||||
collection.add(item)
|
||||
}
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun <T> Array<out T>.toHashSet() : HashSet<T> {
|
||||
return toCollection(HashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun BooleanArray.toHashSet() : HashSet<Boolean> {
|
||||
return toCollection(HashSet<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun ByteArray.toHashSet() : HashSet<Byte> {
|
||||
return toCollection(HashSet<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun CharArray.toHashSet() : HashSet<Char> {
|
||||
return toCollection(HashSet<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun DoubleArray.toHashSet() : HashSet<Double> {
|
||||
return toCollection(HashSet<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun FloatArray.toHashSet() : HashSet<Float> {
|
||||
return toCollection(HashSet<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun IntArray.toHashSet() : HashSet<Int> {
|
||||
return toCollection(HashSet<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun LongArray.toHashSet() : HashSet<Long> {
|
||||
return toCollection(HashSet<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun ShortArray.toHashSet() : HashSet<Short> {
|
||||
return toCollection(HashSet<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.toHashSet() : HashSet<T> {
|
||||
return toCollection(HashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HashSet of all elements
|
||||
*/
|
||||
public fun <T> Stream<T>.toHashSet() : HashSet<T> {
|
||||
return toCollection(HashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun <T> Array<out T>.toLinkedList() : LinkedList<T> {
|
||||
return toCollection(LinkedList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun BooleanArray.toLinkedList() : LinkedList<Boolean> {
|
||||
return toCollection(LinkedList<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun ByteArray.toLinkedList() : LinkedList<Byte> {
|
||||
return toCollection(LinkedList<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun CharArray.toLinkedList() : LinkedList<Char> {
|
||||
return toCollection(LinkedList<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun DoubleArray.toLinkedList() : LinkedList<Double> {
|
||||
return toCollection(LinkedList<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun FloatArray.toLinkedList() : LinkedList<Float> {
|
||||
return toCollection(LinkedList<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun IntArray.toLinkedList() : LinkedList<Int> {
|
||||
return toCollection(LinkedList<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun LongArray.toLinkedList() : LinkedList<Long> {
|
||||
return toCollection(LinkedList<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun ShortArray.toLinkedList() : LinkedList<Short> {
|
||||
return toCollection(LinkedList<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.toLinkedList() : LinkedList<T> {
|
||||
return toCollection(LinkedList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a LinkedList containing all elements
|
||||
*/
|
||||
public fun <T> Stream<T>.toLinkedList() : LinkedList<T> {
|
||||
return toCollection(LinkedList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun <T> Array<out T>.toList() : List<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun BooleanArray.toList() : List<Boolean> {
|
||||
val list = ArrayList<Boolean>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun ByteArray.toList() : List<Byte> {
|
||||
val list = ArrayList<Byte>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun CharArray.toList() : List<Char> {
|
||||
val list = ArrayList<Char>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun DoubleArray.toList() : List<Double> {
|
||||
val list = ArrayList<Double>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun FloatArray.toList() : List<Float> {
|
||||
val list = ArrayList<Float>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun IntArray.toList() : List<Int> {
|
||||
val list = ArrayList<Int>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun LongArray.toList() : List<Long> {
|
||||
val list = ArrayList<Long>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun ShortArray.toList() : List<Short> {
|
||||
val list = ArrayList<Short>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.toList() : List<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun <T> Stream<T>.toList() : List<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun <T> Array<out T>.toSet() : Set<T> {
|
||||
return toCollection(LinkedHashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun BooleanArray.toSet() : Set<Boolean> {
|
||||
return toCollection(LinkedHashSet<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun ByteArray.toSet() : Set<Byte> {
|
||||
return toCollection(LinkedHashSet<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun CharArray.toSet() : Set<Char> {
|
||||
return toCollection(LinkedHashSet<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun DoubleArray.toSet() : Set<Double> {
|
||||
return toCollection(LinkedHashSet<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun FloatArray.toSet() : Set<Float> {
|
||||
return toCollection(LinkedHashSet<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun IntArray.toSet() : Set<Int> {
|
||||
return toCollection(LinkedHashSet<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun LongArray.toSet() : Set<Long> {
|
||||
return toCollection(LinkedHashSet<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun ShortArray.toSet() : Set<Short> {
|
||||
return toCollection(LinkedHashSet<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.toSet() : Set<T> {
|
||||
return toCollection(LinkedHashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of all elements
|
||||
*/
|
||||
public fun <T> Stream<T>.toSet() : Set<T> {
|
||||
return toCollection(LinkedHashSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Array<out T>.toSortedList() : List<T> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun BooleanArray.toSortedList() : List<Boolean> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun ByteArray.toSortedList() : List<Byte> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun CharArray.toSortedList() : List<Char> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun DoubleArray.toSortedList() : List<Double> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun FloatArray.toSortedList() : List<Float> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun IntArray.toSortedList() : List<Int> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun LongArray.toSortedList() : List<Long> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun ShortArray.toSortedList() : List<Short> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Iterable<T>.toSortedList() : List<T> {
|
||||
return sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sorted list of all elements
|
||||
*/
|
||||
public fun <T: Comparable<T>> Stream<T>.toSortedList() : List<T> {
|
||||
return toArrayList().sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun <T> Array<out T>.toSortedSet() : SortedSet<T> {
|
||||
return toCollection(TreeSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun BooleanArray.toSortedSet() : SortedSet<Boolean> {
|
||||
return toCollection(TreeSet<Boolean>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun ByteArray.toSortedSet() : SortedSet<Byte> {
|
||||
return toCollection(TreeSet<Byte>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun CharArray.toSortedSet() : SortedSet<Char> {
|
||||
return toCollection(TreeSet<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun DoubleArray.toSortedSet() : SortedSet<Double> {
|
||||
return toCollection(TreeSet<Double>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun FloatArray.toSortedSet() : SortedSet<Float> {
|
||||
return toCollection(TreeSet<Float>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun IntArray.toSortedSet() : SortedSet<Int> {
|
||||
return toCollection(TreeSet<Int>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun LongArray.toSortedSet() : SortedSet<Long> {
|
||||
return toCollection(TreeSet<Long>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun ShortArray.toSortedSet() : SortedSet<Short> {
|
||||
return toCollection(TreeSet<Short>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun <T> Iterable<T>.toSortedSet() : SortedSet<T> {
|
||||
return toCollection(TreeSet<T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SortedSet of all elements
|
||||
*/
|
||||
public fun <T> Stream<T>.toSortedSet() : SortedSet<T> {
|
||||
return toCollection(TreeSet<T>())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun <T> Array<out T>.binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun ByteArray.binarySearch(element: Byte, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun CharArray.binarySearch(element: Char, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun DoubleArray.binarySearch(element: Double, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun FloatArray.binarySearch(element: Float, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun IntArray.binarySearch(element: Int, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun LongArray.binarySearch(element: Long, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun ShortArray.binarySearch(element: Short, fromIndex: Int = 0, toIndex: Int = size - 1) : Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun <T> Array<out T>.copyOf(newSize: Int = size) : Array<T> {
|
||||
return Arrays.copyOf(this, newSize) as Array<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun BooleanArray.copyOf(newSize: Int = size) : BooleanArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun ByteArray.copyOf(newSize: Int = size) : ByteArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun CharArray.copyOf(newSize: Int = size) : CharArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun DoubleArray.copyOf(newSize: Int = size) : DoubleArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun FloatArray.copyOf(newSize: Int = size) : FloatArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun IntArray.copyOf(newSize: Int = size) : IntArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun LongArray.copyOf(newSize: Int = size) : LongArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the riginal array
|
||||
*/
|
||||
public fun ShortArray.copyOf(newSize: Int = size) : ShortArray {
|
||||
return Arrays.copyOf(this, newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun <T> Array<out T>.copyOfRange(from: Int, to: Int) : Array<T> {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun BooleanArray.copyOfRange(from: Int, to: Int) : BooleanArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun ByteArray.copyOfRange(from: Int, to: Int) : ByteArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun CharArray.copyOfRange(from: Int, to: Int) : CharArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun DoubleArray.copyOfRange(from: Int, to: Int) : DoubleArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun FloatArray.copyOfRange(from: Int, to: Int) : FloatArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun IntArray.copyOfRange(from: Int, to: Int) : IntArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun LongArray.copyOfRange(from: Int, to: Int) : LongArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of range of original array
|
||||
*/
|
||||
public fun ShortArray.copyOfRange(from: Int, to: Int) : ShortArray {
|
||||
return Arrays.copyOfRange(this, from, to)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun <T> Array<out T>.fill(element: T) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun BooleanArray.fill(element: Boolean) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun ByteArray.fill(element: Byte) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun CharArray.fill(element: Char) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun DoubleArray.fill(element: Double) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun FloatArray.fill(element: Float) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun IntArray.fill(element: Int) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun LongArray.fill(element: Long) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills original array with the provided value
|
||||
*/
|
||||
public fun ShortArray.fill(element: Short) : Unit {
|
||||
Arrays.fill(this, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements that are instances of specified class
|
||||
*/
|
||||
public fun <T, R: T> Array<out T>.filterIsInstance(klass: Class<R>) : List<R> {
|
||||
return filterIsInstanceTo(ArrayList<R>(), klass)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements that are instances of specified class
|
||||
*/
|
||||
public fun <T, R: T> Iterable<T>.filterIsInstance(klass: Class<R>) : List<R> {
|
||||
return filterIsInstanceTo(ArrayList<R>(), klass)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream containing all elements that are instances of specified class
|
||||
*/
|
||||
public fun <T, R: T> Stream<T>.filterIsInstance(klass: Class<R>) : Stream<T> {
|
||||
return FilteringStream(this, true, { klass.isInstance(it) })
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements that are instances of specified class into the given *collection*
|
||||
*/
|
||||
public fun <T, C: MutableCollection<in R>, R: T> Array<out T>.filterIsInstanceTo(collection: C, klass: Class<R>) : C {
|
||||
for (element in this) if (klass.isInstance(element)) collection.add(element as R)
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements that are instances of specified class into the given *collection*
|
||||
*/
|
||||
public fun <T, C: MutableCollection<in R>, R: T> Iterable<T>.filterIsInstanceTo(collection: C, klass: Class<R>) : C {
|
||||
for (element in this) if (klass.isInstance(element)) collection.add(element as R)
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all elements that are instances of specified class into the given *collection*
|
||||
*/
|
||||
public fun <T, C: MutableCollection<in R>, R: T> Stream<T>.filterIsInstanceTo(collection: C, klass: Class<R>) : C {
|
||||
for (element in this) if (klass.isInstance(element)) collection.add(element as R)
|
||||
return collection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun <T> Array<out T>.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun ByteArray.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun CharArray.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun DoubleArray.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun FloatArray.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun IntArray.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun LongArray.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun ShortArray.sort(fromIndex : Int = 0, toIndex : Int = size - 1) : Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
package kotlin
|
||||
|
||||
//
|
||||
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
|
||||
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
|
||||
//
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Array<out T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun BooleanArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ByteArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun CharArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun DoubleArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun FloatArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun IntArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun LongArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ShortArray.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Iterable<T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Stream<T>.appendString(buffer: Appendable, separator: String = ", ", prefix: String ="", postfix: String = "", limit: Int = -1, truncated: String = "...") : Unit {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
val text = if (element == null) "null" else element.toString()
|
||||
buffer.append(text)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Array<out T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun BooleanArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ByteArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun CharArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun DoubleArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun FloatArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun IntArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun LongArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun ShortArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Iterable<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
|
||||
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
|
||||
* a special *truncated* separator (which defaults to "..."
|
||||
*/
|
||||
public fun <T> Stream<T>.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "...") : String {
|
||||
val buffer = StringBuilder()
|
||||
appendString(buffer, separator, prefix, postfix, limit, truncated)
|
||||
return buffer.toString()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user