kotlin.Standard.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-stdlib Show documentation
Show all versions of kotlin-stdlib Show documentation
Kotlin Standard Library for JVM
package kotlin
import java.util.ArrayList
import java.util.HashSet
import java.util.LinkedList
/**
Helper to make java.util.Enumeration usable in for
*/
public fun java.util.Enumeration.iterator(): Iterator = object: Iterator {
override fun hasNext(): Boolean = hasMoreElements()
public override fun next() : T = nextElement()
}
/*
* Extension functions on the standard Kotlin types to behave like the java.lang.* and java.util.* collections
*/
/**
Add iterated elements to given container
*/
/*
public fun > Iterator.toCollection(container: U) : U {
while(hasNext())
container.add(next())
return container
}
*/
/**
Add iterated elements to java.util.ArrayList
*/
public fun Iterator.toArrayList() : ArrayList = toCollection(ArrayList())
/**
Add iterated elements to java.util.HashSet
*/
public fun Iterator.toHashSet() : HashSet = toCollection(HashSet())
/**
* Creates a tuple of type [[Pair]] from this and *that* which can be useful for creating [[Map]] literals
* with less noise, for example
* @includeFunctionBody ../../test/MapTest.kt createUsingTo
*/
public fun A.to(that: B): Pair = Pair(this, that)
/**
Run function f
*/
public inline fun run(f: () -> T) : T = f()
/**
* Execute f with given receiver
*/
public inline fun with(receiver: T, f: T.() -> R) : R = receiver.f()
/**
* Converts receiver to body parameter
*/
public inline fun T.let(f: (T) -> R): R = f(this)