mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Add isLatest
to nodes returned from the GetDependencies call.
This commit is contained in:
parent
2ebf932d21
commit
50b1ded7bb
10 changed files with 101 additions and 33 deletions
|
@ -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, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue