
org.jetbrains.kotlin.js.translate.utils.utils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.js.translate.utils
fun List.splitToRanges(classifier: (T) -> S): List, S>> {
if (isEmpty()) return emptyList()
var lastIndex = 0
var lastClass: S = classifier(this[0])
val result = mutableListOf, S>>()
for ((index, e) in asSequence().withIndex().drop(1)) {
val cls = classifier(e)
if (cls != lastClass) {
result += Pair(subList(lastIndex, index), lastClass)
lastClass = cls
lastIndex = index
}
}
result += Pair(subList(lastIndex, size), lastClass)
return result
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy