com.lightningkite.khrysalis.util.forEachBetween.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-plugin-common Show documentation
Show all versions of kotlin-compiler-plugin-common Show documentation
Common translational tools between Typescript and Swift.
The newest version!
package com.lightningkite.khrysalis.util
import java.util.concurrent.*
inline fun Iterable.forEachBetween(
forItem: (T) -> Unit,
between: () -> Unit
) {
var hasDoneFirst = false
forEach {
if (hasDoneFirst) {
between()
} else {
hasDoneFirst = true
}
forItem(it)
}
}
inline fun Sequence.forEachBetween(
forItem: (T) -> Unit,
between: () -> Unit
) {
var hasDoneFirst = false
forEach {
if (hasDoneFirst) {
between()
} else {
hasDoneFirst = true
}
forItem(it)
}
}
inline fun Iterable.forEachBetweenIndexed(
forItem: (Int, T) -> Unit,
between: () -> Unit
) {
var hasDoneFirst = false
forEachIndexed { index, it ->
if (hasDoneFirst) {
between()
} else {
hasDoneFirst = true
}
forItem(index, it)
}
}
inline fun Sequence.forEachBetweenIndexed(
forItem: (Int, T) -> Unit,
between: () -> Unit
) {
var hasDoneFirst = false
forEachIndexed { index, it ->
if (hasDoneFirst) {
between()
} else {
hasDoneFirst = true
}
forItem(index, it)
}
}
fun Collection.forEachMultithreaded(action: (T)->Unit) {
this.parallelStream().forEach(action)
}
fun Sequence.forEachMultithreaded(action: (T)->Unit) {
// this.asStream().parallel().forEach(action)
this.forEach(action)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy