From f4ec905aff72837ff3dbc6756caddf3d3aa657f4 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 16 Jun 2021 01:51:26 +0800 Subject: [PATCH] Make `CombinedStateObserver.toString` more readable --- .../network/handler/state/CombinedStateObserver.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/network/handler/state/CombinedStateObserver.kt b/mirai-core/src/commonMain/kotlin/network/handler/state/CombinedStateObserver.kt index 0587e35bc..6c341be82 100644 --- a/mirai-core/src/commonMain/kotlin/network/handler/state/CombinedStateObserver.kt +++ b/mirai-core/src/commonMain/kotlin/network/handler/state/CombinedStateObserver.kt @@ -49,7 +49,16 @@ internal class CombinedStateObserver( } override fun toString(): String { - return "CombinedStateObserver(first=$first, last=$last)" + return asSequence().joinToString( + prefix = "CombinedStateObserver[", + postfix = "]", + separator = " -> " + ) { it.toString() } + } + + private fun asSequence(): Sequence = sequence { + if (first is CombinedStateObserver) yieldAll(first.asSequence()) else yield(first) + if (last is CombinedStateObserver) yieldAll(last.asSequence()) else yield(last) } companion object {