Skip to content

Commit

Permalink
Merge pull request #202 from robstoll/bc/move-DefaultPeekingIterator
Browse files Browse the repository at this point in the history
move default peeking iterator
  • Loading branch information
robstoll authored Mar 4, 2024
2 parents feb4f70 + 44f7660 commit 799691b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
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

0 comments on commit 799691b

Please sign in to comment.