diff --git a/fleet/util/core/src/fleet/util/CollectionsUtil.kt b/fleet/util/core/src/fleet/util/CollectionsUtil.kt index 86236b523631..d34b40f4bedb 100644 --- a/fleet/util/core/src/fleet/util/CollectionsUtil.kt +++ b/fleet/util/core/src/fleet/util/CollectionsUtil.kt @@ -3,7 +3,6 @@ package fleet.util import fleet.util.logging.KLogger import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.transformWhile @@ -31,6 +30,9 @@ fun Iterable.associateByUnique(keySelector: (T) -> K): Map = } } +/** + * Same idea as [kotlin.collections.singleOrNull] but will throw if the collection contains more than one element. + * */ inline fun Iterable.singleOrNullOrThrow(p: (T) -> Boolean = { true }): T? { var single: T? = null var found = false