Given a tree like structure, and an operation to fetch the children of a node, e.g:
typealias NodeReference = URL
data class Node(
val data:Data,
val childrenList:List<NodeReference>)
suspend fun resolve(nodeRef:NodeReference) : Node
Do you know a blueprint to implement a crawler function having the signature
fun nodeList(rootNode:NodeReference) : List<Node> =
runBlocking(...) {
...
}
returning all nodes of the tree using Kotlin coroutines?
To solve this problem efficiently, you should:
rootRef: NodeReference
to get arootNode: Node
nodeList
method for allchildren
of therootNode
rootNode
to themHere is how you can do it:
If you want to use the current thread to execute
nodesList
, you can do it as follows: