All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.Standard.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
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)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy