// NOTE this file is auto-generated from stdlib/ktSrc/JavaIterables.kt package std import java.util.* /** Returns true if any elements in the collection match the given predicate */ inline fun Array.any(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (predicate(elem)) { return true } } return false } /** Returns true if all elements in the collection match the given predicate */ inline fun Array.all(predicate: (T)-> Boolean) : Boolean { for (elem in this) { if (!predicate(elem)) { return false } } return true } /** Returns the first item in the collection which matches the given predicate or null if none matched */ inline fun Array.find(predicate: (T)-> Boolean) : T? { for (elem in this) { if (predicate(elem)) return elem } return null } /** Returns a new collection containing all elements in this collection which match the given predicate */ inline fun Array.filter(result: Collection = ArrayList(), predicate: (T)-> Boolean) : Collection { for (elem in this) { if (predicate(elem)) result.add(elem) } return result } /** Returns a new collection containing all elements in this collection which do not match the given predicate */ inline fun Array.filterNot(result: Collection = ArrayList(), predicate: (T)-> Boolean) : Collection { for (elem in this) { if (!predicate(elem)) result.add(elem) } return result } /** * Returns the result of transforming each item in the collection to a one or more values which * are concatenated together into a single collection */ inline fun Array.flatMap(result: Collection = ArrayList(), transform: (T)-> Collection) : Collection { for (elem in this) { val coll = transform(elem) if (coll != null) { for (r in coll) { result.add(r) } } } return result } /** Performs the given operation on each element inside the collection */ inline fun Array.foreach(operation: (element: T) -> Unit) { for (elem in this) operation(elem) } /** Creates a String from all the elements in the collection, using the seperator between them and using the given prefix and postfix if supplied */ inline fun Array.join(separator: String, prefix: String = "", postfix: String = "") : String { val buffer = StringBuilder(prefix) var first = true for (elem in this) { if (first) first = false else buffer.append(separator) buffer.append(elem) } buffer.append(postfix) return buffer.toString().sure() } inline fun > Array.to(result: C) : C { for (elem in this) result.add(elem) return result } inline fun Array.toLinkedList() : LinkedList = this.to(LinkedList()) inline fun Array.toList() : List = this.to(ArrayList()) inline fun Array.toSet() : Set = this.to(HashSet()) /** TODO figure out necessary variance/generics ninja stuff... :) inline fun Array.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List { val answer = this.toList() answer.sort(transform) return answer } */