inline fun <T> Enumeration<T>.asSequence(): Sequence<T> (source)

Platform and version requirements: JVM

Creates a sequence that returns all values from this enumeration. The sequence is constrained to be iterated only once.

import kotlin.test.*
import kotlin.coroutines.experimental.buildIterator
import kotlin.coroutines.experimental.buildSequence

fun main(args: Array<String>) {
val numbers = java.util.Hashtable<String, Int>()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.put("three", 3)

// when you have an Enumeration from some old code
val enumeration: java.util.Enumeration<String> = numbers.keys()

// you can wrap it in a sequence and transform further with sequence operations
val sequence = enumeration.asSequence().sorted()
println(sequence.toList()) // [one, three, two]

// the resulting sequence is one-shot
// sequence.toList() //  will fail