From 0a2a5896ece71f9d37930274c86b09a5fdf38644 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Wed, 5 Aug 2020 15:38:00 +0200 Subject: Add tests checking omitting of obvious types --- core/src/main/kotlin/model/WithChildren.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core/src') 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 WithChildren>.firstMemberOfType(): T wher return withDescendants().filterIsInstance().first() } +inline fun WithChildren>.firstMemberOfType( + predicate: (T) -> Boolean +): T where T : WithChildren<*> = withDescendants().filterIsInstance().first(predicate) + + inline fun WithChildren>.firstMemberOfTypeOrNull(): T? where T : WithChildren<*> { return withDescendants().filterIsInstance().firstOrNull() } @@ -66,7 +71,7 @@ fun T.dfs(predicate: (T) -> Boolean): T? where T : WithChildren = if (pre children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() } -fun > T.asPrintableTree( +fun > T.asPrintableTree( nodeNameBuilder: Appendable.(T) -> Unit = { append(it.toString()) } ): String { fun Appendable.append(element: T, ownPrefix: String, childPrefix: String) { -- cgit