Is that the best way to build a map for a type tha...
# getting-started
b
Is that the best way to build a map for a type that only handles length and item(x) :
Copy code
/**
 * Applies the given [transform] to each of the Nodes from the NodeList
 *
 */
inline fun <R> NodeList.map(transform: (Node) -> R): List<R> {
    val array = ArrayList<R>(this.length)
    for (n in 0 until this.length)
        array[n] = transform(this.item(n))
    return array
}
p
I guess you cannot make that
NodeList
implements
Iterable<Node>
. What do you think about idea to implement
asIterable()
extension function:
Copy code
fun NodeList.asIterable(): Iterable<Node> = object : Iterable<Node> { /* ... */ }
So that you can use all functions from std lib (like
map
and
filter
) for your collection?
Copy code
nodeList.asIterable().map { /* ... */ }
b
hmmm NodeList is org.w3c.dom.NodeList