bjonnh
03/08/2019, 8:01 PM/**
* 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
}
Pavlo Liapota
03/08/2019, 8:16 PMNodeList
implements Iterable<Node>
.
What do you think about idea to implement asIterable()
extension function:
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?
nodeList.asIterable().map { /* ... */ }
bjonnh
03/08/2019, 10:45 PM