Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move default peeking iterator #202

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ tasks.withType<JavaCompile> {
}
tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
with(freeCompilerArgs) {
add("-opt-in=kotlin.RequiresOptIn")
add("-Xexpect-actual-classes")
}
}
}

detekt {
allRules = true
config = files("${rootProject.projectDir}/gradle/scripts/detekt.yml")
config.from(files("${rootProject.projectDir}/gradle/scripts/detekt.yml"))
}

val detektTasks = tasks.withType<io.gitlab.arturbosch.detekt.Detekt>()
Expand Down
16 changes: 9 additions & 7 deletions src/commonMain/kotlin/ch/tutteli/kbox/PeekingIterator.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.tutteli.kbox

import ch.tutteli.kbox.impl.DefaultPeekingIterator

/**
* An [Iterator] which provides the [peek] function in addition.
*/
Expand All @@ -14,16 +16,16 @@ interface PeekingIterator<out T : Any> : Iterator<T> {
/**
* Necessary so that extension methods can extend it.
*/
companion object
companion object {
/**
* Platform independent method which creates a [PeekingIterator] based on a given [itr].
*/
operator fun <T : Any> invoke(itr: Iterator<T>): PeekingIterator<T> = DefaultPeekingIterator(itr)
}
}

/**
* Platform independent method which creates a [PeekingIterator] based on a given [itr].
*/
fun <T : Any> PeekingIterator.Companion.create(itr: Iterator<T>): PeekingIterator<T> = DefaultPeekingIterator(itr)

/**
* Wraps this [Iterator] into a [PeekingIterator] and returns it.
* @return The newly created [PeekingIterator].
*/
fun <T : Any> Iterator<T>.toPeekingIterator() = PeekingIterator.create(this)
fun <T : Any> Iterator<T>.toPeekingIterator() = PeekingIterator(this)
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package ch.tutteli.kbox
package ch.tutteli.kbox.impl

import ch.tutteli.kbox.JvmSynchronized
import ch.tutteli.kbox.PeekingIterator

/**
* An [Iterator] which provides the [peek] function in addition.
Expand Down