1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Add isLatest to nodes returned from the GetDependencies call.

This commit is contained in:
Cedric Beust 2017-02-01 20:47:00 -08:00
parent 2ebf932d21
commit 50b1ded7bb
10 changed files with 101 additions and 33 deletions

View file

@ -0,0 +1,35 @@
package com.beust.kobalt.internal
/**
* Generic operations on graph-like structures.
*/
object GraphUtil {
/**
* Apply the operation in `closure` to all the nodes in the tree.
*/
fun <T> map(roots: List<T>, children: (T) -> List<T>, closure: (T) -> Unit) {
roots.forEach {
closure(it)
map(children(it), children, closure)
}
}
/**
* Display each node in the roots by calling the `display` function on each of them.
*/
fun <T> displayGraph(roots: List<T>,
children: (T) -> List<T>,
display: (node: T, indent: String) -> Unit) {
fun pd(node: T, indent: String) {
display(node, indent)
children(node).forEach {
pd(it, indent + " ")
}
}
roots.forEach {
pd(it, "")
}
}
}