aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/model/WithChildren.kt
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/model/WithChildren.kt')
-rw-r--r--core/src/main/kotlin/model/WithChildren.kt7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/src/main/kotlin/model/WithChildren.kt b/core/src/main/kotlin/model/WithChildren.kt
index 4aba51c6..59a14acc 100644
--- a/core/src/main/kotlin/model/WithChildren.kt
+++ b/core/src/main/kotlin/model/WithChildren.kt
@@ -23,6 +23,11 @@ inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfType(): T wher
return withDescendants().filterIsInstance<T>().first()
}
+inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfType(
+ predicate: (T) -> Boolean
+): T where T : WithChildren<*> = withDescendants().filterIsInstance<T>().first(predicate)
+
+
inline fun <reified T> WithChildren<WithChildren<*>>.firstMemberOfTypeOrNull(): T? where T : WithChildren<*> {
return withDescendants().filterIsInstance<T>().firstOrNull()
}
@@ -66,7 +71,7 @@ fun <T> T.dfs(predicate: (T) -> Boolean): T? where T : WithChildren<T> = if (pre
children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
}
-fun <T: WithChildren<T>> T.asPrintableTree(
+fun <T : WithChildren<T>> T.asPrintableTree(
nodeNameBuilder: Appendable.(T) -> Unit = { append(it.toString()) }
): String {
fun Appendable.append(element: T, ownPrefix: String, childPrefix: String) {