diff --git a/arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/ank.kt b/arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/ank.kt index 15a4bf5ab7d..919ccbfda4c 100644 --- a/arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/ank.kt +++ b/arrow-libs/ank/arrow-ank/src/main/kotlin/arrow/ank/ank.kt @@ -2,10 +2,7 @@ package arrow.ank import arrow.core.Validated import arrow.core.ValidatedNel -import arrow.core.invalidNel import arrow.core.sequenceValidated -import arrow.core.validNel -import arrow.fx.coroutines.nonFatalOrThrow import java.nio.file.Path import kotlin.math.ln import kotlin.math.pow @@ -21,13 +18,6 @@ fun Long.humanBytes(): String { return String.format("%.1f %sB", this / unit.toDouble().pow(exp.toDouble()), pre) } -suspend fun Validated.Companion.catchNel(f: suspend () -> A): ValidatedNel = - try { - f().validNel() - } catch (e: Throwable) { - e.nonFatalOrThrow().invalidNel() - } - suspend fun ank(source: Path, target: Path, compilerArgs: List, ankOps: AnkOps): Unit = with(ankOps) { printConsole(colored(ANSI_PURPLE, AnkHeader)) val heapSize = Runtime.getRuntime().totalMemory() diff --git a/arrow-libs/ank/gradle.properties b/arrow-libs/ank/gradle.properties index 684eaed7476..6c21d28a87b 100644 --- a/arrow-libs/ank/gradle.properties +++ b/arrow-libs/ank/gradle.properties @@ -9,4 +9,6 @@ kotlin.incremental=true # Kotlin Test configuration #Parallelism needs to be set to 1 since the concurrent tests in arrow-effects become flaky otherwise kotlintest.parallelism=1 -kotlin.stdlib.default.dependency=false + +# Reason: https://youtrack.jetbrains.com/issue/KT-46847 +# kotlin.stdlib.default.dependency=false diff --git a/arrow-libs/core/arrow-annotations/build.gradle b/arrow-libs/core/arrow-annotations/build.gradle index a74fe9fa2a0..970b563a566 100644 --- a/arrow-libs/core/arrow-annotations/build.gradle +++ b/arrow-libs/core/arrow-annotations/build.gradle @@ -6,14 +6,13 @@ plugins { apply from: "$SUB_PROJECT_MPP" apply from: "$DOC_CREATION" apply from: "$PUBLICATION_MPP" -apply from: "$ANIMALSNIFFER" +apply from: "$ANIMALSNIFFER_MPP" kotlin { sourceSets { - jvmMain { + commonMain { dependencies { - compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" - api "io.kindedj:kindedj:$KINDEDJ_VERSION" + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" } } } diff --git a/arrow-libs/core/arrow-annotations/src/jvmMain/java/arrow/extension.kt b/arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/extension.kt similarity index 100% rename from arrow-libs/core/arrow-annotations/src/jvmMain/java/arrow/extension.kt rename to arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/extension.kt diff --git a/arrow-libs/core/arrow-annotations/src/jvmMain/java/arrow/optics.kt b/arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/optics.kt similarity index 100% rename from arrow-libs/core/arrow-annotations/src/jvmMain/java/arrow/optics.kt rename to arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/optics.kt diff --git a/arrow-libs/core/arrow-annotations/src/jvmMain/java/arrow/synthetic.kt b/arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/synthetic.kt similarity index 100% rename from arrow-libs/core/arrow-annotations/src/jvmMain/java/arrow/synthetic.kt rename to arrow-libs/core/arrow-annotations/src/commonMain/kotlin/arrow/synthetic.kt diff --git a/arrow-libs/core/arrow-continuations/build.gradle b/arrow-libs/core/arrow-continuations/build.gradle index bfb800dedc3..8758bc34bac 100644 --- a/arrow-libs/core/arrow-continuations/build.gradle +++ b/arrow-libs/core/arrow-continuations/build.gradle @@ -7,11 +7,16 @@ apply from: "$SUB_PROJECT_MPP" apply from: "$TEST_COVERAGE" apply from: "$DOC_CREATION" apply from: "$PUBLICATION_MPP" -apply from: "$ANIMALSNIFFER" +apply from: "$ANIMALSNIFFER_MPP" apply plugin: 'kotlinx-atomicfu' kotlin { sourceSets { + commonMain { + dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" + } + } jvmMain { dependencies { compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/Effect.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Effect.kt similarity index 100% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/Effect.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Effect.kt diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/Reset.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt similarity index 100% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/Reset.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ControlThrowable.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ControlThrowable.kt new file mode 100644 index 00000000000..97365dc14d2 --- /dev/null +++ b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ControlThrowable.kt @@ -0,0 +1,9 @@ +package arrow.continuations.generic + +/** + * A [Throwable] class intended for control flow. + * Instance of [ControlThrowable] should **not** be caught, + * and `arrow.core.NonFatal` does not catch this [Throwable]. + * Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable]. + */ +expect open class ControlThrowable() : Throwable diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/DelimContScope.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimContScope.kt similarity index 98% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/DelimContScope.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimContScope.kt index 776bb2f4f63..76a445c456e 100644 --- a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/DelimContScope.kt +++ b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimContScope.kt @@ -65,7 +65,7 @@ internal open class DelimContScope(private val f: suspend RestrictedScope. override suspend fun shift(f: suspend RestrictedScope.(DelimitedContinuation) -> R): A = suspendCoroutineUninterceptedOrReturn { continueMain -> val delCont = SingleShotCont(continueMain, shiftFnContinuations) - assert(nextShift == null) + require(nextShift == null) nextShift = suspend { this.f(delCont) } COROUTINE_SUSPENDED } @@ -75,7 +75,7 @@ internal open class DelimContScope(private val f: suspend RestrictedScope. */ suspend fun shiftCPS(f: suspend (DelimitedContinuation) -> R, c: suspend DelimitedScope.(A) -> B): Nothing = suspendCoroutineUninterceptedOrReturn { - assert(nextShift == null) + require(nextShift == null) nextShift = suspend { f(CPSCont(c)) } COROUTINE_SUSPENDED } @@ -116,7 +116,7 @@ internal open class DelimContScope(private val f: suspend RestrictedScope. // we can return directly if we never suspended/called shift else return@invoke it as R } - assert(resultVar !== EMPTY_VALUE) + require(resultVar !== EMPTY_VALUE) // We need to finish the partially evaluated shift blocks by passing them our result. // This will update the result via the continuations that now finish up for (c in shiftFnContinuations.asReversed()) c.resume(resultVar as R) diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/DelimitedCont.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimitedCont.kt similarity index 100% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/DelimitedCont.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimitedCont.kt diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt similarity index 97% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt index 92d509d2850..147d3ad1308 100644 --- a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt +++ b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt @@ -77,14 +77,14 @@ internal open class MultiShotDelimContScope(val f: suspend RestrictedScope suspendCoroutineUninterceptedOrReturn { continueMain -> val c = MultiShotCont(continueMain, f, stack, shiftFnContinuations) val s: suspend RestrictedScope.() -> R = { this.func(c) } - assert(nextShift.compareAndSet(null, s)) + require(nextShift.compareAndSet(null, s)) COROUTINE_SUSPENDED } suspend fun shiftCPS(func: suspend DelimitedScope.(DelimitedContinuation) -> R, c: suspend DelimitedScope.(A) -> B): Nothing = suspendCoroutine { val s: suspend DelimitedScope.() -> R = { func(CPSCont(c)) } - assert(nextShift.compareAndSet(null, s)) + require(nextShift.compareAndSet(null, s)) } // This assumes RestrictSuspension or at least assumes the user to never reference the parent scope in f. @@ -115,7 +115,7 @@ internal open class MultiShotDelimContScope(val f: suspend RestrictedScope } } else return@invoke it as R } - assert(resultVar.value != null) + require(resultVar.value != null) for (c in shiftFnContinuations.asReversed()) c.resume(resultVar.value!!) return resultVar.value!! } diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ShortCircuit.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ShortCircuit.kt similarity index 100% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ShortCircuit.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ShortCircuit.kt diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt similarity index 100% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/Token.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt similarity index 52% rename from arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/Token.kt rename to arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt index b39af7d3475..84087b2d59c 100644 --- a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/Token.kt +++ b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt @@ -2,5 +2,6 @@ package arrow.continuations.generic /** Represents a unique identifier using object equality. */ internal class Token { - override fun toString(): String = "Token(${Integer.toHexString(hashCode())})" + @ExperimentalUnsignedTypes + override fun toString(): String = "Token(${hashCode().toUInt().toString(16)})" } diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ControlThrowable.kt b/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ControlThrowable.kt index 0f327b8f1eb..831f1dfdda8 100644 --- a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ControlThrowable.kt +++ b/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ControlThrowable.kt @@ -1,11 +1,12 @@ + package arrow.continuations.generic /** * A [Throwable] class intended for control flow. - * Instance of [ControlThrowable] should **not** be caught, + * Instance of [ControlThrowable.kt] should **not** be caught, * and `arrow.core.NonFatal` does not catch this [Throwable]. - * Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable]. + * Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable.kt]. */ -open class ControlThrowable : Throwable() { +actual open class ControlThrowable : Throwable() { override fun fillInStackTrace(): Throwable = this } diff --git a/arrow-libs/core/arrow-core-retrofit/build.gradle b/arrow-libs/core/arrow-core-retrofit/build.gradle index 24b299e3c31..f7902c76e28 100644 --- a/arrow-libs/core/arrow-core-retrofit/build.gradle +++ b/arrow-libs/core/arrow-core-retrofit/build.gradle @@ -1,32 +1,21 @@ plugins { - id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.jvm" id "org.jlleitschuh.gradle.ktlint" } -apply from: "$SUB_PROJECT_MPP" +apply from: "$SUB_PROJECT" apply from: "$TEST_COVERAGE" apply from: "$DOC_CREATION" -apply from: "$PUBLICATION_MPP" +apply from: "$PUBLICATION" apply from: "$ANIMALSNIFFER" -kotlin { - sourceSets { - jvmMain { - dependencies { - compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" - compileOnly project(":arrow-core") - compileOnly "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION" - } - } - - jvmTest { - dependencies { - compileOnly "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION" - runtimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION" - implementation project(":arrow-core-test") - implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION" - implementation "com.squareup.okhttp3:mockwebserver:$MOCKWEBSERVER_VERSION" - } - } - } +dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" + compileOnly project(":arrow-core") + compileOnly "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION" + testCompileOnly "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION" + testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION" + testImplementation project(":arrow-core-test") + testImplementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION" + testImplementation "com.squareup.okhttp3:mockwebserver:$MOCKWEBSERVER_VERSION" } diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapter.kt b/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapter.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapter.kt rename to arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapter.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/ArrowResponseECallAdapter.kt b/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/ArrowResponseECallAdapter.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/ArrowResponseECallAdapter.kt rename to arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/ArrowResponseECallAdapter.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt b/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt rename to arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/ResponseE.kt b/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/ResponseE.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/ResponseE.kt rename to arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/ResponseE.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/eitherAdapter.kt b/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/eitherAdapter.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmMain/kotlin/arrow/retrofit/adapter/either/eitherAdapter.kt rename to arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/eitherAdapter.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt rename to arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt rename to arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/mock/ErrorMock.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/mock/ErrorMock.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/mock/ErrorMock.kt rename to arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/mock/ErrorMock.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/mock/ResponseMock.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/mock/ResponseMock.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/mock/ResponseMock.kt rename to arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/mock/ResponseMock.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/retrofit/SuspedApiClientTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspedApiClientTest.kt similarity index 100% rename from arrow-libs/core/arrow-core-retrofit/src/jvmTest/kotlin/arrow/retrofit/adapter/retrofit/SuspedApiClientTest.kt rename to arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspedApiClientTest.kt diff --git a/arrow-libs/core/arrow-core-test/build.gradle b/arrow-libs/core/arrow-core-test/build.gradle index e6fd8acdbaf..71a6ccae3fc 100644 --- a/arrow-libs/core/arrow-core-test/build.gradle +++ b/arrow-libs/core/arrow-core-test/build.gradle @@ -8,6 +8,7 @@ apply from: "$PUBLICATION" apply from: "$ANIMALSNIFFER" dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" api project(":arrow-core") api project(":arrow-continuations") api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION" diff --git a/arrow-libs/core/arrow-core/build.gradle b/arrow-libs/core/arrow-core/build.gradle index a72465c78ff..a3ab0cbbb61 100644 --- a/arrow-libs/core/arrow-core/build.gradle +++ b/arrow-libs/core/arrow-core/build.gradle @@ -9,18 +9,22 @@ apply from: "$SUB_PROJECT_MPP" apply from: "$TEST_COVERAGE" apply from: "$DOC_CREATION" apply from: "$PUBLICATION_MPP" -apply from: "$ANIMALSNIFFER" +apply from: "$ANIMALSNIFFER_MPP" kotlin { sourceSets { - jvmMain { + commonMain { dependencies { - compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" - compileOnly "org.codehaus.mojo:animal-sniffer-annotations:1.19" + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" api project(":arrow-continuations") api project(":arrow-annotations") } } + jvmMain { + dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" + } + } jvmTest { dependencies { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/ArrowCoreInternalException.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/ArrowCoreInternalException.kt new file mode 100644 index 00000000000..36fb0dd9ac7 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/ArrowCoreInternalException.kt @@ -0,0 +1,4 @@ +package arrow.core + +@PublishedApi +internal expect object ArrowCoreInternalException : RuntimeException diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Comparison.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Comparison.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Comparison.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Comparison.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Const.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Const.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Const.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Const.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Either.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 0845b36b11b..011dff0434f 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -5,6 +5,8 @@ import arrow.core.Either.Left import arrow.core.Either.Right import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup +import kotlin.jvm.JvmName +import kotlin.jvm.JvmStatic /** * diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Endo.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Endo.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Endo.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Endo.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Eval.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Eval.kt similarity index 92% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Eval.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Eval.kt index 1e525710470..49787919b76 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Eval.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Eval.kt @@ -1,7 +1,7 @@ package arrow.core import arrow.typeclasses.Monoid -import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement +import kotlin.jvm.JvmStatic /** * Eval is a monad which controls evaluation of a value or a computation that produces a value. @@ -233,7 +233,7 @@ sealed class Eval { is FlatMap -> object : FlatMap() { override fun start(): Eval = (this@Eval).start() - @IgnoreJRERequirement + // @IgnoreJRERequirement override fun run(s: S): Eval = object : FlatMap() { override fun start(): Eval = (this@Eval).run(s) as Eval @@ -381,7 +381,17 @@ fun Eval.zip( c: Eval, map: (A, B, C) -> D ): Eval = - zip(b, c, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, _, _, _, _, _, _, _ -> map(aa, bb, cc) } + zip( + b, + c, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit + ) { aa, bb, cc, _, _, _, _, _, _, _ -> map(aa, bb, cc) } fun Eval.zip( b: Eval, @@ -389,7 +399,17 @@ fun Eval.zip( d: Eval, map: (A, B, C, D) -> E ): Eval = - zip(b, c, d, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, _, _, _, _, _, _ -> map(aa, bb, cc, dd) } + zip( + b, + c, + d, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit, + Eval.Now.unit + ) { aa, bb, cc, dd, _, _, _, _, _, _ -> map(aa, bb, cc, dd) } fun Eval.zip( b: Eval, @@ -398,7 +418,15 @@ fun Eval.zip( e: Eval, map: (A, B, C, D, E) -> F ): Eval = - zip(b, c, d, e, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, _, _, _, _, _ -> map(aa, bb, cc, dd, ee) } + zip(b, c, d, e, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, _, _, _, _, _ -> + map( + aa, + bb, + cc, + dd, + ee + ) + } fun Eval.zip( b: Eval, @@ -408,7 +436,16 @@ fun Eval.zip( f: Eval, map: (A, B, C, D, E, F) -> G ): Eval = - zip(b, c, d, e, f, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, _, _, _, _ -> map(aa, bb, cc, dd, ee, ff) } + zip(b, c, d, e, f, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, _, _, _, _ -> + map( + aa, + bb, + cc, + dd, + ee, + ff + ) + } fun Eval.zip( b: Eval, @@ -419,7 +456,17 @@ fun Eval.zip( g: Eval, map: (A, B, C, D, E, F, G) -> H ): Eval = - zip(b, c, d, e, f, g, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, _, _, _ -> map(aa, bb, cc, dd, ee, ff, gg) } + zip(b, c, d, e, f, g, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, _, _, _ -> + map( + aa, + bb, + cc, + dd, + ee, + ff, + gg + ) + } fun Eval.zip( b: Eval, @@ -431,7 +478,18 @@ fun Eval.zip( h: Eval, map: (A, B, C, D, E, F, G, H) -> I ): Eval = - zip(b, c, d, e, f, g, h, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, _, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh) } + zip(b, c, d, e, f, g, h, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, _, _ -> + map( + aa, + bb, + cc, + dd, + ee, + ff, + gg, + hh + ) + } fun Eval.zip( b: Eval, @@ -444,7 +502,19 @@ fun Eval.zip( i: Eval, map: (A, B, C, D, E, F, G, H, I) -> J ): Eval = - zip(b, c, d, e, f, g, h, i, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, ii, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh, ii) } + zip(b, c, d, e, f, g, h, i, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, ii, _ -> + map( + aa, + bb, + cc, + dd, + ee, + ff, + gg, + hh, + ii + ) + } fun Eval.zip( b: Eval, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Ior.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt index abd48600b19..4d6ac1cc4c7 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt @@ -5,6 +5,7 @@ import arrow.core.Ior.Left import arrow.core.Ior.Right import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup +import kotlin.jvm.JvmStatic typealias IorNel = Ior, B> diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Iterable.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt similarity index 98% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonEmptyList.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index 88b77dafdab..0ad8e48729f 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -3,6 +3,7 @@ package arrow.core import arrow.core.Either.Left import arrow.core.Either.Right import arrow.typeclasses.Semigroup +import kotlin.jvm.JvmStatic typealias Nel = NonEmptyList @@ -201,13 +202,12 @@ class NonEmptyList( override fun equals(other: Any?): Boolean { if (this === other) return true - if (other?.javaClass != javaClass) return false - - other as NonEmptyList<*> - - if (all != other.all) return false - - return true + other?.let { + if (it::class != this::class) return false + (other as NonEmptyList<*>) + if (all != other.all) return false + return true + } ?: return false } override fun hashCode(): Int = diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonFatal.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonFatal.kt new file mode 100644 index 00000000000..ceca519510e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonFatal.kt @@ -0,0 +1,45 @@ +package arrow.core + +import kotlin.coroutines.cancellation.CancellationException + +/** + * Extractor of non-fatal Throwable. Will not match fatal errors like `VirtualMachineError` + * (for example, `OutOfMemoryError` and `StackOverflowError`, subclasses of `VirtualMachineError`), `ThreadDeath`, + * `LinkageError`, `InterruptedException`. + * This will also not match [CancellationException] since that's a fatal exception in Kotlin for cancellation purposes. + * + * Checks whether the passed [t] Throwable is NonFatal. + * + * @param t the Throwable to check + * @return true if the provided `Throwable` is to be considered non-fatal, or false if it is to be considered fatal + * + * ```kotlin:ank:playground + * import arrow.* + * import arrow.core.* + * + * fun unsafeFunction(i: Int): String = + * when (i) { + * 1 -> throw IllegalArgumentException("Non-Fatal") + * 2 -> throw OutOfMemoryError("Fatal") + * else -> "Hello" + * } + * + * fun main(args: Array) { + * val nonFatal: Either = + * //sampleStart + * try { + * Right(unsafeFunction(1)) + * } catch (t: Throwable) { + * if (NonFatal(t)) { + * Left(t) + * } else { + * throw t + * } + * } + * //sampleEnd + * println(nonFatal) + * } + * ``` + * + */ +expect fun NonFatal(t: Throwable): Boolean diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Nullable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Nullable.kt similarity index 98% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Nullable.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Nullable.kt index 79c440b606a..36949b58dc7 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Nullable.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Nullable.kt @@ -2,6 +2,8 @@ package arrow.core +import kotlin.jvm.JvmStatic + object Nullable { @JvmStatic diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Option.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 2c375ec3f93..4194b050f84 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -3,6 +3,8 @@ package arrow.core import arrow.core.Either.Right import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup +import kotlin.jvm.JvmName +import kotlin.jvm.JvmStatic /** * diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Pair.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Pair.kt similarity index 89% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Pair.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Pair.kt index 4c9553d1567..112a7fb24c5 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Pair.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Pair.kt @@ -4,6 +4,8 @@ package arrow.core import arrow.typeclasses.Semigroup +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName operator fun , B : Comparable> Pair.compareTo(other: Pair): Int { val first = first.compareTo(other.first) diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Sequence.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Sequence.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Triple.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Triple.kt similarity index 86% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Triple.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Triple.kt index c4fe1597ca5..453c155c2fb 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Triple.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Triple.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + operator fun , B : Comparable, C : Comparable> Triple.compareTo(other: Triple): Int { val first = first.compareTo(other.first) return if (first == 0) { diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple10.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple10.kt similarity index 96% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple10.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple10.kt index d56a4452da5..00439be4d08 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple10.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple10.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple10( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple4.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple4.kt similarity index 92% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple4.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple4.kt index 608f03f49dc..6690ff449bd 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple4.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple4.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple4( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple5.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple5.kt similarity index 93% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple5.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple5.kt index fbe70fc1cd8..4c3784daee7 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple5.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple5.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple5( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple6.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple6.kt similarity index 94% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple6.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple6.kt index 67ad381f913..e743a41918a 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple6.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple6.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple6( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple7.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple7.kt similarity index 95% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple7.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple7.kt index 93d27dd3c4c..00fb2026aeb 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple7.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple7.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple7( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple8.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple8.kt similarity index 95% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple8.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple8.kt index 3200fb89a4b..40a0d58459b 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple8.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple8.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple8( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple9.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple9.kt similarity index 96% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple9.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple9.kt index 0f9ffe5eb6e..e019753b028 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Tuple9.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple9.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple9( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/TupleN.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/TupleN.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt index 419f98686ce..6b6d1902cc5 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/TupleN.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt @@ -3,6 +3,9 @@ package arrow.core +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + data class Tuple11( val first: A, val second: B, diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Validated.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Validated.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt index 2fe2936a3bf..7b363291ebe 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/Validated.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt @@ -4,6 +4,8 @@ import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup import arrow.core.Either.Left import arrow.core.Either.Right +import kotlin.jvm.JvmName +import kotlin.jvm.JvmStatic typealias ValidatedNel = Validated, A> typealias Valid = Validated.Valid diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/composition.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/composition.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/composition.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/composition.kt index ef3e33415e2..737efba5db8 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/composition.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/composition.kt @@ -1,6 +1,8 @@ @file:JvmName("Composition") package arrow.core +import kotlin.jvm.JvmName + infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R = AndThen2(this).andThen(f) diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/either.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/eval.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/eval.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/eval.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/eval.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/nullable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/nullable.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/nullable.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/nullable.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/option.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/computations/option.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/option.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/currying.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/currying.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/currying.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/currying.kt index a80e17071a3..936dfdeac08 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/currying.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/currying.kt @@ -1,6 +1,8 @@ @file:JvmName("Currying") package arrow.core +import kotlin.jvm.JvmName + fun ((P1, P2) -> R).curried(): (P1) -> (P2) -> R = { p1: P1 -> { p2: P2 -> this(p1, p2) } } diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/map.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/map.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/memoization.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/memoization.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt index d04d660445b..430e52c8053 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/memoization.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt @@ -3,6 +3,7 @@ package arrow.core import kotlinx.atomicfu.atomic import kotlinx.atomicfu.loop +import kotlin.jvm.JvmName /** * Memoizes the given **pure** function so that invocations with the same arguments will only execute the function once. diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/nonFatalOrThrow.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/nonFatalOrThrow.kt new file mode 100644 index 00000000000..c23d968d325 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/nonFatalOrThrow.kt @@ -0,0 +1,36 @@ +package arrow.core + +/** + * Returns the Throwable if NonFatal and throws it otherwise. + * + * @throws Throwable the Throwable `this` if Fatal + * @return the Throwable `this` if NonFatal + * + * ```kotlin:ank:playground + * import arrow.* + * import arrow.core.* + * + * fun unsafeFunction(i: Int): String = + * when (i) { + * 1 -> throw IllegalArgumentException("Non-Fatal") + * 2 -> throw OutOfMemoryError("Fatal") + * else -> "Hello" + * } + * + * fun main(args: Array) { + * val nonFatal: Either = + * //sampleStart + * try { + * Right(unsafeFunction(1)) + * } catch (t: Throwable) { + * Left(t.nonFatalOrThrow()) + * } + * //sampleEnd + * println(nonFatal) + * } + * ``` + * + */ +// https://youtrack.jetbrains.com/issue/KT-36036 +fun Throwable.nonFatalOrThrow(): Throwable = + if (NonFatal(this)) this else throw this diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/partials.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/partials.kt similarity index 98% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/partials.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/partials.kt index d42fe9fbfba..2d22a7ded2b 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/partials.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/partials.kt @@ -1,6 +1,8 @@ @file:JvmName("Partials") package arrow.core +import kotlin.jvm.JvmName + fun ((P1) -> R).partially1(p1: P1): () -> R = { this(p1) } diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/predef.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt similarity index 81% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/predef.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt index 6d60d251b9c..d4f0783a9f1 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/predef.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt @@ -4,14 +4,6 @@ import arrow.typeclasses.Semigroup inline fun identity(a: A): A = a -@PublishedApi -internal object ArrowCoreInternalException : RuntimeException( - "Arrow-Core internal error. Please let us know and create a ticket at https://github.com/arrow-kt/arrow-core/issues/new/choose", - null -) { - override fun fillInStackTrace(): Throwable = this -} - const val TailRecMDeprecation: String = "tailRecM is deprecated together with the Kind type classes since it's meant for writing kind-based polymorphic stack-safe programs." diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/string.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/string.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/string.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/string.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/utils.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/utils.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/utils.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/utils.kt diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Monoid.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt similarity index 99% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Monoid.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt index fda4f23be1b..218d1cfcf95 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Monoid.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt @@ -11,6 +11,8 @@ import arrow.core.combineAll import arrow.core.compose import arrow.core.flatten import arrow.core.identity +import kotlin.jvm.JvmName +import kotlin.jvm.JvmStatic import kotlin.collections.plus as _plus interface Monoid : Semigroup { diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Semigroup.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt similarity index 98% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Semigroup.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt index c1261d1de19..06c16fd17f0 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Semigroup.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt @@ -9,6 +9,8 @@ import arrow.core.Option import arrow.core.Validated import arrow.core.combine import arrow.core.compose +import kotlin.jvm.JvmName +import kotlin.jvm.JvmStatic interface Semigroup { /** diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Semiring.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semiring.kt similarity index 98% rename from arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Semiring.kt rename to arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semiring.kt index 0f8414e2b0a..eba85d0bc09 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/typeclasses/Semiring.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semiring.kt @@ -1,5 +1,8 @@ package arrow.typeclasses +import kotlin.jvm.JvmName +import kotlin.jvm.JvmStatic + /** * The [Semiring] type class for a given type `A` combines both a commutative additive [Monoid] and a multiplicative [Monoid]. * It requires the multiplicative [Monoid] to distribute over the additive one. The operations of the multiplicative [Monoid] have been renamed to diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/ArrowCoreInternalException.kt b/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/ArrowCoreInternalException.kt new file mode 100644 index 00000000000..3906cc5bc75 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/ArrowCoreInternalException.kt @@ -0,0 +1,9 @@ +package arrow.core + +@PublishedApi +internal actual object ArrowCoreInternalException : RuntimeException( + "Arrow-Core internal error. Please let us know and create a ticket at https://github.com/arrow-kt/arrow-core/issues/new/choose", + null +) { + override fun fillInStackTrace(): Throwable = this +} diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonFatal.kt b/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonFatal.kt index e54a87790ae..c6c4cbe1e34 100644 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonFatal.kt +++ b/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/NonFatal.kt @@ -1,84 +1,12 @@ +@file:JvmMultifileClass +@file:JvmName("NonFatalKt") package arrow.core import arrow.continuations.generic.ControlThrowable import kotlin.coroutines.cancellation.CancellationException -/** - * Extractor of non-fatal Throwable. Will not match fatal errors like `VirtualMachineError` - * (for example, `OutOfMemoryError` and `StackOverflowError`, subclasses of `VirtualMachineError`), `ThreadDeath`, - * `LinkageError`, `InterruptedException`. - * This will also not match [CancellationException] since that's a fatal exception in Kotlin for cancellation purposes. - * - * Checks whether the passed [t] Throwable is NonFatal. - * - * @param t the Throwable to check - * @return true if the provided `Throwable` is to be considered non-fatal, or false if it is to be considered fatal - * - * ```kotlin:ank:playground - * import arrow.* - * import arrow.core.* - * - * fun unsafeFunction(i: Int): String = - * when (i) { - * 1 -> throw IllegalArgumentException("Non-Fatal") - * 2 -> throw OutOfMemoryError("Fatal") - * else -> "Hello" - * } - * - * fun main(args: Array) { - * val nonFatal: Either = - * //sampleStart - * try { - * Right(unsafeFunction(1)) - * } catch (t: Throwable) { - * if (NonFatal(t)) { - * Left(t) - * } else { - * throw t - * } - * } - * //sampleEnd - * println(nonFatal) - * } - * ``` - * - */ -fun NonFatal(t: Throwable): Boolean = +actual fun NonFatal(t: Throwable): Boolean = when (t) { is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError, is ControlThrowable, is CancellationException -> false else -> true } - -/** - * Returns the Throwable if NonFatal and throws it otherwise. - * - * @throws Throwable the Throwable `this` if Fatal - * @return the Throwable `this` if NonFatal - * - * ```kotlin:ank:playground - * import arrow.* - * import arrow.core.* - * - * fun unsafeFunction(i: Int): String = - * when (i) { - * 1 -> throw IllegalArgumentException("Non-Fatal") - * 2 -> throw OutOfMemoryError("Fatal") - * else -> "Hello" - * } - * - * fun main(args: Array) { - * val nonFatal: Either = - * //sampleStart - * try { - * Right(unsafeFunction(1)) - * } catch (t: Throwable) { -* Left(t.nonFatalOrThrow()) - * } - * //sampleEnd - * println(nonFatal) - * } - * ``` - * - */ -fun Throwable.nonFatalOrThrow(): Throwable = - if (NonFatal(this)) this else throw this diff --git a/arrow-libs/core/gradle.properties b/arrow-libs/core/gradle.properties index c3af4228b06..5ed6b2dc4f6 100644 --- a/arrow-libs/core/gradle.properties +++ b/arrow-libs/core/gradle.properties @@ -10,4 +10,6 @@ kotlin.incremental=true #Parallelism needs to be set to 1 since the concurrent tests in arrow-effects become flaky otherwise kotlintest.parallelism=1 kapt.incremental.apt=false -kotlin.stdlib.default.dependency=false + +# Reason: https://youtrack.jetbrains.com/issue/KT-46847 +# kotlin.stdlib.default.dependency=false diff --git a/arrow-libs/fx/arrow-fx-coroutines-test/build.gradle b/arrow-libs/fx/arrow-fx-coroutines-test/build.gradle index df8f2126bca..e841222eccc 100644 --- a/arrow-libs/fx/arrow-fx-coroutines-test/build.gradle +++ b/arrow-libs/fx/arrow-fx-coroutines-test/build.gradle @@ -11,6 +11,7 @@ apply from: "$PUBLICATION" apply from: "$ANIMALSNIFFER" dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" api project(":arrow-core") api project(":arrow-fx-coroutines") diff --git a/arrow-libs/fx/arrow-fx-coroutines/build.gradle b/arrow-libs/fx/arrow-fx-coroutines/build.gradle index 0b61cacee9d..3ae0e9877d6 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/build.gradle +++ b/arrow-libs/fx/arrow-fx-coroutines/build.gradle @@ -12,20 +12,27 @@ apply from: "$PUBLICATION_MPP" kotlin { sourceSets { - jvmMain { + commonMain { dependencies { api project(":arrow-core") + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION" } } + jvmMain { + dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" + } + } + jvmTest { dependencies { implementation project(":arrow-fx-coroutines-test") implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$KOTLINX_COROUTINES_VERSION" - implementation "io.kotest:kotest-runner-junit5-jvm:$KOTEST_VERSION" // for kotest framework - implementation "io.kotest:kotest-assertions-core-jvm:$KOTEST_VERSION" // for kotest core jvm assertions - implementation "io.kotest:kotest-property-jvm:$KOTEST_VERSION" // for kotest property test + implementation "io.kotest:kotest-runner-junit5:$KOTEST_VERSION" // for kotest framework + implementation "io.kotest:kotest-assertions-core:$KOTEST_VERSION" // for kotest core jvm assertions + implementation "io.kotest:kotest-property:$KOTEST_VERSION" // for kotest property test } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Atomic.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Atomic.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Atomic.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Atomic.kt diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Bracket.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt similarity index 99% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Bracket.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt index c97f7cf3c70..45950811251 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Bracket.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt @@ -1,5 +1,6 @@ package arrow.fx.coroutines +import arrow.core.nonFatalOrThrow import kotlinx.coroutines.CancellationException import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.withContext diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt similarity index 97% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt index 58e4783ed41..6edbb2611c2 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt @@ -69,7 +69,7 @@ private constructor( markOrResetFailures(attempt) } is Open -> { - val now = System.currentTimeMillis() + val now = timeInMillis() if (now >= curr.expiresAt) { // The Open state has expired, so we are letting just one // task to execute, while transitioning into HalfOpen @@ -122,7 +122,7 @@ private constructor( else throw result.value } else { // N.B. this could be canceled, however we don't care - val now = System.currentTimeMillis() + val now = timeInMillis() // We've gone over the permitted failures threshold, // so we need to open the circuit breaker val update = Open(now, resetTimeout, CompletableDeferred()) @@ -180,7 +180,7 @@ private constructor( val nextTimeout: Double = if (maxResetTimeout.isFinite() && value > maxResetTimeout) maxResetTimeout else value - val ts = System.currentTimeMillis() + val ts = timeInMillis() state.value = Open(ts, nextTimeout, awaitClose) onOpen.invoke() } @@ -326,7 +326,11 @@ private constructor( "Closed(failures=$failures)" } - class Open internal constructor(val startedAt: Long, val resetTimeoutNanos: Double, internal val awaitClose: CompletableDeferred) : State() { + class Open internal constructor( + val startedAt: Long, + val resetTimeoutNanos: Double, + internal val awaitClose: CompletableDeferred + ) : State() { /** [State] of the [CircuitBreaker] in which the circuit * breaker rejects all tasks with an [ExecutionRejected]. @@ -345,7 +349,11 @@ private constructor( * exponential backoff factor for the next transition from * `HalfOpen` to `Open`, in case the reset attempt fails */ - constructor(startedAt: Long, resetTimeoutNanos: Double) : this(startedAt, resetTimeoutNanos, CompletableDeferred()) + constructor(startedAt: Long, resetTimeoutNanos: Double) : this( + startedAt, + resetTimeoutNanos, + CompletableDeferred() + ) /** The timestamp in milliseconds since the epoch, specifying * when the `Open` state is to transition to [HalfOpen]. @@ -372,7 +380,10 @@ private constructor( } } - class HalfOpen internal constructor(val resetTimeoutNanos: Double, internal val awaitClose: CompletableDeferred) : State() { + class HalfOpen internal constructor( + val resetTimeoutNanos: Double, + internal val awaitClose: CompletableDeferred + ) : State() { /** [State] of the [CircuitBreaker] in which the circuit * breaker has already allowed a task to go through, as a reset diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverse.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverse.kt similarity index 98% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverse.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverse.kt index 01e409e7581..1875f078396 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverse.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverse.kt @@ -13,6 +13,8 @@ import kotlinx.coroutines.sync.withPermit import kotlin.coroutines.ContinuationInterceptor import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName /** * Sequences all tasks in [n] parallel processes on [Dispatchers.Default] and return the result. diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverseEither.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseEither.kt similarity index 99% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverseEither.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseEither.kt index 228627fc33b..b411f04d5fc 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverseEither.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseEither.kt @@ -14,6 +14,8 @@ import kotlinx.coroutines.sync.withPermit import kotlin.coroutines.ContinuationInterceptor import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName /** * Sequences all tasks in [n] parallel processes on [Dispatchers.Default] and return the result. diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt similarity index 99% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt index faf21b448ab..f8787a22956 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt @@ -16,6 +16,8 @@ import kotlinx.coroutines.sync.withPermit import kotlin.coroutines.ContinuationInterceptor import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName /** * Traverses this [Iterable] and runs [f] in [n] parallel operations on [CoroutineContext]. diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParZip.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ParZip.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Platform.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Platform.kt similarity index 94% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Platform.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Platform.kt index 0a02b6a0e3a..1433bf0f146 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Platform.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Platform.kt @@ -2,7 +2,7 @@ package arrow.fx.coroutines import kotlinx.atomicfu.atomic import kotlinx.atomicfu.updateAndGet -import kotlinx.coroutines.runBlocking +import kotlin.jvm.JvmName internal const val ArrowExceptionMessage = "Arrow-kt internal error. Please let us know and create a ticket at https://github.com/arrow-kt/arrow/issues/new/choose" @@ -11,9 +11,6 @@ internal class ArrowInternalException(override val message: String = ArrowExcept object Platform { - internal fun unsafeRunSync(f: suspend () -> A): A = - runBlocking { f() } - fun composeErrors(first: Throwable, res: Result): Throwable { res.fold({ first }, { e -> first.addSuppressed(e) }) return first @@ -154,9 +151,3 @@ class AtomicIntW(a: Int) { override fun toString(): String = value.toString() } - -fun Throwable.nonFatalOrThrow(): Throwable = - when (this) { - is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError -> throw this - else -> this - } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Race2.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Race2.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Race3.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt similarity index 98% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Race3.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt index b5c88a73360..23e40363fc3 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Race3.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt @@ -1,5 +1,6 @@ package arrow.fx.coroutines +import arrow.core.nonFatalOrThrow import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt similarity index 84% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Resource.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt index fac35885a52..a1fedc16dd2 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Resource.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt @@ -1,11 +1,8 @@ package arrow.fx.coroutines import arrow.core.Either +import arrow.core.andThen import arrow.core.identity -import java.io.Closeable -import java.util.concurrent.ExecutorService -import java.util.concurrent.Executors -import kotlin.coroutines.CoroutineContext /** * [Resource] models resource allocation and releasing. It is especially useful when multiple resources that depend on each other @@ -334,85 +331,6 @@ sealed class Resource { fun defer(f: suspend () -> Resource): Resource = Resource.Defer(f) - /** - * Creates a single threaded [CoroutineContext] as a [Resource]. - * Upon release an orderly shutdown of the [ExecutorService] takes place in which previously submitted - * tasks are executed, but no new tasks will be accepted. - * - * ```kotlin:ank:playground - * import arrow.fx.coroutines.* - * import java.util.concurrent.Executors - * import java.util.concurrent.atomic.AtomicInteger - * import kotlin.math.max - * - * suspend fun main(): Unit { - * val pool = Resource.fromExecutor { - * val ctr = AtomicInteger(0) - * val size = max(2, Runtime.getRuntime().availableProcessors()) - * Executors.newFixedThreadPool(size) { r -> - * Thread(r, "computation-${ctr.getAndIncrement()}") - * .apply { isDaemon = true } - * } - * } - * - * pool.use { ctx -> - * listOf(1, 2, 3, 4, 5).parTraverse(ctx) { i -> - * println("#$i running on ${Thread.currentThread().name}") - * } - * } - * } - * ``` - */ - fun fromExecutor(f: suspend () -> ExecutorService): Resource = - Resource(f) { s -> s.shutdown() }.map(ExecutorService::asCoroutineContext) - - /** - * Creates a [Resource] from an [Closeable], which uses [Closeable.close] for releasing. - * - * ```kotlin:ank:playground - * import arrow.fx.coroutines.* - * import java.io.FileInputStream - * - * suspend fun copyFile(src: String, dest: String): Unit = - * Resource.fromClosable { FileInputStream(src) } - * .zip(Resource.fromClosable { FileInputStream(dest) }) - * .use { (a: FileInputStream, b: FileInputStream) -> - * /** read from [a] and write to [b]. **/ - * // Both resources will be closed accordingly to their #close methods - * } - * ``` - */ - fun fromClosable(f: suspend () -> A): Resource = - Resource(f) { s -> s.close() } - - /** - * Creates a single threaded [CoroutineContext] as a [Resource]. - * Upon release an orderly shutdown of the [ExecutorService] takes place in which previously submitted - * tasks are executed, but no new tasks will be accepted. - * - * ```kotlin:ank:playground - * import arrow.fx.coroutines.* - * import kotlinx.coroutines.withContext - * - * val singleCtx = Resource.singleThreadContext("single") - * - * suspend fun main(): Unit = - * singleCtx.use { ctx -> - * withContext(ctx) { - * println("I am running on ${Thread.currentThread().name}") - * } - * } - * ``` - */ - fun singleThreadContext(name: String): Resource = - fromExecutor { - Executors.newSingleThreadExecutor { r -> - Thread(r, name).apply { - isDaemon = true - } - } - } - @Suppress("UNCHECKED_CAST") fun tailRecM(a: A, f: (A) -> Resource>): Resource { fun loop(r: Resource>): Resource = when (r) { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Schedule.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt similarity index 99% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Schedule.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt index 10868c768e4..9ec04cb8fd6 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/Schedule.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt @@ -4,11 +4,13 @@ import arrow.core.Either import arrow.core.Eval import arrow.core.identity import arrow.core.left +import arrow.core.nonFatalOrThrow import arrow.core.right import arrow.fx.coroutines.Schedule.ScheduleImpl import kotlinx.coroutines.delay import kotlinx.coroutines.ensureActive import kotlin.coroutines.coroutineContext +import kotlin.jvm.JvmName import kotlin.math.max import kotlin.math.min import kotlin.math.pow diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/builders.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/builders.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/builders.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/builders.kt diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/flow.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt similarity index 96% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/flow.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt index 74a097b484a..5dfda3e1662 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/flow.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt @@ -8,6 +8,8 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.retryWhen +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName /** * Retries collection of the given flow when an exception occurs in the upstream flow based on a decision by the [schedule]. diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/predef.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/predef.kt new file mode 100644 index 00000000000..6579b1f1540 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/predef.kt @@ -0,0 +1,3 @@ +package arrow.fx.coroutines + +expect fun timeInMillis(): Long diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ResourceExtensions.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ResourceExtensions.kt new file mode 100644 index 00000000000..69d822ab50f --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/ResourceExtensions.kt @@ -0,0 +1,88 @@ +package arrow.fx.coroutines + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.withContext +import java.io.Closeable +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors +import kotlin.coroutines.CoroutineContext + +/** + * Creates a single threaded [CoroutineContext] as a [Resource]. + * Upon release an orderly shutdown of the [ExecutorService] takes place in which previously submitted + * tasks are executed, but no new tasks will be accepted. + * + * ```kotlin:ank:playground + * import arrow.fx.coroutines.* + * import java.util.concurrent.Executors + * import java.util.concurrent.atomic.AtomicInteger + * import kotlin.math.max + * + * suspend fun main(): Unit { + * val pool = Resource.fromExecutor { + * val ctr = AtomicInteger(0) + * val size = max(2, Runtime.getRuntime().availableProcessors()) + * Executors.newFixedThreadPool(size) { r -> + * Thread(r, "computation-${ctr.getAndIncrement()}") + * .apply { isDaemon = true } + * } + * } + * + * pool.use { ctx -> + * listOf(1, 2, 3, 4, 5).parTraverse(ctx) { i -> + * println("#$i running on ${Thread.currentThread().name}") + * } + * } + * } + * ``` + */ +fun Resource.Companion.fromExecutor(f: suspend () -> ExecutorService): Resource = + Resource(f) { s -> s.shutdown() }.map(ExecutorService::asCoroutineDispatcher) + +/** + * Creates a [Resource] from an [Closeable], which uses [Closeable.close] for releasing. + * + * ```kotlin:ank:playground + * import arrow.fx.coroutines.* + * import java.io.FileInputStream + * + * suspend fun copyFile(src: String, dest: String): Unit = + * Resource.fromClosable { FileInputStream(src) } + * .zip(Resource.fromClosable { FileInputStream(dest) }) + * .use { (a: FileInputStream, b: FileInputStream) -> + * /** read from [a] and write to [b]. **/ + * // Both resources will be closed accordingly to their #close methods + * } + * ``` + */ +fun Resource.Companion.fromClosable(f: suspend () -> A): Resource = + Resource(f) { s -> withContext(Dispatchers.IO) { s.close() } } + +/** + * Creates a single threaded [CoroutineContext] as a [Resource]. + * Upon release an orderly shutdown of the [ExecutorService] takes place in which previously submitted + * tasks are executed, but no new tasks will be accepted. + * + * ```kotlin:ank:playground + * import arrow.fx.coroutines.* + * import kotlinx.coroutines.withContext + * + * val singleCtx = Resource.singleThreadContext("single") + * + * suspend fun main(): Unit = + * singleCtx.use { ctx -> + * withContext(ctx) { + * println("I am running on ${Thread.currentThread().name}") + * } + * } + * ``` + */ +fun Resource.Companion.singleThreadContext(name: String): Resource = + fromExecutor { + Executors.newSingleThreadExecutor { r -> + Thread(r, name).apply { + isDaemon = true + } + } + } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/dispatchers.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/dispatchers.kt deleted file mode 100644 index 5a21b6130ee..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/dispatchers.kt +++ /dev/null @@ -1,35 +0,0 @@ -package arrow.fx.coroutines - -import java.util.concurrent.ExecutorService -import kotlin.coroutines.AbstractCoroutineContextElement -import kotlin.coroutines.Continuation -import kotlin.coroutines.ContinuationInterceptor -import kotlin.coroutines.CoroutineContext - -internal fun ExecutorService.asCoroutineContext(): CoroutineContext = - ExecutorServiceContext(this) - -/** - * Wraps an [ExecutorService] in a [CoroutineContext] as a [ContinuationInterceptor] - * scheduling on the [ExecutorService] when [kotlin.coroutines.intrinsics.intercepted] is called. - */ -private class ExecutorServiceContext(val pool: ExecutorService) : - AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { - override fun interceptContinuation(continuation: Continuation): Continuation = - ExecutorServiceContinuation( - pool, - continuation.context.fold(continuation) { cont, element -> - if (element != this@ExecutorServiceContext && element is ContinuationInterceptor) - element.interceptContinuation(cont) else cont - } - ) -} - -/** Wrap existing continuation to resumes itself on the provided [ExecutorService] */ -private class ExecutorServiceContinuation(val pool: ExecutorService, val cont: Continuation) : Continuation { - override val context: CoroutineContext = cont.context - - override fun resumeWith(result: Result) { - pool.execute { cont.resumeWith(result) } - } -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/predef.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/predef.kt index d64ce74dba4..9fa7a84c934 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/predef.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/predef.kt @@ -1,22 +1,15 @@ package arrow.fx.coroutines -import kotlin.coroutines.Continuation -import kotlin.coroutines.intrinsics.createCoroutineUnintercepted -import kotlin.coroutines.resume - -internal inline infix fun ((A) -> B).andThen(crossinline f: (B) -> C): (A) -> C = - { a -> f(this(a)) } - -internal fun Iterable<*>.size(): Int = - when (this) { - is Collection -> size - else -> fold(0) { acc, _ -> acc + 1 } - } - -internal fun (suspend () -> A).startCoroutineUnintercepted(completion: Continuation): Unit = - createCoroutineUnintercepted(completion).resume(Unit) - -/** Represents a unique identifier using object equality. */ -internal class Token { - override fun toString(): String = "Token(${Integer.toHexString(hashCode())})" -} +/* + * For JS: + * ``` + * val x: Number = js("new Date().getTime()") + * return x.toLong() + * ``` + * + * For Native: + * - `getTimeMillis()` + * - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.system/get-time-millis.html + */ +actual fun timeInMillis(): Long = + System.currentTimeMillis() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/AtomicTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/AtomicTest.kt index f59345a5449..74604d824ce 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/AtomicTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/AtomicTest.kt @@ -4,6 +4,7 @@ import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlinx.coroutines.runBlocking class AtomicTest : ArrowFxSpec( spec = { @@ -66,7 +67,7 @@ class AtomicTest : ArrowFxSpec( checkAll(Arb.int()) { x -> val ref = Atomic(x) ref.tryUpdate { - Platform.unsafeRunSync { ref.update(Int::inc) } + runBlocking { ref.update(Int::inc) } it + 1 } shouldBe false } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt index 6868beb5876..1af6722d6a0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt @@ -4,8 +4,11 @@ import arrow.core.Either import arrow.core.left import arrow.core.right import arrow.core.sequenceEither +import io.kotest.assertions.assertSoftly +import io.kotest.assertions.fail import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list @@ -87,9 +90,14 @@ class ParTraverseEitherTest : ArrowFxSpec( "parTraverseEither finishes on single thread " { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - single.use { ctx -> + val res = single.use { ctx -> (0 until i).parTraverseEither(ctx) { Thread.currentThread().name.right() } - } shouldBe (0 until i).map { "single" }.right() + } + assertSoftly { + res.orNull()?.forEach { + it shouldStartWith "single" + } ?: fail("Expected Right but found $res") + } } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt index 60c3504fd92..40edab7c80a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt @@ -1,8 +1,10 @@ package arrow.fx.coroutines import arrow.core.Either +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list @@ -71,11 +73,14 @@ class ParTraverseTest : ArrowFxSpec( l shouldBe (0 until count).toList() } - "parTraverse finishes on single thread " { // 100 is same default length as Arb.list + "parTraverse runs on provided context " { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - single.use { ctx -> + val res = single.use { ctx -> (0 until i).parTraverse(ctx) { Thread.currentThread().name } - } shouldBe (0 until i).map { "single" } + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } @@ -87,13 +92,16 @@ class ParTraverseTest : ArrowFxSpec( ref.get() shouldBe 100 } - "parTraverseN finishes on single thread" { + "parTraverseN runs on provided thread" { checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - single.use { ctx -> + val res = single.use { ctx -> (0 until i).parTraverseN(ctx, 3) { Thread.currentThread().name } - } shouldBe (0 until i).map { "single" } + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt index 976efe96e0a..40272077cc6 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt @@ -7,9 +7,13 @@ import arrow.core.identity import arrow.core.invalidNel import arrow.core.sequenceValidated import arrow.core.validNel +import arrow.core.orNull import arrow.typeclasses.Semigroup +import io.kotest.assertions.assertSoftly +import io.kotest.assertions.fail import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list @@ -88,9 +92,14 @@ class ParTraverseValidatedTest : ArrowFxSpec( "parTraverseValidated finishes on single thread " { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - single.use { ctx -> + val res = single.use { ctx -> (0 until i).parTraverseValidated(ctx, Semigroup.nonEmptyList()) { Thread.currentThread().name.validNel() } - } shouldBe (0 until i).map { "single" }.validNel() + } + assertSoftly { + res.orNull()?.forEach { + it shouldStartWith "single" + } ?: fail("Expected Right but found $res") + } } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNTest.kt index f9ac42c94f6..ce7db96cbd9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNTest.kt @@ -5,6 +5,7 @@ import arrow.core.identity import arrow.core.merge import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.bool @@ -26,15 +27,15 @@ class RaceNTest : ArrowFxSpec( checkAll(Arb.int(1..2)) { choose -> single.zip(racer).use { (single, raceCtx) -> withContext(single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val racedOn = when (choose) { 1 -> raceN(raceCtx, { threadName() }, { never() }).swap().orNull() else -> raceN(raceCtx, { never() }, { threadName() }).orNull() } - racedOn shouldBe racerName - threadName() shouldBe singleThreadName + racedOn shouldStartWith racerName + threadName() shouldStartWith singleThreadName } } } @@ -47,7 +48,7 @@ class RaceNTest : ArrowFxSpec( checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> single.zip(racer).use { (single, raceCtx) -> withContext(single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -56,7 +57,7 @@ class RaceNTest : ArrowFxSpec( } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -77,7 +78,7 @@ class RaceNTest : ArrowFxSpec( "first racer out of 2 always wins on a single thread" { single.use { ctx -> raceN(ctx, threadName, threadName) - } shouldBe Either.Left("single") + }.swap().orNull() shouldStartWith "single" } "Cancelling race 2 cancels all participants" { @@ -139,7 +140,7 @@ class RaceNTest : ArrowFxSpec( checkAll(Arb.int(1..3)) { choose -> single.zip(racer).use { (single, raceCtx) -> withContext(single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val racedOn = when (choose) { 1 -> @@ -153,8 +154,8 @@ class RaceNTest : ArrowFxSpec( .fold({ null }, { null }, ::identity) } - racedOn shouldBe racerName - threadName() shouldBe singleThreadName + racedOn shouldStartWith racerName + threadName() shouldStartWith singleThreadName } } } @@ -167,7 +168,7 @@ class RaceNTest : ArrowFxSpec( checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> single.zip(racer).use { (single, raceCtx) -> withContext(single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -183,7 +184,7 @@ class RaceNTest : ArrowFxSpec( } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -208,9 +209,9 @@ class RaceNTest : ArrowFxSpec( } "first racer out of 3 always wins on a single thread" { - single.use { ctx -> + (single.use { ctx -> raceN(ctx, threadName, threadName, threadName) - } shouldBe Race3.First("single") + } as? Race3.First)?.winner shouldStartWith "single" } "Cancelling race 3 cancels all participants" { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/SuspendRunners.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/SuspendRunners.kt index f72c96429f6..599456e2399 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/SuspendRunners.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/SuspendRunners.kt @@ -7,6 +7,7 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.map import io.kotest.property.checkAll +import kotlinx.coroutines.runBlocking import kotlin.coroutines.Continuation import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.startCoroutine @@ -18,7 +19,7 @@ class SuspendRunners : ArrowFxSpec( var run = false val fa = suspend { run = true } run shouldBe false - Platform.unsafeRunSync(fa) + runBlocking { fa() } run shouldBe true } @@ -26,8 +27,8 @@ class SuspendRunners : ArrowFxSpec( val sideEffect = SideEffect() val fa = suspend { sideEffect.increment(); 1 } - Platform.unsafeRunSync(fa) - Platform.unsafeRunSync(fa) + runBlocking { fa() } + runBlocking { fa() } sideEffect.counter shouldBe 2 } @@ -36,7 +37,7 @@ class SuspendRunners : ArrowFxSpec( checkAll(Arb.throwable()) { e -> val task = suspend { throw e } shouldThrow { - Platform.unsafeRunSync { task.invoke() } + runBlocking { task.invoke() } } shouldBe e } } @@ -44,20 +45,20 @@ class SuspendRunners : ArrowFxSpec( "should yield immediate successful invoke value" { checkAll(Arb.int()) { i -> val task = suspend { i } - val run = Platform.unsafeRunSync { task.invoke() } + val run = runBlocking { task.invoke() } run shouldBe i } } "should return a null value from unsafeRunSync" { - val run = Platform.unsafeRunSync { suspend { null }() } + val run = runBlocking { suspend { null }() } run shouldBe null } "suspend with unsafeRunSync" { checkAll(Arb.int().map { suspend { it } }) { i -> val map = suspend { i() + 1 } - Platform.unsafeRunSync(map) shouldBe (i.invoke() + 1) + runBlocking { map() } shouldBe (i.invoke() + 1) } } @@ -113,7 +114,7 @@ class SuspendRunners : ArrowFxSpec( suspend fun fa(): Int = (0 until (max * 10000)).fold(0) { acc, _ -> addOne(acc) } - Platform.unsafeRunSync { fa() } shouldBe (max * 10000) + runBlocking { fa() } shouldBe (max * 10000) } } ) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt index 7308233e9f0..2a13c720e1a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt @@ -15,8 +15,11 @@ import arrow.fx.coroutines.singleThreadName import arrow.fx.coroutines.suspend import arrow.fx.coroutines.threadName import arrow.fx.coroutines.throwable +import arrow.fx.coroutines.fromExecutor +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.bool @@ -38,13 +41,13 @@ class ParMap2Test : ArrowFxSpec( checkAll { single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val (s1, s2) = parZip(_mapCtx, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b -> Pair(a, b) } - s1 shouldBe mapCtxName - s2 shouldBe mapCtxName - threadName() shouldBe singleThreadName + s1 shouldStartWith mapCtxName + s2 shouldStartWith mapCtxName + threadName() shouldStartWith singleThreadName } } } @@ -57,7 +60,7 @@ class ParMap2Test : ArrowFxSpec( checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -66,7 +69,7 @@ class ParMap2Test : ArrowFxSpec( } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -96,9 +99,12 @@ class ParMap2Test : ArrowFxSpec( "parMapN 2 finishes on single thread" { checkAll(Arb.string()) { - single.use { ctx -> - parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b -> Pair(a, b) } - } shouldBe Pair("single", "single") + val res = single.use { ctx -> + parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b -> listOf(a, b) } + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt index e9079239228..0a7c94660b5 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt @@ -15,8 +15,11 @@ import arrow.fx.coroutines.singleThreadName import arrow.fx.coroutines.suspend import arrow.fx.coroutines.threadName import arrow.fx.coroutines.throwable +import arrow.fx.coroutines.fromExecutor +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.element @@ -38,14 +41,14 @@ class ParMap3Test : ArrowFxSpec( checkAll { single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val (s1, s2, s3) = parZip(_mapCtx, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b, c -> Triple(a, b, c) } - s1 shouldBe mapCtxName - s2 shouldBe mapCtxName - s3 shouldBe mapCtxName - threadName() shouldBe singleThreadName + s1 shouldStartWith mapCtxName + s2 shouldStartWith mapCtxName + s3 shouldStartWith mapCtxName + threadName() shouldStartWith singleThreadName } } } @@ -58,7 +61,7 @@ class ParMap3Test : ArrowFxSpec( checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -83,7 +86,7 @@ class ParMap3Test : ArrowFxSpec( } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -119,9 +122,12 @@ class ParMap3Test : ArrowFxSpec( "parMapN 3 finishes on single thread" { checkAll(Arb.string()) { - single.use { ctx -> - parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b, c -> Triple(a, b, c) } - } shouldBe Triple("single", "single", "single") + val res = single.use { ctx -> + parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b, c -> listOf(a, b, c) } + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt index 9e5c047e970..75c0daf118f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt @@ -16,8 +16,11 @@ import arrow.fx.coroutines.singleThreadName import arrow.fx.coroutines.suspend import arrow.fx.coroutines.threadName import arrow.fx.coroutines.throwable +import arrow.fx.coroutines.fromExecutor +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.element @@ -38,17 +41,17 @@ class ParMap4Test : ArrowFxSpec( checkAll { single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val (s1, s2, s3, s4) = parZip( _mapCtx, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name } ) { a, b, c, d -> Tuple4(a, b, c, d) } - s1 shouldBe mapCtxName - s2 shouldBe mapCtxName - s3 shouldBe mapCtxName - s4 shouldBe mapCtxName - threadName() shouldBe singleThreadName + s1 shouldStartWith mapCtxName + s2 shouldStartWith mapCtxName + s3 shouldStartWith mapCtxName + s4 shouldStartWith mapCtxName + threadName() shouldStartWith singleThreadName } } } @@ -61,7 +64,7 @@ class ParMap4Test : ArrowFxSpec( checkAll(Arb.int(1..4), Arb.throwable()) { choose, e -> single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -96,7 +99,7 @@ class ParMap4Test : ArrowFxSpec( } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -138,9 +141,12 @@ class ParMap4Test : ArrowFxSpec( "parMapN 4 finishes on single thread" { checkAll(Arb.string()) { - single.use { ctx -> - parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b, c, d -> Tuple4(a, b, c, d) } - } shouldBe Tuple4("single", "single", "single", "single") + val res = single.use { ctx -> + parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b, c, d -> listOf(a, b, c, d) } + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt index 6128e5d31fa..c4c9839a70b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt @@ -16,8 +16,11 @@ import arrow.fx.coroutines.singleThreadName import arrow.fx.coroutines.suspend import arrow.fx.coroutines.threadName import arrow.fx.coroutines.throwable +import arrow.fx.coroutines.fromExecutor +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.element @@ -41,18 +44,18 @@ class ParMap5Test : ArrowFxSpec( checkAll { single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val (s1, s2, s3, s4, s5) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName ) { a, b, c, d, e -> Tuple5(a, b, c, d, e) } - s1 shouldBe mapCtxName - s2 shouldBe mapCtxName - s3 shouldBe mapCtxName - s4 shouldBe mapCtxName - s5 shouldBe mapCtxName - threadName() shouldBe singleThreadName + s1 shouldStartWith mapCtxName + s2 shouldStartWith mapCtxName + s3 shouldStartWith mapCtxName + s4 shouldStartWith mapCtxName + s5 shouldStartWith mapCtxName + threadName() shouldStartWith singleThreadName } } } @@ -65,7 +68,7 @@ class ParMap5Test : ArrowFxSpec( checkAll(Arb.int(1..5), Arb.throwable()) { choose, e -> single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -112,7 +115,7 @@ class ParMap5Test : ArrowFxSpec( } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -160,9 +163,9 @@ class ParMap5Test : ArrowFxSpec( "parMapN 5 finishes on single thread" { checkAll(Arb.string()) { - single.use { ctx -> + val res = single.use { ctx -> parZip(ctx, threadName, threadName, threadName, threadName, threadName) { a, b, c, d, e -> - Tuple5( + listOf( a, b, c, @@ -170,7 +173,10 @@ class ParMap5Test : ArrowFxSpec( e ) } - } shouldBe Tuple5("single", "single", "single", "single", "single") + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt index 57f962bc3f5..c8519bbf2ae 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt @@ -16,8 +16,11 @@ import arrow.fx.coroutines.singleThreadName import arrow.fx.coroutines.suspend import arrow.fx.coroutines.threadName import arrow.fx.coroutines.throwable +import arrow.fx.coroutines.fromExecutor +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.element @@ -42,7 +45,7 @@ class ParMap6Test : ArrowFxSpec( checkAll { single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val (s1, s2, s3, s4, s5, s6) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName, threadName @@ -50,13 +53,13 @@ class ParMap6Test : ArrowFxSpec( Tuple6(a, b, c, d, e, f) } - s1 shouldBe mapCtxName - s2 shouldBe mapCtxName - s3 shouldBe mapCtxName - s4 shouldBe mapCtxName - s5 shouldBe mapCtxName - s6 shouldBe mapCtxName - threadName() shouldBe singleThreadName + s1 shouldStartWith mapCtxName + s2 shouldStartWith mapCtxName + s3 shouldStartWith mapCtxName + s4 shouldStartWith mapCtxName + s5 shouldStartWith mapCtxName + s6 shouldStartWith mapCtxName + threadName() shouldStartWith singleThreadName } } } @@ -69,7 +72,7 @@ class ParMap6Test : ArrowFxSpec( checkAll(Arb.int(1..6), Arb.throwable()) { choose, e -> single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -129,7 +132,7 @@ class ParMap6Test : ArrowFxSpec( ) { _, _, _, _, _, _ -> Unit } } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -183,11 +186,14 @@ class ParMap6Test : ArrowFxSpec( "parMapN 6 finishes on single thread" { checkAll(Arb.string()) { - single.use { ctx -> + val res = single.use { ctx -> parZip(ctx, threadName, threadName, threadName, threadName, threadName, threadName) { a, b, c, d, e, f -> - Tuple6(a, b, c, d, e, f) + listOf(a, b, c, d, e, f) } - } shouldBe Tuple6("single", "single", "single", "single", "single", "single") + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt index cc7aec082dd..ca98d4624c9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt @@ -16,8 +16,11 @@ import arrow.fx.coroutines.singleThreadName import arrow.fx.coroutines.suspend import arrow.fx.coroutines.threadName import arrow.fx.coroutines.throwable +import arrow.fx.coroutines.fromExecutor +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.element @@ -42,7 +45,7 @@ class ParMap7Test : ArrowFxSpec( checkAll { single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val (s1, s2, s3, s4, s5, s6, s7) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName, threadName, threadName @@ -50,14 +53,14 @@ class ParMap7Test : ArrowFxSpec( Tuple7(a, b, c, d, e, f, g) } - s1 shouldBe mapCtxName - s2 shouldBe mapCtxName - s3 shouldBe mapCtxName - s4 shouldBe mapCtxName - s5 shouldBe mapCtxName - s6 shouldBe mapCtxName - s7 shouldBe mapCtxName - threadName() shouldBe singleThreadName + s1 shouldStartWith mapCtxName + s2 shouldStartWith mapCtxName + s3 shouldStartWith mapCtxName + s4 shouldStartWith mapCtxName + s5 shouldStartWith mapCtxName + s6 shouldStartWith mapCtxName + s7 shouldStartWith mapCtxName + threadName() shouldStartWith singleThreadName } } } @@ -70,7 +73,7 @@ class ParMap7Test : ArrowFxSpec( checkAll(Arb.int(1..7), Arb.throwable()) { choose, e -> single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -146,7 +149,7 @@ class ParMap7Test : ArrowFxSpec( ) { _, _, _, _, _, _, _ -> Unit } } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -206,7 +209,7 @@ class ParMap7Test : ArrowFxSpec( "parMapN 7 finishes on single thread" { checkAll(Arb.string()) { - single.use { ctx -> + val res = single.use { ctx -> parZip( ctx, threadName, @@ -217,9 +220,12 @@ class ParMap7Test : ArrowFxSpec( threadName, threadName ) { a, b, c, d, e, f, g -> - Tuple7(a, b, c, d, e, f, g) + listOf(a, b, c, d, e, f, g) } - } shouldBe Tuple7("single", "single", "single", "single", "single", "single", "single") + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt index 4f33809c548..baf6907553a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt @@ -16,8 +16,11 @@ import arrow.fx.coroutines.singleThreadName import arrow.fx.coroutines.suspend import arrow.fx.coroutines.threadName import arrow.fx.coroutines.throwable +import arrow.fx.coroutines.fromExecutor +import io.kotest.assertions.assertSoftly import io.kotest.matchers.should import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldStartWith import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.element @@ -42,7 +45,7 @@ class ParMap8Test : ArrowFxSpec( checkAll { single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName val (s1, s2, s3, s4, s5, s6, s7, s8) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName, threadName, threadName, threadName @@ -50,15 +53,15 @@ class ParMap8Test : ArrowFxSpec( Tuple8(a, b, c, d, e, f, g, h) } - s1 shouldBe mapCtxName - s2 shouldBe mapCtxName - s3 shouldBe mapCtxName - s4 shouldBe mapCtxName - s5 shouldBe mapCtxName - s6 shouldBe mapCtxName - s7 shouldBe mapCtxName - s8 shouldBe mapCtxName - threadName() shouldBe singleThreadName + s1 shouldStartWith mapCtxName + s2 shouldStartWith mapCtxName + s3 shouldStartWith mapCtxName + s4 shouldStartWith mapCtxName + s5 shouldStartWith mapCtxName + s6 shouldStartWith mapCtxName + s7 shouldStartWith mapCtxName + s8 shouldStartWith mapCtxName + threadName() shouldStartWith singleThreadName } } } @@ -71,7 +74,7 @@ class ParMap8Test : ArrowFxSpec( checkAll(Arb.int(1..8), Arb.throwable()) { choose, e -> single.zip(mapCtx).use { (_single, _mapCtx) -> withContext(_single) { - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName Either.catch { when (choose) { @@ -164,7 +167,7 @@ class ParMap8Test : ArrowFxSpec( ) { _, _, _, _, _, _, _, _ -> Unit } } } should leftException(e) - threadName() shouldBe singleThreadName + threadName() shouldStartWith singleThreadName } } } @@ -230,11 +233,14 @@ class ParMap8Test : ArrowFxSpec( "parMapN 7 finishes on single thread" { checkAll(Arb.string()) { - single.use { ctx -> + val res = single.use { ctx -> parZip(ctx, threadName, threadName, threadName, threadName, threadName, threadName, threadName, threadName) { a, b, c, d, e, f, g, h -> - Tuple8(a, b, c, d, e, f, g, h) + listOf(a, b, c, d, e, f, g, h) } - } shouldBe Tuple8("single", "single", "single", "single", "single", "single", "single", "single") + } + assertSoftly { + res.forEach { it shouldStartWith "single" } + } } } diff --git a/arrow-libs/fx/arrow-fx-stm/build.gradle b/arrow-libs/fx/arrow-fx-stm/build.gradle index 3215ec9b71d..7f560d18072 100644 --- a/arrow-libs/fx/arrow-fx-stm/build.gradle +++ b/arrow-libs/fx/arrow-fx-stm/build.gradle @@ -9,23 +9,30 @@ apply from: "$SUB_PROJECT_MPP" apply from: "$TEST_COVERAGE" apply from: "$DOC_CREATION" apply from: "$PUBLICATION_MPP" -apply from: "$ANIMALSNIFFER" +apply from: "$ANIMALSNIFFER_MPP" kotlin { sourceSets { - jvmMain { + commonMain { dependencies { api project(":arrow-core") + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION" } } + jvmMain { + dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" + } + } + jvmTest { dependencies { implementation project(":arrow-fx-coroutines-test") - implementation "io.kotest:kotest-runner-junit5-jvm:$KOTEST_VERSION" // for kotest framework - implementation "io.kotest:kotest-assertions-core-jvm:$KOTEST_VERSION" // for kotest core jvm assertions - implementation "io.kotest:kotest-property-jvm:$KOTEST_VERSION" // for kotest property test + implementation "io.kotest:kotest-runner-junit5:$KOTEST_VERSION" // for kotest framework + implementation "io.kotest:kotest-assertions-core:$KOTEST_VERSION" // for kotest core jvm assertions + implementation "io.kotest:kotest-property:$KOTEST_VERSION" // for kotest property test } } } diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/STM.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/STM.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TArray.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TArray.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TArray.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TArray.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TMVar.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMVar.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TMVar.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMVar.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TMap.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMap.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TMap.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TMap.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TQueue.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TQueue.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TQueue.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TQueue.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TSemaphore.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TSemaphore.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TSemaphore.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TSemaphore.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TSet.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TSet.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TSet.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TSet.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TVar.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/TVar.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/Hamt.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Hamt.kt similarity index 100% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/Hamt.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Hamt.kt diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/Impl.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt similarity index 96% rename from arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/Impl.kt rename to arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt index 9d414af9f73..5ec688cf385 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/Impl.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt @@ -154,9 +154,7 @@ internal class STMFrame(val parent: STMFrame? = null) : STM { */ class BlockedIndefinitely : Throwable("Transaction blocked indefinitely") -object RetryException : Throwable("Arrow STM Retry. This should always be caught by arrow internally. Please report this as a bug if that is not the case!") { - override fun fillInStackTrace(): Throwable { return this } -} +expect object RetryException : Throwable // -------- /** diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/RetryException.kt b/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/RetryException.kt new file mode 100644 index 00000000000..10ef624c28d --- /dev/null +++ b/arrow-libs/fx/arrow-fx-stm/src/jvmMain/kotlin/arrow/fx/stm/internal/RetryException.kt @@ -0,0 +1,5 @@ +package arrow.fx.stm.internal + +actual object RetryException : Throwable("Arrow STM Retry. This should always be caught by arrow internally. Please report this as a bug if that is not the case!") { + override fun fillInStackTrace(): Throwable { return this } +} diff --git a/arrow-libs/fx/gradle.properties b/arrow-libs/fx/gradle.properties index c3af4228b06..5ed6b2dc4f6 100644 --- a/arrow-libs/fx/gradle.properties +++ b/arrow-libs/fx/gradle.properties @@ -10,4 +10,6 @@ kotlin.incremental=true #Parallelism needs to be set to 1 since the concurrent tests in arrow-effects become flaky otherwise kotlintest.parallelism=1 kapt.incremental.apt=false -kotlin.stdlib.default.dependency=false + +# Reason: https://youtrack.jetbrains.com/issue/KT-46847 +# kotlin.stdlib.default.dependency=false diff --git a/arrow-libs/gradle.properties b/arrow-libs/gradle.properties index f7169f83837..7983ded8f72 100644 --- a/arrow-libs/gradle.properties +++ b/arrow-libs/gradle.properties @@ -67,7 +67,9 @@ kotlin.incremental=true #Parallelism needs to be set to 1 since the concurrent tests in arrow-effects become flaky otherwise kotlintest.parallelism=1 kapt.incremental.apt=false -kotlin.stdlib.default.dependency=false + +# Reason: https://youtrack.jetbrains.com/issue/KT-46847 +# kotlin.stdlib.default.dependency=false COMMON_SETUP=../gradle/setup.gradle ROOT_PROJECT=../gradle/main.gradle @@ -78,3 +80,4 @@ DOC_CREATION=../../gradle/apidoc-creation.gradle PUBLICATION=../../gradle/publication.gradle PUBLICATION_MPP=../../gradle/publication-mpp.gradle ANIMALSNIFFER=../../gradle/animalsniffer.gradle +ANIMALSNIFFER_MPP=../../gradle/animalsniffer-mpp.gradle diff --git a/arrow-libs/gradle/animalsniffer-mpp.gradle b/arrow-libs/gradle/animalsniffer-mpp.gradle new file mode 100644 index 00000000000..a23b45da3a6 --- /dev/null +++ b/arrow-libs/gradle/animalsniffer-mpp.gradle @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2021 The Arrow Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// -- Gradle Animal Sniffer Plugin: https://github.com/xvik/gradle-animalsniffer-plugin +apply plugin: 'ru.vyarus.animalsniffer' +animalsniffer { + ignore 'java.lang.*' +} +kotlin { + sourceSets { + commonMain { + dependencies { + compileOnly "org.codehaus.mojo:animal-sniffer-annotations:1.19" + } + } + jvmMain { + dependencies { + compileOnly "org.codehaus.mojo:animal-sniffer-annotations:1.19" + } + } + } +} diff --git a/arrow-libs/optics/arrow-optics-test/build.gradle b/arrow-libs/optics/arrow-optics-test/build.gradle index 0ac74e0a641..a1918b28ba1 100644 --- a/arrow-libs/optics/arrow-optics-test/build.gradle +++ b/arrow-libs/optics/arrow-optics-test/build.gradle @@ -8,10 +8,9 @@ apply from: "$PUBLICATION" apply from: "$ANIMALSNIFFER" dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" compile project(":arrow-optics") - compile project(":arrow-core-test") compile "io.kotlintest:kotlintest-runner-junit5:$KOTLIN_TEST_VERSION", excludeArrow - testRuntime "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION" } diff --git a/arrow-libs/optics/arrow-optics/build.gradle b/arrow-libs/optics/arrow-optics/build.gradle index cec13b7db19..05a06a0e7d6 100644 --- a/arrow-libs/optics/arrow-optics/build.gradle +++ b/arrow-libs/optics/arrow-optics/build.gradle @@ -1,26 +1,37 @@ plugins { - id "org.jetbrains.kotlin.jvm" + id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.kapt" id "org.jlleitschuh.gradle.ktlint" } -apply from: "$SUB_PROJECT" +apply from: "$SUB_PROJECT_MPP" apply from: "$TEST_COVERAGE" apply from: "$DOC_CREATION" -apply from: "$PUBLICATION" -apply from: "$ANIMALSNIFFER" +apply from: "$PUBLICATION_MPP" +apply from: "$ANIMALSNIFFER_MPP" -dependencies { - compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" - compile project(":arrow-core") +kotlin { + sourceSets { + commonMain { + dependencies { + api project(":arrow-core") + compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION" + } + } + jvmMain { + dependencies { + compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION" + } + } + jvmTest { + dependencies { + compileOnly project(":arrow-optics-test") + runtimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION" + } + } + } +} - kapt project(":arrow-meta") +dependencies { kaptTest project(":arrow-meta") - - testCompile "junit:junit:$JUNIT_VERSION" - - testRuntime "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION" - testCompile "io.kotlintest:kotlintest-runner-junit5:$KOTLIN_TEST_VERSION", excludeArrow - - testCompile project(":arrow-optics-test") } diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Every.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt index e69539ca2e6..f36b96bb6f7 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt @@ -13,6 +13,7 @@ import arrow.core.Tuple9 import arrow.core.foldLeft import arrow.core.foldMap import arrow.typeclasses.Monoid +import kotlin.jvm.JvmStatic typealias Every = PEvery diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Fold.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Fold.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt index c922d3e70a4..44e3ad5f946 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Fold.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt @@ -12,6 +12,7 @@ import arrow.core.Tuple8 import arrow.core.Tuple9 import arrow.core.identity import arrow.typeclasses.Monoid +import kotlin.jvm.JvmStatic /** * A [Fold] is an optic that allows to focus into structure and get multiple results. diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Getter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Getter.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Iso.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Iso.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt index b8d4c3a0fea..493777554c4 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Iso.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt @@ -12,6 +12,7 @@ import arrow.core.Validated.Valid import arrow.core.compose import arrow.core.identity import arrow.typeclasses.Monoid +import kotlin.jvm.JvmStatic /** * [Iso] is a type alias for [PIso] which fixes the type arguments diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Lens.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Lens.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt index 0e78e661f01..f00eb3694cd 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Lens.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt @@ -4,6 +4,7 @@ import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.identity import arrow.typeclasses.Monoid +import kotlin.jvm.JvmStatic /** * [Lens] is a type alias for [PLens] which fixes the type arguments diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Optional.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Optional.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt index 02d6e5ad4f3..8f89eb71ba1 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Optional.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt @@ -7,6 +7,7 @@ import arrow.core.Some import arrow.core.flatMap import arrow.core.identity import arrow.typeclasses.Monoid +import kotlin.jvm.JvmStatic /** * [Optional] is a type alias for [POptional] which fixes the type arguments diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Prism.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index acbfe6b4a00..a210898be13 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -8,6 +8,7 @@ import arrow.core.compose import arrow.core.flatMap import arrow.core.identity import arrow.typeclasses.Monoid +import kotlin.jvm.JvmStatic /** * [Prism] is a type alias for [PPrism] which fixes the type arguments diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Setter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Setter.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Traversal.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Traversal.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt index e227d04349f..e133600364b 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/Traversal.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt @@ -10,6 +10,7 @@ import arrow.core.Tuple6 import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 +import kotlin.jvm.JvmStatic /** * [Traversal] is a type alias for [PTraversal] which fixes the type arguments diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/at.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/at.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/every.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/index.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/index.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/option.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/dsl/option.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/predef.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/predef.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/std/list.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/std/list.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/std/list.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/std/list.kt diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/At.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/At.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt index 5c62069f709..6f0d46ab669 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/At.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt @@ -11,6 +11,7 @@ import arrow.optics.PLens import arrow.optics.Prism import arrow.optics.Setter import arrow.optics.Traversal +import kotlin.jvm.JvmStatic /** * [At] provides a [Lens] for a structure [S] to focus in [A] at a given index [I]. diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Cons.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Cons.kt similarity index 98% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Cons.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Cons.kt index c45564b3048..672fd71e721 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Cons.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Cons.kt @@ -7,6 +7,7 @@ import arrow.optics.Optional import arrow.optics.PLens import arrow.optics.PPrism import arrow.optics.Prism +import kotlin.jvm.JvmStatic /** * [Cons] provides a [Prism] between [S] and its first element [A] and tail [S]. diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/FilterIndex.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/FilterIndex.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt index 90834e4c84e..882a9a8ca17 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/FilterIndex.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt @@ -5,6 +5,7 @@ import arrow.core.Predicate import arrow.optics.Every import arrow.optics.Iso import arrow.typeclasses.Monoid +import kotlin.jvm.JvmStatic /** * [FilterIndex] provides a [Every] for a structure [S] with all its foci [A] whose index [I] satisfies a predicate. diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Index.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt similarity index 99% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Index.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt index 78c3fd15f3d..bcb18708945 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Index.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt @@ -11,6 +11,7 @@ import arrow.optics.POptional import arrow.optics.Prism import arrow.optics.Setter import arrow.optics.Traversal +import kotlin.jvm.JvmStatic /** * [Index] provides an [Optional] for a structure [S] to focus in an optional [A] at a given index [I]. diff --git a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Snoc.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt similarity index 98% rename from arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Snoc.kt rename to arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt index aca92b9286f..ec6e20a0063 100644 --- a/arrow-libs/optics/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Snoc.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt @@ -8,6 +8,7 @@ import arrow.optics.Iso import arrow.optics.Optional import arrow.optics.PLens import arrow.optics.Prism +import kotlin.jvm.JvmStatic typealias Conj = Snoc diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/DSLTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/DSLTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/DSLTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/DSLTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/EveryTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/EveryTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/EveryTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/EveryTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/FoldTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/FoldTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/FoldTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/FoldTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/GetterTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/GetterTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/GetterTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/GetterTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/IsoTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/IsoTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/IsoTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/IsoTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/LensTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/LensTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/LensTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/LensTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/OptionalTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/OptionalTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/OptionalTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/OptionalTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/PrismTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/PrismTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/PrismTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/PrismTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/SetterTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/SetterTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/SetterTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/SetterTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/TestDomain.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/TestDomain.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/TestDomain.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/TestDomain.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/TraversalTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/TraversalTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/TraversalTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/TraversalTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/EitherInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/EitherInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/EitherInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/EitherInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/IndexInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/IndexInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/ListInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/ListInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/ListInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/ListInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/MapInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/MapInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/MapInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/MapInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/NonEmptyListInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/NonEmptyListInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/NonEmptyListInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/NonEmptyListInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/OptionInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/OptionInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/OptionInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/OptionInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/SequenceInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/SequenceInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/SequenceInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/SequenceInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/SetInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/SetInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/SetInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/SetInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/StringInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/StringInstanceTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/instances/StringInstanceTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/instances/StringInstanceTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/EitherTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/EitherTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/EitherTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/EitherTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/ListTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/ListTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/ListTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/ListTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/MapTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/MapTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/MapTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/MapTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/NonEmptyListTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/NonEmptyListTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/NonEmptyListTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/NonEmptyListTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/OptionTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/OptionTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/OptionTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/OptionTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/StringTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/StringTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/StringTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/StringTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/TupleTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/TupleTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/TupleTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/TupleTest.kt diff --git a/arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/ValidatedTest.kt b/arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/ValidatedTest.kt similarity index 100% rename from arrow-libs/optics/arrow-optics/src/test/kotlin/arrow/optics/std/ValidatedTest.kt rename to arrow-libs/optics/arrow-optics/src/jvmTest/kotlin/arrow/optics/std/ValidatedTest.kt diff --git a/arrow-libs/optics/build.gradle b/arrow-libs/optics/build.gradle index 9bb9d63e137..64c19310a0a 100644 --- a/arrow-libs/optics/build.gradle +++ b/arrow-libs/optics/build.gradle @@ -14,7 +14,6 @@ buildscript { } plugins { - id "org.jetbrains.kotlin.jvm" version "$KOTLIN_VERSION" id "org.jetbrains.kotlin.kapt" version "$KOTLIN_VERSION" apply false id "org.jlleitschuh.gradle.ktlint" version "$KTLINT_GRADLE_VERSION" apply false id "org.jetbrains.dokka" version "$DOKKA_VERSION" apply false diff --git a/arrow-libs/optics/gradle.properties b/arrow-libs/optics/gradle.properties index 684eaed7476..6c21d28a87b 100644 --- a/arrow-libs/optics/gradle.properties +++ b/arrow-libs/optics/gradle.properties @@ -9,4 +9,6 @@ kotlin.incremental=true # Kotlin Test configuration #Parallelism needs to be set to 1 since the concurrent tests in arrow-effects become flaky otherwise kotlintest.parallelism=1 -kotlin.stdlib.default.dependency=false + +# Reason: https://youtrack.jetbrains.com/issue/KT-46847 +# kotlin.stdlib.default.dependency=false