diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt index afa76d2a9..f630055fa 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/collections.kt @@ -9,7 +9,7 @@ package space.kscience.kmath.misc * The same as [zipWithNext], but includes link between last and first element */ public inline fun List.zipWithNextCircular(transform: (a: T, b: T) -> R): List { - if (isEmpty()) return emptyList() + if (size < 2) return emptyList() return indices.map { i -> if (i == size - 1) { transform(last(), first()) @@ -19,4 +19,4 @@ public inline fun List.zipWithNextCircular(transform: (a: T, b: T) -> } } -public fun List.zipWithNextCircular(): List> = zipWithNextCircular { l, r -> l to r } \ No newline at end of file +public fun List.zipWithNextCircular(): List> = zipWithNextCircular { l, r -> l to r } \ No newline at end of file