From ed7f470df2ab0e3ae4eb728f9e01f1f141d48e34 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 29 Jul 2022 10:50:45 +0200 Subject: [PATCH 001/114] The beginning of Arrow 2.0 --- .github/{workflows => unused_workflows}/generate-alpha-tag.yaml | 0 .github/{workflows => unused_workflows}/generate-tag.yaml | 0 .../{workflows => unused_workflows}/publish-landing-page.yaml | 0 .github/{workflows => unused_workflows}/publish.yml | 0 build.gradle.kts | 2 +- gradle.properties | 1 + 6 files changed, 2 insertions(+), 1 deletion(-) rename .github/{workflows => unused_workflows}/generate-alpha-tag.yaml (100%) rename .github/{workflows => unused_workflows}/generate-tag.yaml (100%) rename .github/{workflows => unused_workflows}/publish-landing-page.yaml (100%) rename .github/{workflows => unused_workflows}/publish.yml (100%) diff --git a/.github/workflows/generate-alpha-tag.yaml b/.github/unused_workflows/generate-alpha-tag.yaml similarity index 100% rename from .github/workflows/generate-alpha-tag.yaml rename to .github/unused_workflows/generate-alpha-tag.yaml diff --git a/.github/workflows/generate-tag.yaml b/.github/unused_workflows/generate-tag.yaml similarity index 100% rename from .github/workflows/generate-tag.yaml rename to .github/unused_workflows/generate-tag.yaml diff --git a/.github/workflows/publish-landing-page.yaml b/.github/unused_workflows/publish-landing-page.yaml similarity index 100% rename from .github/workflows/publish-landing-page.yaml rename to .github/unused_workflows/publish-landing-page.yaml diff --git a/.github/workflows/publish.yml b/.github/unused_workflows/publish.yml similarity index 100% rename from .github/workflows/publish.yml rename to .github/unused_workflows/publish.yml diff --git a/build.gradle.kts b/build.gradle.kts index 9ca42d91ed3..2713aa18188 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,7 +24,7 @@ plugins { alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.kotlin.binaryCompatibilityValidator) alias(libs.plugins.arrowGradleConfig.nexus) - alias(libs.plugins.arrowGradleConfig.versioning) + // alias(libs.plugins.arrowGradleConfig.versioning) } apply(plugin = libs.plugins.kotlinx.knit.get().pluginId) diff --git a/gradle.properties b/gradle.properties index ce01f1a4c52..015b803c986 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,6 @@ # Package definitions projects.group=io.arrow-kt +version=2.0.0-SNAPSHOT # Pomfile definitions pom.description=Functional companion to Kotlin's Standard Library pom.url=https://github.com/arrow-kt/arrow/ From cfd44d9769dacfed1777ebb006d40e2f2028fa0b Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Thu, 1 Sep 2022 14:09:21 +0200 Subject: [PATCH 002/114] Resource Arrow 2.0 (#2786) * Flatten Resource ADT, maintain API --- .../kotlin/arrow/core/continuations/Effect.kt | 25 +- .../examples/example-effect-guide-09.kt | 25 +- .../api/arrow-fx-coroutines-test.api | 2 +- .../arrow/fx/coroutines/predef-test-jvm.kt | 2 +- .../kotlin/arrow/fx/coroutines/PredefTest.kt | 35 +- .../api/arrow-fx-coroutines.api | 128 +-- .../kotlin/arrow/fx/coroutines/Resource.kt | 991 ++++++------------ .../fx/coroutines/continuations/resource.kt | 57 - .../arrow/fx/coroutines/ResourceTest.kt | 451 -------- .../kotlin/arrow/fx/coroutines/ScopeSpec.kt | 508 +++++++++ .../arrow/fx/coroutines/ResourceExtensions.kt | 157 ++- .../kotlin/arrow/fx/coroutines/FlowJvmTest.kt | 52 +- .../arrow/fx/coroutines/ParMap2JvmTest.kt | 46 +- .../arrow/fx/coroutines/ParMap3JvmTest.kt | 28 +- .../arrow/fx/coroutines/ParMap4JvmTest.kt | 34 +- .../arrow/fx/coroutines/ParMap5JvmTest.kt | 35 +- .../arrow/fx/coroutines/ParMap6JvmTest.kt | 33 +- .../arrow/fx/coroutines/ParMap7JvmTest.kt | 34 +- .../arrow/fx/coroutines/ParMap8JvmTest.kt | 37 +- .../fx/coroutines/ParTraverseEitherJvmTest.kt | 3 +- .../arrow/fx/coroutines/ParTraverseJvmTest.kt | 8 +- .../coroutines/ParTraverseValidatedJvmTest.kt | 3 +- .../arrow/fx/coroutines/RaceNJvmTest.kt | 102 +- .../arrow/fx/coroutines/ResourceTestJvm.kt | 50 +- .../kotlin/examples/example-resource-01.kt | 5 - .../kotlin/examples/example-resource-02.kt | 30 +- .../kotlin/examples/example-resource-03.kt | 46 +- .../kotlin/examples/example-resource-04.kt | 38 +- .../kotlin/examples/example-resource-05.kt | 45 +- .../kotlin/examples/example-resource-06.kt | 37 +- .../kotlin/examples/example-resource-07.kt | 38 +- .../kotlin/examples/example-resource-08.kt | 33 +- .../kotlin/examples/example-resource-09.kt | 26 - .../kotlin/examples/example-resource-10.kt | 31 - .../kotlin/examples/example-resource-11.kt | 31 - .../example-resource-computations-01.kt | 36 - .../examples/example-resourceextensions-01.kt | 6 +- .../examples/example-resourceextensions-02.kt | 14 +- .../examples/example-resourceextensions-03.kt | 14 +- .../examples/example-resourceextensions-04.kt | 16 +- .../examples/example-resourceextensions-05.kt | 14 + 41 files changed, 1488 insertions(+), 1818 deletions(-) delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/continuations/resource.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-10.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-11.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-computations-01.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt index 94f76c710c5..0f623ea19fe 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt @@ -387,9 +387,9 @@ import kotlin.coroutines.resumeWithException * - * In the following example, we are creating and using a service that has a dependency on two resources: A database and a processor. All resources need to be closed in the correct order at the end. - * However, this program is not safe because it is prone to leak `dataSource` and `userProcessor` when an exception or cancellation signal occurs whilst using the service. - * As a consequence of the resource leak, this program does not guarantee the correct release of resources if something fails while acquiring or using the resource. Additionally manually keeping track of acquisition effects is an unnecessary overhead. - * - * We can split the above program into 3 different steps: - * 1. Acquiring the resource - * 2. Using the resource - * 3. Releasing the resource with either [ExitCase.Completed], [ExitCase.Failure] or [ExitCase.Cancelled]. - * - * That is exactly what `Resource` does, and how we can solve our problem: * - * # Constructing Resource + * If we were using Kotlin JVM, we might've relied on `Closeable` or `AutoCloseable` and rewritten our code to: * - * Creating a resource can be easily done by the `resource` DSL, - * and there are two ways to define the finalizers with `release` or `releaseCase`. + * + * ```kotlin + * suspend fun main(): Unit { + * UserProcessor().use { userProcessor -> + * userProcessor.start() + * DataSource().use { dataSource -> + * dataSource.connect() + * Service(dataSource, userProcessor).processData() + * } + * } * } * ``` * * - * Here `releaseCase` also signals with what [ExitCase] state the `use` step finished. - * - * # Using and composing Resource - * - * Arrow offers the same elegant `bind` DSL for Resource as you might be familiar with from Arrow Core. - * - * ```kotlin - * import arrow.fx.coroutines.* - * import arrow.fx.coroutines.continuations.resource + * However, while we fixed closing of `UserProcessor` and `DataSource` there are issues still with this code: + * 1. It requires implementing `Closeable` or `AutoCloseable`, only possible for Kotlin JVM, not available for Kotlin MPP + * 2. Requires implementing interface, or wrapping external types with i.e. `class CloseableOf(val type: A): Closeable`. + * 3. Requires nesting of different resources in callback tree, not composable. + * 4. Enforces `close` method name, renamed `UserProcessor#shutdown` to `close` + * 5. Cannot run suspend functions upon _fun close(): Unit_. + * 6. No exit signal, we don't know if we exited successfully, with an error or cancellation. + * + * [Resource] solves of these issues. It defines 3 different steps: + * 1. Acquiring the resource of `A`. + * 2. Using `A`. + * 3. Releasing `A` with [ExitCase.Completed], [ExitCase.Failure] or [ExitCase.Cancelled]. + * + * We rewrite our previous example to [Resource] below by: + * 1. Define [Resource] for `UserProcessor`. + * 2. Define [Resource] for `DataSource`, that also logs the [ExitCase]. + * 3. Compose `UserProcessor` and `DataSource` [Resource] together into a [Resource] for `Service`. + * + * + * ```kotlin + * val userProcessor: Resource = resource({ + * UserProcessor().also { it.start() } + * }) { p, _ -> p.shutdown() } * - * val userProcessor = resource { - * UserProcessor().also(UserProcessor::start) - * } release UserProcessor::shutdown - * - * val dataSource = resource { + * val dataSource: Resource = resource({ * DataSource().also { it.connect() } - * } release DataSource::close + * }) { ds, exitCase -> + * println("Releasing $ds with exit: $exitCase") + * withContext(Dispatchers.IO) { ds.close() } + * } * - * suspend fun main(): Unit { - * resource { - * parZip({ userProcessor.bind() }, { dataSource.bind() }) { userProcessor, ds -> - * Service(ds, userProcessor) - * } - * }.use { service -> service.processData() } + * val service: Resource = resource { + * Service(dataSource.bind(), userProcessor.bind()) + * } + * + * suspend fun main(): Unit = resourceScope { + * val data = service.bind().processData() + * println(data) * } * ``` * * - * [Resource]s are immutable and can be composed using [zip] or [parZip]. - * [Resource]s guarantee that their release finalizers are always invoked in the correct order when an exception is raised or the context where the program is running gets canceled. + * There is a lot going on in the snippet above, which we'll analyse in the sections below. + * Looking at the above example it should already give you some idea if the capabilities of [Resource]. * - * To achieve this [Resource] ensures that the `acquire` & `release` step are [NonCancellable]. - * If a cancellation signal, or an exception is received during `acquire`, the resource is assumed to not have been acquired and thus will not trigger the release function. - * => Any composed resources that are already acquired they will be guaranteed to release as expected. + * ## Resource constructors * - * If you don't need a data-type like [Resource] but want a function alternative to `try/catch/finally` with automatic error composition, - * and automatic [NonCancellable] `acquire` and `release` steps use [bracketCase] or [bracket]. - **/ -public sealed class Resource { - - /** - * Use the created resource - * When done will run all finalizers - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * class DataSource { - * fun connect(): Unit = println("Connecting dataSource") - * fun users(): List = listOf("User-1", "User-2", "User-3") - * fun close(): Unit = println("Closed dataSource") - * } - * - * suspend fun main(): Unit { - * val dataSource = resource { - * DataSource().also { it.connect() } - * } release DataSource::close - * - * val res = dataSource - * .use { ds -> "Using data source: ${ds.users()}" } - * .also(::println) - * } - * ``` - * - */ - @Suppress("UNCHECKED_CAST") - public tailrec suspend infix fun use(f: suspend (A) -> B): B = - when (this) { - is Dsl -> { - val effect = ResourceScopeImpl() - val b = try { - val a = dsl(effect) - f(a) - } catch (e: Throwable) { - val ex = if (e is CancellationException) ExitCase.Cancelled(e) else ExitCase.Failure(e) - val ee = withContext(NonCancellable) { - effect.finalizers.get().cancelAll(ex, e) ?: e - } - throw ee - } - withContext(NonCancellable) { - effect.finalizers.get().cancelAll(ExitCase.Completed)?.let { throw it } - } - b - } - - is Allocate -> bracketCase(acquire, f, release) - is Bind<*, *> -> Dsl { - val any = source.bind() - val ff = this@Resource.f as (Any?) -> Resource - ff(any).bind() - }.use(f) - - is Defer -> resource().use(f) - } - - public fun map(f: suspend (A) -> B): Resource = - arrow.fx.coroutines.continuations.resource { f(bind()) } - - /** Useful for setting up/configuring an acquired resource */ - public fun tap(f: suspend (A) -> Unit): Resource = - arrow.fx.coroutines.continuations.resource { bind().also { f(it) } } - - public fun ap(ff: Resource<(A) -> B>): Resource = - arrow.fx.coroutines.continuations.resource { - val a = bind() - ff.bind()(a) - } - - /** - * Create a resource value of [B] from a resource [A] by mapping [f]. - * - * Useful when there is a need to create resources that depend on other resources, - * for combining independent values [zip] provides nicer syntax without the need for callback nesting. - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * object Connection - * class DataSource { - * fun connect(): Unit = println("Connecting dataSource") - * fun connection(): Connection = Connection - * fun close(): Unit = println("Closed dataSource") - * } - * - * class Database(private val database: DataSource) { - * fun init(): Unit = println("Database initialising . . .") - * fun shutdown(): Unit = println("Database shutting down . . .") - * } - * - * suspend fun main(): Unit { - * val dataSource = resource { - * DataSource().also { it.connect() } - * } release DataSource::close - * - * fun database(ds: DataSource): Resource = - * resource { - * Database(ds).also(Database::init) - * } release Database::shutdown - * - * dataSource.flatMap(::database) - * .use { println("Using database which uses dataSource") } - * } - * ``` - * - * - * @see zip to combine independent resources together - * @see parZip for combining independent resources in parallel - */ - public fun flatMap(f: (A) -> Resource): Resource = arrow.fx.coroutines.continuations.resource { - f(bind()).bind() - } - - public inline fun zip(other: Resource, crossinline combine: (A, B) -> C): Resource = - arrow.fx.coroutines.continuations.resource { - combine(bind(), other.bind()) - } - - public fun zip(other: Resource): Resource> = - zip(other, ::Pair) - - /** - * Combines two independent resource values with the provided [map] function, - * returning the resulting immutable [Resource] value. - * The finalizers run in order of left to right by using [flatMap] under the hood, - * but [zip] provides a nicer syntax for combining values that don't depend on each-other. - * - * Useful to compose up to 9 independent resources, - * see example for more details on how to use in code. - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * class UserProcessor { - * fun start(): Unit = println("Creating UserProcessor") - * fun shutdown(): Unit = println("Shutting down UserProcessor") - * fun process(ds: DataSource): List = - * ds.users().map { "Processed $it" } - * } - * - * class DataSource { - * fun connect(): Unit = println("Connecting dataSource") - * fun users(): List = listOf("User-1", "User-2", "User-3") - * fun close(): Unit = println("Closed dataSource") - * } - * - * class Service(val db: DataSource, val userProcessor: UserProcessor) { - * suspend fun processData(): List = userProcessor.process(db) - * } - * - * val userProcessor = resource { - * UserProcessor().also(UserProcessor::start) - * } release UserProcessor::shutdown - * - * val dataSource = resource { - * DataSource().also { it.connect() } - * } release DataSource::close - * - * suspend fun main(): Unit { - * userProcessor.zip(dataSource) { userProcessor, ds -> - * Service(ds, userProcessor) - * }.use { service -> service.processData() } - * } - * ``` - * - * - * @see parZip if you want to combine independent resources in parallel - * @see flatMap to combine resources that rely on each-other. - */ - public inline fun zip( - b: Resource, - c: Resource, - crossinline map: (A, B, C) -> D, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind()) - } - - public inline fun zip( - b: Resource, - c: Resource, - d: Resource, - crossinline map: (A, B, C, D) -> E, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind(), d.bind()) - } - - public inline fun zip( - b: Resource, - c: Resource, - d: Resource, - e: Resource, - crossinline map: (A, B, C, D, E) -> G, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind(), d.bind(), e.bind()) - } - - public inline fun zip( - b: Resource, - c: Resource, - d: Resource, - e: Resource, - f: Resource, - crossinline map: (A, B, C, D, E, F) -> G, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind()) - } - - public inline fun zip( - b: Resource, - c: Resource, - d: Resource, - e: Resource, - f: Resource, - g: Resource, - crossinline map: (A, B, C, D, E, F, G) -> H, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) - } - - public inline fun zip( - b: Resource, - c: Resource, - d: Resource, - e: Resource, - f: Resource, - g: Resource, - h: Resource, - crossinline map: (A, B, C, D, E, F, G, H) -> I, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) - } - - public inline fun zip( - b: Resource, - c: Resource, - d: Resource, - e: Resource, - f: Resource, - g: Resource, - h: Resource, - i: Resource, - crossinline map: (A, B, C, D, E, F, G, H, I) -> J, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) - } - - public inline fun zip( - b: Resource, - c: Resource, - d: Resource, - e: Resource, - f: Resource, - g: Resource, - h: Resource, - i: Resource, - j: Resource, - crossinline map: (A, B, C, D, E, F, G, H, I, J) -> K, - ): Resource = - arrow.fx.coroutines.continuations.resource { - map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind()) - } - - public fun parZip(fb: Resource, f: suspend (A, B) -> C): Resource = - parZip(Dispatchers.Default, fb, f) - - /** - * Composes two [Resource]s together by zipping them in parallel, - * by running both their `acquire` handlers in parallel, and both `release` handlers in parallel. - * - * Useful in the case that starting a resource takes considerable computing resources or time. - * - * ```kotlin - * import arrow.fx.coroutines.* - * import kotlinx.coroutines.delay - * - * class UserProcessor { - * suspend fun start(): Unit { delay(750); println("Creating UserProcessor") } - * fun shutdown(): Unit = println("Shutting down UserProcessor") - * fun process(ds: DataSource): List = - * ds.users().map { "Processed $it" } - * } - * - * class DataSource { - * suspend fun connect(): Unit { delay(1000); println("Connecting dataSource") } - * fun users(): List = listOf("User-1", "User-2", "User-3") - * fun close(): Unit = println("Closed dataSource") - * } - * - * class Service(val db: DataSource, val userProcessor: UserProcessor) { - * suspend fun processData(): List = userProcessor.process(db) - * } - * - * val userProcessor = resource { - * UserProcessor().also { it.start() } - * } release UserProcessor::shutdown - * - * val dataSource = resource { - * DataSource().also { it.connect() } - * } release DataSource::close - * - * suspend fun main(): Unit { - * userProcessor.parZip(dataSource) { userProcessor, ds -> - * Service(ds, userProcessor) - * }.use { service -> service.processData() } - * } - * ``` - * - */ - public fun parZip( - ctx: CoroutineContext = Dispatchers.Default, - fb: Resource, - f: suspend (A, B) -> C, - ): Resource = - arrow.fx.coroutines.continuations.resource { - parZip(ctx, { this@Resource.bind() }, { fb.bind() }) { a, b -> f(a, b) } - } - - @Deprecated( - "Bind is being deprecated. Use resource DSL instead", - ReplaceWith( - "resource { f(source.bind()) }", - "arrow.fx.coroutines.continuations.resource" - ) - ) - public class Bind(public val source: Resource, public val f: (A) -> Resource) : Resource() - - public class Allocate( - public val acquire: suspend () -> A, - public val release: suspend (A, ExitCase) -> Unit, - ) : Resource() - - @Deprecated( - "Defer is being deprecated. Use resource DSL instead", - ReplaceWith( - "resource { resource.invoke().bind() }", - "arrow.fx.coroutines.continuations.resource" - ) - ) - public class Defer(public val resource: suspend () -> Resource) : Resource() - - public data class Dsl(public val dsl: suspend ResourceScope.() -> A) : Resource() - - public companion object { - - @PublishedApi - @Deprecated("This will be removed from the binary in Arrow 2.0", level = DeprecationLevel.ERROR) - internal val unit: Resource = just(Unit) - - /** - * Construct a [Resource] from an allocating function [acquire] and a release function [release]. - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * suspend fun acquireResource(): Int = 42.also { println("Getting expensive resource") } - * suspend fun releaseResource(r: Int, exitCase: ExitCase): Unit = println("Releasing expensive resource: $r, exit: $exitCase") - * - * suspend fun main(): Unit { - * val resource = Resource(::acquireResource, ::releaseResource) - * resource.use { - * println("Expensive resource under use! $it") - * } - * } - * ``` - * - */ - public operator fun invoke( - acquire: suspend () -> A, - release: suspend (A, ExitCase) -> Unit, - ): Resource = Allocate(acquire, release) - - /** - * Create a [Resource] from a pure value [A]. - */ - public fun just(r: A): Resource = - Resource({ r }, { _, _ -> Unit }) - - @Deprecated( - "defer is being deprecated. Use resource DSL instead", - ReplaceWith( - "resource { f().bind() }", - "arrow.fx.coroutines.continuations.resource" - ) - ) - public fun defer(f: suspend () -> Resource): Resource = - Resource.Defer(f) - } -} - -/** - * Marker for `suspend () -> A` to be marked as the [Use] action of a [Resource]. - * Offers a convenient DSL to use [Resource] for simple resources. + * [Resource] works entirely through a DSL, + * which allows _installing_ a `Resource` through the `suspend fun install(acquire: suspend () -> A, release: suspend (A, ExitCase) -> Unit): A` function. * + * `acquire` is used to _allocate_ the `Resource`, + * and before returning the resource `A` it also install the `release` handler into the `ResourceScope`. + * + * We can use `suspend fun` with `Scope` as an extension function receiver to create synthetic constructors for our `Resource`s. + * If you're using _context receivers_ you can also use `context(Scope)` instead. + * + * * ```kotlin - * import arrow.fx.coroutines.* + * suspend fun ResourceScope.userProcessor(): UserProcessor = + * install({ UserProcessor().also { it.start() } }) { processor, _ -> + * processor.shutdown() + * } + * ``` * - * class File(url: String) { - * suspend fun open(): File = this - * suspend fun close(): Unit {} - * override fun toString(): String = "This file contains some interesting content!" + * We can of course also create `lazy` representations of this by wrapping `install` in [resource] and returning the `suspend lambda` value instead. + * + * ```kotlin + * val userProcessor: Resource = resource { + * val x: UserProcessor = install( + * { UserProcessor().also { it.start() } }, + * { processor, _ -> processor.shutdown() } + * ) + * x * } + * ``` * - * suspend fun openFile(uri: String): File = File(uri).open() - * suspend fun closeFile(file: File): Unit = file.close() - * suspend fun fileToString(file: File): String = file.toString() + * There is also a convenience operator for this pattern, but you might have preferred `ResourceScope::userProcessor` instead since it yields the same result. * - * suspend fun main(): Unit { - * val res = resource { - * openFile("data.json") - * } release { file -> - * closeFile(file) - * } use { file -> - * fileToString(file) + * ```kotlin + * val userProcessor2: Resource = resource({ + * UserProcessor().also { it.start() } + * }) { processor, _ -> processor.shutdown() } + * + * val userProcessor3: Resource = ResourceScope::userProcessor + * ``` + * + * + * ## Scope DSL + * + * The [ResourceScope] DSL allows you to _install_ resources, and interact with them in a safe way. + * + * Arrow offers the same elegant `bind` DSL for Resource composition as you might be familiar with from Arrow Core. Which we've already seen above, in our first example. + * What is more interesting, is that we can also compose it with any other existing pattern from Arrow! + * Let's compose our `UserProcessor` and `DataSource` in parallel, so that their `start` and `connect` methods can run in parallel. + * + * + * ```kotlin + * suspend fun ResourceScope.userProcessor(): UserProcessor = + * install({ UserProcessor().also { it.start() } }){ p,_ -> p.shutdown() } + * + * suspend fun ResourceScope.dataSource(): DataSource = + * install({ DataSource().also { it.connect() } }) { ds, _ -> ds.close() } + * + * suspend fun main(): Unit = resourceScope { + * val service = parZip({ userProcessor() }, { dataSource() }) { userProcessor, ds -> + * Service(ds, userProcessor) + * } + * val data = service.processData() + * println(data) * } * ``` - * - */ -@Deprecated( - "Use the resource computation DSL instead", - ReplaceWith( - "resource { acquire() }", - "arrow.fx.coroutines.continuations.resource" - ) -) -public inline class Use(internal val acquire: suspend () -> A) + * + * + * ## Conclusion + * + * [Resource] guarantee that their release finalizers are always invoked in the correct order when an exception is raised or the [kotlinx.coroutines.Job] is running gets canceled. + * + * To achieve this [Resource] ensures that the `acquire` & `release` step are [NonCancellable]. + * If a cancellation signal, or an exception is received during `acquire`, the resource is assumed to not have been acquired and thus will not trigger the release function. + * => Any composed resources that are already acquired they will be guaranteed to release as expected. + * + * If you don't need a data-type like [Resource] but want a function alternative to `try/catch/finally` with automatic error composition, + * and automatic [NonCancellable] `acquire` and `release` steps use [bracketCase] or [bracket]. + **/ +public typealias Resource = suspend ResourceScope.() -> A /** - * Marks an [acquire] operation as the [Resource.use] step of a [Resource]. + * This Marker exists to prevent being able to call `bind` from `install`, and its derived methods. + * This is done to ensure correct usage of [ResourceScope]. */ -@Deprecated( - "Use the resource computation DSL instead", - ReplaceWith( - "resource { acquire() }", - "arrow.fx.coroutines.continuations.resource" - ) -) -public fun resource(acquire: suspend () -> A): Use = Use(acquire) - -@Deprecated("Use the resource computation DSL instead") -public infix fun Use.release(release: suspend (A) -> Unit): Resource = - Resource(acquire) { a, _ -> release(a) } +@ResourceDSL +public object AcquireStep -/** - * Composes a [release] action to a [Resource.use] action creating a [Resource]. - */ -public infix fun Resource.release(release: suspend (A) -> Unit): Resource = - arrow.fx.coroutines.continuations.resource { +@ResourceDSL +public interface ResourceScope { + + /** + * Compose another [Resource] program into this [ResourceScope]. + * All [release] functions [install]ed into the [Resource] lambda will be installed in this [ResourceScope] while respecting the FIFO order. + */ + @ResourceDSL + public suspend fun Resource.bind(): A + + /** + * Install [A] into the [ResourceScope]. + * It's [release] function will be called with the appropriate [ExitCase] if this [ResourceScope] finishes. + * It results either in [ExitCase.Completed], [ExitCase.Cancelled] or [ExitCase.Failure] depending on the terminal state of [Resource] lambda. + */ + @ResourceDSL + public suspend fun install( + acquire: suspend AcquireStep.() -> A, + release: suspend (A, ExitCase) -> Unit, + ): A + + /** Composes a [release] action to a [Resource] value before binding. */ + @ResourceDSL + public suspend infix fun Resource.release(release: suspend (A) -> Unit): A { val a = bind() - Resource({ a }, { _, _ -> release(a) }).bind() + return install({ a }) { a, _ -> release(a) } } - -@Deprecated("Use the resource computation DSL instead") -public infix fun Use.releaseCase(release: suspend (A, ExitCase) -> Unit): Resource = - Resource(acquire, release) - -/** - * Composes a [releaseCase] action to a [Resource.use] action creating a [Resource]. - */ -public infix fun Resource.releaseCase(release: suspend (A, ExitCase) -> Unit): Resource = - arrow.fx.coroutines.continuations.resource { + + /** Composes a [releaseCase] action to a [Resource] value before binding. */ + @ResourceDSL + public suspend infix fun Resource.releaseCase(release: suspend (A, ExitCase) -> Unit): A { val a = bind() - Resource({ a }, { _, ex -> release(a, ex) }).bind() + return install({ a }, release) } + + public suspend infix fun onRelease(release: suspend (ExitCase) -> Unit): Unit = + install({ }) { _, exitCase -> release(exitCase) } +} -@Deprecated("traverseResource is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)")) -public inline fun Iterable.traverseResource(crossinline f: (A) -> Resource): Resource> = - arrow.fx.coroutines.continuations.resource { - map { a -> - f(a).bind() - } - } +@ScopeDSL +public fun resource(block: suspend ResourceScope.() -> A): Resource = block /** - * Traverse this [Iterable] and collects the resulting `Resource` of [f] into a `Resource>`. + * The [resourceScope] function creates the [ResourceScope] instances, + * runs the user [action] while allocating the _installed_ resources. + * upon [ExitCase.Completed], [ExitCase.Cancelled] or [ExitCase.Failure] runs all the `release` finalizers. * - * ```kotlin - * import arrow.fx.coroutines.* + * + * ```kotlin + * suspend fun main(): Unit = resourceScope { + * val dataSource = install({ + * DataSource().also { it.connect() } + * }) { ds, _ -> ds.close() } * - * suspend fun openFile(uri: String): File = File(uri).open() - * suspend fun closeFile(file: File): Unit = file.close() - * suspend fun fileToString(file: File): String = file.toString() - * - * suspend fun main(): Unit { - * val res: List = listOf( - * "data.json", - * "user.json", - * "resource.json" - * ).traverse { uri -> - * resource { - * openFile(uri) - * } release { file -> - * closeFile(file) - * } - * }.use { files -> - * files.map { fileToString(it) } - * } - * res.forEach(::println) + * println("Using data source: ${dataSource.users()}") * } * ``` - * + * */ -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(crossinline f: (A) -> Resource): Resource> = - arrow.fx.coroutines.continuations.resource { - map { a -> - f(a).bind() +@ScopeDSL +public suspend fun resourceScope(action: suspend ResourceScope.() -> A): A { + val scope = ResourceScopeImpl() + val a: A = try { + action(scope) + } catch (e: Throwable) { + val ex = if (e is CancellationException) ExitCase.Cancelled(e) else ExitCase.Failure(e) + val ee = withContext(NonCancellable) { + scope.cancelAll(ex, e) ?: e } + throw ee + } + withContext(NonCancellable) { + scope.cancelAll(ExitCase.Completed)?.let { throw it } } + return a +} + +public suspend infix fun Resource.use(f: suspend (A) -> B): B = + resourceScope { f(bind()) } /** - * Sequences this [Iterable] of [Resource]s. - * [Iterable.map] and [sequence] is equivalent to [traverse]. + * Construct a [Resource] from an allocating function [acquire] and a release function [release]. * * ```kotlin - * import arrow.fx.coroutines.* + * import arrow.fx.coroutines.resource + * import arrow.fx.coroutines.resourceScope * - * class File(url: String) { - * suspend fun open(): File = this - * suspend fun close(): Unit {} - * override fun toString(): String = "This file contains some interesting content!" + * val resource = resource { + * install({ 42.also { println("Getting expensive resource") } }) { r, exitCase -> + * println("Releasing expensive resource: $r, exit: $exitCase") + * } * } * - * suspend fun openFile(uri: String): File = File(uri).open() - * suspend fun closeFile(file: File): Unit = file.close() - * suspend fun fileToString(file: File): String = file.toString() - * - * suspend fun main(): Unit { - * val res: List = listOf( - * "data.json", - * "user.json", - * "resource.json" - * ).map { uri -> - * resource { - * openFile(uri) - * } release { file -> - * closeFile(file) - * } - * }.sequence().use { files -> - * files.map { fileToString(it) } - * } - * res.forEach(::println) + * suspend fun main(): Unit = resourceScope { + * val res = resource.bind() + * println("Expensive resource under use! $res") * } * ``` - * + * */ -@Suppress("NOTHING_TO_INLINE") -public inline fun Iterable>.sequence(): Resource> = - traverse(::identity) +public fun resource( + acquire: suspend () -> A, + release: suspend (A, ExitCase) -> Unit, +): Resource = resource { + install({ acquire() }, release) +} /** - * Runs [Resource.use] and emits [A] of the resource + * Runs [use] and emits [A] of the resource * * ```kotlin - * import arrow.fx.coroutines.* + * import arrow.fx.coroutines.asFlow + * import arrow.fx.coroutines.closeable + * import kotlinx.coroutines.Dispatchers + * import kotlinx.coroutines.flow.flow + * import kotlinx.coroutines.flow.Flow + * import kotlinx.coroutines.flow.asFlow + * import kotlinx.coroutines.flow.emitAll + * import kotlinx.coroutines.flow.flatMapConcat + * import kotlinx.coroutines.flow.flowOn + * import kotlinx.coroutines.flow.map + * import java.nio.file.Path + * import kotlin.io.path.useLines * * fun Flow.writeAll(path: Path): Flow = - * Resource.fromCloseable { path.toFile().outputStream() } + * closeable { path.toFile().outputStream() } * .asFlow() - * .flatMapConcat { writer -> byteFlow.map { writer.write(it) } } + * .flatMapConcat { writer -> map { writer.write(it) } } * .flowOn(Dispatchers.IO) * * fun Path.readAll(): Flow = flow { - * path.useLines { lines -> emitAll(lines) } + * useLines { lines -> emitAll(lines.asFlow()) } * } * - * Path("example.kt") - * .readAll() - * . + * suspend fun main() { + * Path.of("example.kt") + * .readAll() + * .collect(::println) + * } * ``` + * */ public fun Resource.asFlow(): Flow = flow { - use { - emit(it) + resourceScope { + emit(bind()) } } -private class ResourceScopeImpl : ResourceScope { - val finalizers: AtomicRef Unit>> = AtomicRef(emptyList()) - override suspend fun Resource.bind(): A = - when (this) { - is Resource.Dsl -> dsl.invoke(this@ResourceScopeImpl) - is Resource.Allocate -> bracketCase({ - val a = acquire() - val finalizer: suspend (ExitCase) -> Unit = { ex: ExitCase -> release(a, ex) } - finalizers.update(finalizer::prependTo) - a - }, ::identity, { a, ex -> - // Only if ExitCase.Failure, or ExitCase.Cancelled during acquire we cancel - // Otherwise we've saved the finalizer, and it will be called from somewhere else. - if (ex != ExitCase.Completed) { - val e = finalizers.get().cancelAll(ex) - val e2 = runCatching { release(a, ex) }.exceptionOrNull() - Platform.composeErrors(e, e2)?.let { throw it } - } - }) - - is Resource.Bind<*, *> -> { - val dsl: suspend ResourceScope.() -> A = { - val any = source.bind() - val ff = f as (Any?) -> Resource - ff(any).bind() - } - dsl(this@ResourceScopeImpl) +@JvmInline +private value class ResourceScopeImpl( + private val finalizers: AtomicRef Unit>> = AtomicRef(emptyList()), +) : ResourceScope { + override suspend fun Resource.bind(): A = invoke(this@ResourceScopeImpl) + + override suspend fun install(acquire: suspend AcquireStep.() -> A, release: suspend (A, ExitCase) -> Unit): A = + bracketCase({ + val a = acquire(AcquireStep) + val finalizer: suspend (ExitCase) -> Unit = { ex: ExitCase -> release(a, ex) } + finalizers.update(finalizer::prependTo) + a + }, ::identity, { a, ex -> + // Only if ExitCase.Failure, or ExitCase.Cancelled during acquire we cancel + // Otherwise we've saved the finalizer, and it will be called from somewhere else. + if (ex != ExitCase.Completed) { + val e = cancelAll(ex) + val e2 = kotlin.runCatching { release(a, ex) }.exceptionOrNull() + Platform.composeErrors(e, e2)?.let { throw it } } - - is Resource.Defer -> resource().bind() - } -} - -private suspend fun List Unit>.cancelAll( - exitCase: ExitCase, - first: Throwable? = null, -): Throwable? = fold(first) { acc, finalizer -> - val other = kotlin.runCatching { finalizer(exitCase) }.exceptionOrNull() - other?.let { - acc?.apply { addSuppressed(other) } ?: other - } ?: acc + }) + + suspend fun cancelAll( + exitCase: ExitCase, + first: Throwable? = null, + ): Throwable? = finalizers.get().fold(first) { acc, finalizer -> + val other = kotlin.runCatching { finalizer(exitCase) }.exceptionOrNull() + other?.let { + acc?.apply { addSuppressed(other) } ?: other + } ?: acc + } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/continuations/resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/continuations/resource.kt deleted file mode 100644 index 5b9e414771d..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/continuations/resource.kt +++ /dev/null @@ -1,57 +0,0 @@ -package arrow.fx.coroutines.continuations - -import arrow.fx.coroutines.Resource - -/** - * Computation block for the [Resource] type. - * The [Resource] allows us to describe resources as immutable values, - * and compose them together in simple ways. - * This way you can split the logic of what a `Resource` is and how it should be closed from how you use them. - * - * * # Using and composing Resource - * - * ```kotlin - * import arrow.fx.coroutines.continuations.resource - * import arrow.fx.coroutines.release - * - * class UserProcessor { - * fun start(): Unit = println("Creating UserProcessor") - * fun shutdown(): Unit = println("Shutting down UserProcessor") - * fun process(ds: DataSource): List = - * ds.users().map { "Processed $it" } - * } - * - * class DataSource { - * fun connect(): Unit = println("Connecting dataSource") - * fun users(): List = listOf("User-1", "User-2", "User-3") - * fun close(): Unit = println("Closed dataSource") - * } - * - * class Service(val db: DataSource, val userProcessor: UserProcessor) { - * suspend fun processData(): List = userProcessor.process(db) - * } - * - * //sampleStart - * val userProcessor = resource { - * UserProcessor().also(UserProcessor::start) - * } release UserProcessor::shutdown - * - * val dataSource = resource { - * DataSource().also { it.connect() } - * } release DataSource::close - * - * suspend fun main(): Unit { - * resource { - * Service(dataSource.bind(), userProcessor.bind()) - * }.use { service -> service.processData() } - * } - * //sampleEnd - * ``` - * - */ -public interface ResourceScope { - public suspend fun Resource.bind(): A -} - -public fun resource(f: suspend ResourceScope.() -> A): Resource = - Resource.Dsl(f) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt deleted file mode 100644 index f68e052ed3d..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt +++ /dev/null @@ -1,451 +0,0 @@ -package arrow.fx.coroutines - -import arrow.core.Either -import arrow.core.identity -import arrow.core.left -import io.kotest.assertions.fail -import io.kotest.matchers.collections.shouldContainExactly -import io.kotest.matchers.should -import io.kotest.matchers.shouldBe -import io.kotest.matchers.types.shouldBeInstanceOf -import io.kotest.matchers.types.shouldBeTypeOf -import io.kotest.property.Arb -import io.kotest.property.arbitrary.bool -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.map -import io.kotest.property.arbitrary.negativeInt -import io.kotest.property.arbitrary.positiveInt -import io.kotest.property.arbitrary.string -import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.async -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.toList - -class ResourceTest : ArrowFxSpec( - spec = { - - "Can consume resource" { - checkAll(Arb.int()) { n -> - val r = Resource({ n }, { _, _ -> Unit }) - - r.use { it + 1 } shouldBe n + 1 - } - } - - "flatMap resource is released first" { - checkAll(Arb.positiveInt(), Arb.negativeInt()) { a, b -> - val l = mutableListOf() - fun r(n: Int) = Resource({ n.also(l::add) }, { it, _ -> l.add(-it) }) - - r(a).flatMap { r(it + b) } - .use { it + 1 } shouldBe (a + b) + 1 - - l.shouldContainExactly(a, a + b, -a - b, -a) - } - } - - "value resource is released with Complete" { - checkAll(Arb.int()) { n -> - val p = CompletableDeferred() - Resource({ n }, { _, ex -> require(p.complete(ex)) }) - .use { Unit } - - p.await() shouldBe ExitCase.Completed - } - } - - "error resource finishes with error" { - checkAll(Arb.throwable()) { e -> - val p = CompletableDeferred() - val r = Resource({ throw e }, { _, ex -> require(p.complete(ex)) }) - - Either.catch { - r.use { it + 1 } - } should leftException(e) - } - } - - "never use can be cancelled with ExitCase.Completed" { - checkAll(Arb.int()) { n -> - val p = CompletableDeferred() - val start = CompletableDeferred() - val r = Resource({ n }, { _, ex -> require(p.complete(ex)) }) - - val f = async { - r.use { - require(start.complete(Unit)) - never() - } - } - - start.await() - f.cancel() - p.await().shouldBeInstanceOf() - } - } - - "traverseResource: identity" { - checkAll( - Arb.list(Arb.int()), - Arb.functionAToB(Arb.string()) - ) { list, f -> - list.traverse { Resource.just(f(it)) } resourceShouldBe Resource.just(list.map(f)) - } - } - - "traverse: map + sequence == traverse" { - checkAll( - Arb.list(Arb.int()), - Arb.string().map { { _: Int -> Resource.just(it) } } - ) { list, f -> - list.traverse(f) resourceShouldBe list.map(f).sequence() - } - } - "traverse: parallelComposition" { - checkAll( - Arb.list(Arb.int()), - Arb.functionAToB(Arb.string()), - Arb.functionAToB(Arb.string()) - ) { list, f, g -> - - val ff = list.traverse { Resource.just(f(it)) } - val gg = list.traverse { Resource.just(g(it)) } - - val result = ff.zip(gg).map { (a, b) -> - a.zip(b) - } - - list.traverse { Resource.just(f(it) to g(it)) } resourceShouldBe result - } - } - - "traverse: leftToRight" { - checkAll(Arb.list(Arb.int())) { list -> - list.traverse { Resource.just(it) } - .use(::identity) shouldBe list - } - } - - "Resource can close from either" { - val exit = CompletableDeferred() - arrow.core.computations.either { - arrow.fx.coroutines.continuations.resource { - Resource({ 1 }) { _, ex -> require(exit.complete(ex)) }.bind() - "error".left().bind() - 1 - }.use { it } - } shouldBe "error".left() - // Should be ExitCase.Cancelled but still Failure due to ShortCircuit - // Effect will fix this issue by properly shifting and cancelling - exit.await().shouldBeTypeOf() - } - - val depth: Int = 100 - - class CheckableAutoClose { - var started = true - fun close() { - started = false - } - } - - fun closeable(): Resource = - Resource({ CheckableAutoClose() }) { a, _ -> a.close() } - - "parZip - success" { - val all = (1..depth).traverse { closeable() }.parZip( - (1..depth).traverse { closeable() } - ) { a, b -> a + b }.use { all -> - all.also { all.forEach { it.started shouldBe true } } - } - all.forEach { it.started shouldBe false } - } - - fun generate(): Pair>, Resource> { - val promises = (1..depth).map { Pair(it, CompletableDeferred()) } - val res = promises.fold(Resource({ 0 }, { _, _ -> })) { acc, (i, promise) -> - acc.flatMap { ii: Int -> - Resource({ ii + i }) { _, _ -> - require(promise.complete(i)) - } - } - } - return Pair(promises.map { it.second }, res) - } - - "parZip - deep finalizers are called when final one blows" { - io.kotest.property.checkAll(3, Arb.int(10..100)) { - val (promises, resource) = generate() - assertThrowable { - resource.flatMap { - Resource({ throw RuntimeException() }) { _, _ -> } - }.parZip(Resource({ }) { _, _ -> }) { _, _ -> } - .use { fail("It should never reach here") } - }.shouldBeTypeOf() - - (1..depth).zip(promises) { i, promise -> - promise.await() shouldBe i - } - } - } - - "parZip - deep finalizers are called when final one cancels" { - io.kotest.property.checkAll(3, Arb.int(10..100)) { - val cancel = CancellationException(null, null) - val (promises, resource) = generate() - assertThrowable { - resource.flatMap { - Resource({ throw cancel }) { _, _ -> } - }.parZip(Resource({ }) { _, _ -> }) { _, _ -> } - .use { fail("It should never reach here") } - }.shouldBeTypeOf() - - (1..depth).zip(promises) { i, promise -> - promise.await() shouldBe i - } - } - } - - // Test multiple release triggers on acquire fail. - "parZip - Deep finalizers get called on left or right cancellation" { - checkAll(Arb.bool()) { isLeft -> - val cancel = CancellationException(null, null) - val (promises, resource) = generate() - val latch = CompletableDeferred() - assertThrowable { - val res = if (isLeft) Resource({ - latch.await() shouldBe (1..depth).sum() - throw cancel - }) { _, _ -> }.parZip(resource.flatMap { - Resource({ require(latch.complete(it)) }) { _, _ -> } - }) { _, _ -> } - else resource.flatMap { - Resource({ require(latch.complete(it)) }) { _, _ -> } - }.parZip(Resource({ - latch.await() shouldBe (1..depth).sum() - throw cancel - }) { _, _ -> }) { _, _ -> } - - res.use { fail("It should never reach here") } - }.shouldBeTypeOf() - - (1..depth).zip(promises) { i, promise -> - promise.await() shouldBe i - } - } - } - - "parZip - Right CancellationException on acquire" { - checkAll(Arb.int()) { i -> - val cancel = CancellationException(null, null) - val released = CompletableDeferred>() - val started = CompletableDeferred() - assertThrowable { - Resource({ require(started.complete(Unit)); i }, { ii, ex -> - require(released.complete(ii to ex)) - }).parZip(Resource({ started.await(); throw cancel }) { _, _ -> }) { _, _ -> } - .use { fail("It should never reach here") } - }.shouldBeTypeOf() - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - Left CancellationException on acquire" { - checkAll(Arb.int()) { i -> - val cancel = CancellationException(null, null) - val released = CompletableDeferred>() - val started = CompletableDeferred() - - assertThrowable { - Resource({ - started.await() - throw cancel - }) { _, _ -> } - .parZip(Resource({ require(started.complete(Unit)); i }, { ii, ex -> - require(released.complete(ii to ex)) - })) { _, _ -> } - .use { fail("It should never reach here") } - }.shouldBeTypeOf() - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - Right error on acquire" { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> - val released = CompletableDeferred>() - val started = CompletableDeferred() - assertThrowable { - Resource( - { require(started.complete(Unit)); i }, - { ii, ex -> require(released.complete(ii to ex)) } - ).parZip( - Resource({ started.await(); throw throwable }) { _, _ -> } - ) { _, _ -> } - .use { fail("It should never reach here") } - } shouldBe throwable - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - Left error on acquire" { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> - val released = CompletableDeferred>() - val started = CompletableDeferred() - assertThrowable { - Resource({ - started.await() - throw throwable - }) { _, _ -> } - .parZip( - Resource( - { require(started.complete(Unit)); i }, - { ii, ex -> require(released.complete(ii to ex)) } - )) { _, _ -> } - .use { fail("It should never reach here") } - } shouldBe throwable - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - Right CancellationException on release" { - checkAll(Arb.int()) { i -> - val cancel = CancellationException(null, null) - val released = CompletableDeferred>() - - assertThrowable { - Resource({ i }, { ii, ex -> require(released.complete(ii to ex)) }) - .parZip( - Resource({ }) { _, _ -> throw cancel } - ) { _, _ -> } - .use { } - }.shouldBeTypeOf() - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - Left CancellationException on release" { - checkAll(Arb.int()) { i -> - val cancel = CancellationException(null, null) - val released = CompletableDeferred>() - - assertThrowable { - Resource({ }) { _, _ -> throw cancel } - .parZip( - Resource({ i }, { ii, ex -> require(released.complete(ii to ex)) }) - ) { _, _ -> } - .use { /*fail("It should never reach here")*/ } - }.shouldBeTypeOf() - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - Right error on release" { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> - val released = CompletableDeferred>() - - assertThrowable { - Resource({ i }, { ii, ex -> require(released.complete(ii to ex)) }) - .parZip( - Resource({ }) { _, _ -> throw throwable } - ) { _, _ -> } - .use { } - } shouldBe throwable - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - Left error on release" { - checkAll(Arb.int(), Arb.throwable()) { i, throwable -> - val released = CompletableDeferred>() - - assertThrowable { - Resource({ }) { _, _ -> throw throwable } - .parZip( - Resource({ i }, { ii, ex -> require(released.complete(ii to ex)) }) - ) { _, _ -> } - .use { } - } shouldBe throwable - - val (ii, ex) = released.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } - - "parZip - error in use" { - checkAll(Arb.int(), Arb.int(), Arb.throwable()) { a, b, throwable -> - val releasedA = CompletableDeferred>() - val releasedB = CompletableDeferred>() - - assertThrowable { - Resource({ a }) { aa, ex -> require(releasedA.complete(aa to ex)) } - .parZip( - Resource({ b }) { bb, ex -> require(releasedB.complete(bb to ex)) } - ) { _, _ -> } - .use { throw throwable } - } shouldBe throwable - - val (aa, exA) = releasedA.await() - aa shouldBe a - exA.shouldBeTypeOf() - - val (bb, exB) = releasedB.await() - bb shouldBe b - exB.shouldBeTypeOf() - } - } - - "parZip - runs in parallel" { - checkAll(Arb.int(), Arb.int()) { a, b -> - val r = Atomic("") - val modifyGate = CompletableDeferred() - - Resource({ - modifyGate.await() - r.update { i -> "$i$a" } - }) { _, _ -> } - .parZip(Resource({ - r.set("$b") - require(modifyGate.complete(0)) - }) { _, _ -> }) { _a, _b -> _a to _b } - .use { - r.get() shouldBe "$b$a" - } - } - } - - "resource.asFlow()" { - checkAll(Arb.int()) { n -> - val r = Resource({ n }, { _, _ -> Unit }) - - r.asFlow().map { it + 1 }.toList() shouldBe listOf(n + 1) - } - } - } -) - -@Suppress("UNCHECKED_CAST") -private suspend infix fun Resource.resourceShouldBe(expected: Resource): Unit = - zip(expected).use { (a, b) -> a shouldBe b } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt new file mode 100644 index 00000000000..a0d9a3cebaa --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt @@ -0,0 +1,508 @@ +package arrow.fx.coroutines + +import arrow.core.Either +import arrow.core.continuations.either +import arrow.core.left +import io.kotest.assertions.fail +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.collections.shouldContainExactly +import io.kotest.matchers.should +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeInstanceOf +import io.kotest.matchers.types.shouldBeTypeOf +import io.kotest.property.Arb +import io.kotest.property.arbitrary.bool +import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.list +import io.kotest.property.arbitrary.negativeInt +import io.kotest.property.arbitrary.positiveInt +import io.kotest.property.checkAll +import io.kotest.property.arbitrary.string +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.async +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.toList + +class ResourceTest : StringSpec({ + + "acquire - success - identity" { + checkAll(Arb.int()) { n -> + resourceScope { + install({ n }) { _, _ -> } shouldBe n + } + } + } + + "respect FIFO order installed release functions" { + checkAll(Arb.positiveInt(), Arb.negativeInt()) { a, b -> + val order = mutableListOf() + + suspend fun ResourceScope.scoped(n: Int): Int = + install({ n.also(order::add) }, { it, _ -> order.add(-it) }) + + resourceScope { + val x = scoped(a) + val y = scoped(x + b) + y + 1 shouldBe (a + b) + 1 + } + + order.shouldContainExactly(a, a + b, -a - b, -a) + } + } + + "value resource is released with Complete" { + checkAll(Arb.int()) { n -> + val p = CompletableDeferred() + resourceScope { + install({ n }) { _, ex -> require(p.complete(ex)) } + } + p.await() shouldBe ExitCase.Completed + } + } + + "error resource finishes with error" { + checkAll(Arb.throwable()) { e -> + val p = CompletableDeferred() + suspend fun ResourceScope.failingScope(): Nothing = + install({ throw e }, { _, ex -> require(p.complete(ex)) }) + + Either.catch { + resourceScope { failingScope() } + } should leftException(e) + } + } + + "never use can be cancelled with ExitCase.Completed" { + checkAll(Arb.int()) { n -> + val p = CompletableDeferred() + val start = CompletableDeferred() + suspend fun ResourceScope.n(): Int = install({ n }, { _, ex -> require(p.complete(ex)) }) + + val f = async { + resourceScope { + n() + require(start.complete(Unit)) + never() + } + } + + start.await() + f.cancel() + p.await().shouldBeInstanceOf() + } + } + + "Map + bind (traverse)" { + checkAll( + Arb.list(Arb.int()), + Arb.functionAToB(Arb.string()) + ) { list, f -> + resourceScope { + list.map { + resource { f(it) }.bind() + } + } shouldBe list.map(f) + } + } + + "Resource can close from either" { + val exit = CompletableDeferred() + either { + resourceScope { + install({ 1 }) { _, ex -> + require(exit.complete(ex)) + } + shift("error") + } + } shouldBe "error".left() + exit.await().shouldBeTypeOf() + } + + val depth: Int = 10 + + class CheckableAutoClose { + var started = true + fun close() { + started = false + } + } + + "parZip - success" { + suspend fun ResourceScope.closeable(): CheckableAutoClose = + install({ CheckableAutoClose() } ) { a: CheckableAutoClose, _: ExitCase -> a.close() } + + resourceScope { + parZip({ + (1..depth).map { closeable() } + }, { + (1..depth).map { closeable() } + }, { a, b -> a + b }) + } + } + + fun generate(): Pair>, Resource> { + val promises = (1..depth).map { Pair(it, CompletableDeferred()) } + val res = promises.fold(resource({ 0 }, { _, _ -> })) { acc, (i, promise) -> + resource { + val ii = acc.bind() + install({ ii + i }) { _, _ -> + require(promise.complete(i)) + } + } + } + return Pair(promises.map { it.second }, res) + } + + "parZip - deep finalizers are called when final one blows" { + io.kotest.property.checkAll(3, Arb.int(10..100)) { + val (promises, resource) = generate() + shouldThrow { + resourceScope { + parZip({ + resource.bind() + throw RuntimeException() + }, { }) { _, _ -> } + fail("It should never reach here") + } + } + + (1..depth).zip(promises) { i, promise -> + promise.await() shouldBe i + } + } + } + + "parZip - deep finalizers are called when final one cancels" { + checkAll(3, Arb.int(10..100)) { + val cancel = CancellationException(null, null) + val (promises, resource) = generate() + shouldThrow { + resourceScope { + parZip({}, { + resource.bind() + throw cancel + }) { _, _ -> } + fail("It should never reach here") + } + } + + (1..depth).zip(promises) { i, promise -> + promise.await() shouldBe i + } + } + } + + // Test multiple release triggers on acquire fail. + "parZip - Deep finalizers get called on left or right cancellation" { + checkAll(Arb.bool()) { isLeft -> + val cancel = CancellationException(null, null) + val (promises, resource) = generate() + val latch = CompletableDeferred() + shouldThrow { + resourceScope { + if (isLeft) { + parZip({ + latch.await() shouldBe (1..depth).sum() + throw cancel + }, { + val i = resource.bind() + require(latch.complete(i)) + }) { _, _ -> } + } else { + parZip({ + val i = resource.bind() + require(latch.complete(i)) + }, { + latch.await() shouldBe (1..depth).sum() + throw cancel + }) { _, _ -> } + } + fail("It should never reach here") + } + } + + (1..depth).zip(promises) { i, promise -> + promise.await() shouldBe i + } + } + } + + "parZip - Right CancellationException on acquire" { + checkAll(Arb.int()) { i -> + val cancel = CancellationException(null, null) + val released = CompletableDeferred>() + val started = CompletableDeferred() + shouldThrow { + resourceScope { + parZip({ + install({ + require(started.complete(Unit)) + i }, { ii: Int, ex: ExitCase -> + require(released.complete(ii to ex)) + }) + }, { + started.await() + throw cancel + }) { _, _ -> } + fail("It should never reach here") + } + } + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - Left CancellationException on acquire" { + checkAll(Arb.int()) { i -> + val cancel = CancellationException(null, null) + val released = CompletableDeferred>() + val started = CompletableDeferred() + + shouldThrow { + resourceScope { + parZip({ + started.await() + throw cancel + }, { + install({ + require(started.complete(Unit)) + i }, { ii: Int, ex: ExitCase -> + require(released.complete(ii to ex)) + }) + }) { _, _ -> } + fail("It should never reach here") + } + } + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - Right error on acquire" { + checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + val released = CompletableDeferred>() + val started = CompletableDeferred() + shouldThrow { + resourceScope { + parZip({ + install({ + require(started.complete(Unit)) + i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) } + ) + }, { + started.await() + throw throwable + }) { _, _ -> } + fail("It should never reach here") + } + + } shouldBe throwable + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - Left error on acquire" { + checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + val released = CompletableDeferred>() + val started = CompletableDeferred() + shouldThrow { + resourceScope { + parZip({ + started.await() + throw throwable + }, { + install({ + require(started.complete(Unit)) + i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) } + ) + }) { _, _ -> } + fail("It should never reach here") + } + } shouldBe throwable + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - Right CancellationException on release" { + checkAll(Arb.int()) { i -> + val cancel = CancellationException(null, null) + val released = CompletableDeferred>() + + shouldThrow { + resourceScope { + parZip({ + install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) + }, { + install({ }, { _: Unit, _: ExitCase -> throw cancel }) + }) { _, _ -> } + } + } + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - Left CancellationException on release" { + checkAll(Arb.int()) { i -> + val cancel = CancellationException(null, null) + val released = CompletableDeferred>() + + shouldThrow { + resourceScope { + parZip({ + install({ }, { _: Unit, _: ExitCase -> throw cancel }) + }, { + install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) + }) { _, _ -> } + } + } + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - Right error on release" { + checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + val released = CompletableDeferred>() + + shouldThrow { + resourceScope { + parZip({ + install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) + }, { + install({ }, { _: Unit, _: ExitCase -> throw throwable }) + }) { _, _ -> } + } + } shouldBe throwable + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - Left error on release" { + checkAll(Arb.int(), Arb.throwable()) { i, throwable -> + val released = CompletableDeferred>() + + shouldThrow { + resourceScope { + parZip({ + install({ }, { _: Unit, _: ExitCase -> throw throwable }) + }, { + install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) + }) { _, _ -> } + } + } shouldBe throwable + + val (ii, ex) = released.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } + + "parZip - error in use" { + checkAll(Arb.int(), Arb.int(), Arb.throwable()) { a, b, throwable -> + val releasedA = CompletableDeferred>() + val releasedB = CompletableDeferred>() + + shouldThrow { + resourceScope { + parZip({ + install({ a } ) { aa: Int, ex: ExitCase -> require(releasedA.complete(aa to ex)) } + }, { + install({ b } ) { bb: Int, ex: ExitCase -> require(releasedB.complete(bb to ex)) } + }) { _, _ -> } + throw throwable + } + } shouldBe throwable + + val (aa, exA) = releasedA.await() + aa shouldBe a + exA.shouldBeTypeOf() + + val (bb, exB) = releasedB.await() + bb shouldBe b + exB.shouldBeTypeOf() + } + } + + "parZip - cancellation in use" { + checkAll(Arb.int(), Arb.int()) { a, b -> + val releasedA = CompletableDeferred>() + val releasedB = CompletableDeferred>() + + shouldThrow { + resourceScope { + parZip({ + install({ a } ) { aa: Int, ex: ExitCase -> require(releasedA.complete(aa to ex)) } + }, { + install({ b } ) { bb: Int, ex: ExitCase -> require(releasedB.complete(bb to ex)) } + }) { _, _ -> } + throw CancellationException("") + } + } + + val (aa, exA) = releasedA.await() + aa shouldBe a + exA.shouldBeTypeOf() + + val (bb, exB) = releasedB.await() + bb shouldBe b + exB.shouldBeTypeOf() + } + } + + "resource.asFlow()" { + checkAll(Arb.int()) { n -> + val released = CompletableDeferred() + val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) + + r.asFlow().map { it + 1 }.toList() shouldBe listOf(n + 1) + + released.await() shouldBe ExitCase.Completed + } + } + + "resource.asFlow() - failed" { + checkAll(Arb.int(), Arb.throwable()) { n, throwable -> + val released = CompletableDeferred() + val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) + + shouldThrow { + r.asFlow().collect { throw throwable } + } shouldBe throwable + + released.await().shouldBeTypeOf().failure shouldBe throwable + } + } + + "resource.asFlow() - cancelled" { + checkAll(Arb.int()) { n -> + val released = CompletableDeferred() + val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) + + shouldThrow { + r.asFlow().collect { throw CancellationException("") } + } + + released.await().shouldBeTypeOf() + } + } +}) 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 index 9a5b9bed923..444f2d5fdda 100644 --- 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 @@ -1,12 +1,30 @@ package arrow.fx.coroutines +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExecutorCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.newFixedThreadPoolContext +import kotlinx.coroutines.newSingleThreadContext +import kotlinx.coroutines.runInterruptible import kotlinx.coroutines.withContext import java.io.Closeable import java.util.concurrent.ExecutorService -import java.util.concurrent.Executors +import java.util.concurrent.TimeUnit import kotlin.coroutines.CoroutineContext +import kotlin.time.Duration + +@ResourceDSL +public suspend fun ResourceScope.executor( + timeout: Duration = Duration.INFINITE, + closingDispatcher: CoroutineDispatcher = Dispatchers.IO, + create: suspend () -> ExecutorService, +): ExecutorCoroutineDispatcher = install({ create() } ) { s: ExecutorService, _: ExitCase -> + s.shutdown() + runInterruptible(closingDispatcher) { + s.awaitTermination(timeout.inWholeMilliseconds, TimeUnit.MILLISECONDS) + } +}.asCoroutineDispatcher() /** * Creates a single threaded [CoroutineContext] as a [Resource]. @@ -14,13 +32,15 @@ import kotlin.coroutines.CoroutineContext * tasks are executed, but no new tasks will be accepted. * * ```kotlin - * import arrow.fx.coroutines.* + * import arrow.fx.coroutines.executor + * import arrow.fx.coroutines.use + * import arrow.fx.coroutines.parTraverse * import java.util.concurrent.Executors * import java.util.concurrent.atomic.AtomicInteger * import kotlin.math.max * * suspend fun main(): Unit { - * val pool = Resource.fromExecutor { + * val pool = executor { * val ctr = AtomicInteger(0) * val size = max(2, Runtime.getRuntime().availableProcessors()) * Executors.newFixedThreadPool(size) { r -> @@ -38,48 +58,74 @@ import kotlin.coroutines.CoroutineContext * ``` * */ -public fun Resource.Companion.fromExecutor(f: suspend () -> ExecutorService): Resource = - Resource(f) { s, _ -> s.shutdown() }.map(ExecutorService::asCoroutineDispatcher) +public fun executor( + timeout: Duration = Duration.INFINITE, + closingDispatcher: CoroutineDispatcher = Dispatchers.IO, + create: suspend () -> ExecutorService, +): Resource = + resource { + executor(timeout, closingDispatcher, create) + } /** * Creates a [Resource] from an [Closeable], which uses [Closeable.close] for releasing. * * ```kotlin - * import arrow.fx.coroutines.* + * import arrow.fx.coroutines.resourceScope + * import arrow.fx.coroutines.closeable * import java.io.FileInputStream * * suspend fun copyFile(src: String, dest: String): Unit = - * Resource.fromCloseable { FileInputStream(src) } - * .zip(Resource.fromCloseable { FileInputStream(dest) }) - * .use { (a: FileInputStream, b: FileInputStream) -> - * /** read from [a] and write to [b]. **/ - * // Both resources will be closed accordingly to their #close methods - * } + * resourceScope { + * val a: FileInputStream = closeable { FileInputStream(src) } + * val b: FileInputStream = closeable { FileInputStream(dest) } + * /** read from `a` and write to `b`. **/ + * } // Both resources will be closed accordingly to their #close methods * ``` * */ -public fun Resource.Companion.fromCloseable(f: suspend () -> A): Resource = - Resource(f) { s, _ -> withContext(Dispatchers.IO) { s.close() } } +@ResourceDSL +public suspend fun ResourceScope.closeable( + closingDispatcher: CoroutineDispatcher = Dispatchers.IO, + closeable: suspend () -> A, +): A = install({ closeable() } ) { s: A, _: ExitCase -> withContext(closingDispatcher) { s.close() } } + +public fun closeable( + closingDispatcher: CoroutineDispatcher = Dispatchers.IO, + closeable: suspend () -> A, +): Resource = resource { + closeable(closingDispatcher, closeable) +} /** - * Creates a [Resource] from an [AutoCloseable], which uses [AutoCloseable.close] for releasing. + * Creates a [Resource] from an [AutoClos eable], which uses [AutoCloseable.close] for releasing. * * ```kotlin - * import arrow.fx.coroutines.* + * import arrow.fx.coroutines.resourceScope + * import arrow.fx.coroutines.autoCloseable * import java.io.FileInputStream * * suspend fun copyFile(src: String, dest: String): Unit = - * Resource.fromAutoCloseable { FileInputStream(src) } - * .zip(Resource.fromAutoCloseable { FileInputStream(dest) }) - * .use { (a: FileInputStream, b: FileInputStream) -> - * /** read from [a] and write to [b]. **/ - * // Both resources will be closed accordingly to their #close methods - * } + * resourceScope { + * val a: FileInputStream = autoCloseable { FileInputStream(src) } + * val b: FileInputStream = autoCloseable { FileInputStream(dest) } + * /** read from [a] and write to [b]. **/ + * } // Both resources will be closed accordingly to their #close methods * ``` * */ -public fun Resource.Companion.fromAutoCloseable(f: suspend () -> A): Resource = - Resource(f) { s, _ -> withContext(Dispatchers.IO) { s.close() } } +@ResourceDSL +public suspend fun ResourceScope.autoCloseable( + closingDispatcher: CoroutineDispatcher = Dispatchers.IO, + autoCloseable: suspend () -> A, +): A = install({ autoCloseable() } ) { s: A, _: ExitCase -> withContext(closingDispatcher) { s.close() } } + +public fun autoCloseable( + closingDispatcher: CoroutineDispatcher = Dispatchers.IO, + autoCloseable: suspend () -> A, +): Resource = resource { + autoCloseable(closingDispatcher, autoCloseable) +} /** * Creates a single threaded [CoroutineContext] as a [Resource]. @@ -87,25 +133,56 @@ public fun Resource.Companion.fromAutoCloseable(f: suspend ( * tasks are executed, but no new tasks will be accepted. * * ```kotlin - * import arrow.fx.coroutines.* + * import arrow.fx.coroutines.resourceScope + * import arrow.fx.coroutines.singleThreadContext * import kotlinx.coroutines.withContext + * import kotlinx.coroutines.ExecutorCoroutineDispatcher * - * val singleCtx = Resource.singleThreadContext("single") - * - * suspend fun main(): Unit = - * singleCtx.use { ctx -> - * withContext(ctx) { - * println("I am running on ${Thread.currentThread().name}") - * } + * suspend fun main(): Unit = resourceScope { + * val single: ExecutorCoroutineDispatcher = singleThreadContext("single") + * withContext(single) { + * println("I am running on ${Thread.currentThread().name}") * } + * } + * ``` + * ```text + * I am running on single * ``` * */ -public fun Resource.Companion.singleThreadContext(name: String): Resource = - fromExecutor { - Executors.newSingleThreadExecutor { r -> - Thread(r, name).apply { - isDaemon = true - } - } - } +@ResourceDSL +public suspend fun ResourceScope.singleThreadContext(name: String): ExecutorCoroutineDispatcher = + closeable { newSingleThreadContext(name) } + +public fun singleThreadContext(name: String): Resource = + resource { singleThreadContext(name) } + +/** + * 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 + * import arrow.fx.coroutines.fixedThreadPoolContext + * import arrow.fx.coroutines.resourceScope + * import kotlinx.coroutines.withContext + * import kotlinx.coroutines.ExecutorCoroutineDispatcher + * + * suspend fun main(): Unit = resourceScope { + * val pool: ExecutorCoroutineDispatcher = fixedThreadPoolContext(8, "custom-pool") + * withContext(pool) { + * println("I am running on ${Thread.currentThread().name}") + * } + * } + * ``` + * ```text + * I am running on custom-pool-1 + * ``` + * + */ +@ResourceDSL +public suspend fun ResourceScope.fixedThreadPoolContext(nThreads: Int, name: String): ExecutorCoroutineDispatcher = + closeable { newFixedThreadPoolContext(nThreads, name) } + +public fun fixedThreadPoolContext(nThreads: Int, name: String): Resource = + resource { fixedThreadPoolContext(nThreads, name) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt index bfcfec5d811..88e1a3fb653 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt @@ -41,63 +41,67 @@ class FlowJvmTest : ArrowFxSpec(spec = { .collect() } timestamps.size shouldBe 3 - + // total run should be between start time + delay * 3 AND start + tolerance % val min = start + (delayMs * 2) val max = min + delayMs / 10 - + timestamps.last() shouldBeGreaterThanOrEqual min timestamps.last() shouldBeLessThan max } } } - + "parMap - single thread - identity" { - single.use { ctx -> + resourceScope { + val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> flow.parMap { it }.flowOn(ctx) .toList() shouldBe flow.toList() } } } - + "parMap - flowOn" { - single.use { ctx -> + resourceScope { + val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> flow.parMap { Thread.currentThread().name }.flowOn(ctx) .toList().forEach { - it shouldContain singleThreadName + it shouldContain "single" } } } } - + "parMapUnordered - single thread - identity" { - single.use { ctx -> + resourceScope { + val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> flow.parMapUnordered { it }.flowOn(ctx) .toSet() shouldBe flow.toSet() } } } - + "parMapUnordered - flowOn" { - single.use { ctx -> + resourceScope { + val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> flow.parMap { Thread.currentThread().name }.flowOn(ctx) .toList().forEach { - it shouldContain singleThreadName + it shouldContain "single" } } } } - + "fixedDelay" { runBlockingTest { checkAll(Arb.positiveInts().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> val emissionDuration = waitPeriod / 10L var state: Long? = null - + val rate = flow { emit(delay(Duration.milliseconds(waitPeriod))) }.repeat() .map { val now = state ?: currentTime @@ -109,7 +113,7 @@ class FlowJvmTest : ArrowFxSpec(spec = { } .take(n) .toList() - + rate.first() shouldBe 0 // First element is immediately rate.drop(1).forEach { act -> act shouldBe (waitPeriod + emissionDuration) // Remaining elements all take delay + emission duration @@ -117,13 +121,13 @@ class FlowJvmTest : ArrowFxSpec(spec = { } } } - + "fixedRate" { runBlockingTest { checkAll(Arb.positiveInts().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> val emissionDuration = waitPeriod / 10 var state: Long? = null - + val rate = fixedRate(Duration.milliseconds(waitPeriod)) { currentTime } .map { val now = state ?: currentTime @@ -135,7 +139,7 @@ class FlowJvmTest : ArrowFxSpec(spec = { } .take(n) .toList() - + rate.first() shouldBe 0 // First element is immediately rate.drop(1).forEach { act -> // Remaining elements all take total of waitPeriod, emissionDuration is correctly taken into account. @@ -144,13 +148,13 @@ class FlowJvmTest : ArrowFxSpec(spec = { } } } - + "fixedRate(dampen = true)" { val waitPeriod = 1000L val n = 3 val timeout = (n + 1) * waitPeriod + 500 val buffer = mutableListOf() - + withTimeoutOrNull(timeout) { fixedRate(Duration.milliseconds(waitPeriod), true) { timeInMillis() } .mapIndexed { index, _ -> @@ -158,16 +162,16 @@ class FlowJvmTest : ArrowFxSpec(spec = { } .collect(buffer::add) } - + buffer.size shouldBe 2 } - + "fixedRate(dampen = false)" { val waitPeriod = 1000L val n = 3 val timeout = (n + 1) * waitPeriod + 500 val buffer = mutableListOf() - + withTimeoutOrNull(timeout) { fixedRate(Duration.milliseconds(waitPeriod), false) { timeInMillis() } .mapIndexed { index, _ -> @@ -175,7 +179,7 @@ class FlowJvmTest : ArrowFxSpec(spec = { } .collect(buffer::add) } - + buffer.size shouldBe n + 1 } }) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap2JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap2JvmTest.kt index 8b00e61cdd4..673e86f8c28 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap2JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap2JvmTest.kt @@ -8,57 +8,55 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import kotlinx.coroutines.withContext -import java.util.concurrent.Executors +import kotlin.coroutines.CoroutineContext class ParMap2JvmTest : ArrowFxSpec( spec = { + val mapCtxName = "parMap2" + "parMapN 2 returns to original context" { - val mapCtxName = "parMap2" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(2, NamedThreadFactory { mapCtxName }) } - + checkAll { - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(2, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + val (s1, s2) = parZip( _mapCtx, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b -> Pair(a, b) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName - threadName() shouldStartWith singleThreadName + Thread.currentThread().name shouldStartWith "single" } } } } - + "parMapN 2 returns to original context on failure" { - val mapCtxName = "parMap2" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(2, NamedThreadFactory { mapCtxName }) } - checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(2, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + Either.catch { when (choose) { 1 -> parZip(_mapCtx, { e.suspend() }, { never() }) { _, _ -> Unit } else -> parZip(_mapCtx, { never() }, { e.suspend() }) { _, _ -> Unit } } } should leftException(e) - - threadName() shouldStartWith singleThreadName + + Thread.currentThread().name shouldStartWith "single" } } } } - + "parMapN 2 finishes on single thread" { checkAll(Arb.string()) { - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") parZip(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b -> listOf(a, b) } } assertSoftly { @@ -68,3 +66,11 @@ class ParMap2JvmTest : ArrowFxSpec( } } ) + +suspend fun parallelCtx( + nThreads: Int, + mapCtxName: String, + use: suspend (CoroutineContext, CoroutineContext) -> Unit, +): Unit = resourceScope { + use(singleThreadContext("single"), fixedThreadPoolContext(nThreads, mapCtxName)) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap3JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap3JvmTest.kt index 6a05ff2b79a..bc252008de8 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap3JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap3JvmTest.kt @@ -8,28 +8,26 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import kotlinx.coroutines.withContext -import java.util.concurrent.Executors class ParMap3JvmTest : ArrowFxSpec(spec = { "parMapN 3 returns to original context" { val mapCtxName = "parMap3" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(3, NamedThreadFactory { mapCtxName }) } checkAll { - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(3, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + val (s1, s2, s3) = parZip( _mapCtx, { Thread.currentThread().name }, { Thread.currentThread().name }, { Thread.currentThread().name }) { a, b, c -> Triple(a, b, c) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName - threadName() shouldStartWith singleThreadName + Thread.currentThread().name shouldStartWith "single" } } } @@ -37,13 +35,12 @@ class ParMap3JvmTest : ArrowFxSpec(spec = { "parMapN 3 returns to original context on failure" { val mapCtxName = "parMap3" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(3, NamedThreadFactory { mapCtxName }) } checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(3, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + Either.catch { when (choose) { 1 -> parZip( @@ -52,12 +49,14 @@ class ParMap3JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _ -> Unit } + 2 -> parZip( _mapCtx, { never() }, { e.suspend() }, { never() } ) { _, _, _ -> Unit } + else -> parZip( _mapCtx, { never() }, @@ -66,8 +65,8 @@ class ParMap3JvmTest : ArrowFxSpec(spec = { ) { _, _, _ -> Unit } } } should leftException(e) - - threadName() shouldStartWith singleThreadName + + Thread.currentThread().name shouldStartWith "single" } } } @@ -75,7 +74,8 @@ class ParMap3JvmTest : ArrowFxSpec(spec = { "parMapN 3 finishes on single thread" { checkAll(Arb.string()) { - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") parZip( ctx, { Thread.currentThread().name }, diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap4JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap4JvmTest.kt index a5392518179..14aafbd0d89 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap4JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap4JvmTest.kt @@ -9,18 +9,17 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import kotlinx.coroutines.withContext -import java.util.concurrent.Executors class ParMap4JvmTest : ArrowFxSpec( spec = { + val mapCtxName = "parMap4" + "parMapN 4 returns to original context" { - val mapCtxName = "parMap4" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(4, NamedThreadFactory { mapCtxName }) } checkAll { - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(4, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + val (s1, s2, s3, s4) = parZip( _mapCtx, { Thread.currentThread().name }, @@ -28,26 +27,23 @@ class ParMap4JvmTest : ArrowFxSpec( { Thread.currentThread().name }, { Thread.currentThread().name } ) { a, b, c, d -> Tuple4(a, b, c, d) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName s4 shouldStartWith mapCtxName - threadName() shouldStartWith singleThreadName + Thread.currentThread().name shouldStartWith "single" } } } } "parMapN 4 returns to original context on failure" { - val mapCtxName = "parMap4" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(4, NamedThreadFactory { mapCtxName }) } - checkAll(Arb.int(1..4), Arb.throwable()) { choose, e -> - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(4, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + Either.catch { when (choose) { 1 -> parZip( @@ -57,6 +53,7 @@ class ParMap4JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _ -> Unit } + 2 -> parZip( _mapCtx, { never() }, @@ -64,6 +61,7 @@ class ParMap4JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _ -> Unit } + 3 -> parZip( _mapCtx, { never() }, @@ -71,6 +69,7 @@ class ParMap4JvmTest : ArrowFxSpec( { e.suspend() }, { never() } ) { _, _, _, _ -> Unit } + else -> parZip( _mapCtx, { never() }, @@ -80,8 +79,8 @@ class ParMap4JvmTest : ArrowFxSpec( ) { _, _, _, _ -> Unit } } } should leftException(e) - - threadName() shouldStartWith singleThreadName + + Thread.currentThread().name shouldStartWith "single" } } } @@ -89,7 +88,8 @@ class ParMap4JvmTest : ArrowFxSpec( "parMapN 4 finishes on single thread" { checkAll(Arb.string()) { - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") parZip( ctx, { Thread.currentThread().name }, diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap5JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap5JvmTest.kt index c055b2d955b..516c426bf22 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap5JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap5JvmTest.kt @@ -10,45 +10,41 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext -import java.util.concurrent.Executors class ParMap5JvmTest : ArrowFxSpec( spec = { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } + val mapCtxName = "parMap5" + "parMapN 5 returns to original context" { - val mapCtxName = "parMap5" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(5, NamedThreadFactory { mapCtxName }) } checkAll { - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(5, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + 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 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName s4 shouldStartWith mapCtxName s5 shouldStartWith mapCtxName - threadName() shouldStartWith singleThreadName + threadName() shouldStartWith "single" } } } } "parMapN 5 returns to original context on failure" { - val mapCtxName = "parMap5" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(5, NamedThreadFactory { mapCtxName }) } - checkAll(Arb.int(1..5), Arb.throwable()) { choose, e -> - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(5, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + Either.catch { when (choose) { 1 -> parZip( @@ -59,6 +55,7 @@ class ParMap5JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _ -> Unit } + 2 -> parZip( _mapCtx, { never() }, @@ -67,6 +64,7 @@ class ParMap5JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _ -> Unit } + 3 -> parZip( _mapCtx, { never() }, @@ -75,6 +73,7 @@ class ParMap5JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _ -> Unit } + 4 -> parZip( _mapCtx, { never() }, @@ -83,6 +82,7 @@ class ParMap5JvmTest : ArrowFxSpec( { e.suspend() }, { never() } ) { _, _, _, _, _ -> Unit } + else -> parZip( _mapCtx, { never() }, @@ -93,8 +93,8 @@ class ParMap5JvmTest : ArrowFxSpec( ) { _, _, _, _, _ -> Unit } } } should leftException(e) - - threadName() shouldStartWith singleThreadName + + threadName() shouldStartWith "single" } } } @@ -102,7 +102,8 @@ class ParMap5JvmTest : ArrowFxSpec( "parMapN 5 finishes on single thread" { checkAll(Arb.string()) { - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") parZip(ctx, threadName, threadName, threadName, threadName, threadName) { a, b, c, d, e -> listOf( a, diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap6JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap6JvmTest.kt index aae35e4f970..349016c08ad 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap6JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap6JvmTest.kt @@ -10,47 +10,42 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext -import java.util.concurrent.Executors class ParMap6JvmTest : ArrowFxSpec(spec = { + val mapCtxName = "parMap6" val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } "parMapN 6 returns to original context" { - val mapCtxName = "parMap6" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(6, NamedThreadFactory { mapCtxName }) } checkAll { - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(6, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + val (s1, s2, s3, s4, s5, s6) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName, threadName ) { a, b, c, d, e, f -> Tuple6(a, b, c, d, e, f) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName s4 shouldStartWith mapCtxName s5 shouldStartWith mapCtxName s6 shouldStartWith mapCtxName - threadName() shouldStartWith singleThreadName + threadName() shouldStartWith "single" } } } } "parMapN 6 returns to original context on failure" { - val mapCtxName = "parMap6" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(6, NamedThreadFactory { mapCtxName }) } - checkAll(Arb.int(1..6), Arb.throwable()) { choose, e -> - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(6, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + Either.catch { when (choose) { 1 -> parZip( @@ -62,6 +57,7 @@ class ParMap6JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _ -> Unit } + 2 -> parZip( _mapCtx, { never() }, @@ -71,6 +67,7 @@ class ParMap6JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _ -> Unit } + 3 -> parZip( _mapCtx, { never() }, @@ -80,6 +77,7 @@ class ParMap6JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _ -> Unit } + 4 -> parZip( _mapCtx, { never() }, @@ -89,6 +87,7 @@ class ParMap6JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _ -> Unit } + 5 -> parZip( _mapCtx, { never() }, @@ -98,6 +97,7 @@ class ParMap6JvmTest : ArrowFxSpec(spec = { { e.suspend() }, { never() } ) { _, _, _, _, _, _ -> Unit } + else -> parZip( _mapCtx, { never() }, @@ -109,7 +109,7 @@ class ParMap6JvmTest : ArrowFxSpec(spec = { ) { _, _, _, _, _, _ -> Unit } } } should leftException(e) - threadName() shouldStartWith singleThreadName + threadName() shouldStartWith "single" } } } @@ -117,7 +117,8 @@ class ParMap6JvmTest : ArrowFxSpec(spec = { "parMapN 6 finishes on single thread" { checkAll(Arb.string()) { - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") parZip(ctx, threadName, threadName, threadName, threadName, threadName, threadName) { a, b, c, d, e, f -> listOf(a, b, c, d, e, f) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt index 75b6bc51714..45c5e666531 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt @@ -10,27 +10,25 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext -import java.util.concurrent.Executors class ParMap7JvmTest : ArrowFxSpec( spec = { + val mapCtxName = "parMap7" val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } "parMapN 7 returns to original context" { - val mapCtxName = "parMap7" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(7, NamedThreadFactory { mapCtxName }) } checkAll { - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(7, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + val (s1, s2, s3, s4, s5, s6, s7) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName, threadName, threadName ) { a, b, c, d, e, f, g -> Tuple7(a, b, c, d, e, f, g) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName @@ -38,21 +36,18 @@ class ParMap7JvmTest : ArrowFxSpec( s5 shouldStartWith mapCtxName s6 shouldStartWith mapCtxName s7 shouldStartWith mapCtxName - threadName() shouldStartWith singleThreadName + threadName() shouldStartWith "single" } } } } "parMapN 7 returns to original context on failure" { - val mapCtxName = "parMap7" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(7, NamedThreadFactory { mapCtxName }) } - checkAll(Arb.int(1..7), Arb.throwable()) { choose, e -> - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(7, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + Either.catch { when (choose) { 1 -> parZip( @@ -65,6 +60,7 @@ class ParMap7JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _, _, _ -> Unit } + 2 -> parZip( _mapCtx, { never() }, @@ -75,6 +71,7 @@ class ParMap7JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _, _, _ -> Unit } + 3 -> parZip( _mapCtx, { never() }, @@ -85,6 +82,7 @@ class ParMap7JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _, _, _ -> Unit } + 4 -> parZip( _mapCtx, { never() }, @@ -95,6 +93,7 @@ class ParMap7JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _, _, _ -> Unit } + 5 -> parZip( _mapCtx, { never() }, @@ -105,6 +104,7 @@ class ParMap7JvmTest : ArrowFxSpec( { never() }, { never() } ) { _, _, _, _, _, _, _ -> Unit } + 6 -> parZip( _mapCtx, { never() }, @@ -115,6 +115,7 @@ class ParMap7JvmTest : ArrowFxSpec( { e.suspend() }, { never() } ) { _, _, _, _, _, _, _ -> Unit } + else -> parZip( _mapCtx, { never() }, @@ -127,7 +128,7 @@ class ParMap7JvmTest : ArrowFxSpec( ) { _, _, _, _, _, _, _ -> Unit } } } should leftException(e) - threadName() shouldStartWith singleThreadName + threadName() shouldStartWith "single" } } } @@ -135,7 +136,8 @@ class ParMap7JvmTest : ArrowFxSpec( "parMapN 7 finishes on single thread" { checkAll(Arb.string()) { - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") parZip( ctx, threadName, diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt index 9cc8d3368a8..40632cb5648 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt @@ -10,26 +10,24 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext -import java.util.concurrent.Executors class ParMap8JvmTest : ArrowFxSpec(spec = { + val mapCtxName = "parMap8" val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } "parMapN 8 returns to original context" { - val mapCtxName = "parMap8" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(8, NamedThreadFactory { mapCtxName }) } checkAll { - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(7, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + val (s1, s2, s3, s4, s5, s6, s7, s8) = parZip( _mapCtx, 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) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName @@ -38,21 +36,18 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { s6 shouldStartWith mapCtxName s7 shouldStartWith mapCtxName s8 shouldStartWith mapCtxName - threadName() shouldStartWith singleThreadName + threadName() shouldStartWith "single" } } } } "parMapN 8 returns to original context on failure" { - val mapCtxName = "parMap8" - val mapCtx = Resource.fromExecutor { Executors.newFixedThreadPool(8, NamedThreadFactory { mapCtxName }) } - checkAll(Arb.int(1..8), Arb.throwable()) { choose, e -> - single.zip(mapCtx).use { (_single, _mapCtx) -> + parallelCtx(7, mapCtxName) { _single, _mapCtx -> withContext(_single) { - threadName() shouldStartWith singleThreadName - + threadName() shouldStartWith "single" + Either.catch { when (choose) { 1 -> parZip( @@ -66,6 +61,7 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _, _, _ -> Unit } + 2 -> parZip( _mapCtx, { never() }, @@ -77,8 +73,9 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _, _, _ -> Unit } + 3 -> parZip( - + { never() }, { never() }, { e.suspend() }, @@ -87,6 +84,7 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _, _ -> Unit } + 4 -> parZip( _mapCtx, { never() }, @@ -98,6 +96,7 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _, _, _ -> Unit } + 5 -> parZip( _mapCtx, { never() }, @@ -109,6 +108,7 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _, _, _ -> Unit } + 6 -> parZip( _mapCtx, { never() }, @@ -120,6 +120,7 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { { never() }, { never() } ) { _, _, _, _, _, _, _, _ -> Unit } + 7 -> parZip( _mapCtx, { never() }, @@ -131,6 +132,7 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { { e.suspend() }, { never() } ) { _, _, _, _, _, _, _, _ -> Unit } + else -> parZip( _mapCtx, { never() }, @@ -144,7 +146,7 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { ) { _, _, _, _, _, _, _, _ -> Unit } } } should leftException(e) - threadName() shouldStartWith singleThreadName + threadName() shouldStartWith "single" } } } @@ -152,7 +154,8 @@ class ParMap8JvmTest : ArrowFxSpec(spec = { "parMapN 8 finishes on single thread" { checkAll(Arb.string()) { - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") parZip( ctx, threadName, diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherJvmTest.kt index e437a49960b..028d332693c 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseEitherJvmTest.kt @@ -11,7 +11,8 @@ class ParTraverseEitherJvmTest : ArrowFxSpec( spec = { "parTraverseEither finishes on single thread " { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") (0 until i).parTraverseEither(ctx) { Thread.currentThread().name.right() } } assertSoftly { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseJvmTest.kt index 9e334649c43..d2e754787ce 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseJvmTest.kt @@ -8,7 +8,8 @@ import io.kotest.property.arbitrary.int class ParTraverseJvmTest : ArrowFxSpec(spec = { "parTraverse runs on provided context " { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") (0 until i).parTraverse(ctx) { Thread.currentThread().name } } assertSoftly { @@ -16,10 +17,11 @@ class ParTraverseJvmTest : ArrowFxSpec(spec = { } } } - + "parTraverseN runs on provided thread" { checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") (0 until i).parTraverseN(ctx, 3) { Thread.currentThread().name } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt index fb0cea00416..eabcac3060b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt @@ -12,7 +12,8 @@ import io.kotest.property.arbitrary.int class ParTraverseValidatedJvmTest : ArrowFxSpec(spec = { "parTraverseValidated finishes on single thread " { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - val res = single.use { ctx -> + val res = resourceScope { + val ctx = singleThreadContext("single") (0 until i).parTraverseValidated(ctx, Semigroup.nonEmptyList()) { Thread.currentThread().name.validNel() } } assertSoftly { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt index dc3fbbb6f14..21e2e405225 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt @@ -7,120 +7,126 @@ import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import kotlinx.coroutines.withContext -import java.util.concurrent.Executors class RaceNJvmTest : ArrowFxSpec( spec = { "race2 returns to original context" { val racerName = "race2" - val racer = Resource.fromExecutor { Executors.newFixedThreadPool(2, NamedThreadFactory { racerName }) } - checkAll(Arb.int(1..2)) { choose -> - single.zip(racer).use { (single, raceCtx) -> - withContext(single) { - threadName() shouldStartWith singleThreadName - + resourceScope { + val pool = fixedThreadPoolContext(2, racerName) + withContext(singleThreadContext("single")) { + Thread.currentThread().name shouldStartWith "single" + val racedOn = when (choose) { - 1 -> raceN(raceCtx, { threadName() }, { never() }).swap().orNull() - else -> raceN(raceCtx, { never() }, { threadName() }).orNull() + 1 -> raceN(pool, { Thread.currentThread().name }, { never() }).swap().orNull() + else -> raceN(pool, { never() }, { Thread.currentThread().name }).orNull() } - + racedOn shouldStartWith racerName - threadName() shouldStartWith singleThreadName + Thread.currentThread().name shouldStartWith "single" } } } } - + "race2 returns to original context on failure" { val racerName = "race2" - val racer = Resource.fromExecutor { Executors.newFixedThreadPool(2, NamedThreadFactory { racerName }) } - + checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> - single.zip(racer).use { (single, raceCtx) -> - withContext(single) { - threadName() shouldStartWith singleThreadName - + resourceScope { + val pool = fixedThreadPoolContext(2, racerName) + withContext(singleThreadContext("single")) { + Thread.currentThread().name shouldStartWith "single" + Either.catch { when (choose) { - 1 -> raceN(raceCtx, { e.suspend() }, { never() }).swap().orNull() - else -> raceN(raceCtx, { never() }, { e.suspend() }).orNull() + 1 -> raceN(pool, { e.suspend() }, { never() }).swap().orNull() + else -> raceN(pool, { never() }, { e.suspend() }).orNull() } } should leftException(e) - - threadName() shouldStartWith singleThreadName + + Thread.currentThread().name shouldStartWith "single" } } } } - + "first racer out of 2 always wins on a single thread" { - single.use { ctx -> - raceN(ctx, { threadName() }, { threadName() }) + resourceScope { + val ctx = singleThreadContext("single") + raceN(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) }.swap().orNull() shouldStartWith "single" } - + "race3 returns to original context" { val racerName = "race3" - val racer = Resource.fromExecutor { Executors.newFixedThreadPool(3, NamedThreadFactory { racerName }) } - + checkAll(Arb.int(1..3)) { choose -> - single.zip(racer).use { (single, raceCtx) -> + parallelCtx(3, racerName) { single, raceCtx -> withContext(single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + val racedOn = when (choose) { 1 -> - raceN(raceCtx, { threadName() }, { never() }, { never() }) + raceN(raceCtx, { Thread.currentThread().name }, { never() }, { never() }) .fold(::identity, { null }, { null }) + 2 -> - raceN(raceCtx, { never() }, { threadName() }, { never() }) + raceN(raceCtx, { never() }, { Thread.currentThread().name }, { never() }) .fold({ null }, ::identity, { null }) + else -> - raceN(raceCtx, { never() }, { never() }, { threadName() }) + raceN(raceCtx, { never() }, { never() }, { Thread.currentThread().name }) .fold({ null }, { null }, ::identity) } - + racedOn shouldStartWith racerName - threadName() shouldStartWith singleThreadName + Thread.currentThread().name shouldStartWith "single" } } } } - + "race3 returns to original context on failure" { val racerName = "race3" - val racer = Resource.fromExecutor { Executors.newFixedThreadPool(3, NamedThreadFactory { racerName }) } - + checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> - single.zip(racer).use { (single, raceCtx) -> + parallelCtx(3, racerName) { single, raceCtx -> withContext(single) { - threadName() shouldStartWith singleThreadName - + Thread.currentThread().name shouldStartWith "single" + Either.catch { when (choose) { 1 -> raceN(raceCtx, { e.suspend() }, { never() }, { never() }) .fold(::identity, { null }, { null }) + 2 -> raceN(raceCtx, { never() }, { e.suspend() }, { never() }) .fold({ null }, ::identity, { null }) + else -> raceN(raceCtx, { never() }, { never() }, { e.suspend() }) .fold({ null }, { null }, ::identity) } } should leftException(e) - - threadName() shouldStartWith singleThreadName + + Thread.currentThread().name shouldStartWith "single" } } } } - + "first racer out of 3 always wins on a single thread" { - (single.use { ctx -> - raceN(ctx, { threadName() }, { threadName() }, { threadName() }) - } as? Race3.First)?.winner shouldStartWith "single" + resourceScope { + val ctx = singleThreadContext("single") + raceN( + ctx, + { Thread.currentThread().name }, + { Thread.currentThread().name }, + { Thread.currentThread().name }) as? Race3.First + }?.winner shouldStartWith "single" } } ) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt index f2049b4062e..0d00ee59a14 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt @@ -8,61 +8,67 @@ import java.io.Closeable import io.kotest.property.Arb class ResourceTestJvm : ArrowFxSpec(spec = { - + class AutoCloseableTest() : AutoCloseable { val didClose = AtomicBoolean(false) override fun close() = didClose.set(true) } - + class CloseableTest() : Closeable { val didClose = AtomicBoolean(false) override fun close() = didClose.set(true) } - + "AutoCloseable closes" { checkAll { val t = AutoCloseableTest() - - Resource.fromAutoCloseable { t } - .use {} - + + resourceScope { + autoCloseable { t } + } + t.didClose.get() shouldBe true } } - + "AutoCloseable closes on error" { checkAll(Arb.throwable()) { throwable -> val t = AutoCloseableTest() - + shouldThrow { - Resource.fromAutoCloseable { t } - .use { throw throwable } + resourceScope { + autoCloseable { t } + throw throwable + } } shouldBe throwable - + t.didClose.get() shouldBe true } } - + "Closeable closes" { checkAll() { val t = CloseableTest() - - Resource.fromCloseable { t } - .use {} - + + resourceScope { + closeable { t } + } + t.didClose.get() shouldBe true } } - + "Closeable closes on error" { checkAll(Arb.throwable()) { throwable -> val t = CloseableTest() - + shouldThrow { - Resource.fromCloseable { t } - .use { throw throwable } + resourceScope { + closeable { t } + throw throwable + } } shouldBe throwable - + t.didClose.get() shouldBe true } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt index 12cb1a9be07..93ee7786688 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt @@ -1,18 +1,13 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource01 -import arrow.fx.coroutines.* - class UserProcessor { fun start(): Unit = println("Creating UserProcessor") fun shutdown(): Unit = println("Shutting down UserProcessor") - fun process(ds: DataSource): List = - ds.users().map { "Processed $it" } } class DataSource { fun connect(): Unit = println("Connecting dataSource") - fun users(): List = listOf("User-1", "User-2", "User-3") fun close(): Unit = println("Closed dataSource") } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt index 73bc6a73dc9..9d0a4061988 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt @@ -1,16 +1,28 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource02 -import arrow.fx.coroutines.* +import java.io.Closeable -val resourceA = resource { - "A" -} release { a -> - println("Releasing $a") +class UserProcessor : Closeable { + fun start(): Unit = println("Creating UserProcessor") + override fun close(): Unit = println("Shutting down UserProcessor") } -val resourceB = resource { - "B" -} releaseCase { b, exitCase -> - println("Releasing $b with exit: $exitCase") +class DataSource : Closeable { + fun connect(): Unit = println("Connecting dataSource") + override fun close(): Unit = println("Closed dataSource") +} + +class Service(val db: DataSource, val userProcessor: UserProcessor) { + suspend fun processData(): List = throw RuntimeException("I'm going to leak resources by not closing them") +} + +suspend fun main(): Unit { + UserProcessor().use { userProcessor -> + userProcessor.start() + DataSource().use { dataSource -> + dataSource.connect() + Service(dataSource, userProcessor).processData() + } + } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt index d369bbbf7fd..2d977c79930 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt @@ -1,38 +1,44 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource03 -import arrow.fx.coroutines.* -import arrow.fx.coroutines.continuations.resource +import arrow.fx.coroutines.Resource +import arrow.fx.coroutines.resource +import arrow.fx.coroutines.resourceScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext class UserProcessor { - fun start(): Unit = println("Creating UserProcessor") - fun shutdown(): Unit = println("Shutting down UserProcessor") - fun process(ds: DataSource): List = - ds.users().map { "Processed $it" } + suspend fun start(): Unit = withContext(Dispatchers.IO) { println("Creating UserProcessor") } + suspend fun shutdown(): Unit = withContext(Dispatchers.IO) { + println("Shutting down UserProcessor") + } } class DataSource { fun connect(): Unit = println("Connecting dataSource") - fun users(): List = listOf("User-1", "User-2", "User-3") fun close(): Unit = println("Closed dataSource") } class Service(val db: DataSource, val userProcessor: UserProcessor) { - suspend fun processData(): List = userProcessor.process(db) + suspend fun processData(): List = throw RuntimeException("I'm going to leak resources by not closing them") } -val userProcessor = resource { - UserProcessor().also(UserProcessor::start) -} release UserProcessor::shutdown +val userProcessor: Resource = resource({ + UserProcessor().also { it.start() } +}) { p, _ -> p.shutdown() } -val dataSource = resource { +val dataSource: Resource = resource({ DataSource().also { it.connect() } -} release DataSource::close - -suspend fun main(): Unit { - resource { - parZip({ userProcessor.bind() }, { dataSource.bind() }) { userProcessor, ds -> - Service(ds, userProcessor) - } - }.use { service -> service.processData() } +}) { ds, exitCase -> + println("Releasing $ds with exit: $exitCase") + withContext(Dispatchers.IO) { ds.close() } +} + +val service: Resource = resource { + Service(dataSource.bind(), userProcessor.bind()) +} + +suspend fun main(): Unit = resourceScope { + val data = service.bind().processData() + println(data) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt index f3f67d497cc..aab22cf814e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt @@ -1,20 +1,34 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource04 -import arrow.fx.coroutines.* +import arrow.fx.coroutines.ResourceScope +import arrow.fx.coroutines.Resource +import arrow.fx.coroutines.resource +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext -class DataSource { - fun connect(): Unit = println("Connecting dataSource") - fun users(): List = listOf("User-1", "User-2", "User-3") - fun close(): Unit = println("Closed dataSource") +class UserProcessor { + suspend fun start(): Unit = withContext(Dispatchers.IO) { println("Creating UserProcessor") } + suspend fun shutdown(): Unit = withContext(Dispatchers.IO) { + println("Shutting down UserProcessor") + } } -suspend fun main(): Unit { - val dataSource = resource { - DataSource().also { it.connect() } - } release DataSource::close +suspend fun ResourceScope.userProcessor(): UserProcessor = + install({ UserProcessor().also { it.start() } }) { processor, _ -> + processor.shutdown() + } - val res = dataSource - .use { ds -> "Using data source: ${ds.users()}" } - .also(::println) +val userProcessor: Resource = resource { + val x: UserProcessor = install( + { UserProcessor().also { it.start() } }, + { processor, _ -> processor.shutdown() } + ) + x } + +val userProcessor2: Resource = resource({ + UserProcessor().also { it.start() } +}) { processor, _ -> processor.shutdown() } + +val userProcessor3: Resource = ResourceScope::userProcessor diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt index 24d8787a74b..ac6b0f44eec 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt @@ -1,30 +1,39 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource05 -import arrow.fx.coroutines.* +import arrow.fx.coroutines.ResourceScope +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.parZip +import arrow.fx.coroutines.resource +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class UserProcessor { + suspend fun start(): Unit = withContext(Dispatchers.IO) { println("Creating UserProcessor") } + suspend fun shutdown(): Unit = withContext(Dispatchers.IO) { + println("Shutting down UserProcessor") + } +} -object Connection class DataSource { - fun connect(): Unit = println("Connecting dataSource") - fun connection(): Connection = Connection - fun close(): Unit = println("Closed dataSource") + suspend fun connect(): Unit = withContext(Dispatchers.IO) { println("Connecting dataSource") } + suspend fun close(): Unit = withContext(Dispatchers.IO) { println("Closed dataSource") } } -class Database(private val database: DataSource) { - fun init(): Unit = println("Database initialising . . .") - fun shutdown(): Unit = println("Database shutting down . . .") +class Service(val db: DataSource, val userProcessor: UserProcessor) { + suspend fun processData(): List = (0..10).map { "Processed : $it" } } -suspend fun main(): Unit { - val dataSource = resource { - DataSource().also { it.connect() } - } release DataSource::close +suspend fun ResourceScope.userProcessor(): UserProcessor = + install({ UserProcessor().also { it.start() } }){ p,_ -> p.shutdown() } - fun database(ds: DataSource): Resource = - resource { - Database(ds).also(Database::init) - } release Database::shutdown +suspend fun ResourceScope.dataSource(): DataSource = + install({ DataSource().also { it.connect() } }) { ds, _ -> ds.close() } - dataSource.flatMap(::database) - .use { println("Using database which uses dataSource") } +suspend fun main(): Unit = resourceScope { + val service = parZip({ userProcessor() }, { dataSource() }) { userProcessor, ds -> + Service(ds, userProcessor) + } + val data = service.processData() + println(data) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt index 327b70776c7..9a1bd665e14 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt @@ -1,35 +1,20 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource06 -import arrow.fx.coroutines.* - -class UserProcessor { - fun start(): Unit = println("Creating UserProcessor") - fun shutdown(): Unit = println("Shutting down UserProcessor") - fun process(ds: DataSource): List = - ds.users().map { "Processed $it" } -} +import arrow.fx.coroutines.resourceScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext class DataSource { - fun connect(): Unit = println("Connecting dataSource") - fun users(): List = listOf("User-1", "User-2", "User-3") - fun close(): Unit = println("Closed dataSource") + suspend fun connect(): Unit = withContext(Dispatchers.IO) { println("Connecting dataSource") } + suspend fun close(): Unit = withContext(Dispatchers.IO) { println("Closed dataSource") } + suspend fun users(): List = listOf("User-1", "User-2", "User-3") } -class Service(val db: DataSource, val userProcessor: UserProcessor) { - suspend fun processData(): List = userProcessor.process(db) -} - -val userProcessor = resource { - UserProcessor().also(UserProcessor::start) -} release UserProcessor::shutdown - -val dataSource = resource { - DataSource().also { it.connect() } -} release DataSource::close +suspend fun main(): Unit = resourceScope { + val dataSource = install({ + DataSource().also { it.connect() } + }) { ds, _ -> ds.close() } -suspend fun main(): Unit { - userProcessor.zip(dataSource) { userProcessor, ds -> - Service(ds, userProcessor) - }.use { service -> service.processData() } + println("Using data source: ${dataSource.users()}") } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt index 2a2f16c1d4f..161326cdab0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt @@ -1,36 +1,16 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource07 -import arrow.fx.coroutines.* -import kotlinx.coroutines.delay +import arrow.fx.coroutines.resource +import arrow.fx.coroutines.resourceScope -class UserProcessor { - suspend fun start(): Unit { delay(750); println("Creating UserProcessor") } - fun shutdown(): Unit = println("Shutting down UserProcessor") - fun process(ds: DataSource): List = - ds.users().map { "Processed $it" } +val resource = resource { + install({ 42.also { println("Getting expensive resource") } }) { r, exitCase -> + println("Releasing expensive resource: $r, exit: $exitCase") + } } -class DataSource { - suspend fun connect(): Unit { delay(1000); println("Connecting dataSource") } - fun users(): List = listOf("User-1", "User-2", "User-3") - fun close(): Unit = println("Closed dataSource") -} - -class Service(val db: DataSource, val userProcessor: UserProcessor) { - suspend fun processData(): List = userProcessor.process(db) -} - -val userProcessor = resource { - UserProcessor().also { it.start() } -} release UserProcessor::shutdown - -val dataSource = resource { - DataSource().also { it.connect() } -} release DataSource::close - -suspend fun main(): Unit { - userProcessor.parZip(dataSource) { userProcessor, ds -> - Service(ds, userProcessor) - }.use { service -> service.processData() } +suspend fun main(): Unit = resourceScope { + val res = resource.bind() + println("Expensive resource under use! $res") } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt index b1743db3bdf..a122e785632 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt @@ -1,14 +1,31 @@ // This file was automatically generated from Resource.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResource08 -import arrow.fx.coroutines.* +import arrow.fx.coroutines.asFlow +import arrow.fx.coroutines.closeable +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.asFlow +import kotlinx.coroutines.flow.emitAll +import kotlinx.coroutines.flow.flatMapConcat +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import java.nio.file.Path +import kotlin.io.path.useLines -suspend fun acquireResource(): Int = 42.also { println("Getting expensive resource") } -suspend fun releaseResource(r: Int, exitCase: ExitCase): Unit = println("Releasing expensive resource: $r, exit: $exitCase") +fun Flow.writeAll(path: Path): Flow = + closeable { path.toFile().outputStream() } + .asFlow() + .flatMapConcat { writer -> map { writer.write(it) } } + .flowOn(Dispatchers.IO) -suspend fun main(): Unit { - val resource = Resource(::acquireResource, ::releaseResource) - resource.use { - println("Expensive resource under use! $it") - } +fun Path.readAll(): Flow = flow { + useLines { lines -> emitAll(lines.asFlow()) } +} + +suspend fun main() { + Path.of("example.kt") + .readAll() + .collect(::println) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt deleted file mode 100644 index 7b9020cc4c0..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt +++ /dev/null @@ -1,26 +0,0 @@ -// This file was automatically generated from Resource.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleResource09 - -import arrow.fx.coroutines.* - -class File(url: String) { - suspend fun open(): File = this - suspend fun close(): Unit {} - override fun toString(): String = "This file contains some interesting content!" -} - -suspend fun openFile(uri: String): File = File(uri).open() -suspend fun closeFile(file: File): Unit = file.close() -suspend fun fileToString(file: File): String = file.toString() - -suspend fun main(): Unit { - val res = resource { - openFile("data.json") - } release { file -> - closeFile(file) - } use { file -> - fileToString(file) - } - - println(res) -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-10.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-10.kt deleted file mode 100644 index 57e567884b4..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-10.kt +++ /dev/null @@ -1,31 +0,0 @@ -// This file was automatically generated from Resource.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleResource10 - -import arrow.fx.coroutines.* - -class File(url: String) { - suspend fun open(): File = this - suspend fun close(): Unit {} - override fun toString(): String = "This file contains some interesting content!" -} - -suspend fun openFile(uri: String): File = File(uri).open() -suspend fun closeFile(file: File): Unit = file.close() -suspend fun fileToString(file: File): String = file.toString() - -suspend fun main(): Unit { - val res: List = listOf( - "data.json", - "user.json", - "resource.json" - ).traverse { uri -> - resource { - openFile(uri) - } release { file -> - closeFile(file) - } - }.use { files -> - files.map { fileToString(it) } - } - res.forEach(::println) -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-11.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-11.kt deleted file mode 100644 index 3987d148522..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-11.kt +++ /dev/null @@ -1,31 +0,0 @@ -// This file was automatically generated from Resource.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleResource11 - -import arrow.fx.coroutines.* - -class File(url: String) { - suspend fun open(): File = this - suspend fun close(): Unit {} - override fun toString(): String = "This file contains some interesting content!" -} - -suspend fun openFile(uri: String): File = File(uri).open() -suspend fun closeFile(file: File): Unit = file.close() -suspend fun fileToString(file: File): String = file.toString() - -suspend fun main(): Unit { - val res: List = listOf( - "data.json", - "user.json", - "resource.json" - ).map { uri -> - resource { - openFile(uri) - } release { file -> - closeFile(file) - } - }.sequence().use { files -> - files.map { fileToString(it) } - } - res.forEach(::println) -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-computations-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-computations-01.kt deleted file mode 100644 index 918baf6a9e3..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-computations-01.kt +++ /dev/null @@ -1,36 +0,0 @@ -// This file was automatically generated from resource.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleResourceComputations01 - -import arrow.fx.coroutines.continuations.resource -import arrow.fx.coroutines.release - -class UserProcessor { - fun start(): Unit = println("Creating UserProcessor") - fun shutdown(): Unit = println("Shutting down UserProcessor") - fun process(ds: DataSource): List = - ds.users().map { "Processed $it" } -} - -class DataSource { - fun connect(): Unit = println("Connecting dataSource") - fun users(): List = listOf("User-1", "User-2", "User-3") - fun close(): Unit = println("Closed dataSource") -} - -class Service(val db: DataSource, val userProcessor: UserProcessor) { - suspend fun processData(): List = userProcessor.process(db) -} - -val userProcessor = resource { - UserProcessor().also(UserProcessor::start) -} release UserProcessor::shutdown - -val dataSource = resource { - DataSource().also { it.connect() } -} release DataSource::close - -suspend fun main(): Unit { - resource { - Service(dataSource.bind(), userProcessor.bind()) - }.use { service -> service.processData() } -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt index 5a87fcb8a8d..d391d97d3a3 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt @@ -1,13 +1,15 @@ // This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResourceextensions01 -import arrow.fx.coroutines.* +import arrow.fx.coroutines.executor +import arrow.fx.coroutines.use +import arrow.fx.coroutines.parTraverse import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicInteger import kotlin.math.max suspend fun main(): Unit { - val pool = Resource.fromExecutor { + val pool = executor { val ctr = AtomicInteger(0) val size = max(2, Runtime.getRuntime().availableProcessors()) Executors.newFixedThreadPool(size) { r -> diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt index a5dfe9dd952..af4c56052c4 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt @@ -1,13 +1,13 @@ // This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResourceextensions02 -import arrow.fx.coroutines.* +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.closeable import java.io.FileInputStream suspend fun copyFile(src: String, dest: String): Unit = - Resource.fromCloseable { FileInputStream(src) } - .zip(Resource.fromCloseable { FileInputStream(dest) }) - .use { (a: FileInputStream, b: FileInputStream) -> - /** read from [a] and write to [b]. **/ - // Both resources will be closed accordingly to their #close methods - } + resourceScope { + val a: FileInputStream = closeable { FileInputStream(src) } + val b: FileInputStream = closeable { FileInputStream(dest) } + /** read from `a` and write to `b`. **/ + } // Both resources will be closed accordingly to their #close methods diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt index 2a07b2582dc..cbdf566e457 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt @@ -1,13 +1,13 @@ // This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResourceextensions03 -import arrow.fx.coroutines.* +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.autoCloseable import java.io.FileInputStream suspend fun copyFile(src: String, dest: String): Unit = - Resource.fromAutoCloseable { FileInputStream(src) } - .zip(Resource.fromAutoCloseable { FileInputStream(dest) }) - .use { (a: FileInputStream, b: FileInputStream) -> - /** read from [a] and write to [b]. **/ - // Both resources will be closed accordingly to their #close methods - } + resourceScope { + val a: FileInputStream = autoCloseable { FileInputStream(src) } + val b: FileInputStream = autoCloseable { FileInputStream(dest) } + /** read from [a] and write to [b]. **/ + } // Both resources will be closed accordingly to their #close methods diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt index 596e08c1934..82a7d7c1ae0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt @@ -1,14 +1,14 @@ // This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. package arrow.fx.coroutines.examples.exampleResourceextensions04 -import arrow.fx.coroutines.* +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.singleThreadContext import kotlinx.coroutines.withContext +import kotlinx.coroutines.ExecutorCoroutineDispatcher -val singleCtx = Resource.singleThreadContext("single") - -suspend fun main(): Unit = - singleCtx.use { ctx -> - withContext(ctx) { - println("I am running on ${Thread.currentThread().name}") - } +suspend fun main(): Unit = resourceScope { + val single: ExecutorCoroutineDispatcher = singleThreadContext("single") + withContext(single) { + println("I am running on ${Thread.currentThread().name}") } +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt new file mode 100644 index 00000000000..9b7080d25a3 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResourceextensions05 + +import arrow.fx.coroutines.fixedThreadPoolContext +import arrow.fx.coroutines.resourceScope +import kotlinx.coroutines.withContext +import kotlinx.coroutines.ExecutorCoroutineDispatcher + +suspend fun main(): Unit = resourceScope { + val pool: ExecutorCoroutineDispatcher = fixedThreadPoolContext(8, "custom-pool") + withContext(pool) { + println("I am running on ${Thread.currentThread().name}") + } +} From bf07694d61afad282fc0a3dd8518e0ea2be29f1e Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Fri, 2 Sep 2022 10:40:23 +0200 Subject: [PATCH 003/114] [Arrow 2.0] Effect without suspending shift (#2797) * Shift without suspend, inline all the rest * Add new error handlers signatures * Make ShiftCancellationException private --- arrow-libs/core/arrow-core/api/arrow-core.api | 686 ++++++------------ .../commonMain/kotlin/arrow/core/Either.kt | 170 ++--- .../arrow/core/continuations/Builders.kt | 104 +++ .../arrow/core/continuations/EagerEffect.kt | 204 ------ .../core/continuations/EagerEffectScope.kt | 269 ------- .../kotlin/arrow/core/continuations/Effect.kt | 484 +++++------- .../arrow/core/continuations/EffectScope.kt | 294 -------- .../arrow/core/continuations/ErrorHandlers.kt | 111 +++ .../kotlin/arrow/core/continuations/Fold.kt | 80 ++ .../arrow/core/continuations/Mappers.kt | 45 ++ .../kotlin/arrow/core/continuations/Shift.kt | 110 +++ .../kotlin/arrow/core/continuations/either.kt | 12 - .../kotlin/arrow/core/continuations/ior.kt | 83 --- .../arrow/core/continuations/nullable.kt | 67 -- .../kotlin/arrow/core/continuations/option.kt | 64 -- .../kotlin/arrow/core/continuations/result.kt | 41 -- .../core/continuations/EagerEffectSpec.kt | 154 +++- .../arrow/core/continuations/EffectSpec.kt | 389 +++++----- .../arrow/core/continuations/IorSpec.kt | 4 +- .../arrow/core/continuations/OptionSpec.kt | 2 +- .../StructuredConcurrencySpec.kt | 6 +- .../kotlin/arrow/core/continuations/predef.kt | 4 +- .../arrow/core/continuations/EffectUsage.kt | 10 +- .../examples/example-eager-effect-01.kt | 17 - .../examples/example-eager-effect-02.kt | 26 - .../examples/example-eager-effect-scope-01.kt | 12 - .../examples/example-eager-effect-scope-02.kt | 20 - .../examples/example-eager-effect-scope-03.kt | 14 - .../examples/example-eager-effect-scope-04.kt | 14 - .../examples/example-eager-effect-scope-05.kt | 15 - .../examples/example-eager-effect-scope-06.kt | 18 - .../examples/example-eager-effect-scope-07.kt | 16 - .../examples/example-eager-effect-scope-08.kt | 20 - .../examples/example-eager-effect-scope-09.kt | 16 - .../kotlin/examples/example-effect-01.kt | 21 +- .../kotlin/examples/example-effect-02.kt | 57 +- ...ffect-guide-03.kt => example-effect-03.kt} | 3 +- .../kotlin/examples/example-effect-04.kt | 55 ++ ...ffect-guide-05.kt => example-effect-05.kt} | 3 +- ...ffect-guide-06.kt => example-effect-06.kt} | 3 +- ...ffect-guide-07.kt => example-effect-07.kt} | 3 +- ...ffect-guide-08.kt => example-effect-08.kt} | 3 +- ...ffect-guide-09.kt => example-effect-09.kt} | 3 +- ...ffect-guide-10.kt => example-effect-10.kt} | 4 +- ...ffect-guide-11.kt => example-effect-11.kt} | 3 +- ...ffect-guide-12.kt => example-effect-12.kt} | 3 +- ...ffect-guide-13.kt => example-effect-13.kt} | 3 +- .../examples/example-effect-error-01.kt | 14 + .../examples/example-effect-error-02.kt | 14 + .../examples/example-effect-error-03.kt | 16 + .../examples/example-effect-guide-01.kt | 17 - .../examples/example-effect-guide-02.kt | 49 -- .../examples/example-effect-guide-04.kt | 33 - .../examples/example-effect-scope-01.kt | 12 - .../examples/example-effect-scope-02.kt | 20 - .../examples/example-effect-scope-03.kt | 21 - .../examples/example-effect-scope-04.kt | 14 - .../examples/example-effect-scope-05.kt | 14 - .../examples/example-effect-scope-06.kt | 15 - .../examples/example-effect-scope-07.kt | 18 - .../examples/example-effect-scope-08.kt | 16 - .../examples/example-effect-scope-09.kt | 20 - .../examples/example-effect-scope-10.kt | 16 - .../kotlin/examples/example-either-45.kt | 20 +- .../kotlin/examples/example-either-46.kt | 5 +- .../kotlin/examples/example-either-47.kt | 5 +- .../kotlin/examples/example-either-48.kt | 13 +- .../kotlin/examples/example-either-49.kt | 19 +- .../kotlin/examples/example-either-50.kt | 18 +- .../kotlin/examples/example-either-51.kt | 11 +- .../kotlin/examples/example-either-52.kt | 9 +- .../kotlin/examples/example-either-53.kt | 12 +- .../kotlin/examples/example-either-54.kt | 13 + 73 files changed, 1477 insertions(+), 2702 deletions(-) create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffect.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffectScope.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EffectScope.kt create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/either.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ior.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/nullable.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/option.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/result.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-03.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-04.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-05.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-06.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-07.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-08.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-09.kt rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-03.kt => example-effect-03.kt} (84%) create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-05.kt => example-effect-05.kt} (91%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-06.kt => example-effect-06.kt} (93%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-07.kt => example-effect-07.kt} (93%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-08.kt => example-effect-08.kt} (91%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-09.kt => example-effect-09.kt} (92%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-10.kt => example-effect-10.kt} (93%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-11.kt => example-effect-11.kt} (88%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-12.kt => example-effect-12.kt} (87%) rename arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/{example-effect-guide-13.kt => example-effect-13.kt} (88%) create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-04.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-03.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-04.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-05.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-06.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-07.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-08.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-09.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 7ae8ccad9bc..e6aee5404b0 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -263,6 +263,7 @@ public final class arrow/core/EitherKt { public static final fun leftWiden (Larrow/core/Either;)Larrow/core/Either; public static final fun merge (Larrow/core/Either;)Ljava/lang/Object; public static final fun orNull (Larrow/core/Either;)Ljava/lang/Object; + public static final fun recover (Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; public static final fun redeem (Larrow/core/Either;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun redeemWith (Larrow/core/Either;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun replicate (Larrow/core/Either;ILarrow/typeclasses/Monoid;)Larrow/core/Either; @@ -2584,473 +2585,266 @@ public final class arrow/core/continuations/AtomicRefKt { public static final fun updateAndGet (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } -public final class arrow/core/continuations/Eager : arrow/core/continuations/ShiftCancellationException { - public fun (Larrow/core/continuations/Token;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)V - public final fun getRecover ()Lkotlin/jvm/functions/Function1; - public final fun getShifted ()Ljava/lang/Object; - public final fun getToken ()Larrow/core/continuations/Token; - public fun toString ()Ljava/lang/String; -} - -public abstract interface class arrow/core/continuations/EagerEffect { - public abstract fun attempt ()Larrow/core/continuations/EagerEffect; - public abstract fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun handleError (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun handleErrorWith (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun orNull ()Ljava/lang/Object; - public abstract fun redeem (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun redeemWith (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun toEither ()Larrow/core/Either; - public abstract fun toIor ()Larrow/core/Ior; - public abstract fun toOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public abstract fun toValidated ()Larrow/core/Validated; -} - -public final class arrow/core/continuations/EagerEffect$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EagerEffect;)Larrow/core/continuations/EagerEffect; - public static fun flatMap (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun fold (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun handleError (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun handleErrorWith (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun map (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun orNull (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; - public static fun redeem (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun redeemWith (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun toEither (Larrow/core/continuations/EagerEffect;)Larrow/core/Either; - public static fun toIor (Larrow/core/continuations/EagerEffect;)Larrow/core/Ior; - public static fun toOption (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static fun toValidated (Larrow/core/continuations/EagerEffect;)Larrow/core/Validated; -} - -public final class arrow/core/continuations/EagerEffectKt { - public static final fun eagerEffect (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/EagerEffect; - public static final fun merge (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/EagerEffectScope { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EagerEffectScope$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun ensure (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EagerEffectScopeKt { - public static final fun ensureNotNull (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/Effect { - public abstract fun attempt ()Larrow/core/continuations/Effect; - public abstract fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun handleError (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun handleErrorWith (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun orNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun redeem (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun redeemWith (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun toEither (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toIor (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toValidated (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/Effect$DefaultImpls { - public static fun attempt (Larrow/core/continuations/Effect;)Larrow/core/continuations/Effect; - public static fun fold (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun handleError (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun handleErrorWith (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun orNull (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun redeem (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun redeemWith (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun toEither (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toIor (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toOption (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toValidated (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +public final class arrow/core/continuations/DefaultShift : arrow/core/continuations/Shift { + public fun ()V + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun shift (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/Effect { + public static final fun _fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun _foldOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; + public static final fun catch (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; + public static final fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; + public static final fun either (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; + public static final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun ior (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; + public static final fun nullable (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun option (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; + public static final fun orNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun orNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; + public static final fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; + public static final fun result (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun shiftedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/continuations/DefaultShift;)Ljava/lang/Object; + public static final fun toEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; + public static final fun toEither (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toIor (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; + public static final fun toIor (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; + public static final fun toOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; + public static final fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; + public static final fun toValidated (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public abstract interface annotation class arrow/core/continuations/EffectDSL : java/lang/annotation/Annotation { } public final class arrow/core/continuations/EffectKt { - public static final fun effect (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static final fun merge (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/EffectScope { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectScope$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectScopeKt { - public static final fun ensureNotNull (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/FoldContinuation : arrow/core/continuations/Token, arrow/core/continuations/EffectScope, kotlin/coroutines/Continuation { - public field recover Lkotlin/jvm/functions/Function2; - public fun (Larrow/core/continuations/Token;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)V - public fun (Larrow/core/continuations/Token;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)V - public fun (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun eagerEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; + public static final fun effect (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; +} + +public final class arrow/core/continuations/IorShift : arrow/core/continuations/Shift, arrow/typeclasses/Semigroup { + public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/Shift;)V + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun getContext ()Lkotlin/coroutines/CoroutineContext; - public final fun getRecover ()Lkotlin/jvm/functions/Function2; - public fun resumeWith (Ljava/lang/Object;)V - public final fun setRecover (Lkotlin/jvm/functions/Function2;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/IorEagerEffectScope : arrow/core/continuations/EagerEffectScope, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/EagerEffectScope;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getLeftState ()Ljava/util/concurrent/atomic/AtomicReference; + public final fun invoke (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/IorEffectScope : arrow/core/continuations/EffectScope, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/EffectScope;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun shift (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/NullableShift : arrow/core/continuations/Shift { + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final synthetic fun box-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/NullableShift; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun getLeftState ()Ljava/util/concurrent/atomic/AtomicReference; - public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/NullableEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/NullableEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun constructor-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/Shift; + public static final fun ensure-impl (Larrow/core/continuations/Shift;Z)V + public static final fun ensureNotNull-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z + public static fun equals-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Larrow/core/continuations/Shift;Larrow/core/continuations/Shift;)Z public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun hashCode-impl (Larrow/core/continuations/Shift;)I + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; + public fun shift (Ljava/lang/Void;)Ljava/lang/Object; + public static fun shift-impl (Larrow/core/continuations/Shift;Ljava/lang/Void;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/NullableEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/NullableEffectScope; + public static fun toString-impl (Larrow/core/continuations/Shift;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Larrow/core/continuations/Shift; +} + +public final class arrow/core/continuations/OptionShift : arrow/core/continuations/Shift { + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final synthetic fun box-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/OptionShift; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun constructor-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/Shift; + public static final fun ensure-impl (Larrow/core/continuations/Shift;Z)V + public static final fun ensureNotNull-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z + public static fun equals-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Larrow/core/continuations/Shift;Larrow/core/continuations/Shift;)Z public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun hashCode-impl (Larrow/core/continuations/Shift;)I + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun shift (Larrow/core/None;)Ljava/lang/Object; + public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; + public static fun shift-impl (Larrow/core/continuations/Shift;Larrow/core/None;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/NullableKt { - public static final fun ensureNotNull-0Rsnnio (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensureNotNull-7s8y1X8 (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/OptionEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/OptionEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public fun shift (Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/OptionEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/OptionEffectScope; + public static fun toString-impl (Larrow/core/continuations/Shift;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Larrow/core/continuations/Shift; +} + +public final class arrow/core/continuations/ResultShift : arrow/core/continuations/Shift { + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final synthetic fun box-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/ResultShift; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public fun shift (Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/OptionKt { - public static final fun ensureNotNull-09sQPHg (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensureNotNull-dxZa7OQ (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toOption (Larrow/core/continuations/EagerEffect;)Larrow/core/Option; - public static final fun toOption (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/ResultEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/ResultEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun constructor-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/Shift; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z + public static fun equals-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Larrow/core/continuations/Shift;Larrow/core/continuations/Shift;)Z public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun hashCode-impl (Larrow/core/continuations/Shift;)I + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; + public fun shift (Ljava/lang/Throwable;)Ljava/lang/Object; + public static fun shift-impl (Larrow/core/continuations/Shift;Ljava/lang/Throwable;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/ResultEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/ResultEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/ResultKt { - public static final fun toResult (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; - public static final fun toResult (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract class arrow/core/continuations/ShiftCancellationException : java/util/concurrent/CancellationException { -} - -public final class arrow/core/continuations/Suspend : arrow/core/continuations/ShiftCancellationException { - public fun (Larrow/core/continuations/Token;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)V - public final fun getRecover ()Lkotlin/jvm/functions/Function2; - public final fun getShifted ()Ljava/lang/Object; - public final fun getToken ()Larrow/core/continuations/Token; - public fun toString ()Ljava/lang/String; -} - -public class arrow/core/continuations/Token { - public fun ()V - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/continuations/either { - public static final field INSTANCE Larrow/core/continuations/either; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/ior { - public static final field INSTANCE Larrow/core/continuations/ior; - public final fun eager (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function2;)Larrow/core/Ior; - public final fun invoke (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/nullable { - public static final field INSTANCE Larrow/core/continuations/nullable; - public final fun eager (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/option { - public static final field INSTANCE Larrow/core/continuations/option; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/result { - public static final field INSTANCE Larrow/core/continuations/result; - public final fun eager-IoAF18A (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke-gIAlu-s (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun toString-impl (Larrow/core/continuations/Shift;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Larrow/core/continuations/Shift; +} + +public abstract interface class arrow/core/continuations/Shift { + public abstract fun bind (Larrow/core/Either;)Ljava/lang/Object; + public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public abstract fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun shift (Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/Shift$DefaultImpls { + public static fun bind (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun catch (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/ShiftKt { + public static final fun catch (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static final fun ensure (Larrow/core/continuations/Shift;ZLkotlin/jvm/functions/Function0;)V + public static final fun ensureNotNull (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public static final fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static final fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; } public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Semigroup { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index c96a712caf6..3d479b8ede2 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -3,6 +3,9 @@ package arrow.core import arrow.core.Either.Companion.resolve import arrow.core.Either.Left import arrow.core.Either.Right +import arrow.core.continuations.Shift +import arrow.core.continuations.either +import arrow.core.continuations.ensure import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup import kotlin.experimental.ExperimentalTypeInference @@ -1229,6 +1232,32 @@ public sealed class Either { map { Unit } } +/** + * Recover from [E] when encountering [Left]. + * You can either return a new value of [A], or short-circuit by shifting with a value of [E2]. + * + * ```kotlin + * import arrow.core.Either + * import arrow.core.left + * import arrow.core.recover + * + * object User + * object Error + * + * val error: Either = Error.left() + * + * val a: Either = error.recover { error -> User } // Either.Right(User) + * val b: Either = error.recover { error -> shift("other-failure") } // Either.Left(other-failure) + * val c: Either = error.recover { error -> User } // Either.Right(User) + * ``` + * + */ +public inline fun Either.recover(recover: Shift.(E) -> A): Either = + when (this) { + is Right -> this + is Left -> either { recover(value) } + } + /** * Binds the given function across [Right]. * @@ -1257,7 +1286,7 @@ public fun Either>.flatten(): Either = * Left(12).getOrElse { 17 } // Result: 17 * } * ``` - * + * */ public inline fun Either<*, B>.getOrElse(default: () -> B): B = fold({ default() }, ::identity) @@ -1275,7 +1304,7 @@ public inline fun Either<*, B>.getOrElse(default: () -> B): B = * Left(12).orNull() // Result: null * } * ``` - * + * */ @Deprecated("Duplicated API. Please use Either's member function orNull. This will be removed towards Arrow 2.0", ReplaceWith("orNull()")) public fun Either<*, B>.orNull(): B? = @@ -1296,7 +1325,7 @@ public fun Either<*, B>.orNull(): B? = * Left(12).getOrHandle { it + 5 } // Result: 17 * } * ``` - * + * */ public inline fun Either.getOrHandle(default: (A) -> B): B = fold({ default(it) }, ::identity) @@ -1324,7 +1353,7 @@ public inline fun Either.getOrHandle(default: (A) -> B): B = * left.filterOrElse({ it > 10 }, { -1 }) // Result: Left(12) * } * ``` - * + * */ public inline fun Either.filterOrElse(predicate: (B) -> Boolean, default: () -> A): Either = flatMap { if (predicate(it)) Right(it) else Left(default()) } @@ -1357,7 +1386,7 @@ public inline fun Either.filterOrElse(predicate: (B) -> Boolean, de * //sampleEnd * } * ``` - * + * */ public inline fun Either.filterOrOther(predicate: (B) -> Boolean, default: (B) -> A): Either = flatMap { @@ -1379,7 +1408,7 @@ public inline fun Either.filterOrOther(predicate: (B) -> Boolean, d * Left(12).merge() // Result: 12 * } * ``` - * + * */ public inline fun Either.merge(): A = fold(::identity, ::identity) @@ -1404,7 +1433,7 @@ public inline fun Either.merge(): A = * Left(12).leftIfNull({ -1 }) // Result: Left(12) * } * ``` - * + * */ public inline fun Either.leftIfNull(default: () -> A): Either = flatMap { it.rightIfNotNull { default() } } @@ -1456,7 +1485,7 @@ public fun A.right(): Either = Right(this) * null.rightIfNotNull { "left" } // Left(a="left") * } * ``` - * + * */ public inline fun B?.rightIfNotNull(default: () -> A): Either = when (this) { null -> Left(default()) @@ -1477,22 +1506,13 @@ public inline fun Any?.rightIfNull(default: () -> A): Either = * This is like `flatMap` for the exception. */ public inline fun Either.handleErrorWith(f: (A) -> Either): Either = - when (this) { - is Left -> f(this.value) - is Right -> this - } + recover { f(it).bind() } public inline fun Either.handleError(f: (A) -> B): Either = - when (this) { - is Left -> f(value).right() - is Right -> this - } + recover { f(it) } public inline fun Either.redeem(fe: (A) -> C, fa: (B) -> C): Either = - when (this) { - is Left -> fe(value).right() - is Right -> map(fa) - } + either { fa(bind()) }.recover { fe(it) } public operator fun , B : Comparable> Either.compareTo(other: Either): Int = fold( @@ -1531,7 +1551,7 @@ public fun Iterable>.combineAll(MA: Monoid, MB: Monoid * println(chars) * } * ``` - * + * */ public fun Either.widen(): Either = this @@ -1540,31 +1560,17 @@ public fun Either.leftWiden(): Either = this public fun Either.zip(fb: Either, f: (B, C) -> D): Either = - flatMap { b -> - fb.map { c -> f(b, c) } - } + either { f(bind(), fb.bind()) } public fun Either.zip(fb: Either): Either> = - flatMap { a -> - fb.map { b -> Pair(a, b) } - } + either { Pair(bind(), fb.bind()) } public inline fun Either.zip( c: Either, d: Either, map: (B, C, D) -> E ): Either = - zip( - c, - d, - Right.unit, - Right.unit, - Right.unit, - Right.unit, - Right.unit, - Right.unit, - Right.unit - ) { b, c, d, _, _, _, _, _, _, _ -> map(b, c, d) } + either { map(bind(), c.bind(), d.bind()) } public inline fun Either.zip( c: Either, @@ -1572,17 +1578,7 @@ public inline fun Either.zip( e: Either, map: (B, C, D, E) -> F ): Either = - zip( - c, - d, - e, - Right.unit, - Right.unit, - Right.unit, - Right.unit, - Right.unit, - Right.unit - ) { b, c, d, e, _, _, _, _, _, _ -> map(b, c, d, e) } + either { map(bind(), c.bind(), d.bind(), e.bind()) } public inline fun Either.zip( c: Either, @@ -1591,17 +1587,7 @@ public inline fun Either.zip( f: Either, map: (B, C, D, E, F) -> G ): Either = - zip( - c, - d, - e, - f, - Right.unit, - Right.unit, - Right.unit, - Right.unit, - Right.unit - ) { b, c, d, e, f, _, _, _, _, _ -> map(b, c, d, e, f) } + either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind()) } public inline fun Either.zip( c: Either, @@ -1611,16 +1597,7 @@ public inline fun Either.zip( g: Either, map: (B, C, D, E, F, G) -> H ): Either = - zip(c, d, e, f, g, Right.unit, Right.unit, Right.unit, Right.unit) { b, c, d, e, f, g, _, _, _, _ -> - map( - b, - c, - d, - e, - f, - g - ) - } + either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) } public inline fun Either.zip( c: Either, @@ -1631,17 +1608,7 @@ public inline fun Either.zip( h: Either, map: (B, C, D, E, F, G, H) -> I ): Either = - zip(c, d, e, f, g, h, Right.unit, Right.unit, Right.unit) { b, c, d, e, f, g, h, _, _, _ -> - map( - b, - c, - d, - e, - f, - g, - h - ) - } + either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) } public inline fun Either.zip( c: Either, @@ -1653,7 +1620,7 @@ public inline fun Either.zip( i: Either, map: (B, C, D, E, F, G, H, I) -> J ): Either = - zip(c, d, e, f, g, h, i, Right.unit, Right.unit) { b, c, d, e, f, g, h, i, _, _ -> map(b, c, d, e, f, g, h, i) } + either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) } public inline fun Either.zip( c: Either, @@ -1666,7 +1633,7 @@ public inline fun Either.zip( j: Either, map: (B, C, D, E, F, G, H, I, J) -> K ): Either = - zip(c, d, e, f, g, h, i, j, Right.unit) { b, c, d, e, f, g, h, i, j, _ -> map(b, c, d, e, f, g, h, i, j) } + either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind()) } public inline fun Either.zip( c: Either, @@ -1679,28 +1646,9 @@ public inline fun Either.zip( j: Either, k: Either, map: (B, C, D, E, F, G, H, I, J, K) -> L -): Either = - flatMap { bb -> - c.flatMap { cc -> - d.flatMap { dd -> - e.flatMap { ee -> - f.flatMap { ff -> - g.flatMap { gg -> - h.flatMap { hh -> - i.flatMap { ii -> - j.flatMap { jj -> - k.map { kk -> - map(bb, cc, dd, ee, ff, gg, hh, ii, jj, kk) - } - } - } - } - } - } - } - } - } - } +): Either = either { + map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind(), k.bind()) +} public fun Either.replicate(n: Int, MB: Monoid): Either = if (n <= 0) MB.empty().right() @@ -1712,16 +1660,14 @@ public fun Either.replicate(n: Int, MB: Monoid): Either = } public inline fun Either.ensure(error: () -> A, predicate: (B) -> Boolean): Either = - when (this) { - is Right -> if (predicate(this.value)) this else error().left() - is Left -> this + either { + val b = bind() + ensure(predicate(b), error) + b } public inline fun Either.redeemWith(fa: (A) -> Either, fb: (B) -> Either): Either = - when (this) { - is Left -> fa(this.value) - is Right -> fb(this.value) - } + either { fold({ fa(it).bind() }, { fb(it).bind() }) } public fun Either>.sequence(): List> = traverse(::identity) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt new file mode 100644 index 00000000000..06abb84dc15 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt @@ -0,0 +1,104 @@ +@file:JvmMultifileClass +@file:JvmName("Effect") +@file:OptIn(ExperimentalTypeInference::class, ExperimentalContracts::class) + +package arrow.core.continuations + +import arrow.core.Either +import arrow.core.EmptyValue +import arrow.core.Ior +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.core.identity +import arrow.typeclasses.Semigroup +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract +import kotlin.experimental.ExperimentalTypeInference +import kotlin.jvm.JvmInline +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + +public inline fun either(@BuilderInference block: Shift.() -> A): Either = + fold({ block.invoke(this) }, { Either.Left(it) }, { Either.Right(it) }) + +public inline fun nullable(block: NullableShift.() -> A): A? = + fold({ block(NullableShift(this)) }, { null }, ::identity) + +public inline fun result(action: ResultShift.() -> A): Result = + fold({ action(ResultShift(this)) }, Result.Companion::failure, Result.Companion::success) + +public inline fun option(action: OptionShift.() -> A): Option = + fold({ action(OptionShift(this)) }, ::identity, ::Some) + +public inline fun ior(semigroup: Semigroup, @BuilderInference action: IorShift.() -> A): Ior = + fold({ IorShift(semigroup, this).invoke(action) }, { Ior.Left(it) }, ::identity) + +@JvmInline +public value class NullableShift(private val cont: Shift) : Shift { + @EffectDSL + public fun ensure(value: Boolean): Unit = ensure(value) { null } + override fun shift(r: Nothing?): B = cont.shift(r) + public fun Option.bind(): B = bind { shift(null) } + + public fun B?.bind(): B { + contract { returns() implies (this@bind != null) } + return this ?: shift(null) + } + + public fun ensureNotNull(value: B?): B { + contract { returns() implies (value != null) } + return ensureNotNull(value) { null } + } +} + +@JvmInline +public value class ResultShift(private val cont: Shift) : Shift { + override fun shift(r: Throwable): B = cont.shift(r) + public fun Result.bind(): B = fold(::identity) { shift(it) } +} + +@JvmInline +public value class OptionShift(private val cont: Shift) : Shift { + override fun shift(r: None): B = cont.shift(r) + public fun Option.bind(): B = bind { shift(None) } + public fun ensure(value: Boolean): Unit = ensure(value) { None } + + public fun ensureNotNull(value: B?): B { + contract { returns() implies (value != null) } + return ensureNotNull(value) { None } + } +} + +public class IorShift @PublishedApi internal constructor(semigroup: Semigroup, private val effect: Shift) : + Shift, Semigroup by semigroup { + + // TODO this is a mess... + @PublishedApi + internal var leftState: AtomicRef = AtomicRef(EmptyValue) + override fun shift(r: E): B = effect.shift(combine(r)) + + public fun Ior.bind(): B = + when (this) { + is Ior.Left -> shift(value) + is Ior.Right -> value + is Ior.Both -> { + combine(leftValue) + rightValue + } + } + + @PublishedApi + internal inline operator fun invoke(action: IorShift.() -> A): Ior { + val res = action(this) + val leftState = leftState.get() + return if (leftState === EmptyValue) Ior.Right(res) + else Ior.Both(EmptyValue.unbox(leftState), res) + } + + @Suppress("UNCHECKED_CAST") + private fun combine(other: E): E = + leftState.updateAndGet { state -> + if (state === EmptyValue) other else EmptyValue.unbox(state).combine(other) + } as E +} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffect.kt deleted file mode 100644 index e5a7269cb54..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffect.kt +++ /dev/null @@ -1,204 +0,0 @@ -package arrow.core.continuations - -import arrow.core.Either -import arrow.core.Ior -import arrow.core.Option -import arrow.core.Some -import arrow.core.Validated -import arrow.core.identity -import arrow.core.nonFatalOrThrow -import kotlin.coroutines.Continuation -import kotlin.coroutines.EmptyCoroutineContext -import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn -import kotlin.coroutines.RestrictsSuspension - -/** - * [RestrictsSuspension] version of [Effect]. This version runs eagerly, and can be used in - * non-suspending code. - * An [effect] computation interoperates with an [EagerEffect] via `bind`. - * @see Effect - */ -public interface EagerEffect { - - /** - * Runs the non-suspending computation by creating a [Continuation] with an [EmptyCoroutineContext], - * and running the `fold` function over the computation. - * - * When the [EagerEffect] has shifted with [R] it will [recover] the shifted value to [B], and when it - * ran the computation to completion it will [transform] the value [A] to [B]. - * - * ```kotlin - * import arrow.core.continuations.eagerEffect - * import io.kotest.matchers.shouldBe - * - * fun main() { - * val shift = eagerEffect { - * shift("Hello, World!") - * }.fold({ str: String -> str }, { int -> int.toString() }) - * shift shouldBe "Hello, World!" - * - * val res = eagerEffect { - * 1000 - * }.fold({ str: String -> str.length }, { int -> int }) - * res shouldBe 1000 - * } - * ``` - * - */ - public fun fold(recover: (R) -> B, transform: (A) -> B): B - - /** - * Like `fold` but also allows folding over any unexpected [Throwable] that might have occurred. - * @see fold - */ - public fun fold( - error: (error: Throwable) -> B, - recover: (shifted: R) -> B, - transform: (value: A) -> B - ): B = - try { - fold(recover, transform) - } catch (e: Throwable) { - error(e.nonFatalOrThrow()) - } - - /** - * [fold] the [EagerEffect] into an [Ior]. Where the shifted value [R] is mapped to [Ior.Left], and - * result value [A] is mapped to [Ior.Right]. - */ - public fun toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } - - /** - * [fold] the [EagerEffect] into an [Either]. Where the shifted value [R] is mapped to [Either.Left], and - * result value [A] is mapped to [Either.Right]. - */ - public fun toEither(): Either = fold({ Either.Left(it) }) { Either.Right(it) } - - /** - * [fold] the [EagerEffect] into an [Validated]. Where the shifted value [R] is mapped to - * [Validated.Invalid], and result value [A] is mapped to [Validated.Valid]. - */ - public fun toValidated(): Validated = - fold({ Validated.Invalid(it) }) { Validated.Valid(it) } - - /** - * [fold] the [EagerEffect] into an [A?]. Where the shifted value [R] is mapped to - * [null], and result value [A]. - */ - public fun orNull(): A? = fold({ null }, ::identity) - - /** - * [fold] the [EagerEffect] into an [Option]. Where the shifted value [R] is mapped to [Option] by the - * provided function [orElse], and result value [A] is mapped to [Some]. - */ - public fun toOption(orElse: (R) -> Option<@UnsafeVariance A>): Option = - fold(orElse, ::Some) - - @Deprecated(deprecateMonadAppFunctorOperators, ReplaceWith("flatMap { eagerEffect { f(it) } }")) - public fun map(f: (A) -> B): EagerEffect = flatMap { a -> eagerEffect { f(a) } } - - @Deprecated(deprecateMonadAppFunctorOperators) - public fun flatMap(f: (A) -> EagerEffect<@UnsafeVariance R, B>): EagerEffect = eagerEffect { - f(bind()).bind() - } - - public fun attempt(): EagerEffect> = eagerEffect { - kotlin.runCatching { bind() } - } - - public fun handleError(f: (R) -> @UnsafeVariance A): EagerEffect = eagerEffect { - fold(f, ::identity) - } - - public fun handleErrorWith(f: (R) -> EagerEffect): EagerEffect = - eagerEffect { - toEither().fold({ r -> f(r).bind() }, ::identity) - } - - public fun redeem(f: (R) -> B, g: (A) -> B): EagerEffect = eagerEffect { - fold(f, g) - } - - public fun redeemWith( - f: (R) -> EagerEffect, - g: (A) -> EagerEffect - ): EagerEffect = eagerEffect { fold(f, g).bind() } -} - -@PublishedApi -internal class Eager(val token: Token, val shifted: Any?, val recover: (Any?) -> Any?) : - ShiftCancellationException() { - override fun toString(): String = "ShiftCancellationException($message)" -} - -/** - * DSL for constructing `EagerEffect` values - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.None - * import arrow.core.Option - * import arrow.core.Validated - * import arrow.core.continuations.eagerEffect - * import io.kotest.assertions.fail - * import io.kotest.matchers.shouldBe - * - * fun main() { - * eagerEffect { - * val x = Either.Right(1).bind() - * val y = Validated.Valid(2).bind() - * val z = Option(3).bind { "Option was empty" } - * x + y + z - * }.fold({ fail("Shift can never be the result") }, { it shouldBe 6 }) - * - * eagerEffect { - * val x = Either.Right(1).bind() - * val y = Validated.Valid(2).bind() - * val z: Int = None.bind { "Option was empty" } - * x + y + z - * }.fold({ it shouldBe "Option was empty" }, { fail("Int can never be the result") }) - * } - * ``` - * - */ -public fun eagerEffect(f: suspend EagerEffectScope.() -> A): EagerEffect = DefaultEagerEffect(f) - -private class DefaultEagerEffect(private val f: suspend EagerEffectScope.() -> A) : EagerEffect { - override fun fold(recover: (R) -> B, transform: (A) -> B): B { - val token = Token() - val eagerEffectScope = - object : EagerEffectScope { - // Shift away from this Continuation by intercepting it, and completing it with - // ShiftCancellationException - // This is needed because this function will never yield a result, - // so it needs to be cancelled to properly support coroutine cancellation - override suspend fun shift(r: R): B = - // Some interesting consequences of how Continuation Cancellation works in Kotlin. - // We have to throw CancellationException to signal the Continuation was cancelled, and we - // shifted away. - // This however also means that the user can try/catch shift and recover from the - // CancellationException and thus effectively recovering from the cancellation/shift. - // This means try/catch is also capable of recovering from monadic errors. - // See: EagerEffectSpec - try/catch tests - throw Eager(token, r, recover as (Any?) -> Any?) - } - - return try { - suspend { transform(f(eagerEffectScope)) } - .startCoroutineUninterceptedOrReturn(Continuation(EmptyCoroutineContext) { result -> - result.getOrElse { throwable -> - if (throwable is Eager && token == throwable.token) { - throwable.recover(throwable.shifted) as B - } else throw throwable - } - }) as B - } catch (e: Eager) { - if (token == e.token) e.recover(e.shifted) as B - else throw e - } - } -} - -private const val deprecateMonadAppFunctorOperators: String = "Operators related to Functor, Applicative or Monad hierarchies are being deprecated in favor of bind" - -public fun EagerEffect.merge(): A = fold(::identity, ::identity) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffectScope.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffectScope.kt deleted file mode 100644 index 2eedc8bf645..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffectScope.kt +++ /dev/null @@ -1,269 +0,0 @@ -package arrow.core.continuations - -import arrow.core.Either -import arrow.core.EmptyValue -import arrow.core.None -import arrow.core.Option -import arrow.core.Some -import arrow.core.Validated -import arrow.core.identity -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.coroutines.RestrictsSuspension -import kotlin.experimental.ExperimentalTypeInference -import kotlin.jvm.JvmInline - -/** Context of the [EagerEffect] DSL. */ -@RestrictsSuspension -public interface EagerEffectScope { - - /** Short-circuit the [EagerEffect] computation with value [R]. - * - * ```kotlin - * import arrow.core.continuations.eagerEffect - * import io.kotest.assertions.fail - * import io.kotest.matchers.shouldBe - * - * fun main() { - * eagerEffect { - * shift("SHIFT ME") - * }.fold({ it shouldBe "SHIFT ME" }, { fail("Computation never finishes") }) - * } - * ``` - * - */ - public suspend fun shift(r: R): B - - /** - * Runs the [EagerEffect] to finish, returning [B] or [shift] in case of [R]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.continuations.EagerEffect - * import arrow.core.continuations.eagerEffect - * import arrow.core.identity - * import io.kotest.matchers.shouldBe - * - * fun Either.toEagerEffect(): EagerEffect = eagerEffect { - * fold({ e -> shift(e) }, ::identity) - * } - * - * fun main() { - * val either = Either.Left("failed") - * eagerEffect { - * val x: Int = either.toEagerEffect().bind() - * x - * }.toEither() shouldBe either - * } - * ``` - * - */ - public suspend fun EagerEffect.bind(): B { - var left: Any? = EmptyValue - var right: Any? = EmptyValue - fold({ r -> left = r }, { a -> right = a }) - return if (left === EmptyValue) EmptyValue.unbox(right) else shift(EmptyValue.unbox(left)) - } - - /** - * Folds [Either] into [EagerEffect], by returning [B] or a shift with [R]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.continuations.eagerEffect - * import io.kotest.matchers.shouldBe - * - * fun main() { - * val either = Either.Right(9) - * eagerEffect { - * val x: Int = either.bind() - * x - * }.toEither() shouldBe either - * } - * ``` - * - */ - public suspend fun Either.bind(): B = - when (this) { - is Either.Left -> shift(value) - is Either.Right -> value - } - - /** - * Folds [Validated] into [EagerEffect], by returning [B] or a shift with [R]. - * - * ```kotlin - * import arrow.core.Validated - * import arrow.core.continuations.eagerEffect - * import io.kotest.matchers.shouldBe - * - * fun main() { - * val validated = Validated.Valid(40) - * eagerEffect { - * val x: Int = validated.bind() - * x - * }.toValidated() shouldBe validated - * } - * ``` - * - */ - public suspend fun Validated.bind(): B = - when (this) { - is Validated.Valid -> value - is Validated.Invalid -> shift(value) - } - - /** - * Folds [Result] into [EagerEffect], by returning [B] or a transforming [Throwable] into [R] and - * shifting the result. - * - * ```kotlin - * import arrow.core.continuations.eagerEffect - * import arrow.core.identity - * import io.kotest.matchers.shouldBe - * - * private val default = "failed" - * fun main() { - * val result = Result.success(1) - * eagerEffect { - * val x: Int = result.bind { _: Throwable -> default } - * x - * }.fold({ default }, ::identity) shouldBe result.getOrElse { default } - * } - * ``` - * - */ - public suspend fun Result.bind(transform: (Throwable) -> R): B = - fold(::identity) { throwable -> shift(transform(throwable)) } - - /** - * Folds [Option] into [EagerEffect], by returning [B] or a transforming [None] into [R] and shifting the - * result. - * - * ```kotlin - * import arrow.core.None - * import arrow.core.Option - * import arrow.core.continuations.eagerEffect - * import arrow.core.getOrElse - * import arrow.core.identity - * import io.kotest.matchers.shouldBe - * - * private val default = "failed" - * fun main() { - * val option: Option = None - * eagerEffect { - * val x: Int = option.bind { default } - * x - * }.fold({ default }, ::identity) shouldBe option.getOrElse { default } - * } - * ``` - * - */ - public suspend fun Option.bind(shift: () -> R): B = - when (this) { - None -> shift(shift()) - is Some -> value - } - - /** - * ensure that condition is `true`, if it's `false` it will `shift` with the provided value [R]. - * Monadic version of [kotlin.require]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.continuations.eagerEffect - * import io.kotest.matchers.shouldBe - * - * fun main() { - * val condition = true - * val failure = "failed" - * val int = 4 - * eagerEffect { - * ensure(condition) { failure } - * int - * }.toEither() shouldBe if(condition) Either.Right(int) else Either.Left(failure) - * } - * ``` - * - */ - public suspend fun ensure(condition: Boolean, shift: () -> R): Unit = - if (condition) Unit else shift(shift()) - - /** - * Encloses an action for which you want to catch any `shift`. - * [attempt] is used in combination with [catch]. - * - * ``` - * attempt { ... } catch { ... } - * ``` - * - * The [f] may `shift` into a different `EagerEffectScope`, giving - * the chance for a later [catch] to change the shifted value. - * This is useful to simulate re-throwing of exceptions. - */ - @OptIn(ExperimentalTypeInference::class) - public suspend fun attempt( - @BuilderInference - f: suspend EagerEffectScope.() -> A, - ): suspend EagerEffectScope.() -> A = f - - - /** - * When the [EagerEffect] has shifted with [R] it will [recover] - * the shifted value to [A], and when it ran the computation to - * completion it will return the value [A]. - * [catch] is used in combination with [attempt]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.None - * import arrow.core.Option - * import arrow.core.Validated - * import arrow.core.continuations.eagerEffect - * import io.kotest.assertions.fail - * import io.kotest.matchers.shouldBe - * - * fun main() { - * eagerEffect { - * val x = Either.Right(1).bind() - * val y = Validated.Valid(2).bind() - * val z = - * attempt { None.bind { "Option was empty" } } catch { 0 } - * x + y + z - * }.fold({ fail("Shift can never be the result") }, { it shouldBe 3 }) - * } - * ``` - * - */ - public infix fun (suspend EagerEffectScope.() -> A).catch( - recover: EagerEffectScope.(E) -> A, - ): A = eagerEffect(this).fold({ recover(it) }, ::identity) -} - -/** - * Ensure that [value] is not `null`. if it's non-null it will be smart-casted and returned if it's - * `false` it will `shift` with the provided value [R]. Monadic version of [kotlin.requireNotNull]. - * - * ```kotlin - * import arrow.core.continuations.eagerEffect - * import arrow.core.continuations.ensureNotNull - * import arrow.core.left - * import arrow.core.right - * import io.kotest.matchers.shouldBe - * - * fun main() { - * val failure = "failed" - * val int: Int? = null - * eagerEffect { - * ensureNotNull(int) { failure } - * }.toEither() shouldBe (int?.right() ?: failure.left()) - * } - * ``` - * - */ -@OptIn(ExperimentalContracts::class) -public suspend fun EagerEffectScope.ensureNotNull(value: B?, shift: () -> R): B { - contract { returns() implies (value != null) } - return value ?: shift(shift()) -} - diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt index 0f623ea19fe..802dc7fac1c 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt @@ -1,33 +1,23 @@ +@file:JvmMultifileClass +@file:OptIn(ExperimentalTypeInference::class) + package arrow.core.continuations -import arrow.core.Either -import arrow.core.Ior -import arrow.core.NonFatal -import arrow.core.Option -import arrow.core.Some -import arrow.core.Validated -import arrow.core.identity -import arrow.core.nonFatalOrThrow -import kotlin.coroutines.Continuation -import kotlin.coroutines.CoroutineContext -import kotlin.coroutines.cancellation.CancellationException -import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED -import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn -import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn -import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException +import kotlin.experimental.ExperimentalTypeInference +import kotlin.jvm.JvmMultifileClass /** - * [Effect] represents a function of `suspend () -> A`, that short-circuit with a value of [R] (and [Throwable]), - * or completes with a value of [A]. + * [Effect] represents a function of `suspend Shift.() -> A`, that short-circuit with a value of `R` or `Throwable`, or completes with a value of `A`. * - * So [Effect] is defined by `suspend fun fold(f: suspend (R) -> B, g: suspend (A) -> B): B`, - * to map both values of [R] and [A] to a value of `B`. + * So [Effect] is defined by `suspend fun fold(recover: suspend (Throwable) -> B, resolve: suspend (R) -> B, transform: suspend (A) -> B): B`, + * to map all values of `R`, `Throwable` and `A` to a value of `B`. * * * [Writing a program with Effect](#writing-a-program-with-effect) * [Handling errors](#handling-errors) + * [recover](#recover) + * [catch](#catch) * [Structured Concurrency](#structured-concurrency) * [Arrow Fx Coroutines](#arrow-fx-coroutines) * [parZip](#parzip) @@ -42,7 +32,6 @@ import kotlin.coroutines.resumeWithException * * - * * ## Writing a program with Effect * * Let's write a small program to read a file from disk, and instead of having the program work exception based we want to @@ -50,13 +39,14 @@ import kotlin.coroutines.resumeWithException * * We'll start by defining a small function that accepts a [String], and does some simply validation to check that the path * is not empty. If the path is empty, we want to program to result in `EmptyPath`. So we're immediately going to see how - * we can raise an error of any arbitrary type [R] by using the function `shift`. The name `shift` comes shifting (or - * changing, especially unexpectedly), away from the computation and finishing the `Continuation` with [R]. + * we can raise an error of any arbitrary type `R` by using the function `shift`. The name `shift` comes shifting (or + * changing, especially unexpectedly), away from the computation and finishing the `Continuation` with `R`. * * * ```kotlin * object EmptyPath @@ -66,11 +56,10 @@ import kotlin.coroutines.resumeWithException * } * ``` * - * Here we see how we can define an `Effect` which has `EmptyPath` for the shift type [R], and `Unit` for the success - * type [A]. + * Here we see how we can define an `Effect` which has `EmptyPath` for the shift type `R`, and `Unit` for the success type `A`. * * Patterns like validating a [Boolean] is very common, and the [Effect] DSL offers utility functions like [kotlin.require] - * and [kotlin.requireNotNull]. They're named [EffectScope.ensure] and [ensureNotNull] to avoid conflicts with the `kotlin` namespace. + * and [kotlin.requireNotNull]. They're named [ensure] and [ensureNotNull] to avoid conflicts with the `kotlin` namespace. * So let's rewrite the function from above to use the DSL instead. * * ```kotlin @@ -79,7 +68,7 @@ import kotlin.coroutines.resumeWithException * ensure(path.isNotEmpty()) { EmptyPath } * } * ``` - * + * * * Now that we have the path, we can read from the `File` and return it as a domain model `Content`. * We also want to take a look at what exceptions reading from a file might occur `FileNotFoundException` & `SecurityError`, @@ -92,7 +81,13 @@ import kotlin.coroutines.resumeWithException * import arrow.core.Validated * import arrow.core.continuations.Effect * import arrow.core.continuations.effect + * import arrow.core.continuations.fold + * import arrow.core.continuations.toEither + * import arrow.core.continuations.toValidated + * import arrow.core.continuations.toIor + * import arrow.core.continuations.toOption * import arrow.core.continuations.ensureNotNull + * import arrow.core.continuations.ensure * import io.kotest.matchers.collections.shouldNotBeEmpty * import io.kotest.matchers.shouldBe * import io.kotest.matchers.types.shouldBeInstanceOf @@ -148,7 +143,7 @@ import kotlin.coroutines.resumeWithException * .body.shouldNotBeEmpty() * } * ``` - * + * * * The functions above are available out of the box, but it's easy to define your own extension functions in terms * of `fold`. Implementing the `toEither()` operator is as simple as: @@ -159,6 +154,7 @@ import kotlin.coroutines.resumeWithException * import arrow.core.Option * import arrow.core.Some * import arrow.core.continuations.Effect + * import arrow.core.continuations.fold * import arrow.core.identity * --> * ```kotlin @@ -168,66 +164,152 @@ import kotlin.coroutines.resumeWithException * suspend fun Effect.toOption(): Option = * fold(::identity) { Some(it) } * ``` - * + * * - * Adding your own syntax to `EffectScope` is not advised, yet, but will be easy once "Multiple Receivers" become available. + * Adding your own syntax to `Shift` is not advised, yet, but will be easy once "Multiple Receivers" become available. * * ``` - * context(EffectScope) + * context(Shift) * suspend fun Either.bind(): A = * when (this) { * is Either.Left -> shift(value) * is Either.Right -> value * } * - * context(EffectScope) + * context(Shift) * fun Option.bind(): A = * fold({ shift(it) }, ::identity) * ``` * * ## Handling errors * - * Handling errors of type [R] is the same as handling errors for any other data type in Arrow. - * `Effect` offers `handleError`, `handleErrorWith`, `redeem`, `redeemWith` and `attempt`. + * An Effect has 2 error channels: `Throwable` and `R` + * There are two separate handlers to transform either of the error channels. + * + * - `recover` to handle, and transform any error of type `R`. + * - `catch` to handle, and transform and error of type `Throwable`. + * + * ### recover + * + * `recover` handles the error of type `R`, + * by providing a new value of type `A`, raising a different error of type `E`, or throwing an exception. * - * As you can see in the examples below it is possible to resolve errors of [R] or `Throwable` in `Effect` in a generic manner. - * There is no need to run `Effect` into `Either` before you can access [R], - * you can simply call the same functions on `Effect` as you would on `Either` directly. + * Let's take a look at some examples: + * + * We define a `val failed` of type `Effect`, that represents a failed effect with value "failed". * * * ```kotlin * val failed: Effect = * effect { shift("failed") } + * ``` + * + * We can `recover` the failure, and resolve it by providing a default value of `-1` or the length of the `error: String`. + * + * ```kotlin + * val default: Effect = + * failed.recover { -1 } * * val resolved: Effect = - * failed.handleError { it.length } + * failed.recover { it.length } + * ``` * + * As you can see the resulting `error` is now of type `Nothing`, since we did not raise any new errors. + * So our `Effect` knows that no short-circuiting will occur during execution. Awesome! + * But it can also infer to any other error type that you might want instead, because it's never going to occur. + * So as you see below, we can even assign our `Effect` to `Effect`, where `E` can be any type. + * + * ```kotlin + * val default2: Effect = default + * val resolved2: Effect = resolved + * ``` + * + * `recover` also allows us to _change_ the error type when we resolve the error of type `R`. + * Below we handle our error of `String` and turn it into `List` using `reversed().toList()`. + * This is a powerful operation, since it allows us to transform our error types across boundaries or layers. + * + * ```kotlin * val newError: Effect, Int> = - * failed.handleErrorWith { str -> - * effect { shift(str.reversed().toList()) } + * failed.recover { str -> + * shift(str.reversed().toList()) * } + * ``` * - * val redeemed: Effect = - * failed.redeem({ str -> str.length }, ::identity) + * Finally, since `recover` supports `suspend` we can safely call other `suspend` code and throw `Throwable` into the `suspend` system. + * This is typically undesired, since you should prefer lifting `Throwable` into typed values of `R` to make them compile-time tracked. * - * val captured: Effect> = - * effect { 1 }.attempt() + * ```kotlin + * val newException: Effect = + * failed.recover { str -> throw RuntimeException(str) } + * ``` * - * suspend fun main() { - * failed.toEither() shouldBe Either.Left("failed") - * resolved.toEither() shouldBe Either.Right(6) - * newError.toEither() shouldBe Either.Left(listOf('d', 'e', 'l', 'i', 'a', 'f')) - * redeemed.toEither() shouldBe Either.Right(6) - * captured.toEither() shouldBe Either.Right(Result.success(1)) + * ### catch + * + * `catch` gives us the same powers as `recover`, but instead of resolving `R` we're recovering from any unexpected `Throwable`. + * Unexpected, because the expectation is that all `Throwable` get turned into `R` unless it's a fatal/unexpected. + * This operator is useful when you need to work/wrap foreign code, especially Java SDKs or any code that is heavily based on exceptions. + * + * Below we've defined a `foreign` value that represents wrapping a foreign API which might throw `RuntimeException`. + * + * ```kotlin + * val foreign = effect { + * throw RuntimeException("BOOM!") * } * ``` - * + * + * We can `catch` to run the effect recovering from any exception, + * and recover it by providing a default value of `-1` or the length of the [Throwable.message]. + * + * ```kotlin + * val default3: Effect = + * foreign.catch { -1 } + * + * val resolved3: Effect = + * foreign.catch { it.message?.length ?: -1 } + * ``` + * + * A big difference with `recover` is that `catch` **cannot** change the error type of `R` because it doesn't resolve it, so it stays unchanged. + * You can however compose `recover`, and `v` to resolve the error type **and** recover the exception. + * + * ```kotlin + * val default4: Effect = + * foreign + * .recover { -1 } + * .catch { -2 } + * ``` + * + * `catch` however offers an overload that can _refine the exception_. + * Let's say you're wrapping some database interactions that might throw `java.sql.SqlException`, or `org.postgresql.util.PSQLException`, + * then you might only be interested in those exceptions and not `Throwable`. `catch` allows you to install multiple handlers for specific exceptions. + * If the desired exception is not matched, then it stays in the `suspend` exception channel and will be thrown or recovered at a later point. + * + * ```kotlin + * val default5: Effect = + * foreign + * .catch { ex: RuntimeException -> -1 } + * .catch { ex: java.sql.SQLException -> -2 } + * ``` + * + * Finally, since `catch` also supports `suspend` we can safely call other `suspend` code and throw `Throwable` into the `suspend` system. + * This can be useful if refinement of exceptions is not sufficient, for example in the case of `org.postgresql.util.PSQLException` you might want to + * check the `SQLState` to check for a `foreign key violation` and rethrow the exception if not matched. + * + * ```kotlin + * suspend fun java.sql.SQLException.isForeignKeyViolation(): Boolean = true + * + * val rethrown: Effect = + * failed.catch { ex: java.sql.SQLException -> + * if(ex.isForeignKeyViolation()) shift("foreign key violation") + * else throw ex + * } + * ``` + * + * * * Note: * Handling errors can also be done with `try/catch` but this is **not recommended**, it uses `CancellationException` which is used to cancel `Coroutine`s and is advised not to capture in Kotlin. @@ -235,7 +317,7 @@ import kotlin.coroutines.resumeWithException * * ## Structured Concurrency * - * `Effect` relies on `kotlin.cancellation.CancellationException` to `shift` error values of type [R] inside the `Continuation` since it effectively cancels/short-circuits it. + * `Effect` relies on `kotlin.cancellation.CancellationException` to `shift` error values of type `R` inside the `Continuation` since it effectively cancels/short-circuits it. * For this reason `shift` adheres to the same rules as [`Structured Concurrency`](https://kotlinlang.org/docs/coroutines-basics.html#structured-concurrency) * * Let's overview below how `shift` behaves with the different concurrency builders from Arrow Fx & KotlinX Coroutines. @@ -246,6 +328,7 @@ import kotlin.coroutines.resumeWithException * * + * * * #### parTraverse * + * * * `parTraverse` will launch 5 tasks, for every element in `1..5`. * The last task to get scheduled will `shift` with "error", and it will cancel the other launched tasks before returning. @@ -319,6 +403,7 @@ import kotlin.coroutines.resumeWithException * #### raceN * + * * * `raceN` races `n` suspend functions in parallel, and cancels all participating functions when a winner is found. * We can consider the function that `shift`s the winner of the race, except with a shifted value instead of a successful one. @@ -356,6 +441,7 @@ import kotlin.coroutines.resumeWithException * #### bracketCase / Resource * + * * * + * * * ### KotlinX * #### withContext @@ -427,7 +514,9 @@ import kotlin.coroutines.resumeWithException * + * * * #### async * @@ -489,6 +578,7 @@ import kotlin.coroutines.resumeWithException * * + * * * #### launch * * + * * * #### Strange edge cases * * **NOTE** * Capturing `shift` into a lambda, and leaking it outside of `Effect` to be invoked outside will yield unexpected results. - * Below we capture `shift` from inside the DSL, and then invoke it outside its context `EffectScope`. + * Below we capture `shift` from inside the DSL, and then invoke it outside its context `Shift`. * * - */ -public interface Effect { - /** - * Runs the suspending computation by creating a [Continuation], and running the `fold` function - * over the computation. - * - * When the [Effect] has shifted with [R] it will [recover] the shifted value to [B], and when it - * ran the computation to completion it will [transform] the value [A] to [B]. - * - * ```kotlin - * import arrow.core.continuations.effect - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * val shift = effect { - * shift("Hello, World!") - * }.fold({ str: String -> str }, { int -> int.toString() }) - * shift shouldBe "Hello, World!" - * - * val res = effect { - * 1000 - * }.fold({ str: String -> str.length }, { int -> int }) - * res shouldBe 1000 - * } - * ``` - * - */ - public suspend fun fold( - recover: suspend (shifted: R) -> B, - transform: suspend (value: A) -> B - ): B - - /** - * Like [fold] but also allows folding over any unexpected [Throwable] that might have occurred. - * @see fold - */ - public suspend fun fold( - error: suspend (error: Throwable) -> B, - recover: suspend (shifted: R) -> B, - transform: suspend (value: A) -> B - ): B = - try { - fold(recover, transform) - } catch (e: Throwable) { - error(e.nonFatalOrThrow()) - } - - /** - * [fold] the [Effect] into an [Either]. Where the shifted value [R] is mapped to [Either.Left], and - * result value [A] is mapped to [Either.Right]. - */ - public suspend fun toEither(): Either = fold({ Either.Left(it) }) { Either.Right(it) } - - /** - * [fold] the [Effect] into an [Ior]. Where the shifted value [R] is mapped to [Ior.Left], and - * result value [A] is mapped to [Ior.Right]. - */ - public suspend fun toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } - - /** - * [fold] the [Effect] into an [Validated]. Where the shifted value [R] is mapped to - * [Validated.Invalid], and result value [A] is mapped to [Validated.Valid]. - */ - public suspend fun toValidated(): Validated = - fold({ Validated.Invalid(it) }) { Validated.Valid(it) } - - /** - * [fold] the [Effect] into an [Option]. Where the shifted value [R] is mapped to [Option] by the - * provided function [orElse], and result value [A] is mapped to [Some]. - */ - public suspend fun toOption(orElse: suspend (R) -> Option<@UnsafeVariance A>): Option = fold(orElse, ::Some) - - /** - * [fold] the [Effect] into an [A?]. Where the shifted value [R] is mapped to - * [null], and result value [A]. - */ - public suspend fun orNull(): A? = fold({ null }, ::identity) - - /** Runs the [Effect] and captures any [NonFatal] exception into [Result]. */ - public fun attempt(): Effect> = effect { - try { - Result.success(bind()) - } catch (e: Throwable) { - Result.failure(e.nonFatalOrThrow()) - } - } - - public fun handleError(recover: suspend (R) -> @UnsafeVariance A): Effect = effect { - fold(recover, ::identity) - } - - public fun handleErrorWith(recover: suspend (R) -> Effect): Effect = effect { - fold({ recover(it).bind() }, ::identity) - } - - public fun redeem(recover: suspend (R) -> B, transform: suspend (A) -> B): Effect = - effect { - fold(recover, transform) - } - - public fun redeemWith( - recover: suspend (R) -> Effect, - transform: suspend (A) -> Effect - ): Effect = effect { fold(recover, transform).bind() } -} - -/** - * **AVOID USING THIS TYPE, it's meant for low-level cancellation code** When in need in low-level - * code, you can use this type to differentiate between a foreign [CancellationException] and the - * one from [Effect]. - */ -public sealed class ShiftCancellationException : CancellationException("Shifted Continuation") - -/** - * Holds `R` and `suspend (R) -> B`, the exception that wins the race, will get to execute - * `recover`. - */ -@PublishedApi -internal class Suspend(val token: Token, val shifted: Any?, val recover: suspend (Any?) -> Any?) : - ShiftCancellationException() { - override fun toString(): String = "ShiftCancellationException($message)" -} - -/** Class that represents a unique token by hash comparison **/ -@PublishedApi -internal open class Token { - override fun toString(): String = "Token(${hashCode().toString(16)})" -} - -/** - * Continuation that runs the `recover` function, after attempting to calculate [B]. In case we - * encounter a `shift` after suspension, we will receive [Result.failure] with - * [ShiftCancellationException]. In that case we still need to run `suspend (R) -> B`, which is what - * we do inside the body of this `Continuation`, and we complete the [parent] [Continuation] with - * the result. + * */ -@PublishedApi -@Deprecated( - "This will become private in Arrow 2.0, and is not going to be visible from binary anymore", - level = DeprecationLevel.WARNING -) -internal class FoldContinuation( - override val context: CoroutineContext, - private val error: suspend (Throwable) -> B, - private val parent: Continuation, -) : Continuation, Token(), EffectScope { - - constructor(ignored: Token, context: CoroutineContext, parent: Continuation) : this(context, { throw it }, parent) - constructor( - ignored: Token, - context: CoroutineContext, - error: suspend (Throwable) -> B, - parent: Continuation, - ) : this(context, error, parent) - - lateinit var recover: suspend (R) -> Any? - - // Shift away from this Continuation by intercepting it, and completing it with - // ShiftCancellationException - // This is needed because this function will never yield a result, - // so it needs to be cancelled to properly support coroutine cancellation - override suspend fun shift(r: R): B = - // Some interesting consequences of how Continuation Cancellation works in Kotlin. - // We have to throw CancellationException to signal the Continuation was cancelled, and we - // shifted away. - // This however also means that the user can try/catch shift and recover from the - // CancellationException and thus effectively recovering from the cancellation/shift. - // This means try/catch is also capable of recovering from monadic errors. - // See: EffectSpec - try/catch tests - throw Suspend(this, r, recover as suspend (Any?) -> Any?) - - // In contrast to `createCoroutineUnintercepted this doesn't create a new ContinuationImpl - private fun (suspend () -> B).startCoroutineUnintercepted() { - try { - when (val res = startCoroutineUninterceptedOrReturn(parent)) { - COROUTINE_SUSPENDED -> Unit - else -> parent.resume(res as B) - } - // We need to wire all immediately throw exceptions to the parent Continuation - } catch (e: Throwable) { - parent.resumeWithException(e) - } - } - - override fun resumeWith(result: Result) { - result.fold(parent::resume) { throwable -> - when { - throwable is Suspend && this === throwable.token -> - suspend { throwable.recover(throwable.shifted) as B }.startCoroutineUnintercepted() - - throwable is Suspend -> parent.resumeWith(result) - else -> suspend { error(throwable.nonFatalOrThrow()) }.startCoroutineUnintercepted() - } - } - } -} +public typealias Effect = suspend Shift.() -> A -/** - * DSL for constructing Effect values - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.None - * import arrow.core.Option - * import arrow.core.Validated - * import arrow.core.continuations.effect - * import io.kotest.assertions.fail - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * effect { - * val x = Either.Right(1).bind() - * val y = Validated.Valid(2).bind() - * val z = Option(3).bind { "Option was empty" } - * x + y + z - * }.fold({ fail("Shift can never be the result") }, { it shouldBe 6 }) - * - * effect { - * val x = Either.Right(1).bind() - * val y = Validated.Valid(2).bind() - * val z: Int = None.bind { "Option was empty" } - * x + y + z - * }.fold({ it shouldBe "Option was empty" }, { fail("Int can never be the result") }) - * } - * ``` - * - */ -public fun effect(f: suspend EffectScope.() -> A): Effect = DefaultEffect(f) +public inline fun effect(@BuilderInference noinline block: suspend Shift.() -> A): Effect = block -private class DefaultEffect(val f: suspend EffectScope.() -> A) : Effect { - - override suspend fun fold( - recover: suspend (shifted: R) -> B, - transform: suspend (value: A) -> B, - ): B = fold({ throw it }, recover, transform) - - // We create a `Token` for fold Continuation, so we can properly differentiate between nested folds - override suspend fun fold( - error: suspend (error: Throwable) -> B, - recover: suspend (shifted: R) -> B, - transform: suspend (value: A) -> B, - ): B = - suspendCoroutineUninterceptedOrReturn { cont -> - val shift = FoldContinuation(cont.context, error, cont) - shift.recover = recover - try { - val fold: suspend EffectScope.() -> B = { transform(f(this)) } - fold.startCoroutineUninterceptedOrReturn(shift, shift) - } catch (e: Suspend) { - if (shift === e.token) { - val f: suspend () -> B = { e.recover(e.shifted) as B } - f.startCoroutineUninterceptedOrReturn(cont) - } else throw e - } catch (e: Throwable) { - val f: suspend () -> B = { error(e.nonFatalOrThrow()) } - f.startCoroutineUninterceptedOrReturn(cont) - } - } -} +/** The same behavior and API as [Effect] except without requiring _suspend_. */ +public typealias EagerEffect = Shift.() -> A -public suspend fun Effect.merge(): A = fold(::identity, ::identity) +public inline fun eagerEffect(@BuilderInference noinline block: Shift.() -> A): EagerEffect = block diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EffectScope.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EffectScope.kt deleted file mode 100644 index 8a6a5b46466..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EffectScope.kt +++ /dev/null @@ -1,294 +0,0 @@ -package arrow.core.continuations - -import arrow.core.Either -import arrow.core.EmptyValue -import arrow.core.None -import arrow.core.Option -import arrow.core.Some -import arrow.core.Validated -import arrow.core.identity -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.experimental.ExperimentalTypeInference -import kotlin.jvm.JvmInline - -/** Context of the [Effect] DSL. */ -public interface EffectScope { - /** - * Short-circuit the [Effect] computation with value [R]. - * - * ```kotlin - * import arrow.core.continuations.effect - * import io.kotest.assertions.fail - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * effect { - * shift("SHIFT ME") - * }.fold({ it shouldBe "SHIFT ME" }, { fail("Computation never finishes") }) - * } - * ``` - * - */ - public suspend fun shift(r: R): B - - /** - * Runs the [Effect] to finish, returning [B] or [shift] in case of [R]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.continuations.Effect - * import arrow.core.continuations.effect - * import arrow.core.identity - * import io.kotest.matchers.shouldBe - * - * suspend fun Either.toEffect(): Effect = effect { - * fold({ e -> shift(e) }, ::identity) - * } - * - * suspend fun main() { - * val either = Either.Left("failed") - * effect { - * val x: Int = either.toEffect().bind() - * x - * }.toEither() shouldBe either - * } - * ``` - * - */ - public suspend fun Effect.bind(): B = fold(this@EffectScope::shift, ::identity) - - /** - * Runs the [EagerEffect] to finish, returning [B] or [shift] in case of [R], - * bridging eager computations into suspending. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.continuations.EagerEffect - * import arrow.core.continuations.eagerEffect - * import arrow.core.continuations.effect - * import arrow.core.identity - * import io.kotest.matchers.shouldBe - * - * suspend fun Either.toEagerEffect(): EagerEffect = eagerEffect { - * fold({ e -> shift(e) }, ::identity) - * } - * - * suspend fun main() { - * val either = Either.Left("failed") - * effect { - * val x: Int = either.toEagerEffect().bind() - * x - * }.toEither() shouldBe either - * } - * ``` - * - */ - public suspend fun EagerEffect.bind(): B { - var left: Any? = EmptyValue - var right: Any? = EmptyValue - fold({ r -> left = r }, { a -> right = a }) - return if (left === EmptyValue) EmptyValue.unbox(right) else shift(EmptyValue.unbox(left)) - } - - /** - * Folds [Either] into [Effect], by returning [B] or a shift with [R]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.continuations.effect - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * val either = Either.Right(9) - * effect { - * val x: Int = either.bind() - * x - * }.toEither() shouldBe either - * } - * ``` - * - */ - public suspend fun Either.bind(): B = - when (this) { - is Either.Left -> shift(value) - is Either.Right -> value - } - - /** - * Folds [Validated] into [Effect], by returning [B] or a shift with [R]. - * - * ```kotlin - * import arrow.core.Validated - * import arrow.core.continuations.effect - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * val validated = Validated.Valid(40) - * effect { - * val x: Int = validated.bind() - * x - * }.toValidated() shouldBe validated - * } - * ``` - * - */ - public suspend fun Validated.bind(): B = - when (this) { - is Validated.Valid -> value - is Validated.Invalid -> shift(value) - } - - /** - * Folds [Result] into [Effect], by returning [B] or a transforming [Throwable] into [R] and - * shifting the result. - * - * ```kotlin - * import arrow.core.continuations.effect - * import arrow.core.identity - * import io.kotest.matchers.shouldBe - * - * private val default = "failed" - * suspend fun main() { - * val result = Result.success(1) - * effect { - * val x: Int = result.bind { _: Throwable -> default } - * x - * }.fold({ default }, ::identity) shouldBe result.getOrElse { default } - * } - * ``` - * - */ - public suspend fun Result.bind(transform: (Throwable) -> R): B = - fold(::identity) { throwable -> shift(transform(throwable)) } - - /** - * Folds [Option] into [Effect], by returning [B] or a transforming [None] into [R] and shifting the - * result. - * - * ```kotlin - * import arrow.core.None - * import arrow.core.Option - * import arrow.core.continuations.effect - * import arrow.core.getOrElse - * import arrow.core.identity - * import io.kotest.matchers.shouldBe - * - * private val default = "failed" - * suspend fun main() { - * val option: Option = None - * effect { - * val x: Int = option.bind { default } - * x - * }.fold({ default }, ::identity) shouldBe option.getOrElse { default } - * } - * ``` - * - */ - public suspend fun Option.bind(shift: () -> R): B = - when (this) { - None -> shift(shift()) - is Some -> value - } - - /** - * ensure that condition is `true`, if it's `false` it will `shift` with the provided value [R]. - * Monadic version of [kotlin.require]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.continuations.effect - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * val condition = true - * val failure = "failed" - * val int = 4 - * effect { - * ensure(condition) { failure } - * int - * }.toEither() shouldBe if(condition) Either.Right(int) else Either.Left(failure) - * } - * ``` - * - */ - public suspend fun ensure(condition: Boolean, shift: () -> R): Unit = - if (condition) Unit else shift(shift()) - - /** - * Encloses an action for which you want to catch any `shift`. - * [attempt] is used in combination with [catch]. - * - * ``` - * attempt { ... } catch { ... } - * ``` - * - * The [f] may `shift` into a different `EffectScope`, giving - * the chance for a later [catch] to change the shifted value. - * This is useful to simulate re-throwing of exceptions. - */ - @OptIn(ExperimentalTypeInference::class) - public suspend fun attempt( - @BuilderInference - f: suspend EffectScope.() -> A, - ): suspend EffectScope.() -> A = f - - /** - * When the [Effect] has shifted with [R] it will [recover] - * the shifted value to [A], and when it ran the computation to - * completion it will return the value [A]. - * [catch] is used in combination with [attempt]. - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.None - * import arrow.core.Option - * import arrow.core.Validated - * import arrow.core.continuations.effect - * import io.kotest.assertions.fail - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * effect { - * val x = Either.Right(1).bind() - * val y = Validated.Valid(2).bind() - * val z = - * attempt { None.bind { "Option was empty" } } catch { 0 } - * x + y + z - * }.fold({ fail("Shift can never be the result") }, { it shouldBe 3 }) - * } - * ``` - * - */ - public suspend infix fun (suspend EffectScope.() -> A).catch( - recover: suspend EffectScope.(E) -> A, - ): A = effect(this).fold({ recover(it) }, ::identity) -} - -/** - * Ensure that [value] is not `null`. if it's non-null it will be smart-casted and returned if it's - * `false` it will `shift` with the provided value [R]. Monadic version of [kotlin.requireNotNull]. - * - * ```kotlin - * import arrow.core.continuations.effect - * import arrow.core.continuations.ensureNotNull - * import arrow.core.left - * import arrow.core.right - * import io.kotest.matchers.shouldBe - * - * suspend fun main() { - * val failure = "failed" - * val int: Int? = null - * effect { - * ensureNotNull(int) { failure } - * }.toEither() shouldBe (int?.right() ?: failure.left()) - * } - * ``` - * - */ -@OptIn(ExperimentalContracts::class) -public suspend fun EffectScope.ensureNotNull(value: B?, shift: () -> R): B { - contract { returns() implies (value != null) } - return value ?: shift(shift()) -} - diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt new file mode 100644 index 00000000000..9493b0aa8dd --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt @@ -0,0 +1,111 @@ +@file:JvmMultifileClass +@file:JvmName("Effect") +@file:OptIn(ExperimentalTypeInference::class) + +package arrow.core.continuations + +import arrow.core.nonFatalOrThrow +import kotlin.experimental.ExperimentalTypeInference +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + +/** + * Catch the shifted value [E] of the `Effect`. + * You can either return a value a new value of [A], + * or short-circuit the effect by shifting with a value of [E], + * or raise an exception into [suspend]. + * + * ```kotlin + * import arrow.core.continuations.effect + * import arrow.core.continuations.recover + * + * object User + * object Error + * + * val error = effect { shift(Error) } // // Shift(error) + * + * val a = error.recover { error -> User } // Success(User) + * val b = error.recover { error -> shift("other-failure") } // Shift(other-failure) + * val c = error.recover { error -> throw RuntimeException("BOOM") } // Exception(BOOM) + * ``` + * + */ +public infix fun Effect.recover(@BuilderInference resolve: suspend Shift.(shifted: E) -> A): Effect = + effect { recover(resolve) } + +/** + * Catch any unexpected exceptions, and [resolve] them. + * You can either return a value a new value of [A], + * or short-circuit the effect by shifting with a value of [E], + * or raise an exception into [suspend]. + * + * ```kotlin + * import arrow.core.continuations.effect + * import arrow.core.continuations.catch + * + * object User + * object Error + * + * val exception = effect { throw RuntimeException("BOOM") } // Exception(BOOM) + * + * val a = exception.catch { error -> error.message?.length ?: -1 } // Success(5) + * val b = exception.catch { shift(Error) } // Shift(error) + * val c = exception.catch { throw RuntimeException("other-failure") } // Exception(other-failure) + * ``` + * + */ +public infix fun Effect.catch(@BuilderInference resolve: suspend Shift.(throwable: Throwable) -> A): Effect = + effect { catch(resolve) } + +/** + * A version of [catch] that refines the [Throwable] to [T]. + * This is useful for wrapping foreign code, such as database, network calls, etc. + * + * ```kotlin + * import arrow.core.continuations.effect + * import arrow.core.continuations.catch + * + * object User + * object Error + * + * val x = effect { + * throw IllegalArgumentException("builder missed args") + * }.catch { shift(Error) } + * ``` + * + * If you don't need an `error` value when wrapping your foreign code you can use `Nothing` to fill the type parameter. + * + * ```kotlin + * val y = effect { + * throw IllegalArgumentException("builder missed args") + * }.catch { shift(Error) } + * ``` + * + */ +@JvmName("catchReified") +public inline infix fun Effect.catch( + @BuilderInference crossinline recover: suspend Shift.(T) -> A, +): Effect = + effect { catch { t: Throwable -> if (t is T) recover(t) else throw t } } + +/** Runs the [Effect] and captures any [nonFatalOrThrow] exception into [Result]. */ +public fun Effect.catch(): Effect> = + effect { + try { + Result.success(invoke()) + } catch (e: Throwable) { + Result.failure(e.nonFatalOrThrow()) + } + } + +public infix fun EagerEffect.recover(@BuilderInference resolve: Shift.(shifted: E) -> A): EagerEffect = + eagerEffect { recover(resolve) } + +public infix fun EagerEffect.catch(@BuilderInference recover: Shift.(throwable: Throwable) -> A): EagerEffect = + eagerEffect { catch(recover) } + +@JvmName("catchReified") +public inline infix fun EagerEffect.catch( + @BuilderInference crossinline recover: Shift.(T) -> A, +): EagerEffect = + eagerEffect { catch { t: Throwable -> if (t is T) recover(t) else throw t } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt new file mode 100644 index 00000000000..260dcd902ca --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt @@ -0,0 +1,80 @@ +@file:JvmMultifileClass +@file:JvmName("Effect") +@file:OptIn(ExperimentalTypeInference::class) + +package arrow.core.continuations + +import arrow.core.nonFatalOrThrow +import kotlin.coroutines.cancellation.CancellationException +import kotlin.experimental.ExperimentalTypeInference +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + +/** + * `invoke` the [Effect] and [fold] the result: + * - _success_ [transform] result of [A] to a value of [B]. + * - _shift_ [recover] from `shifted` value of [R] to a value of [B]. + * - _exception_ [error] from [Throwable] by transforming value into [B]. + * + * This method should never be wrapped in `try`/`catch` as it will not throw any unexpected errors, + * it will only result in [CancellationException], or fatal exceptions such as `OutOfMemoryError`. + */ +public suspend fun Effect.fold( + error: suspend (error: Throwable) -> B, + recover: suspend (shifted: R) -> B, + transform: suspend (value: A) -> B, +): B = fold({ invoke() }, { error(it) }, { recover(it) }, { transform(it) }) + +public suspend fun Effect.fold( + recover: suspend (shifted: R) -> B, + transform: suspend (value: A) -> B, +): B = fold({ throw it }, recover, transform) + +public fun EagerEffect.fold(recover: (R) -> B, transform: (A) -> B): B = + fold({ throw it }, recover, transform) + +public inline fun EagerEffect.fold( + error: (error: Throwable) -> B, + recover: (shifted: R) -> B, + transform: (value: A) -> B, +): B = fold({ invoke(this) }, error, recover, transform) + +@JvmName("_foldOrThrow") +public inline fun fold( + @BuilderInference program: Shift.() -> A, + recover: (shifted: R) -> B, + transform: (value: A) -> B, +): B = fold(program, { throw it }, recover, transform) + +@JvmName("_fold") +public inline fun fold( + @BuilderInference program: Shift.() -> A, + error: (error: Throwable) -> B, + recover: (shifted: R) -> B, + transform: (value: A) -> B, +): B { + val shift = DefaultShift() + return try { + transform(program(shift)) + } catch (e: CancellationException) { + recover(e.shiftedOrRethrow(shift)) + } catch (e: Throwable) { + error(e.nonFatalOrThrow()) + } +} + +/** Returns the shifted value, rethrows the CancellationException if not our scope */ +@PublishedApi +internal fun CancellationException.shiftedOrRethrow(shift: DefaultShift): R = + if (this is ShiftCancellationException && this.shift === shift) _shifted as R + else throw this + +/** Serves as both purposes of a scope-reference token, and a default implementation for Shift. */ +@PublishedApi +internal class DefaultShift : Shift { + override fun shift(r: Any?): B = throw ShiftCancellationException(r, this) +} + +/** CancellationException is required to cancel coroutines when shifting from within them. */ +private class ShiftCancellationException(val _shifted: Any?, val shift: Shift) : + CancellationException("Shifted Continuation") diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt new file mode 100644 index 00000000000..9df1bb9e3b6 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt @@ -0,0 +1,45 @@ +@file:JvmMultifileClass +@file:JvmName("Effect") + +package arrow.core.continuations + +import arrow.core.Either +import arrow.core.Ior +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.core.Validated +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + +/** Run the [Effect] by returning [Either.Right] of [A], or [Either.Left] of [E]. */ +public suspend fun Effect.toEither(): Either = either { invoke() } +public fun EagerEffect.toEither(): Either = either { invoke() } + +/** Run the [Effect] by returning [Validated.Valid] of [A], or [Validated.Invalid] of [E]. */ +public suspend fun Effect.toValidated(): Validated = fold({ Validated.Invalid(it) }) { Validated.Valid(it) } +public fun EagerEffect.toValidated(): Validated = fold({ Validated.Invalid(it) }) { Validated.Valid(it) } + +/** Run the [Effect] by returning [Ior.Right] of [A], or [Ior.Left] of [E]. */ +public suspend fun Effect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } +public fun EagerEffect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } + +/** Run the [Effect] by returning [A], or `null` if shifted with [E]. */ +public suspend fun Effect.orNull(): A? = fold({ _: E -> null }) { it } +public fun EagerEffect.orNull(): A? = fold({ _: E -> null }) { it } + +/** Run the [Effect] by returning [Option] of [A], [orElse] run the fallback lambda and returning its result of [Option] of [A]. */ +public suspend fun Effect.toOption(orElse: suspend (E) -> Option): Option = fold(orElse) { Some(it) } +public fun EagerEffect.toOption(orElse: (E) -> Option): Option = fold(orElse) { Some(it) } + +/** Run the [Effect] by returning [Option] of [A], or [None] if shifted with [None]. */ +public suspend fun Effect.toOption(): Option = option { invoke() } +public fun EagerEffect.toOption(): Option = option { invoke() } + +/** Run the [Effect] by returning [Result] of [A], [orElse] run the fallback lambda and returning its result of [Result] of [A]. */ +public suspend fun Effect.toResult(orElse: suspend (E) -> Result): Result = fold({ orElse(it) }, { Result.success(it) }) +public fun EagerEffect.toResult(orElse: (E) -> Result): Result = fold({ orElse(it) }, { Result.success(it) }) + +/** Run the [Effect] by returning [Result] of [A], or [Result.Failure] if shifted with [Throwable]. */ +public suspend fun Effect.toResult(): Result = result { invoke() } +public fun EagerEffect.toResult(): Result = result { invoke() } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt new file mode 100644 index 00000000000..1e13f47c1c6 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt @@ -0,0 +1,110 @@ +@file:OptIn(ExperimentalTypeInference::class) + +package arrow.core.continuations + +import arrow.core.Either +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.core.Validated +import arrow.core.identity +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract +import kotlin.experimental.ExperimentalTypeInference +import kotlin.jvm.JvmName + +@DslMarker +public annotation class EffectDSL + +public interface Shift { + public fun shift(r: R): A + + public fun EagerEffect.bind(): A = invoke(this@Shift) + public operator fun EagerEffect.invoke(): A = invoke(this@Shift) + + public suspend fun Effect.bind(): A = invoke(this@Shift) + public suspend operator fun Effect.invoke(): A = invoke(this@Shift) + + public fun Either.bind(): A = when (this) { + is Either.Left -> shift(value) + is Either.Right -> value + } + + public fun Validated.bind(): A = when (this) { + is Validated.Invalid -> shift(value) + is Validated.Valid -> value + } + + // TODO can be inlined with context receivers, and top-level + public fun Option.bind(transform: Shift.(None) -> A): A = + when (this) { + None -> transform(None) + is Some -> value + } + + // TODO can be inlined with context receivers, and top-level + public fun Result.bind(transform: (Throwable) -> R): A = + fold(::identity) { throwable -> shift(transform(throwable)) } + + @EffectDSL + public suspend infix fun Effect.recover(@BuilderInference resolve: suspend Shift.(E) -> A): A = + recover({ invoke() }) { resolve(it) } + + @EffectDSL + public infix fun EagerEffect.recover(@BuilderInference resolve: Shift.(E) -> A): A = + recover({ invoke() }, resolve) + + @EffectDSL + public suspend fun Effect.recover( + @BuilderInference action: suspend Shift.() -> A, + @BuilderInference resolve: suspend Shift.(E) -> A, + @BuilderInference recover: suspend Shift.(Throwable) -> A, + ): A = fold({ action(this) }, { recover(it) }, { resolve(it) }, { it }) + + @EffectDSL + public suspend fun Effect.catch( + @BuilderInference recover: suspend Shift.(Throwable) -> A, + ): A = fold({ recover(it) }, { shift(it) }, { it }) + + @EffectDSL + public fun EagerEffect.catch( + @BuilderInference recover: Shift.(Throwable) -> A, + ): A = fold({ recover(it) }, { shift(it) }, { it }) +} + +@EffectDSL +public inline fun Shift.recover( + @BuilderInference action: Shift.() -> A, + @BuilderInference resolve: Shift.(E) -> A +): A = fold({ action(this) }, { throw it }, { resolve(it) }, { it }) + +@EffectDSL +public inline fun Shift.recover( + @BuilderInference action: Shift.() -> A, + @BuilderInference resolve: Shift.(E) -> A, + @BuilderInference recover: Shift.(Throwable) -> A, +): A = fold({ action(this) }, { recover(it) }, { resolve(it) }, { it }) + +@EffectDSL +public inline fun Shift.catch( + @BuilderInference action: Shift.() -> A, + @BuilderInference recover: Shift.(Throwable) -> A, +): A = fold({ action(this) }, { recover(it) }, { shift(it) }, { it }) + +@EffectDSL +@JvmName("catchReified") +public inline fun Shift.catch( + @BuilderInference action: Shift.() -> A, + @BuilderInference recover: Shift.(T) -> A, +): A = catch(action) { t: Throwable -> if (t is T) recover(t) else throw t } + +@EffectDSL +public inline fun Shift.ensure(condition: Boolean, shift: () -> R): Unit = + if (condition) Unit else shift(shift()) + +@OptIn(ExperimentalContracts::class) +@EffectDSL +public inline fun Shift.ensureNotNull(value: B?, shift: () -> R): B { + contract { returns() implies (value != null) } + return value ?: shift(shift()) +} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/either.kt deleted file mode 100644 index a03b738ef37..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/either.kt +++ /dev/null @@ -1,12 +0,0 @@ -package arrow.core.continuations - -import arrow.core.Either - -@Suppress("ClassName") -public object either { - public inline fun eager(noinline f: suspend EagerEffectScope.() -> A): Either = - eagerEffect(f).toEither() - - public suspend operator fun invoke(f: suspend EffectScope.() -> A): Either = - effect(f).toEither() -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ior.kt deleted file mode 100644 index 99ff373005a..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ior.kt +++ /dev/null @@ -1,83 +0,0 @@ -package arrow.core.continuations - -import arrow.core.EmptyValue -import arrow.core.Ior -import arrow.core.identity -import arrow.typeclasses.Semigroup - -@Suppress("ClassName") -public object ior { - public inline fun eager( - semigroup: Semigroup, - crossinline f: suspend IorEagerEffectScope.() -> A - ): Ior = - eagerEffect> { - val effect = IorEagerEffectScope(semigroup, this) - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - val res = f(effect) - val leftState = effect.leftState.get() - if (leftState === EmptyValue) Ior.Right(res) else Ior.Both(EmptyValue.unbox(leftState), res) - }.fold({ Ior.Left(it) }, ::identity) - - public suspend inline operator fun invoke( - semigroup: Semigroup, - crossinline f: suspend IorEffectScope.() -> A - ): Ior = - effect> { - val effect = IorEffectScope(semigroup, this) - val res = f(effect) - val leftState = effect.leftState.get() - if (leftState === EmptyValue) Ior.Right(res) else Ior.Both(EmptyValue.unbox(leftState), res) - }.fold({ Ior.Left(it) }, ::identity) -} - -public class IorEffectScope(semigroup: Semigroup, private val effect: EffectScope) : - EffectScope, Semigroup by semigroup { - - @PublishedApi - internal var leftState: AtomicRef = AtomicRef(EmptyValue) - - private fun combine(other: E): E = - leftState.updateAndGet { state -> - if (state === EmptyValue) other else EmptyValue.unbox(state).combine(other) - } as - E - - public suspend fun Ior.bind(): B = - when (this) { - is Ior.Left -> shift(value) - is Ior.Right -> value - is Ior.Both -> { - combine(leftValue) - rightValue - } - } - - override suspend fun shift(r: E): B = effect.shift(combine(r)) -} - -public class IorEagerEffectScope(semigroup: Semigroup, private val effect: EagerEffectScope) : - EagerEffectScope, Semigroup by semigroup { - - @PublishedApi - internal var leftState: AtomicRef = AtomicRef(EmptyValue) - - private fun combine(other: E): E = - leftState.updateAndGet { state -> - if (state === EmptyValue) other else EmptyValue.unbox(state).combine(other) - } as - E - - public suspend fun Ior.bind(): B = - when (this) { - is Ior.Left -> shift(value) - is Ior.Right -> value - is Ior.Both -> { - combine(leftValue) - rightValue - } - } - - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - override suspend fun shift(r: E): B = effect.shift(combine(r)) -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/nullable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/nullable.kt deleted file mode 100644 index 1a485754b41..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/nullable.kt +++ /dev/null @@ -1,67 +0,0 @@ -package arrow.core.continuations - -import arrow.core.Option -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.jvm.JvmInline - -@JvmInline -public value class NullableEffectScope(private val cont: EffectScope) : EffectScope { - override suspend fun shift(r: Nothing?): B = - cont.shift(r) - - public suspend fun Option.bind(): B = - bind { null } - - @OptIn(ExperimentalContracts::class) - public suspend fun B?.bind(): B { - contract { returns() implies (this@bind != null) } - return this ?: shift(null) - } - - public suspend fun ensure(value: Boolean): Unit = - ensure(value) { null } -} - -@JvmInline -public value class NullableEagerEffectScope(private val cont: EagerEffectScope) : EagerEffectScope { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - override suspend fun shift(r: Nothing?): B = - cont.shift(r) - - public suspend fun Option.bind(): B = - bind { null } - - @OptIn(ExperimentalContracts::class) - public suspend fun B?.bind(): B { - contract { returns() implies (this@bind != null) } - return this ?: shift(null) - } - - public suspend fun ensure(value: Boolean): Unit = - ensure(value) { null } -} - -@OptIn(ExperimentalContracts::class) -public suspend fun NullableEffectScope.ensureNotNull(value: B?): B { - contract { returns() implies (value != null) } - return ensureNotNull(value) { null } -} - -@OptIn(ExperimentalContracts::class) -public suspend fun NullableEagerEffectScope.ensureNotNull(value: B?): B { - contract { returns() implies (value != null) } - return ensureNotNull(value) { null } -} - -@Suppress("ClassName") -public object nullable { - public inline fun eager(crossinline f: suspend NullableEagerEffectScope.() -> A): A? = - eagerEffect { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - f(NullableEagerEffectScope(this)) - }.orNull() - - public suspend inline operator fun invoke(crossinline f: suspend NullableEffectScope.() -> A): A? = - effect { f(NullableEffectScope(this)) }.orNull() -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/option.kt deleted file mode 100644 index 1e518d0d408..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/option.kt +++ /dev/null @@ -1,64 +0,0 @@ -package arrow.core.continuations - -import arrow.core.None -import arrow.core.Option -import arrow.core.Some -import arrow.core.identity -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.jvm.JvmInline - -public suspend fun Effect.toOption(): Option = - fold(::identity) { Some(it) } - -public fun EagerEffect.toOption(): Option = - fold(::identity) { Some(it) } - -@JvmInline -public value class OptionEffectScope(private val cont: EffectScope) : EffectScope { - override suspend fun shift(r: None): B = - cont.shift(r) - - public suspend fun Option.bind(): B = - bind { None } - - public suspend fun ensure(value: Boolean): Unit = - ensure(value) { None } -} - -@OptIn(ExperimentalContracts::class) -public suspend fun OptionEffectScope.ensureNotNull(value: B?): B { - contract { returns() implies (value != null) } - return ensureNotNull(value) { None } -} - -@OptIn(ExperimentalContracts::class) -public suspend fun OptionEagerEffectScope.ensureNotNull(value: B?): B { - contract { returns() implies (value != null) } - return ensureNotNull(value) { None } -} - -@JvmInline -public value class OptionEagerEffectScope(private val cont: EagerEffectScope) : EagerEffectScope { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - override suspend fun shift(r: None): B = - cont.shift(r) - - public suspend fun Option.bind(): B = - bind { None } - - public suspend fun ensure(value: Boolean): Unit = - ensure(value) { None } -} - -@Suppress("ClassName") -public object option { - public inline fun eager(crossinline f: suspend OptionEagerEffectScope.() -> A): Option = - eagerEffect { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - f(OptionEagerEffectScope(this)) - }.toOption() - - public suspend inline operator fun invoke(crossinline f: suspend OptionEffectScope.() -> A): Option = - effect { f(OptionEffectScope(this)) }.toOption() -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/result.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/result.kt deleted file mode 100644 index 9b0d7faa89c..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/result.kt +++ /dev/null @@ -1,41 +0,0 @@ -package arrow.core.continuations - -import arrow.core.identity -import kotlin.jvm.JvmInline - -public suspend fun Effect.toResult(): Result = - fold({ Result.failure(it) }, { Result.success(it) }) - -public fun EagerEffect.toResult(): Result = - fold({ Result.failure(it) }, { Result.success(it) }) - -@JvmInline -public value class ResultEffectScope(private val cont: EffectScope) : EffectScope { - override suspend fun shift(r: Throwable): B = - cont.shift(r) - - public suspend fun Result.bind(): B = - fold(::identity) { shift(it) } -} - -@JvmInline -public value class ResultEagerEffectScope(private val cont: EagerEffectScope) : EagerEffectScope { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - override suspend fun shift(r: Throwable): B = - cont.shift(r) - - public suspend fun Result.bind(): B = - fold(::identity) { shift(it) } -} - -@Suppress("ClassName") -public object result { - public inline fun eager(crossinline f: suspend ResultEagerEffectScope.() -> A): Result = - eagerEffect { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - f(ResultEagerEffectScope(this)) - }.toResult() - - public suspend inline operator fun invoke(crossinline f: suspend ResultEffectScope.() -> A): Result = - effect { f(ResultEffectScope(this)) }.toResult() -} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt index 7c32aeae4c4..9dcee7f3610 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt @@ -5,7 +5,9 @@ import arrow.core.identity import arrow.core.left import arrow.core.right import io.kotest.assertions.fail +import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean @@ -19,7 +21,7 @@ import kotlinx.coroutines.CompletableDeferred class EagerEffectSpec : StringSpec({ "try/catch - can recover from shift" { checkAll(Arb.int(), Arb.string()) { i, s -> - eagerEffect { + eagerEffect { try { shift(s) } catch (e: Throwable) { @@ -28,13 +30,13 @@ class EagerEffectSpec : StringSpec({ }.fold({ fail("Should never come here") }, ::identity) shouldBe i } } - + "try/catch - finally works" { checkAll(Arb.string(), Arb.int()) { s, i -> val promise = CompletableDeferred() - eagerEffect { + eagerEffect { try { - shift(s) + shift(s) } finally { require(promise.complete(i)) } @@ -43,7 +45,7 @@ class EagerEffectSpec : StringSpec({ promise.await() shouldBe i } } - + "try/catch - First shift is ignored and second is returned" { checkAll(Arb.int(), Arb.string(), Arb.string()) { i, s, s2 -> eagerEffect { @@ -57,57 +59,70 @@ class EagerEffectSpec : StringSpec({ }.fold(::identity) { fail("Should never come here") } shouldBe s2 } } - + "attempt - catch" { checkAll(Arb.int(), Arb.long()) { i, l -> eagerEffect { - attempt { + eagerEffect { shift(l) - } catch { ll -> + } recover { ll -> ll shouldBe l i } }.runCont() shouldBe i } } - + "attempt - no catch" { checkAll(Arb.int(), Arb.long()) { i, l -> eagerEffect { - attempt { + eagerEffect { i - } catch { ll -> + } recover { ll -> ll shouldBe l i + 1 } }.runCont() shouldBe i } } - - "immediate values" { eagerEffect { 1 }.toEither().orNull() shouldBe 1 } - - "immediate short-circuit" { eagerEffect { shift("hello") }.runCont() shouldBe "hello" } - - "Rethrows immediate exceptions" { + + "attempt - shift from catch" { + checkAll(Arb.int(), Arb.long(), Arb.string()) { i, l, error -> + eagerEffect { + eagerEffect { + shift(l) + } recover { ll -> + ll shouldBe l + shift(error) + } + }.runCont() shouldBe error + } + } + + "values" { eagerEffect { 1 }.toEither().orNull() shouldBe 1 } + + "short-circuit" { eagerEffect { shift("hello") }.runCont() shouldBe "hello" } + + "Rethrows exceptions" { val e = RuntimeException("test") Either.catch { eagerEffect { throw e }.runCont() } shouldBe Either.Left(e) } - + "ensure null in eager either computation" { checkAll(Arb.boolean(), Arb.int(), Arb.string()) { predicate, success, shift -> - either.eager { + either { ensure(predicate) { shift } success } shouldBe if (predicate) success.right() else shift.left() } } - + "ensureNotNull in eager either computation" { fun square(i: Int): Int = i * i - + checkAll(Arb.int().orNull(), Arb.string()) { i: Int?, shift: String -> val res = - either.eager { + either { val ii = i ensureNotNull(ii) { shift } square(ii) // Smart-cast by contract @@ -116,22 +131,83 @@ class EagerEffectSpec : StringSpec({ res shouldBe expected } } - - "low-level use-case: distinguish between concurrency error and shift exception" { - val effect = eagerEffect { shift("Shift") } - val e = RuntimeException("test") - Either.catch { - eagerEffect { - try { - effect.bind() - } catch (shiftError: Suspend) { - fail("Should never come here") - } catch (eagerShiftError: Eager) { - throw e - } catch (otherError: Throwable) { - fail("Should never come here") - } - }.runCont() - } shouldBe Either.Left(e) + + "catch - happy path" { + checkAll(Arb.string()) { str -> + eagerEffect { + str + }.recover { fail("It should never catch a success value") } + .runCont() shouldBe str + } + } + + "catch - error path and recover" { + checkAll(Arb.int(), Arb.string()) { int, fallback -> + eagerEffect { + shift(int) + fail("It should never reach this point") + }.recover { fallback } + .runCont() shouldBe fallback + } + } + + "catch - error path and re-shift" { + checkAll(Arb.int(), Arb.string()) { int, fallback -> + eagerEffect { + shift(int) + fail("It should never reach this point") + }.recover { shift(fallback) } + .runCont() shouldBe fallback + } + } + + "catch - error path and throw" { + checkAll(Arb.int(), Arb.string()) { int, msg -> + shouldThrow { + eagerEffect { + shift(int) + fail("It should never reach this point") + }.recover { throw RuntimeException(msg) } + .runCont() + }.message.shouldNotBeNull() shouldBe msg + } + } + + "attempt - happy path" { + checkAll(Arb.string()) { str -> + eagerEffect { + str + }.catch { fail("It should never catch a success value") } + .runCont() shouldBe str + } + } + + "attempt - error path and recover" { + checkAll(Arb.string(), Arb.string()) { msg, fallback -> + eagerEffect { + throw RuntimeException(msg) + }.catch { fallback } + .runCont() shouldBe fallback + } + } + + "attempt - error path and re-shift" { + checkAll(Arb.string(), Arb.int()) { msg, fallback -> + eagerEffect { + throw RuntimeException(msg) + }.catch { shift(fallback) } + .runCont() shouldBe fallback + } + } + + "attempt - error path and throw" { + checkAll(Arb.string(), Arb.string()) { msg, msg2 -> + shouldThrow { + eagerEffect { + throw RuntimeException(msg) + }.catch { throw RuntimeException(msg2) } + .runCont() + }.message.shouldNotBeNull() shouldBe msg2 + } } }) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt index af23c30c529..79679cde04c 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt @@ -7,6 +7,7 @@ import arrow.core.right import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.arbitrary @@ -30,248 +31,171 @@ import kotlinx.coroutines.withContext class EffectSpec : StringSpec({ "try/catch - can recover from shift" { - checkAll(Arb.int(), Arb.string()) { i, s -> - effect { + checkAll(Arb.int().suspend(), Arb.string().suspend()) { i, s -> + effect { try { - shift(s) + shift(s()) } catch (e: Throwable) { - i + i() } - }.fold({ fail("Should never come here") }, ::identity) shouldBe i + }.fold({ fail("Should never come here") }, ::identity) shouldBe i() } } - - "try/catch - can recover from shift suspended" { - checkAll(Arb.int(), Arb.string()) { i, s -> - effect { - try { - shift(s.suspend()) - } catch (e: Throwable) { - i - } - }.fold({ fail("Should never come here") }, ::identity) shouldBe i - } - } - + "try/catch - finally works" { - checkAll(Arb.string(), Arb.int()) { s, i -> + checkAll(Arb.string().suspend(), Arb.int().suspend()) { s, i -> val promise = CompletableDeferred() - effect { + effect { try { - shift(s) + shift(s().suspend()) } finally { - require(promise.complete(i)) + require(promise.complete(i())) } } - .fold(::identity) { fail("Should never come here") } shouldBe s - promise.await() shouldBe i + .fold(::identity) { fail("Should never come here") } shouldBe s() + promise.await() shouldBe i() } } - - "try/catch - finally works suspended" { - checkAll(Arb.string(), Arb.int()) { s, i -> - val promise = CompletableDeferred() - effect { - try { - shift(s.suspend()) - } finally { - require(promise.complete(i)) - } - } - .fold(::identity) { fail("Should never come here") } shouldBe s - promise.await() shouldBe i - } - } - + "try/catch - First shift is ignored and second is returned" { - checkAll(Arb.int(), Arb.string(), Arb.string()) { i, s, s2 -> - effect { - val x: Int = - try { - shift(s) - } catch (e: Throwable) { - i - } - shift(s2) - } - .fold(::identity) { fail("Should never come here") } shouldBe s2 - } - } - - "try/catch - First shift is ignored and second is returned suspended" { - checkAll(Arb.int(), Arb.string(), Arb.string()) { i, s, s2 -> + checkAll(Arb.int().suspend(), Arb.string().suspend(), Arb.string().suspend()) { i, s, s2 -> effect { - val x: Int = - try { - shift(s.suspend()) - } catch (e: Throwable) { - i - } - shift(s2.suspend()) + val x: Int = try { + shift(s()) + } catch (e: Throwable) { + i() + } + shift(s2()) } - .fold(::identity) { fail("Should never come here") } shouldBe s2 + .fold(::identity) { fail("Should never come here") } shouldBe s2() } } - + "attempt - catch" { - checkAll(Arb.int(), Arb.long()) { i, l -> + checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> effect { - attempt { - shift(l) - } catch { ll -> - ll shouldBe l - i + effect { + shift(l()) + } recover { ll -> + ll shouldBe l() + i() } - }.runCont() shouldBe i + }.runCont() shouldBe i() } } - + "attempt - no catch" { - checkAll(Arb.int(), Arb.long()) { i, l -> + checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> effect { - attempt { - i - } catch { ll -> - ll shouldBe l - i + 1 + effect { + i() + } recover { ll -> + ll shouldBe l() + i() + 1 } - }.runCont() shouldBe i + }.runCont() shouldBe i() } } - + "eagerEffect can be consumed within an Effect computation" { - checkAll(Arb.int(), Arb.int()) { a, b -> + checkAll(Arb.int(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = eagerEffect { a } - - effect { - val aa = eager.bind() - aa + b.suspend() - }.runCont() shouldBe (a + b) + + effect { + val bb = b() + val aa = eager() + aa + bb + }.runCont() shouldBe (a + b()) } } - + "eagerEffect shift short-circuits effect computation" { - checkAll(Arb.string(), Arb.int()) { a, b -> + checkAll(Arb.string(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = eagerEffect { shift(a) } - - effect { - val aa = eager.bind() - aa + b.suspend() + + effect { + val bb = b() + val aa = eager() + aa + bb }.runCont() shouldBe a } } - - "immediate values" { effect { 1 }.value() shouldBe 1 } - - "suspended value" { effect { 1.suspend() }.value() shouldBe 1 } - - "immediate short-circuit" { - effect { shift("hello") }.runCont() shouldBe "hello" - } - - "suspended short-circuit" { - effect { shift("hello".suspend()) }.runCont() shouldBe "hello" - } - - "Rethrows immediate exceptions" { - val e = RuntimeException("test") - Either.catch { effect { throw e }.runCont() } shouldBe Either.Left(e) + + "success" { + checkAll(Arb.int().suspend()) { i -> + effect { i() }.value() shouldBe i() + } } - - "Rethrows suspended exceptions" { - val e = RuntimeException("test") - Either.catch { effect { e.suspend() }.runCont() } shouldBe Either.Left(e) + + "short-circuit" { + checkAll(Arb.string().suspend()) { msg -> + effect { + shift(msg()) + }.runCont() shouldBe msg() + } } - - "Can short-circuit immediately from nested blocks" { - effect { - effect { shift("test") }.runCont() - fail("Should never reach this point") + + "Rethrows exceptions" { + checkAll(Arb.string().suspend()) { msg -> + shouldThrow { + effect { + throw RuntimeException(msg()) + }.toEither() + }.message shouldBe msg() } - .runCont() shouldBe "test" } - - "Can short-circuit suspended from nested blocks" { - effect { - effect { shift("test".suspend()) }.runCont() - fail("Should never reach this point") + + "Can short-circuit from nested blocks" { + checkAll(Arb.string().suspend()) { msg -> + effect { + effect { shift(msg()) }.runCont() + fail("Should never reach this point") + } + .runCont() shouldBe msg() } - .runCont() shouldBe "test" } - + "Can short-circuit immediately after suspending from nested blocks" { - effect { - effect { - 1L.suspend() - shift("test".suspend()) - } - .runCont() - fail("Should never reach this point") + checkAll(Arb.string().suspend()) { msg -> + effect { + effect { + 1L.suspend() + shift(msg()) + }.runCont() + fail("Should never reach this point") + }.runCont() shouldBe msg() } - .runCont() shouldBe "test" } - + "ensure null in either computation" { - checkAll(Arb.boolean(), Arb.int(), Arb.string()) { predicate, success, shift -> - either { - ensure(predicate) { shift } - success - } shouldBe if (predicate) success.right() else shift.left() + checkAll( + Arb.boolean().suspend(), + Arb.int().suspend(), + Arb.string().suspend() + ) { predicate, success, shift -> + either { + ensure(predicate()) { shift() } + success() + } shouldBe if (predicate()) success().right() else shift().left() } } - + "ensureNotNull in either computation" { fun square(i: Int): Int = i * i - - checkAll(Arb.int().orNull(), Arb.string()) { i: Int?, shift: String -> + + checkAll(Arb.int().orNull().suspend(), Arb.string().suspend()) { i, shift-> val res = either { - val ii = i - ensureNotNull(ii) { shift } + val ii = i() + ensureNotNull(ii) { shift() } square(ii) // Smart-cast by contract } - val expected = i?.let(::square)?.right() ?: shift.left() + val expected = i()?.let(::square)?.right() ?: shift().left() res shouldBe expected } } - - "low-level use-case: distinguish between concurrency error and shift exception" { - val effect = effect { shift("Shift") } - val e = RuntimeException("test") - Either.catch { - effect { - try { - effect.bind() - } catch (eagerShiftError: Eager) { - fail("Should never come here") - } catch (shiftError: Suspend) { - e.suspend() - } catch (otherError: Throwable) { - fail("Should never come here") - } - }.runCont() - } shouldBe Either.Left(e) - } - - "low-level use-case: eager shift exception within effect computations doesn't change shift exception" { - val effect = eagerEffect { shift("Shift") } - val e = RuntimeException("test") - Either.catch { - effect { - try { - effect.bind() - } catch (eagerShiftError: Eager) { - fail("Should never come here") - } catch (shiftError: Suspend) { - e.suspend() - } catch (otherError: Throwable) { - fail("Should never come here") - } - }.runCont() - } shouldBe Either.Left(e) - } "#2760 - dispatching in nested Effect blocks does not make the nested Continuation to hang" { checkAll(Arb.string()) { msg -> @@ -280,7 +204,7 @@ class EffectSpec : shift(Failure(msg)) } - effect { + effect { failure().bind() 1 }.fold( @@ -289,19 +213,19 @@ class EffectSpec : ) shouldBe Failure(msg) } } - + "#2779 - handleErrorWith does not make nested Continuations hang" { checkAll(Arb.string()) { error -> val failed: Effect = effect { withContext(Dispatchers.Default) {} shift(error) } - + val newError: Effect, Int> = - failed.handleErrorWith { str -> - effect { shift(str.reversed().toList()) } + failed.recover { str -> + shift(str.reversed().toList()) } - + newError.toEither() shouldBe Either.Left(error.reversed().toList()) } } @@ -312,7 +236,7 @@ class EffectSpec : withContext(Dispatchers.Default) {} shift(error) } - + val newError: Effect, Int> = effect { failed.fold({ r -> @@ -321,7 +245,7 @@ class EffectSpec : }.bind() }, ::identity) } - + newError.toEither() shouldBe Either.Left(error.reversed().toList()) } } @@ -351,7 +275,7 @@ class EffectSpec : }.runCont() shouldBe fallback() } } - + "Can throw from thrown exceptions" { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> shouldThrow { @@ -365,6 +289,85 @@ class EffectSpec : }.message shouldBe fallback() } } + + "catch - happy path" { + checkAll(Arb.string().suspend()) { str -> + effect { + str() + }.recover { fail("It should never catch a success value") } + .runCont() shouldBe str() + } + } + + "catch - error path and recover" { + checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> + effect { + shift(int()) + fail("It should never reach this point") + }.recover { fallback() } + .runCont() shouldBe fallback() + } + } + + "catch - error path and re-shift" { + checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> + effect { + shift(int()) + fail("It should never reach this point") + }.recover { shift(fallback()) } + .runCont() shouldBe fallback() + } + } + + "catch - error path and throw" { + checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, msg -> + shouldThrow { + effect { + shift(int()) + fail("It should never reach this point") + }.recover { throw RuntimeException(msg()) } + .runCont() + }.message.shouldNotBeNull() shouldBe msg() + } + } + + "attempt - happy path" { + checkAll(Arb.string().suspend()) { str -> + effect { + str() + }.catch { fail("It should never catch a success value") } + .runCont() shouldBe str() + } + } + + "attempt - error path and recover" { + checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> + effect { + throw RuntimeException(msg()) + }.catch { fallback() } + .runCont() shouldBe fallback() + } + } + + "attempt - error path and re-shift" { + checkAll(Arb.string().suspend(), Arb.int().suspend()) { msg, fallback -> + effect { + throw RuntimeException(msg()) + }.catch { shift(fallback()) } + .runCont() shouldBe fallback() + } + } + + "attempt - error path and throw" { + checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, msg2 -> + shouldThrow { + effect { + throw RuntimeException(msg()) + }.catch { throw RuntimeException(msg2()) } + .runCont() + }.message.shouldNotBeNull() shouldBe msg2() + } + } }) private data class Failure(val msg: String) @@ -383,13 +386,13 @@ private fun Arb.suspend(): Arb A> = internal suspend fun Throwable.suspend(): Nothing = suspendCoroutineUninterceptedOrReturn { cont -> suspend { throw this } .startCoroutine(Continuation(Dispatchers.Default) { cont.intercepted().resumeWith(it) }) - + COROUTINE_SUSPENDED } internal suspend fun A.suspend(): A = suspendCoroutineUninterceptedOrReturn { cont -> suspend { this } .startCoroutine(Continuation(Dispatchers.Default) { cont.intercepted().resumeWith(it) }) - + COROUTINE_SUSPENDED } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/IorSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/IorSpec.kt index 5f759ff52a9..566bb880cb3 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/IorSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/IorSpec.kt @@ -41,7 +41,7 @@ class IorSpec : } "Accumulates eagerly" { - ior.eager(Semigroup.string()) { + ior(Semigroup.string()) { val one = Ior.Both("Hello", 1).bind() val two = Ior.Both(", World!", 2).bind() one + two @@ -49,7 +49,7 @@ class IorSpec : } "Accumulates with Either eagerly" { - ior.eager(Semigroup.string()) { + ior(Semigroup.string()) { val one = Ior.Both("Hello", 1).bind() val two: Int = Either.Left(", World!").bind() one + two diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt index 59d677ac9b7..c062d828802 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt @@ -41,7 +41,7 @@ class OptionSpec : StringSpec({ } "eager short circuit null" { - option.eager { + option { val number: Int = "s".length ensureNotNull(number.takeIf { it > 1 }) throw IllegalStateException("This should not be executed") diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt index e3049932bc7..8b3b558dfb7 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt @@ -47,12 +47,10 @@ class StructuredConcurrencySpec : async { started.await() shift("hello") - } - .await() + }.await() never.await() } - } - .runCont() shouldBe "hello" + }.runCont() shouldBe "hello" withTimeout(2.seconds) { cancelled.await().shouldNotBeNull().message shouldBe "Shifted Continuation" diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/predef.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/predef.kt index c608946d68b..226dfec69ff 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/predef.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/predef.kt @@ -4,8 +4,8 @@ import arrow.core.identity suspend fun Effect.value(): A = fold(::identity, ::identity) -suspend fun Effect<*, *>.runCont(): Any? = fold(::identity, ::identity) +suspend fun Effect.runCont(): Any? = fold(::identity, ::identity) fun EagerEffect.value(): A = fold(::identity, ::identity) -fun EagerEffect<*, *>.runCont(): Any? = fold(::identity, ::identity) +fun EagerEffect.runCont(): Any? = fold(::identity, ::identity) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt index b61c79d6db7..1509b0d0028 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt @@ -9,15 +9,15 @@ sealed interface OtherError : MyError { object Actual : OtherError } -context(EffectScope) +context(Shift) suspend fun subprogram(): Unit = println("Hello SubProgram!") -context(EffectScope) +context(Shift) suspend fun otherprogram(): Unit = println("Hello OtherProgram!") -context(EffectScope) +context(Shift) suspend fun fail(): MyResponse = shift(OtherError.Actual) @@ -38,11 +38,11 @@ object EmptyResponse : MyResponse data class ErrorResponse(val error: Throwable) : MyResponse data class BodyResponse(val body: String) : MyResponse -context(EffectScope) +context(Shift) suspend fun respondWithBody(): BodyResponse = BodyResponse("Hello Program!") -context(EffectScope) +context(Shift) suspend fun attemptOrError(): MyResponse = ErrorResponse(RuntimeException("Oh no!")) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-01.kt deleted file mode 100644 index 3516aaae56c..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-01.kt +++ /dev/null @@ -1,17 +0,0 @@ -// This file was automatically generated from EagerEffect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffect01 - -import arrow.core.continuations.eagerEffect -import io.kotest.matchers.shouldBe - -fun main() { - val shift = eagerEffect { - shift("Hello, World!") - }.fold({ str: String -> str }, { int -> int.toString() }) - shift shouldBe "Hello, World!" - - val res = eagerEffect { - 1000 - }.fold({ str: String -> str.length }, { int -> int }) - res shouldBe 1000 -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-02.kt deleted file mode 100644 index 4fa5402ed60..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-02.kt +++ /dev/null @@ -1,26 +0,0 @@ -// This file was automatically generated from EagerEffect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffect02 - -import arrow.core.Either -import arrow.core.None -import arrow.core.Option -import arrow.core.Validated -import arrow.core.continuations.eagerEffect -import io.kotest.assertions.fail -import io.kotest.matchers.shouldBe - -fun main() { - eagerEffect { - val x = Either.Right(1).bind() - val y = Validated.Valid(2).bind() - val z = Option(3).bind { "Option was empty" } - x + y + z - }.fold({ fail("Shift can never be the result") }, { it shouldBe 6 }) - - eagerEffect { - val x = Either.Right(1).bind() - val y = Validated.Valid(2).bind() - val z: Int = None.bind { "Option was empty" } - x + y + z - }.fold({ it shouldBe "Option was empty" }, { fail("Int can never be the result") }) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-01.kt deleted file mode 100644 index 5c14e191cc2..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-01.kt +++ /dev/null @@ -1,12 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope01 - -import arrow.core.continuations.eagerEffect -import io.kotest.assertions.fail -import io.kotest.matchers.shouldBe - -fun main() { - eagerEffect { - shift("SHIFT ME") - }.fold({ it shouldBe "SHIFT ME" }, { fail("Computation never finishes") }) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-02.kt deleted file mode 100644 index 77b9d72a89e..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-02.kt +++ /dev/null @@ -1,20 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope02 - -import arrow.core.Either -import arrow.core.continuations.EagerEffect -import arrow.core.continuations.eagerEffect -import arrow.core.identity -import io.kotest.matchers.shouldBe - -fun Either.toEagerEffect(): EagerEffect = eagerEffect { - fold({ e -> shift(e) }, ::identity) -} - -fun main() { - val either = Either.Left("failed") - eagerEffect { - val x: Int = either.toEagerEffect().bind() - x - }.toEither() shouldBe either -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-03.kt deleted file mode 100644 index c3044107ff5..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-03.kt +++ /dev/null @@ -1,14 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope03 - -import arrow.core.Either -import arrow.core.continuations.eagerEffect -import io.kotest.matchers.shouldBe - -fun main() { - val either = Either.Right(9) - eagerEffect { - val x: Int = either.bind() - x - }.toEither() shouldBe either -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-04.kt deleted file mode 100644 index c7e36de2b1b..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-04.kt +++ /dev/null @@ -1,14 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope04 - -import arrow.core.Validated -import arrow.core.continuations.eagerEffect -import io.kotest.matchers.shouldBe - -fun main() { - val validated = Validated.Valid(40) - eagerEffect { - val x: Int = validated.bind() - x - }.toValidated() shouldBe validated -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-05.kt deleted file mode 100644 index 91d6b7da7e7..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-05.kt +++ /dev/null @@ -1,15 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope05 - -import arrow.core.continuations.eagerEffect -import arrow.core.identity -import io.kotest.matchers.shouldBe - -private val default = "failed" -fun main() { - val result = Result.success(1) - eagerEffect { - val x: Int = result.bind { _: Throwable -> default } - x - }.fold({ default }, ::identity) shouldBe result.getOrElse { default } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-06.kt deleted file mode 100644 index a21aa401fe2..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-06.kt +++ /dev/null @@ -1,18 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope06 - -import arrow.core.None -import arrow.core.Option -import arrow.core.continuations.eagerEffect -import arrow.core.getOrElse -import arrow.core.identity -import io.kotest.matchers.shouldBe - -private val default = "failed" -fun main() { - val option: Option = None - eagerEffect { - val x: Int = option.bind { default } - x - }.fold({ default }, ::identity) shouldBe option.getOrElse { default } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-07.kt deleted file mode 100644 index 9338d3e4f54..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-07.kt +++ /dev/null @@ -1,16 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope07 - -import arrow.core.Either -import arrow.core.continuations.eagerEffect -import io.kotest.matchers.shouldBe - -fun main() { - val condition = true - val failure = "failed" - val int = 4 - eagerEffect { - ensure(condition) { failure } - int - }.toEither() shouldBe if(condition) Either.Right(int) else Either.Left(failure) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-08.kt deleted file mode 100644 index a68c64d66ca..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-08.kt +++ /dev/null @@ -1,20 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope08 - -import arrow.core.Either -import arrow.core.None -import arrow.core.Option -import arrow.core.Validated -import arrow.core.continuations.eagerEffect -import io.kotest.assertions.fail -import io.kotest.matchers.shouldBe - -fun main() { - eagerEffect { - val x = Either.Right(1).bind() - val y = Validated.Valid(2).bind() - val z = - attempt { None.bind { "Option was empty" } } catch { 0 } - x + y + z - }.fold({ fail("Shift can never be the result") }, { it shouldBe 3 }) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-09.kt deleted file mode 100644 index 9bd00d04b02..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eager-effect-scope-09.kt +++ /dev/null @@ -1,16 +0,0 @@ -// This file was automatically generated from EagerEffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEagerEffectScope09 - -import arrow.core.continuations.eagerEffect -import arrow.core.continuations.ensureNotNull -import arrow.core.left -import arrow.core.right -import io.kotest.matchers.shouldBe - -fun main() { - val failure = "failed" - val int: Int? = null - eagerEffect { - ensureNotNull(int) { failure } - }.toEither() shouldBe (int?.right() ?: failure.left()) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt index 19fc37c45ee..7653712b8f4 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt @@ -1,17 +1,18 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEffect01 +import arrow.core.continuations.Effect import arrow.core.continuations.effect -import io.kotest.matchers.shouldBe +import arrow.core.continuations.ensureNotNull +import arrow.core.continuations.ensure -suspend fun main() { - val shift = effect { - shift("Hello, World!") - }.fold({ str: String -> str }, { int -> int.toString() }) - shift shouldBe "Hello, World!" +object EmptyPath - val res = effect { - 1000 - }.fold({ str: String -> str.length }, { int -> int }) - res shouldBe 1000 +fun readFile(path: String): Effect = effect { + if (path.isEmpty()) shift(EmptyPath) else Unit +} + +fun readFile2(path: String?): Effect = effect { + ensureNotNull(path) { EmptyPath } + ensure(path.isNotEmpty()) { EmptyPath } } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt index 4073b9fdfce..1e323abc263 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt @@ -2,25 +2,54 @@ package arrow.core.examples.exampleEffect02 import arrow.core.Either +import arrow.core.Ior import arrow.core.None -import arrow.core.Option import arrow.core.Validated +import arrow.core.continuations.Effect import arrow.core.continuations.effect -import io.kotest.assertions.fail +import arrow.core.continuations.fold +import arrow.core.continuations.toEither +import arrow.core.continuations.toValidated +import arrow.core.continuations.toIor +import arrow.core.continuations.toOption +import arrow.core.continuations.ensureNotNull +import arrow.core.continuations.ensure +import io.kotest.matchers.collections.shouldNotBeEmpty import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeInstanceOf +import java.io.File +import java.io.FileNotFoundException + +@JvmInline +value class Content(val body: List) + +sealed interface FileError +@JvmInline value class SecurityError(val msg: String?) : FileError +@JvmInline value class FileNotFound(val path: String) : FileError +object EmptyPath : FileError { + override fun toString() = "EmptyPath" +} + +fun readFile(path: String?): Effect = effect { + ensureNotNull(path) { EmptyPath } + ensure(path.isNotEmpty()) { EmptyPath } + try { + val lines = File(path).readLines() + Content(lines) + } catch (e: FileNotFoundException) { + shift(FileNotFound(path)) + } catch (e: SecurityException) { + shift(SecurityError(e.message)) + } +} suspend fun main() { - effect { - val x = Either.Right(1).bind() - val y = Validated.Valid(2).bind() - val z = Option(3).bind { "Option was empty" } - x + y + z - }.fold({ fail("Shift can never be the result") }, { it shouldBe 6 }) + readFile("").toEither() shouldBe Either.Left(EmptyPath) + readFile("knit.properties").toValidated() shouldBe Validated.Invalid(FileNotFound("knit.properties")) + readFile("gradle.properties").toIor() shouldBe Ior.Left(FileNotFound("gradle.properties")) + readFile("README.MD").toOption { None } shouldBe None - effect { - val x = Either.Right(1).bind() - val y = Validated.Valid(2).bind() - val z: Int = None.bind { "Option was empty" } - x + y + z - }.fold({ it shouldBe "Option was empty" }, { fail("Int can never be the result") }) + readFile("build.gradle.kts").fold({ _: FileError -> null }, { it }) + .shouldBeInstanceOf() + .body.shouldNotBeEmpty() } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-03.kt similarity index 84% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-03.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-03.kt index cfd166ecda4..d4c272eb814 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-03.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-03.kt @@ -1,11 +1,12 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide03 +package arrow.core.examples.exampleEffect03 import arrow.core.Either import arrow.core.None import arrow.core.Option import arrow.core.Some import arrow.core.continuations.Effect +import arrow.core.continuations.fold import arrow.core.identity suspend fun Effect.toEither(): Either = diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt new file mode 100644 index 00000000000..add17cff915 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt @@ -0,0 +1,55 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEffect04 + +import arrow.core.continuations.Effect +import arrow.core.continuations.effect +import arrow.core.continuations.recover +import arrow.core.continuations.catch + +val failed: Effect = + effect { shift("failed") } + +val default: Effect = + failed.recover { -1 } + +val resolved: Effect = + failed.recover { it.length } + +val default2: Effect = default +val resolved2: Effect = resolved + +val newError: Effect, Int> = + failed.recover { str -> + shift(str.reversed().toList()) + } + +val newException: Effect = + failed.recover { str -> throw RuntimeException(str) } + +val foreign = effect { + throw RuntimeException("BOOM!") +} + +val default3: Effect = + foreign.catch { -1 } + +val resolved3: Effect = + foreign.catch { it.message?.length ?: -1 } + +val default4: Effect = + foreign + .recover { -1 } + .catch { -2 } + +val default5: Effect = + foreign + .catch { ex: RuntimeException -> -1 } + .catch { ex: java.sql.SQLException -> -2 } + +suspend fun java.sql.SQLException.isForeignKeyViolation(): Boolean = true + +val rethrown: Effect = + failed.catch { ex: java.sql.SQLException -> + if(ex.isForeignKeyViolation()) shift("foreign key violation") + else throw ex + } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt similarity index 91% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-05.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt index 4ff9b792766..5701d7b3a08 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-05.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide05 +package arrow.core.examples.exampleEffect05 import arrow.core.continuations.effect +import arrow.core.continuations.fold import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.guaranteeCase import arrow.fx.coroutines.parZip diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-06.kt similarity index 93% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-06.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-06.kt index f13306a75eb..29a0a136457 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-06.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-06.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide06 +package arrow.core.examples.exampleEffect06 import arrow.core.continuations.effect +import arrow.core.continuations.fold import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.guaranteeCase import arrow.fx.coroutines.parTraverse diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt similarity index 93% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-07.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt index 8d8340ed04e..f0b411a222e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-07.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide07 +package arrow.core.examples.exampleEffect07 import arrow.core.continuations.effect +import arrow.core.continuations.fold import arrow.core.merge import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.guaranteeCase diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-08.kt similarity index 91% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-08.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-08.kt index d09c8f092a9..7fe68e33a6b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-08.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-08.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide08 +package arrow.core.examples.exampleEffect08 import arrow.core.continuations.effect +import arrow.core.continuations.fold import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.bracketCase import io.kotest.assertions.fail diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt similarity index 92% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-09.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt index d3655e5ee0b..5936da64f3a 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-09.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide09 +package arrow.core.examples.exampleEffect09 import arrow.core.continuations.effect +import arrow.core.continuations.fold import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.ResourceScope import arrow.fx.coroutines.autoCloseable diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-10.kt similarity index 93% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-10.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-10.kt index 1dcfa20d166..3e1eb29a8ae 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-10.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-10.kt @@ -1,9 +1,11 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide10 +package arrow.core.examples.exampleEffect10 import arrow.core.continuations.Effect import arrow.core.continuations.effect +import arrow.core.continuations.fold import arrow.core.continuations.ensureNotNull +import arrow.core.continuations.ensure import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.guaranteeCase import io.kotest.assertions.fail diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-11.kt similarity index 88% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-11.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-11.kt index 2ba4c626c4a..98d14585a5b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-11.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-11.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide11 +package arrow.core.examples.exampleEffect11 import arrow.core.continuations.effect +import arrow.core.continuations.fold import io.kotest.assertions.fail import io.kotest.matchers.collections.shouldBeIn import kotlinx.coroutines.async diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-12.kt similarity index 87% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-12.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-12.kt index 4a5e8be6381..8b4105198ab 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-12.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-12.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide12 +package arrow.core.examples.exampleEffect12 import arrow.core.continuations.effect +import arrow.core.continuations.fold import io.kotest.assertions.fail import io.kotest.matchers.shouldBe import kotlinx.coroutines.coroutineScope diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-13.kt similarity index 88% rename from arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-13.kt rename to arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-13.kt index e2c8dcdcbea..74de4ee270e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-13.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-13.kt @@ -1,7 +1,8 @@ // This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide13 +package arrow.core.examples.exampleEffect13 import arrow.core.continuations.effect +import arrow.core.continuations.fold import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt new file mode 100644 index 00000000000..47297a7f7b4 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from ErrorHandlers.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEffectError01 + +import arrow.core.continuations.effect +import arrow.core.continuations.recover + +object User +object Error + +val error = effect { shift(Error) } // // Shift(error) + +val a = error.recover { error -> User } // Success(User) +val b = error.recover { error -> shift("other-failure") } // Shift(other-failure) +val c = error.recover { error -> throw RuntimeException("BOOM") } // Exception(BOOM) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt new file mode 100644 index 00000000000..ae04eef943f --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from ErrorHandlers.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEffectError02 + +import arrow.core.continuations.effect +import arrow.core.continuations.catch + +object User +object Error + +val exception = effect { throw RuntimeException("BOOM") } // Exception(BOOM) + +val a = exception.catch { error -> error.message?.length ?: -1 } // Success(5) +val b = exception.catch { shift(Error) } // Shift(error) +val c = exception.catch { throw RuntimeException("other-failure") } // Exception(other-failure) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt new file mode 100644 index 00000000000..d1f053d3573 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from ErrorHandlers.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEffectError03 + +import arrow.core.continuations.effect +import arrow.core.continuations.catch + +object User +object Error + +val x = effect { + throw IllegalArgumentException("builder missed args") +}.catch { shift(Error) } + +val y = effect { + throw IllegalArgumentException("builder missed args") +}.catch { shift(Error) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-01.kt deleted file mode 100644 index 87220b66503..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-01.kt +++ /dev/null @@ -1,17 +0,0 @@ -// This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide01 - -import arrow.core.continuations.Effect -import arrow.core.continuations.effect -import arrow.core.continuations.ensureNotNull - -object EmptyPath - -fun readFile(path: String): Effect = effect { - if (path.isEmpty()) shift(EmptyPath) else Unit -} - -fun readFile2(path: String?): Effect = effect { - ensureNotNull(path) { EmptyPath } - ensure(path.isNotEmpty()) { EmptyPath } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt deleted file mode 100644 index 4db071b7fa8..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt +++ /dev/null @@ -1,49 +0,0 @@ -// This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide02 - -import arrow.core.Either -import arrow.core.Ior -import arrow.core.None -import arrow.core.Validated -import arrow.core.continuations.Effect -import arrow.core.continuations.effect -import arrow.core.continuations.ensureNotNull -import io.kotest.matchers.collections.shouldNotBeEmpty -import io.kotest.matchers.shouldBe -import io.kotest.matchers.types.shouldBeInstanceOf -import java.io.File -import java.io.FileNotFoundException - -@JvmInline -value class Content(val body: List) - -sealed interface FileError -@JvmInline value class SecurityError(val msg: String?) : FileError -@JvmInline value class FileNotFound(val path: String) : FileError -object EmptyPath : FileError { - override fun toString() = "EmptyPath" -} - -fun readFile(path: String?): Effect = effect { - ensureNotNull(path) { EmptyPath } - ensure(path.isNotEmpty()) { EmptyPath } - try { - val lines = File(path).readLines() - Content(lines) - } catch (e: FileNotFoundException) { - shift(FileNotFound(path)) - } catch (e: SecurityException) { - shift(SecurityError(e.message)) - } -} - -suspend fun main() { - readFile("").toEither() shouldBe Either.Left(EmptyPath) - readFile("knit.properties").toValidated() shouldBe Validated.Invalid(FileNotFound("knit.properties")) - readFile("gradle.properties").toIor() shouldBe Ior.Left(FileNotFound("gradle.properties")) - readFile("README.MD").toOption { None } shouldBe None - - readFile("build.gradle.kts").fold({ _: FileError -> null }, { it }) - .shouldBeInstanceOf() - .body.shouldNotBeEmpty() -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-04.kt deleted file mode 100644 index 039a7090e29..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-04.kt +++ /dev/null @@ -1,33 +0,0 @@ -// This file was automatically generated from Effect.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectGuide04 - -import arrow.core.Either -import arrow.core.continuations.Effect -import arrow.core.continuations.effect -import arrow.core.identity -import io.kotest.matchers.shouldBe - -val failed: Effect = - effect { shift("failed") } - -val resolved: Effect = - failed.handleError { it.length } - -val newError: Effect, Int> = - failed.handleErrorWith { str -> - effect { shift(str.reversed().toList()) } - } - -val redeemed: Effect = - failed.redeem({ str -> str.length }, ::identity) - -val captured: Effect> = - effect { 1 }.attempt() - -suspend fun main() { - failed.toEither() shouldBe Either.Left("failed") - resolved.toEither() shouldBe Either.Right(6) - newError.toEither() shouldBe Either.Left(listOf('d', 'e', 'l', 'i', 'a', 'f')) - redeemed.toEither() shouldBe Either.Right(6) - captured.toEither() shouldBe Either.Right(Result.success(1)) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-01.kt deleted file mode 100644 index d46e9c0120f..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-01.kt +++ /dev/null @@ -1,12 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope01 - -import arrow.core.continuations.effect -import io.kotest.assertions.fail -import io.kotest.matchers.shouldBe - -suspend fun main() { - effect { - shift("SHIFT ME") - }.fold({ it shouldBe "SHIFT ME" }, { fail("Computation never finishes") }) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-02.kt deleted file mode 100644 index 8add3675e39..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-02.kt +++ /dev/null @@ -1,20 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope02 - -import arrow.core.Either -import arrow.core.continuations.Effect -import arrow.core.continuations.effect -import arrow.core.identity -import io.kotest.matchers.shouldBe - -suspend fun Either.toEffect(): Effect = effect { - fold({ e -> shift(e) }, ::identity) -} - -suspend fun main() { - val either = Either.Left("failed") - effect { - val x: Int = either.toEffect().bind() - x - }.toEither() shouldBe either -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-03.kt deleted file mode 100644 index 12a2a3eb6eb..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-03.kt +++ /dev/null @@ -1,21 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope03 - -import arrow.core.Either -import arrow.core.continuations.EagerEffect -import arrow.core.continuations.eagerEffect -import arrow.core.continuations.effect -import arrow.core.identity -import io.kotest.matchers.shouldBe - -suspend fun Either.toEagerEffect(): EagerEffect = eagerEffect { - fold({ e -> shift(e) }, ::identity) -} - -suspend fun main() { - val either = Either.Left("failed") - effect { - val x: Int = either.toEagerEffect().bind() - x - }.toEither() shouldBe either -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-04.kt deleted file mode 100644 index 43d90183190..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-04.kt +++ /dev/null @@ -1,14 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope04 - -import arrow.core.Either -import arrow.core.continuations.effect -import io.kotest.matchers.shouldBe - -suspend fun main() { - val either = Either.Right(9) - effect { - val x: Int = either.bind() - x - }.toEither() shouldBe either -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-05.kt deleted file mode 100644 index 2a40e47b9af..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-05.kt +++ /dev/null @@ -1,14 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope05 - -import arrow.core.Validated -import arrow.core.continuations.effect -import io.kotest.matchers.shouldBe - -suspend fun main() { - val validated = Validated.Valid(40) - effect { - val x: Int = validated.bind() - x - }.toValidated() shouldBe validated -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-06.kt deleted file mode 100644 index 996f8515731..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-06.kt +++ /dev/null @@ -1,15 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope06 - -import arrow.core.continuations.effect -import arrow.core.identity -import io.kotest.matchers.shouldBe - -private val default = "failed" -suspend fun main() { - val result = Result.success(1) - effect { - val x: Int = result.bind { _: Throwable -> default } - x - }.fold({ default }, ::identity) shouldBe result.getOrElse { default } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-07.kt deleted file mode 100644 index 877a0362bb1..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-07.kt +++ /dev/null @@ -1,18 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope07 - -import arrow.core.None -import arrow.core.Option -import arrow.core.continuations.effect -import arrow.core.getOrElse -import arrow.core.identity -import io.kotest.matchers.shouldBe - -private val default = "failed" -suspend fun main() { - val option: Option = None - effect { - val x: Int = option.bind { default } - x - }.fold({ default }, ::identity) shouldBe option.getOrElse { default } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-08.kt deleted file mode 100644 index 2df54254d0d..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-08.kt +++ /dev/null @@ -1,16 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope08 - -import arrow.core.Either -import arrow.core.continuations.effect -import io.kotest.matchers.shouldBe - -suspend fun main() { - val condition = true - val failure = "failed" - val int = 4 - effect { - ensure(condition) { failure } - int - }.toEither() shouldBe if(condition) Either.Right(int) else Either.Left(failure) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-09.kt deleted file mode 100644 index 4b4ffa3eb7b..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-09.kt +++ /dev/null @@ -1,20 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope09 - -import arrow.core.Either -import arrow.core.None -import arrow.core.Option -import arrow.core.Validated -import arrow.core.continuations.effect -import io.kotest.assertions.fail -import io.kotest.matchers.shouldBe - -suspend fun main() { - effect { - val x = Either.Right(1).bind() - val y = Validated.Valid(2).bind() - val z = - attempt { None.bind { "Option was empty" } } catch { 0 } - x + y + z - }.fold({ fail("Shift can never be the result") }, { it shouldBe 3 }) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-10.kt deleted file mode 100644 index 0d0dc84b89e..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-scope-10.kt +++ /dev/null @@ -1,16 +0,0 @@ -// This file was automatically generated from EffectScope.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEffectScope10 - -import arrow.core.continuations.effect -import arrow.core.continuations.ensureNotNull -import arrow.core.left -import arrow.core.right -import io.kotest.matchers.shouldBe - -suspend fun main() { - val failure = "failed" - val int: Int? = null - effect { - ensureNotNull(int) { failure } - }.toEither() shouldBe (int?.right() ?: failure.left()) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt index df6411d8a14..2b56f3c4506 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt @@ -1,11 +1,15 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither45 -import arrow.core.Either.Right -import arrow.core.Either.Left -import arrow.core.getOrElse - -fun main() { - Right(12).getOrElse { 17 } // Result: 12 - Left(12).getOrElse { 17 } // Result: 17 -} +import arrow.core.Either +import arrow.core.left +import arrow.core.recover + +object User +object Error + +val error: Either = Error.left() + +val a: Either = error.recover { error -> User } // Either.Right(User) +val b: Either = error.recover { error -> shift("other-failure") } // Either.Left(other-failure) +val c: Either = error.recover { error -> User } // Either.Right(User) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt index e0b22d93443..0de140e5df0 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt @@ -3,8 +3,9 @@ package arrow.core.examples.exampleEither46 import arrow.core.Either.Right import arrow.core.Either.Left +import arrow.core.getOrElse fun main() { - Right(12).orNull() // Result: 12 - Left(12).orNull() // Result: null + Right(12).getOrElse { 17 } // Result: 12 + Left(12).getOrElse { 17 } // Result: 17 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt index 7e170618794..b55ad404f8c 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt @@ -3,9 +3,8 @@ package arrow.core.examples.exampleEither47 import arrow.core.Either.Right import arrow.core.Either.Left -import arrow.core.getOrHandle fun main() { - Right(12).getOrHandle { 17 } // Result: 12 - Left(12).getOrHandle { it + 5 } // Result: 17 + Right(12).orNull() // Result: 12 + Left(12).orNull() // Result: null } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt index 6d282c44373..8ee7acceda5 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt @@ -1,14 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither48 -import arrow.core.Either.* -import arrow.core.Either -import arrow.core.filterOrElse +import arrow.core.Either.Right +import arrow.core.Either.Left +import arrow.core.getOrHandle fun main() { - Right(12).filterOrElse({ it > 10 }, { -1 }) // Result: Right(12) - Right(7).filterOrElse({ it > 10 }, { -1 }) // Result: Left(-1) - - val left: Either = Left(12) - left.filterOrElse({ it > 10 }, { -1 }) // Result: Left(12) + Right(12).getOrHandle { 17 } // Result: 12 + Left(12).getOrHandle { it + 5 } // Result: 17 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt index 2d14098d02d..53f1923b8ac 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt @@ -1,17 +1,14 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither49 -import arrow.core.* +import arrow.core.Either.* +import arrow.core.Either +import arrow.core.filterOrElse -suspend fun main(): Unit { - //sampleStart - Either.Right(7).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) - .let(::println) // Either.Left(Value '7' is not equal to 10") +fun main() { + Right(12).filterOrElse({ it > 10 }, { -1 }) // Result: Right(12) + Right(7).filterOrElse({ it > 10 }, { -1 }) // Result: Left(-1) - Either.Right(10).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) - .let(::println) // Either.Right(10) - - Either.Left(12).filterOrOther({ str: String -> str.contains("impossible") }, { -1 }) - .let(::println) // Either.Left(12) - //sampleEnd + val left: Either = Left(12) + left.filterOrElse({ it > 10 }, { -1 }) // Result: Left(12) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt index 458058b4dff..e8697f9cc61 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt @@ -1,11 +1,17 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither50 -import arrow.core.Either.Left -import arrow.core.Either.Right -import arrow.core.merge +import arrow.core.* -fun main() { - Right(12).merge() // Result: 12 - Left(12).merge() // Result: 12 +suspend fun main(): Unit { + //sampleStart + Either.Right(7).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) + .let(::println) // Either.Left(Value '7' is not equal to 10") + + Either.Right(10).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) + .let(::println) // Either.Right(10) + + Either.Left(12).filterOrOther({ str: String -> str.contains("impossible") }, { -1 }) + .let(::println) // Either.Left(12) + //sampleEnd } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt index 9826b45ba9a..9057d0efa58 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt @@ -1,12 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither51 -import arrow.core.Either.* -import arrow.core.leftIfNull +import arrow.core.Either.Left +import arrow.core.Either.Right +import arrow.core.merge fun main() { - Right(12).leftIfNull({ -1 }) // Result: Right(12) - Right(null).leftIfNull({ -1 }) // Result: Left(-1) - - Left(12).leftIfNull({ -1 }) // Result: Left(12) + Right(12).merge() // Result: 12 + Left(12).merge() // Result: 12 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt index eaf931db471..72aef4d31a3 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt @@ -1,9 +1,12 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither52 -import arrow.core.rightIfNotNull +import arrow.core.Either.* +import arrow.core.leftIfNull fun main() { - "value".rightIfNotNull { "left" } // Right(b="value") - null.rightIfNotNull { "left" } // Left(a="left") + Right(12).leftIfNull({ -1 }) // Result: Right(12) + Right(null).leftIfNull({ -1 }) // Result: Left(-1) + + Left(12).leftIfNull({ -1 }) // Result: Left(12) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt index 37b9c008d27..34946b3a896 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt @@ -1,13 +1,9 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither53 -import arrow.core.* +import arrow.core.rightIfNotNull -fun main(args: Array) { - //sampleStart - val string: Either = "Hello".right() - val chars: Either = - string.widen() - //sampleEnd - println(chars) +fun main() { + "value".rightIfNotNull { "left" } // Right(b="value") + null.rightIfNotNull { "left" } // Left(a="left") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt new file mode 100644 index 00000000000..9e22de7ca0a --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither54 + +import arrow.core.* + +fun main(args: Array) { + //sampleStart + val string: Either = "Hello".right() + val chars: Either = + string.widen() + //sampleEnd + println(chars) +} From e684586956f92c119b782959b0c049714467916a Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 5 Oct 2022 11:32:47 +0200 Subject: [PATCH 004/114] Rename Shift to Raise according to Slack Poll, and add some initial docs (#2827) --- arrow-libs/core/arrow-core/api/arrow-core.api | 254 ++++++++--------- .../commonMain/kotlin/arrow/core/Either.kt | 6 +- .../arrow/core/continuations/Builders.kt | 48 ++-- .../kotlin/arrow/core/continuations/Effect.kt | 90 +++--- .../arrow/core/continuations/ErrorHandlers.kt | 22 +- .../kotlin/arrow/core/continuations/Fold.kt | 16 +- .../kotlin/arrow/core/continuations/Raise.kt | 256 ++++++++++++++++++ .../kotlin/arrow/core/continuations/Shift.kt | 110 -------- .../core/continuations/EagerEffectSpec.kt | 26 +- .../arrow/core/continuations/EffectSpec.kt | 40 +-- .../StructuredConcurrencySpec.kt | 24 +- .../arrow/core/continuations/EffectUsage.kt | 12 +- .../kotlin/examples/example-effect-01.kt | 2 +- .../kotlin/examples/example-effect-02.kt | 4 +- .../kotlin/examples/example-effect-04.kt | 6 +- .../kotlin/examples/example-effect-05.kt | 2 +- .../kotlin/examples/example-effect-06.kt | 2 +- .../kotlin/examples/example-effect-07.kt | 2 +- .../kotlin/examples/example-effect-08.kt | 2 +- .../kotlin/examples/example-effect-09.kt | 2 +- .../kotlin/examples/example-effect-10.kt | 4 +- .../kotlin/examples/example-effect-11.kt | 4 +- .../kotlin/examples/example-effect-12.kt | 6 +- .../kotlin/examples/example-effect-13.kt | 4 +- .../examples/example-effect-error-01.kt | 4 +- .../examples/example-effect-error-02.kt | 2 +- .../examples/example-effect-error-03.kt | 4 +- .../kotlin/examples/example-either-45.kt | 2 +- .../kotlin/arrow/fx/coroutines/ScopeSpec.kt | 2 +- 29 files changed, 552 insertions(+), 406 deletions(-) create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index e6aee5404b0..853d7ae32db 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -2585,7 +2585,7 @@ public final class arrow/core/continuations/AtomicRefKt { public static final fun updateAndGet (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } -public final class arrow/core/continuations/DefaultShift : arrow/core/continuations/Shift { +public final class arrow/core/continuations/DefaultRaise : arrow/core/continuations/Raise { public fun ()V public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; @@ -2597,10 +2597,10 @@ public final class arrow/core/continuations/DefaultShift : arrow/core/continuati public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Object;)Ljava/lang/Object; } public final class arrow/core/continuations/Effect { @@ -2622,7 +2622,7 @@ public final class arrow/core/continuations/Effect { public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; public static final fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; public static final fun result (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun shiftedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/continuations/DefaultShift;)Ljava/lang/Object; + public static final fun shiftedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/continuations/DefaultRaise;)Ljava/lang/Object; public static final fun toEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun toEither (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun toIor (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; @@ -2647,8 +2647,8 @@ public final class arrow/core/continuations/EffectKt { public static final fun effect (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; } -public final class arrow/core/continuations/IorShift : arrow/core/continuations/Shift, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/Shift;)V +public final class arrow/core/continuations/IorRaise : arrow/core/continuations/Raise, arrow/typeclasses/Semigroup { + public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/Raise;)V public fun bind (Larrow/core/Either;)Ljava/lang/Object; public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; @@ -2665,186 +2665,186 @@ public final class arrow/core/continuations/IorShift : arrow/core/continuations/ public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V - public fun shift (Ljava/lang/Object;)Ljava/lang/Object; } -public final class arrow/core/continuations/NullableShift : arrow/core/continuations/Shift { +public final class arrow/core/continuations/NullableRaise : arrow/core/continuations/Raise { public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/NullableShift; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final synthetic fun box-impl (Larrow/core/continuations/Raise;)Larrow/core/continuations/NullableRaise; public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/Shift; - public static final fun ensure-impl (Larrow/core/continuations/Shift;Z)V - public static final fun ensureNotNull-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun constructor-impl (Larrow/core/continuations/Raise;)Larrow/core/continuations/Raise; + public static final fun ensure-impl (Larrow/core/continuations/Raise;Z)V + public static final fun ensureNotNull-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Ljava/lang/Object; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/Shift;Larrow/core/continuations/Shift;)Z + public static fun equals-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Larrow/core/continuations/Raise;Larrow/core/continuations/Raise;)Z public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/Shift;)I + public static fun hashCode-impl (Larrow/core/continuations/Raise;)I public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public fun raise (Ljava/lang/Void;)Ljava/lang/Object; + public static fun raise-impl (Larrow/core/continuations/Raise;Ljava/lang/Void;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/Shift;Ljava/lang/Void;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/Shift;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/Shift; + public static fun toString-impl (Larrow/core/continuations/Raise;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Larrow/core/continuations/Raise; } -public final class arrow/core/continuations/OptionShift : arrow/core/continuations/Shift { +public final class arrow/core/continuations/OptionRaise : arrow/core/continuations/Raise { public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/OptionShift; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final synthetic fun box-impl (Larrow/core/continuations/Raise;)Larrow/core/continuations/OptionRaise; public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/Shift; - public static final fun ensure-impl (Larrow/core/continuations/Shift;Z)V - public static final fun ensureNotNull-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun constructor-impl (Larrow/core/continuations/Raise;)Larrow/core/continuations/Raise; + public static final fun ensure-impl (Larrow/core/continuations/Raise;Z)V + public static final fun ensureNotNull-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Ljava/lang/Object; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/Shift;Larrow/core/continuations/Shift;)Z + public static fun equals-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Larrow/core/continuations/Raise;Larrow/core/continuations/Raise;)Z public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/Shift;)I + public static fun hashCode-impl (Larrow/core/continuations/Raise;)I public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun raise (Larrow/core/None;)Ljava/lang/Object; + public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public static fun raise-impl (Larrow/core/continuations/Raise;Larrow/core/None;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Larrow/core/None;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/Shift;Larrow/core/None;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/Shift;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/Shift; + public static fun toString-impl (Larrow/core/continuations/Raise;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Larrow/core/continuations/Raise; } -public final class arrow/core/continuations/ResultShift : arrow/core/continuations/Shift { +public abstract interface class arrow/core/continuations/Raise { + public abstract fun bind (Larrow/core/Either;)Ljava/lang/Object; + public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public abstract fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/Raise$DefaultImpls { + public static fun bind (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun catch (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/RaiseKt { + public static final fun catch (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static final fun ensure (Larrow/core/continuations/Raise;ZLkotlin/jvm/functions/Function0;)V + public static final fun ensureNotNull (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public static final fun recover (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static final fun recover (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/ResultRaise : arrow/core/continuations/Raise { public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/ResultShift; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; + public static final fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final synthetic fun box-impl (Larrow/core/continuations/Raise;)Larrow/core/continuations/ResultRaise; public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/Shift;)Larrow/core/continuations/Shift; + public static fun catch-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun constructor-impl (Larrow/core/continuations/Raise;)Larrow/core/continuations/Raise; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/Shift;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/Shift;Larrow/core/continuations/Shift;)Z + public static fun equals-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Larrow/core/continuations/Raise;Larrow/core/continuations/Raise;)Z public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/Shift;)I + public static fun hashCode-impl (Larrow/core/continuations/Raise;)I public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun invoke-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public fun raise (Ljava/lang/Throwable;)Ljava/lang/Object; + public static fun raise-impl (Larrow/core/continuations/Raise;Ljava/lang/Throwable;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/Shift;Ljava/lang/Throwable;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/Shift;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/Shift; -} - -public abstract interface class arrow/core/continuations/Shift { - public abstract fun bind (Larrow/core/Either;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/Shift$DefaultImpls { - public static fun bind (Larrow/core/continuations/Shift;Larrow/core/Either;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/Shift;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/Shift;Larrow/core/Validated;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun invoke (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun invoke (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/ShiftKt { - public static final fun catch (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun ensure (Larrow/core/continuations/Shift;ZLkotlin/jvm/functions/Function0;)V - public static final fun ensureNotNull (Larrow/core/continuations/Shift;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static final fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun recover (Larrow/core/continuations/Shift;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun toString-impl (Larrow/core/continuations/Raise;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Larrow/core/continuations/Raise; } public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Semigroup { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 3d479b8ede2..d6e84ec316d 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -3,7 +3,7 @@ package arrow.core import arrow.core.Either.Companion.resolve import arrow.core.Either.Left import arrow.core.Either.Right -import arrow.core.continuations.Shift +import arrow.core.continuations.Raise import arrow.core.continuations.either import arrow.core.continuations.ensure import arrow.typeclasses.Monoid @@ -1247,12 +1247,12 @@ public sealed class Either { * val error: Either = Error.left() * * val a: Either = error.recover { error -> User } // Either.Right(User) - * val b: Either = error.recover { error -> shift("other-failure") } // Either.Left(other-failure) + * val b: Either = error.recover { error -> raise("other-failure") } // Either.Left(other-failure) * val c: Either = error.recover { error -> User } // Either.Right(User) * ``` * */ -public inline fun Either.recover(recover: Shift.(E) -> A): Either = +public inline fun Either.recover(recover: Raise.(E) -> A): Either = when (this) { is Right -> this is Left -> either { recover(value) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt index 06abb84dc15..46b8e8ea3b8 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt @@ -19,31 +19,31 @@ import kotlin.jvm.JvmInline import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName -public inline fun either(@BuilderInference block: Shift.() -> A): Either = +public inline fun either(@BuilderInference block: Raise.() -> A): Either = fold({ block.invoke(this) }, { Either.Left(it) }, { Either.Right(it) }) -public inline fun nullable(block: NullableShift.() -> A): A? = - fold({ block(NullableShift(this)) }, { null }, ::identity) +public inline fun nullable(block: NullableRaise.() -> A): A? = + fold({ block(NullableRaise(this)) }, { null }, ::identity) -public inline fun result(action: ResultShift.() -> A): Result = - fold({ action(ResultShift(this)) }, Result.Companion::failure, Result.Companion::success) +public inline fun result(action: ResultRaise.() -> A): Result = + fold({ action(ResultRaise(this)) }, Result.Companion::failure, Result.Companion::success) -public inline fun option(action: OptionShift.() -> A): Option = - fold({ action(OptionShift(this)) }, ::identity, ::Some) +public inline fun option(action: OptionRaise.() -> A): Option = + fold({ action(OptionRaise(this)) }, ::identity, ::Some) -public inline fun ior(semigroup: Semigroup, @BuilderInference action: IorShift.() -> A): Ior = - fold({ IorShift(semigroup, this).invoke(action) }, { Ior.Left(it) }, ::identity) +public inline fun ior(semigroup: Semigroup, @BuilderInference action: IorRaise.() -> A): Ior = + fold({ IorRaise(semigroup, this).invoke(action) }, { Ior.Left(it) }, ::identity) @JvmInline -public value class NullableShift(private val cont: Shift) : Shift { +public value class NullableRaise(private val cont: Raise) : Raise { @EffectDSL public fun ensure(value: Boolean): Unit = ensure(value) { null } - override fun shift(r: Nothing?): B = cont.shift(r) - public fun Option.bind(): B = bind { shift(null) } + override fun raise(r: Nothing?): B = cont.raise(r) + public fun Option.bind(): B = bind { raise(null) } public fun B?.bind(): B { contract { returns() implies (this@bind != null) } - return this ?: shift(null) + return this ?: raise(null) } public fun ensureNotNull(value: B?): B { @@ -53,15 +53,15 @@ public value class NullableShift(private val cont: Shift) : Shift) : Shift { - override fun shift(r: Throwable): B = cont.shift(r) - public fun Result.bind(): B = fold(::identity) { shift(it) } +public value class ResultRaise(private val cont: Raise) : Raise { + override fun raise(r: Throwable): B = cont.raise(r) + public fun Result.bind(): B = fold(::identity) { raise(it) } } @JvmInline -public value class OptionShift(private val cont: Shift) : Shift { - override fun shift(r: None): B = cont.shift(r) - public fun Option.bind(): B = bind { shift(None) } +public value class OptionRaise(private val cont: Raise) : Raise { + override fun raise(r: None): B = cont.raise(r) + public fun Option.bind(): B = bind { raise(None) } public fun ensure(value: Boolean): Unit = ensure(value) { None } public fun ensureNotNull(value: B?): B { @@ -70,17 +70,17 @@ public value class OptionShift(private val cont: Shift) : Shift { } } -public class IorShift @PublishedApi internal constructor(semigroup: Semigroup, private val effect: Shift) : - Shift, Semigroup by semigroup { +public class IorRaise @PublishedApi internal constructor(semigroup: Semigroup, private val effect: Raise) : + Raise, Semigroup by semigroup { // TODO this is a mess... @PublishedApi internal var leftState: AtomicRef = AtomicRef(EmptyValue) - override fun shift(r: E): B = effect.shift(combine(r)) + override fun raise(r: E): B = effect.raise(combine(r)) public fun Ior.bind(): B = when (this) { - is Ior.Left -> shift(value) + is Ior.Left -> raise(value) is Ior.Right -> value is Ior.Both -> { combine(leftValue) @@ -89,7 +89,7 @@ public class IorShift @PublishedApi internal constructor(semigroup: Semigroup } @PublishedApi - internal inline operator fun invoke(action: IorShift.() -> A): Ior { + internal inline operator fun invoke(action: IorRaise.() -> A): Ior { val res = action(this) val leftState = leftState.get() return if (leftState === EmptyValue) Ior.Right(res) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt index 802dc7fac1c..dc083ce81ad 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt @@ -7,7 +7,7 @@ import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass /** - * [Effect] represents a function of `suspend Shift.() -> A`, that short-circuit with a value of `R` or `Throwable`, or completes with a value of `A`. + * [Effect] represents a function of `suspend Raise.() -> A`, that short-circuit with a value of `R` or `Throwable`, or completes with a value of `A`. * * So [Effect] is defined by `suspend fun fold(recover: suspend (Throwable) -> B, resolve: suspend (R) -> B, transform: suspend (A) -> B): B`, * to map all values of `R`, `Throwable` and `A` to a value of `B`. @@ -39,8 +39,8 @@ import kotlin.jvm.JvmMultifileClass * * We'll start by defining a small function that accepts a [String], and does some simply validation to check that the path * is not empty. If the path is empty, we want to program to result in `EmptyPath`. So we're immediately going to see how - * we can raise an error of any arbitrary type `R` by using the function `shift`. The name `shift` comes shifting (or - * changing, especially unexpectedly), away from the computation and finishing the `Continuation` with `R`. + * we can raise an error of any arbitrary type `R` by using the function `raise`. The name `raise` comes raising an intterupt, or + * changing, especially unexpectedly, away from the computation and finishing the `Continuation` with `R`. * * * - * Adding your own syntax to `Shift` is not advised, yet, but will be easy once "Multiple Receivers" become available. + * Adding your own syntax to `Raise` is not advised, yet, but will be easy once "Multiple Receivers" become available. * * ``` - * context(Shift) + * context(Raise) * suspend fun Either.bind(): A = * when (this) { - * is Either.Left -> shift(value) + * is Either.Left -> raise(value) * is Either.Right -> value * } * - * context(Shift) + * context(Raise) * fun Option.bind(): A = - * fold({ shift(it) }, ::identity) + * fold({ raise(it) }, ::identity) * ``` * * ## Handling errors @@ -206,7 +206,7 @@ import kotlin.jvm.JvmMultifileClass * --> * ```kotlin * val failed: Effect = - * effect { shift("failed") } + * effect { raise("failed") } * ``` * * We can `recover` the failure, and resolve it by providing a default value of `-1` or the length of the `error: String`. @@ -236,7 +236,7 @@ import kotlin.jvm.JvmMultifileClass * ```kotlin * val newError: Effect, Int> = * failed.recover { str -> - * shift(str.reversed().toList()) + * raise(str.reversed().toList()) * } * ``` * @@ -304,7 +304,7 @@ import kotlin.jvm.JvmMultifileClass * * val rethrown: Effect = * failed.catch { ex: java.sql.SQLException -> - * if(ex.isForeignKeyViolation()) shift("foreign key violation") + * if(ex.isForeignKeyViolation()) raise("foreign key violation") * else throw ex * } * ``` @@ -317,10 +317,10 @@ import kotlin.jvm.JvmMultifileClass * * ## Structured Concurrency * - * `Effect` relies on `kotlin.cancellation.CancellationException` to `shift` error values of type `R` inside the `Continuation` since it effectively cancels/short-circuits it. - * For this reason `shift` adheres to the same rules as [`Structured Concurrency`](https://kotlinlang.org/docs/coroutines-basics.html#structured-concurrency) + * `Effect` relies on `kotlin.cancellation.CancellationException` to `raise` error values of type `R` inside the `Continuation` since it effectively cancels/short-circuits it. + * For this reason `raise` adheres to the same rules as [`Structured Concurrency`](https://kotlinlang.org/docs/coroutines-basics.html#structured-concurrency) * - * Let's overview below how `shift` behaves with the different concurrency builders from Arrow Fx & KotlinX Coroutines. + * Let's overview below how `raise` behaves with the different concurrency builders from Arrow Fx & KotlinX Coroutines. * In the examples below we're going to be using a utility to show how _sibling tasks_ get cancelled. * The utility function show below called `awaitExitCase` will `never` finish suspending, and completes a `Deferred` with the `ExitCase`. * `ExitCase` is a sealed class that can be a value of `Failure(Throwable)`, `Cancelled(CancellationException)`, or `Completed`. @@ -345,7 +345,7 @@ import kotlin.jvm.JvmMultifileClass * ``` * * ### Arrow Fx Coroutines - * All operators in Arrow Fx Coroutines run in place, so they have no way of leaking `shift`. + * All operators in Arrow Fx Coroutines run in place, so they have no way of leaking `raise`. * It's there always safe to compose `effect` with any Arrow Fx combinator. Let's see some small examples below. * * #### parZip @@ -355,7 +355,7 @@ import kotlin.jvm.JvmMultifileClass * val error = "Error" * val exit = CompletableDeferred() * effect { - * parZip({ awaitExitCase(exit) }, { shift(error) }) { a, b -> a + b } + * parZip({ awaitExitCase(exit) }, { raise(error) }) { a, b -> a + b } * }.fold({ it shouldBe error }, { fail("Int can never be the result") }) * exit.await().shouldBeTypeOf() * } @@ -387,7 +387,7 @@ import kotlin.jvm.JvmMultifileClass * val exits = (0..3).map { CompletableDeferred() } * effect> { * (0..4).parTraverse { index -> - * if (index == 4) shift(error) + * if (index == 4) raise(error) * else awaitExitCase(exits[index]) * } * }.fold({ msg -> msg shouldBe error }, { fail("Int can never be the result") }) @@ -398,7 +398,7 @@ import kotlin.jvm.JvmMultifileClass * * * `parTraverse` will launch 5 tasks, for every element in `1..5`. - * The last task to get scheduled will `shift` with "error", and it will cancel the other launched tasks before returning. + * The last task to get scheduled will `raise` with "error", and it will cancel the other launched tasks before returning. * * #### raceN * * * `raceN` races `n` suspend functions in parallel, and cancels all participating functions when a winner is found. - * We can consider the function that `shift`s the winner of the race, except with a shifted value instead of a successful one. - * So when a function in the race `shift`s, and thus short-circuiting the race, it will cancel all the participating functions. + * We can consider the function that `raise`s the winner of the race, except with a raised value instead of a successful one. + * So when a function in the race `raise`s, and thus short-circuiting the race, it will cancel all the participating functions. * * #### bracketCase / Resource * @@ -628,8 +628,8 @@ import kotlin.jvm.JvmMultifileClass * #### Strange edge cases * * **NOTE** - * Capturing `shift` into a lambda, and leaking it outside of `Effect` to be invoked outside will yield unexpected results. - * Below we capture `shift` from inside the DSL, and then invoke it outside its context `Shift`. + * Capturing `raise` into a lambda, and leaking it outside of `Effect` to be invoked outside will yield unexpected results. + * Below we capture `raise` from inside the DSL, and then invoke it outside its context `Raise`. * * * ```kotlin * effect Unit> { - * suspend { shift("error") } - * }.fold({ }, { leakedShift -> leakedShift.invoke() }) + * suspend { raise("error") } + * }.fold({ }, { leakedRaise -> leakedRaise.invoke() }) * ``` * * The same violation is possible in all DSLs in Kotlin, including Structured Concurrency. @@ -664,11 +664,11 @@ import kotlin.jvm.JvmMultifileClass * ``` * */ -public typealias Effect = suspend Shift.() -> A +public typealias Effect = suspend Raise.() -> A -public inline fun effect(@BuilderInference noinline block: suspend Shift.() -> A): Effect = block +public inline fun effect(@BuilderInference noinline block: suspend Raise.() -> A): Effect = block /** The same behavior and API as [Effect] except without requiring _suspend_. */ -public typealias EagerEffect = Shift.() -> A +public typealias EagerEffect = Raise.() -> A -public inline fun eagerEffect(@BuilderInference noinline block: Shift.() -> A): EagerEffect = block +public inline fun eagerEffect(@BuilderInference noinline block: Raise.() -> A): EagerEffect = block diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt index 9493b0aa8dd..3012d60950c 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt @@ -22,15 +22,15 @@ import kotlin.jvm.JvmName * object User * object Error * - * val error = effect { shift(Error) } // // Shift(error) + * val error = effect { raise(Error) } // Raise(error) * * val a = error.recover { error -> User } // Success(User) - * val b = error.recover { error -> shift("other-failure") } // Shift(other-failure) + * val b = error.recover { error -> raise("other-failure") } // Raise(other-failure) * val c = error.recover { error -> throw RuntimeException("BOOM") } // Exception(BOOM) * ``` * */ -public infix fun Effect.recover(@BuilderInference resolve: suspend Shift.(shifted: E) -> A): Effect = +public infix fun Effect.recover(@BuilderInference resolve: suspend Raise.(shifted: E) -> A): Effect = effect { recover(resolve) } /** @@ -49,12 +49,12 @@ public infix fun Effect.recover(@BuilderInference resolve: susp * val exception = effect { throw RuntimeException("BOOM") } // Exception(BOOM) * * val a = exception.catch { error -> error.message?.length ?: -1 } // Success(5) - * val b = exception.catch { shift(Error) } // Shift(error) + * val b = exception.catch { raise(Error) } // Raise(error) * val c = exception.catch { throw RuntimeException("other-failure") } // Exception(other-failure) * ``` * */ -public infix fun Effect.catch(@BuilderInference resolve: suspend Shift.(throwable: Throwable) -> A): Effect = +public infix fun Effect.catch(@BuilderInference resolve: suspend Raise.(throwable: Throwable) -> A): Effect = effect { catch(resolve) } /** @@ -70,7 +70,7 @@ public infix fun Effect.catch(@BuilderInference resolve: suspend Sh * * val x = effect { * throw IllegalArgumentException("builder missed args") - * }.catch { shift(Error) } + * }.catch { raise(Error) } * ``` * * If you don't need an `error` value when wrapping your foreign code you can use `Nothing` to fill the type parameter. @@ -78,13 +78,13 @@ public infix fun Effect.catch(@BuilderInference resolve: suspend Sh * ```kotlin * val y = effect { * throw IllegalArgumentException("builder missed args") - * }.catch { shift(Error) } + * }.catch { raise(Error) } * ``` * */ @JvmName("catchReified") public inline infix fun Effect.catch( - @BuilderInference crossinline recover: suspend Shift.(T) -> A, + @BuilderInference crossinline recover: suspend Raise.(T) -> A, ): Effect = effect { catch { t: Throwable -> if (t is T) recover(t) else throw t } } @@ -98,14 +98,14 @@ public fun Effect.catch(): Effect> = } } -public infix fun EagerEffect.recover(@BuilderInference resolve: Shift.(shifted: E) -> A): EagerEffect = +public infix fun EagerEffect.recover(@BuilderInference resolve: Raise.(shifted: E) -> A): EagerEffect = eagerEffect { recover(resolve) } -public infix fun EagerEffect.catch(@BuilderInference recover: Shift.(throwable: Throwable) -> A): EagerEffect = +public infix fun EagerEffect.catch(@BuilderInference recover: Raise.(throwable: Throwable) -> A): EagerEffect = eagerEffect { catch(recover) } @JvmName("catchReified") public inline infix fun EagerEffect.catch( - @BuilderInference crossinline recover: Shift.(T) -> A, + @BuilderInference crossinline recover: Raise.(T) -> A, ): EagerEffect = eagerEffect { catch { t: Throwable -> if (t is T) recover(t) else throw t } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt index 260dcd902ca..a287dd3051f 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt @@ -41,19 +41,19 @@ public inline fun EagerEffect.fold( @JvmName("_foldOrThrow") public inline fun fold( - @BuilderInference program: Shift.() -> A, + @BuilderInference program: Raise.() -> A, recover: (shifted: R) -> B, transform: (value: A) -> B, ): B = fold(program, { throw it }, recover, transform) @JvmName("_fold") public inline fun fold( - @BuilderInference program: Shift.() -> A, + @BuilderInference program: Raise.() -> A, error: (error: Throwable) -> B, recover: (shifted: R) -> B, transform: (value: A) -> B, ): B { - val shift = DefaultShift() + val shift = DefaultRaise() return try { transform(program(shift)) } catch (e: CancellationException) { @@ -65,16 +65,16 @@ public inline fun fold( /** Returns the shifted value, rethrows the CancellationException if not our scope */ @PublishedApi -internal fun CancellationException.shiftedOrRethrow(shift: DefaultShift): R = - if (this is ShiftCancellationException && this.shift === shift) _shifted as R +internal fun CancellationException.shiftedOrRethrow(shift: DefaultRaise): R = + if (this is ShiftCancellationException && this.raise === shift) _shifted as R else throw this /** Serves as both purposes of a scope-reference token, and a default implementation for Shift. */ @PublishedApi -internal class DefaultShift : Shift { - override fun shift(r: Any?): B = throw ShiftCancellationException(r, this) +internal class DefaultRaise : Raise { + override fun raise(r: Any?): B = throw ShiftCancellationException(r, this) } /** CancellationException is required to cancel coroutines when shifting from within them. */ -private class ShiftCancellationException(val _shifted: Any?, val shift: Shift) : +private class ShiftCancellationException(val _shifted: Any?, val raise: Raise) : CancellationException("Shifted Continuation") diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt new file mode 100644 index 00000000000..268951b24d3 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt @@ -0,0 +1,256 @@ +@file:OptIn(ExperimentalTypeInference::class) + +package arrow.core.continuations + +import arrow.core.Either +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.core.Validated +import arrow.core.identity +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract +import kotlin.experimental.ExperimentalTypeInference +import kotlin.jvm.JvmName + +@DslMarker +public annotation class EffectDSL + +/** + * The [Raise] DSL allows you to work with _logical failures_ of type [R]. + * A _logical failure_ does not necessarily mean that the computation has failed, + * but that it has stopped or _short-circuited_. + * + * The [Raise] DSL allows you to [raise] _logical failure_ of type [R], and you can [recover] from them. + * + * ```kotlin + * fun Raise.failure(): Int = raise("failed") + * + * fun Raise.recovered(): String = + * recover({ program() }) { failure: String -> + * "Recovered from $failure" + * } + * ``` + * + * Above we defined a function `failure` that raises a logical failure of type [String] with value `"failed"`. + * And in the function `recovered` we recover from the failure by providing a fallback value, + * and resolving the error type [String] to [Nothing]. Meaning we can track that we recovered from the error in the type. + * + * Since we defined programs in terms of [Raise] they _seamlessly work with any of the builders_ available in Arrow, + * or any you might build for your custom types. + * + * ```kotlin + * fun main() { + * val either: Either = + * either { failure() } // returns Left("failed") + * + * val effect: Effect = + * effect { failure() } + * + * val ior: Ior = + * ior { failure() } + * + * println(either) + * } + * ``` + * + * ```text + * Either.Right(Recovered from failed) + * ``` + */ +public interface Raise { + + /** Raise a _logical failure_ of type [R] */ + public fun raise(r: R): A + + /** + * Invoke an [EagerEffect] inside `this` [Raise] context. + * Any _logical failure_ raised are raised in `this` [Raise] context, + * and thus short-circuits the computation. + * + * @see [recover] if you want to attempt to recover from any _logical failure_. + */ + public operator fun EagerEffect.invoke(): A = invoke(this@Raise) + public fun EagerEffect.bind(): A = invoke(this@Raise) + + /** + * Invoke an [Effect] inside `this` [Raise] context. + * Any _logical failure_ raised are raised in `this` [Raise] context, + * and thus short-circuits the computation. + * + * @see [recover] if you want to attempt to recover from any _logical failure_. + */ + public suspend operator fun Effect.invoke(): A = invoke(this@Raise) + public suspend fun Effect.bind(): A = invoke(this@Raise) + + /** + * Extract the [Either.Right] value of an [Either]. + * Any encountered [Either.Left] will be raised as a _logical failure_ in `this` [Raise] context. + * You can wrap the [bind] call in [recover] if you want to attempt to recover from any _logical failure_. + * + * ```kotlin + * fun main() { + * val left: Either = Either.Left("failed") + * either { + * recover({ left.bind() }) { failure : String -> + * "Recovered from $failure" + * } + * }.also(::println) + * ``` + * ```text + * Either.Right(Recovered from failed) + * ``` + */ + public fun Either.bind(): A = when (this) { + is Either.Left -> raise(value) + is Either.Right -> value + } + + /* Will be removed in subsequent PRs for Arrow 2.x.x */ + public fun Validated.bind(): A = when (this) { + is Validated.Invalid -> raise(value) + is Validated.Valid -> value + } + + /** + * Extract the [Result.success] value out of [Result], + * because [Result] works with [Throwable] as its error type you need to [transform] [Throwable] to [R]. + * + * Note that this functions can currently not be _inline_ without Context Receivers, + * but you can rely on [recover] if you want to run any suspend code in your error handler. + * + * ```kotlin + * fun main() { + * val failure: Result = Result.failure(RuntimeException("Boom!")) + * either { + * recover({ failure.bind() }) { failure: Throwable -> + * delay(10) + * raise("Something bad happened: ${failure.message}") + * } + * }.also(::println) + * ``` + * ```text + * Either.Left(Something bad happened: Boom!) + * ``` + */ + public fun Result.bind(transform: (Throwable) -> R): A = + fold(::identity) { throwable -> raise(transform(throwable)) } + + /** + * Extract the [Some] value out of [Option], + * because [Option] works with [None] as its error type you need to [transform] [None] to [R]. + * + * Note that this functions can currently not be _inline_ without Context Receivers, + * but you can rely on [recover] if you want to run any suspend code in your error handler. + * + * ```kotlin + * fun main() { + * val empty: Option = None + * either { + * recover({ empty.bind() }) { failure: None -> + * delay(10) + * raise("Something bad happened: ${failure.message}") + * } + * }.also(::println) + * ``` + * ```text + * Either.Left(Something bad happened: Boom!) + * ``` + */ + public fun Option.bind(transform: Raise.(None) -> A): A = + when (this) { + None -> transform(None) + is Some -> value + } + + /** + * Execute the [Effect] resulting in [A], + * and recover from any _logical error_ of type [E] by providing a fallback value of type [A], + * or raising a new error of type [R]. + * + * ```kotlin + * suspend fun main() { + * either { + * effect { raise("failed") }.recover { str -> str.length } + * }.also(::println) + * + * either { + * effect { raise("failed") }.recover { str -> shift(-1) } + * }.also(::println) + * } + * ``` + * ```text + * Either.Right(6) + * Either.Left(-1) + * ``` + */ + @EffectDSL + public suspend infix fun Effect.recover(@BuilderInference resolve: suspend Raise.(E) -> A): A = + recover({ invoke() }) { resolve(it) } + + /** @see [recover] */ + @EffectDSL + public infix fun EagerEffect.recover(@BuilderInference resolve: Raise.(E) -> A): A = + recover({ invoke() }, resolve) + + /** + * Execute the [Effect] resulting in [A], + * and recover from any _logical error_ of type [E], and [Throwable], by providing a fallback value of type [A], + * or raising a new error of type [R]. + * + * @see [catch] if you don't need to recover from [Throwable]. + */ + @EffectDSL + public suspend fun Effect.recover( + @BuilderInference action: suspend Raise.() -> A, + @BuilderInference recover: suspend Raise.(E) -> A, + @BuilderInference catch: suspend Raise.(Throwable) -> A, + ): A = fold({ action(this) }, { catch(it) }, { recover(it) }, { it }) + + @EffectDSL + public suspend fun Effect.catch( + @BuilderInference catch: suspend Raise.(Throwable) -> A, + ): A = fold({ catch(it) }, { raise(it) }, { it }) + + @EffectDSL + public fun EagerEffect.catch( + @BuilderInference catch: Raise.(Throwable) -> A, + ): A = fold({ catch(it) }, { raise(it) }, { it }) +} + +@EffectDSL +public inline fun Raise.recover( + @BuilderInference action: Raise.() -> A, + @BuilderInference recover: Raise.(E) -> A, +): A = fold({ action(this) }, { throw it }, { recover(it) }, { it }) + +@EffectDSL +public inline fun Raise.recover( + @BuilderInference action: Raise.() -> A, + @BuilderInference recover: Raise.(E) -> A, + @BuilderInference catch: Raise.(Throwable) -> A, +): A = fold({ action(this) }, { catch(it) }, { recover(it) }, { it }) + +@EffectDSL +public inline fun Raise.catch( + @BuilderInference action: Raise.() -> A, + @BuilderInference catch: Raise.(Throwable) -> A, +): A = fold({ action(this) }, { catch(it) }, { raise(it) }, { it }) + +@EffectDSL +@JvmName("catchReified") +public inline fun Raise.catch( + @BuilderInference action: Raise.() -> A, + @BuilderInference catch: Raise.(T) -> A, +): A = catch(action) { t: Throwable -> if (t is T) catch(t) else throw t } + +@EffectDSL +public inline fun Raise.ensure(condition: Boolean, shift: () -> R): Unit = + if (condition) Unit else raise(shift()) + +@OptIn(ExperimentalContracts::class) +@EffectDSL +public inline fun Raise.ensureNotNull(value: B?, shift: () -> R): B { + contract { returns() implies (value != null) } + return value ?: raise(shift()) +} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt deleted file mode 100644 index 1e13f47c1c6..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Shift.kt +++ /dev/null @@ -1,110 +0,0 @@ -@file:OptIn(ExperimentalTypeInference::class) - -package arrow.core.continuations - -import arrow.core.Either -import arrow.core.None -import arrow.core.Option -import arrow.core.Some -import arrow.core.Validated -import arrow.core.identity -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.experimental.ExperimentalTypeInference -import kotlin.jvm.JvmName - -@DslMarker -public annotation class EffectDSL - -public interface Shift { - public fun shift(r: R): A - - public fun EagerEffect.bind(): A = invoke(this@Shift) - public operator fun EagerEffect.invoke(): A = invoke(this@Shift) - - public suspend fun Effect.bind(): A = invoke(this@Shift) - public suspend operator fun Effect.invoke(): A = invoke(this@Shift) - - public fun Either.bind(): A = when (this) { - is Either.Left -> shift(value) - is Either.Right -> value - } - - public fun Validated.bind(): A = when (this) { - is Validated.Invalid -> shift(value) - is Validated.Valid -> value - } - - // TODO can be inlined with context receivers, and top-level - public fun Option.bind(transform: Shift.(None) -> A): A = - when (this) { - None -> transform(None) - is Some -> value - } - - // TODO can be inlined with context receivers, and top-level - public fun Result.bind(transform: (Throwable) -> R): A = - fold(::identity) { throwable -> shift(transform(throwable)) } - - @EffectDSL - public suspend infix fun Effect.recover(@BuilderInference resolve: suspend Shift.(E) -> A): A = - recover({ invoke() }) { resolve(it) } - - @EffectDSL - public infix fun EagerEffect.recover(@BuilderInference resolve: Shift.(E) -> A): A = - recover({ invoke() }, resolve) - - @EffectDSL - public suspend fun Effect.recover( - @BuilderInference action: suspend Shift.() -> A, - @BuilderInference resolve: suspend Shift.(E) -> A, - @BuilderInference recover: suspend Shift.(Throwable) -> A, - ): A = fold({ action(this) }, { recover(it) }, { resolve(it) }, { it }) - - @EffectDSL - public suspend fun Effect.catch( - @BuilderInference recover: suspend Shift.(Throwable) -> A, - ): A = fold({ recover(it) }, { shift(it) }, { it }) - - @EffectDSL - public fun EagerEffect.catch( - @BuilderInference recover: Shift.(Throwable) -> A, - ): A = fold({ recover(it) }, { shift(it) }, { it }) -} - -@EffectDSL -public inline fun Shift.recover( - @BuilderInference action: Shift.() -> A, - @BuilderInference resolve: Shift.(E) -> A -): A = fold({ action(this) }, { throw it }, { resolve(it) }, { it }) - -@EffectDSL -public inline fun Shift.recover( - @BuilderInference action: Shift.() -> A, - @BuilderInference resolve: Shift.(E) -> A, - @BuilderInference recover: Shift.(Throwable) -> A, -): A = fold({ action(this) }, { recover(it) }, { resolve(it) }, { it }) - -@EffectDSL -public inline fun Shift.catch( - @BuilderInference action: Shift.() -> A, - @BuilderInference recover: Shift.(Throwable) -> A, -): A = fold({ action(this) }, { recover(it) }, { shift(it) }, { it }) - -@EffectDSL -@JvmName("catchReified") -public inline fun Shift.catch( - @BuilderInference action: Shift.() -> A, - @BuilderInference recover: Shift.(T) -> A, -): A = catch(action) { t: Throwable -> if (t is T) recover(t) else throw t } - -@EffectDSL -public inline fun Shift.ensure(condition: Boolean, shift: () -> R): Unit = - if (condition) Unit else shift(shift()) - -@OptIn(ExperimentalContracts::class) -@EffectDSL -public inline fun Shift.ensureNotNull(value: B?, shift: () -> R): B { - contract { returns() implies (value != null) } - return value ?: shift(shift()) -} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt index 9dcee7f3610..e7e2fbba6ff 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt @@ -23,7 +23,7 @@ class EagerEffectSpec : StringSpec({ checkAll(Arb.int(), Arb.string()) { i, s -> eagerEffect { try { - shift(s) + raise(s) } catch (e: Throwable) { i } @@ -36,7 +36,7 @@ class EagerEffectSpec : StringSpec({ val promise = CompletableDeferred() eagerEffect { try { - shift(s) + raise(s) } finally { require(promise.complete(i)) } @@ -51,11 +51,11 @@ class EagerEffectSpec : StringSpec({ eagerEffect { val x: Int = try { - shift(s) + raise(s) } catch (e: Throwable) { i } - shift(s2) + raise(s2) }.fold(::identity) { fail("Should never come here") } shouldBe s2 } } @@ -64,7 +64,7 @@ class EagerEffectSpec : StringSpec({ checkAll(Arb.int(), Arb.long()) { i, l -> eagerEffect { eagerEffect { - shift(l) + raise(l) } recover { ll -> ll shouldBe l i @@ -90,10 +90,10 @@ class EagerEffectSpec : StringSpec({ checkAll(Arb.int(), Arb.long(), Arb.string()) { i, l, error -> eagerEffect { eagerEffect { - shift(l) + raise(l) } recover { ll -> ll shouldBe l - shift(error) + raise(error) } }.runCont() shouldBe error } @@ -101,7 +101,7 @@ class EagerEffectSpec : StringSpec({ "values" { eagerEffect { 1 }.toEither().orNull() shouldBe 1 } - "short-circuit" { eagerEffect { shift("hello") }.runCont() shouldBe "hello" } + "short-circuit" { eagerEffect { raise("hello") }.runCont() shouldBe "hello" } "Rethrows exceptions" { val e = RuntimeException("test") @@ -144,7 +144,7 @@ class EagerEffectSpec : StringSpec({ "catch - error path and recover" { checkAll(Arb.int(), Arb.string()) { int, fallback -> eagerEffect { - shift(int) + raise(int) fail("It should never reach this point") }.recover { fallback } .runCont() shouldBe fallback @@ -154,9 +154,9 @@ class EagerEffectSpec : StringSpec({ "catch - error path and re-shift" { checkAll(Arb.int(), Arb.string()) { int, fallback -> eagerEffect { - shift(int) + raise(int) fail("It should never reach this point") - }.recover { shift(fallback) } + }.recover { raise(fallback) } .runCont() shouldBe fallback } } @@ -165,7 +165,7 @@ class EagerEffectSpec : StringSpec({ checkAll(Arb.int(), Arb.string()) { int, msg -> shouldThrow { eagerEffect { - shift(int) + raise(int) fail("It should never reach this point") }.recover { throw RuntimeException(msg) } .runCont() @@ -195,7 +195,7 @@ class EagerEffectSpec : StringSpec({ checkAll(Arb.string(), Arb.int()) { msg, fallback -> eagerEffect { throw RuntimeException(msg) - }.catch { shift(fallback) } + }.catch { raise(fallback) } .runCont() shouldBe fallback } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt index 79679cde04c..9bce6d3ff39 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt @@ -34,7 +34,7 @@ class EffectSpec : checkAll(Arb.int().suspend(), Arb.string().suspend()) { i, s -> effect { try { - shift(s()) + raise(s()) } catch (e: Throwable) { i() } @@ -47,7 +47,7 @@ class EffectSpec : val promise = CompletableDeferred() effect { try { - shift(s().suspend()) + raise(s().suspend()) } finally { require(promise.complete(i())) } @@ -61,11 +61,11 @@ class EffectSpec : checkAll(Arb.int().suspend(), Arb.string().suspend(), Arb.string().suspend()) { i, s, s2 -> effect { val x: Int = try { - shift(s()) + raise(s()) } catch (e: Throwable) { i() } - shift(s2()) + raise(s2()) } .fold(::identity) { fail("Should never come here") } shouldBe s2() } @@ -75,7 +75,7 @@ class EffectSpec : checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> effect { effect { - shift(l()) + raise(l()) } recover { ll -> ll shouldBe l() i() @@ -113,7 +113,7 @@ class EffectSpec : "eagerEffect shift short-circuits effect computation" { checkAll(Arb.string(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = - eagerEffect { shift(a) } + eagerEffect { raise(a) } effect { val bb = b() @@ -132,7 +132,7 @@ class EffectSpec : "short-circuit" { checkAll(Arb.string().suspend()) { msg -> effect { - shift(msg()) + raise(msg()) }.runCont() shouldBe msg() } } @@ -150,7 +150,7 @@ class EffectSpec : "Can short-circuit from nested blocks" { checkAll(Arb.string().suspend()) { msg -> effect { - effect { shift(msg()) }.runCont() + effect { raise(msg()) }.runCont() fail("Should never reach this point") } .runCont() shouldBe msg() @@ -162,7 +162,7 @@ class EffectSpec : effect { effect { 1L.suspend() - shift(msg()) + raise(msg()) }.runCont() fail("Should never reach this point") }.runCont() shouldBe msg() @@ -201,7 +201,7 @@ class EffectSpec : checkAll(Arb.string()) { msg -> fun failure(): Effect = effect { withContext(Dispatchers.Default) {} - shift(Failure(msg)) + raise(Failure(msg)) } effect { @@ -218,12 +218,12 @@ class EffectSpec : checkAll(Arb.string()) { error -> val failed: Effect = effect { withContext(Dispatchers.Default) {} - shift(error) + raise(error) } val newError: Effect, Int> = failed.recover { str -> - shift(str.reversed().toList()) + raise(str.reversed().toList()) } newError.toEither() shouldBe Either.Left(error.reversed().toList()) @@ -234,14 +234,14 @@ class EffectSpec : checkAll(Arb.string()) { error -> val failed: Effect = effect { withContext(Dispatchers.Default) {} - shift(error) + raise(error) } val newError: Effect, Int> = effect { failed.fold({ r -> effect, Int> { - shift(r.reversed().toList()) + raise(r.reversed().toList()) }.bind() }, ::identity) } @@ -268,7 +268,7 @@ class EffectSpec : effect { throw RuntimeException(msg()) }.fold( - { shift(fallback()) }, + { raise(fallback()) }, ::identity, { it.length } ) @@ -302,7 +302,7 @@ class EffectSpec : "catch - error path and recover" { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> effect { - shift(int()) + raise(int()) fail("It should never reach this point") }.recover { fallback() } .runCont() shouldBe fallback() @@ -312,9 +312,9 @@ class EffectSpec : "catch - error path and re-shift" { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> effect { - shift(int()) + raise(int()) fail("It should never reach this point") - }.recover { shift(fallback()) } + }.recover { raise(fallback()) } .runCont() shouldBe fallback() } } @@ -323,7 +323,7 @@ class EffectSpec : checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, msg -> shouldThrow { effect { - shift(int()) + raise(int()) fail("It should never reach this point") }.recover { throw RuntimeException(msg()) } .runCont() @@ -353,7 +353,7 @@ class EffectSpec : checkAll(Arb.string().suspend(), Arb.int().suspend()) { msg, fallback -> effect { throw RuntimeException(msg()) - }.catch { shift(fallback()) } + }.catch { raise(fallback()) } .runCont() shouldBe fallback() } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt index 8b3b558dfb7..cb17c98dfe7 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt @@ -46,7 +46,7 @@ class StructuredConcurrencySpec : } async { started.await() - shift("hello") + raise("hello") }.await() never.await() } @@ -66,8 +66,8 @@ class StructuredConcurrencySpec : checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { - val fa = async { shift(a) } - val fb = async { shift(b) } + val fa = async { raise(a) } + val fb = async { raise(b) } fa.await() + fb.await() } } @@ -101,7 +101,7 @@ class StructuredConcurrencySpec : asyncTask(start, promise) } startLatches.awaitAll() - shift(a) + raise(a) } val fb = asyncTask(startLatches.first(), fbExit) fa.await() @@ -123,8 +123,8 @@ class StructuredConcurrencySpec : checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { - val fa = async { shift(a) } - val fb = async { shift(b) } + val fa = async { raise(a) } + val fb = async { raise(b) } "I will be overwritten by shift - coroutineScope waits until all async are finished" } } @@ -156,7 +156,7 @@ class StructuredConcurrencySpec : async { startLatches.zip(nestedExits) { start, promise -> asyncTask(start, promise) } startLatches.awaitAll() - shift(a) + raise(a) } str } @@ -174,8 +174,8 @@ class StructuredConcurrencySpec : checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { - launch { shift(a) } - launch { shift(b) } + launch { raise(a) } + launch { raise(b) } "shift does not escape `launch`" } } @@ -205,7 +205,7 @@ class StructuredConcurrencySpec : val fa = launch { startLatches.zip(nestedExits) { start, promise -> launchTask(start, promise) } startLatches.awaitAll() - shift(a) + raise(a) } str } @@ -227,8 +227,8 @@ class StructuredConcurrencySpec : coroutineScope { val shiftedAsync = effect> { - val fa = async { shift(a) } - async { shift(b) } + val fa = async { raise(a) } + async { raise(b) } } .fold({ fail("shift was never awaited, so it never took effect") }, ::identity) shiftedAsync.await() diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt index 1509b0d0028..8553cac0b91 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/continuations/EffectUsage.kt @@ -9,17 +9,17 @@ sealed interface OtherError : MyError { object Actual : OtherError } -context(Shift) +context(Raise) suspend fun subprogram(): Unit = println("Hello SubProgram!") -context(Shift) +context(Raise) suspend fun otherprogram(): Unit = println("Hello OtherProgram!") -context(Shift) +context(Raise) suspend fun fail(): MyResponse = - shift(OtherError.Actual) + raise(OtherError.Actual) fun main() = runBlocking(Dispatchers.Default) { @@ -38,11 +38,11 @@ object EmptyResponse : MyResponse data class ErrorResponse(val error: Throwable) : MyResponse data class BodyResponse(val body: String) : MyResponse -context(Shift) +context(Raise) suspend fun respondWithBody(): BodyResponse = BodyResponse("Hello Program!") -context(Shift) +context(Raise) suspend fun attemptOrError(): MyResponse = ErrorResponse(RuntimeException("Oh no!")) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt index 7653712b8f4..e1b8d3d9498 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-01.kt @@ -9,7 +9,7 @@ import arrow.core.continuations.ensure object EmptyPath fun readFile(path: String): Effect = effect { - if (path.isEmpty()) shift(EmptyPath) else Unit + if (path.isEmpty()) raise(EmptyPath) else Unit } fun readFile2(path: String?): Effect = effect { diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt index 1e323abc263..323e8b6fa0f 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt @@ -37,9 +37,9 @@ fun readFile(path: String?): Effect = effect { val lines = File(path).readLines() Content(lines) } catch (e: FileNotFoundException) { - shift(FileNotFound(path)) + raise(FileNotFound(path)) } catch (e: SecurityException) { - shift(SecurityError(e.message)) + raise(SecurityError(e.message)) } } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt index add17cff915..af45286413c 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-04.kt @@ -7,7 +7,7 @@ import arrow.core.continuations.recover import arrow.core.continuations.catch val failed: Effect = - effect { shift("failed") } + effect { raise("failed") } val default: Effect = failed.recover { -1 } @@ -20,7 +20,7 @@ val resolved2: Effect = resolved val newError: Effect, Int> = failed.recover { str -> - shift(str.reversed().toList()) + raise(str.reversed().toList()) } val newException: Effect = @@ -50,6 +50,6 @@ suspend fun java.sql.SQLException.isForeignKeyViolation(): Boolean = true val rethrown: Effect = failed.catch { ex: java.sql.SQLException -> - if(ex.isForeignKeyViolation()) shift("foreign key violation") + if(ex.isForeignKeyViolation()) raise("foreign key violation") else throw ex } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt index 5701d7b3a08..c17af634fe8 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt @@ -19,7 +19,7 @@ suspend fun awaitExitCase(exit: CompletableDeferred): A = val error = "Error" val exit = CompletableDeferred() effect { - parZip({ awaitExitCase(exit) }, { shift(error) }) { a, b -> a + b } + parZip({ awaitExitCase(exit) }, { raise(error) }) { a, b -> a + b } }.fold({ it shouldBe error }, { fail("Int can never be the result") }) exit.await().shouldBeTypeOf() } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-06.kt index 29a0a136457..88e21428453 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-06.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-06.kt @@ -23,7 +23,7 @@ suspend fun main() { val exits = (0..3).map { CompletableDeferred() } effect> { (0..4).parTraverse { index -> - if (index == 4) shift(error) + if (index == 4) raise(error) else awaitExitCase(exits[index]) } }.fold({ msg -> msg shouldBe error }, { fail("Int can never be the result") }) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt index f0b411a222e..33f4a45af98 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt @@ -23,7 +23,7 @@ suspend fun main() { val error = "Error" val exit = CompletableDeferred() effect { - raceN({ awaitExitCase(exit) }) { shift(error) } + raceN({ awaitExitCase(exit) }) { raise(error) } .merge() // Flatten Either result from race into Int }.fold({ msg -> msg shouldBe error }, { fail("Int can never be the result") }) // It's possible not all parallel task got launched, and in those cases awaitCancellation never ran diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-08.kt index 7fe68e33a6b..26fff45c402 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-08.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-08.kt @@ -18,7 +18,7 @@ suspend fun main() { effect { bracketCase( acquire = { File("build.gradle.kts").bufferedReader() }, - use = { reader: BufferedReader -> shift(error) }, + use = { reader: BufferedReader -> raise(error) }, release = { reader, exitCase -> reader.close() exit.complete(exitCase) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt index 5936da64f3a..e3426a5911b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt @@ -26,7 +26,7 @@ suspend fun main() { resourceScope { effect { val reader = bufferedReader("build.gradle.kts") - shift(error) + raise(error) reader.lineSequence().count() }.fold({ it shouldBe error }, { fail("Int can never be the result") }) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-10.kt index 3e1eb29a8ae..d3a6fd3aab1 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-10.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-10.kt @@ -36,9 +36,9 @@ fun readFile(path: String?): Effect = effect { val lines = File(path).readLines() Content(lines) } catch (e: FileNotFoundException) { - shift(FileNotFound(path)) + raise(FileNotFound(path)) } catch (e: SecurityException) { - shift(SecurityError(e.message)) + raise(SecurityError(e.message)) } } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-11.kt index 98d14585a5b..38d6fe7839b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-11.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-11.kt @@ -13,8 +13,8 @@ suspend fun main() { val errorB = "ErrorB" coroutineScope { effect { - val fa = async { shift(errorA) } - val fb = async { shift(errorB) } + val fa = async { raise(errorA) } + val fb = async { raise(errorB) } fa.await() + fb.await() }.fold({ error -> error shouldBeIn listOf(errorA, errorB) }, { fail("Int can never be the result") }) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-12.kt index 8b4105198ab..a52920f4e3a 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-12.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-12.kt @@ -14,9 +14,9 @@ suspend fun main() { val int = 45 effect { coroutineScope { - launch { shift(errorA) } - launch { shift(errorB) } + launch { raise(errorA) } + launch { raise(errorB) } int } - }.fold({ fail("Shift can never finish") }, { it shouldBe int }) + }.fold({ fail("Raise can never finish") }, { it shouldBe int }) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-13.kt index 74de4ee270e..edd1eb8a83c 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-13.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-13.kt @@ -10,8 +10,8 @@ import kotlinx.coroutines.coroutineScope suspend fun main() { effect Unit> { - suspend { shift("error") } - }.fold({ }, { leakedShift -> leakedShift.invoke() }) + suspend { raise("error") } + }.fold({ }, { leakedRaise -> leakedRaise.invoke() }) val leakedAsync = coroutineScope Deferred> { suspend { diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt index 47297a7f7b4..0de7596cb4e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt @@ -7,8 +7,8 @@ import arrow.core.continuations.recover object User object Error -val error = effect { shift(Error) } // // Shift(error) +val error = effect { raise(Error) } // Raise(error) val a = error.recover { error -> User } // Success(User) -val b = error.recover { error -> shift("other-failure") } // Shift(other-failure) +val b = error.recover { error -> raise("other-failure") } // Raise(other-failure) val c = error.recover { error -> throw RuntimeException("BOOM") } // Exception(BOOM) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt index ae04eef943f..58a49857d52 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt @@ -10,5 +10,5 @@ object Error val exception = effect { throw RuntimeException("BOOM") } // Exception(BOOM) val a = exception.catch { error -> error.message?.length ?: -1 } // Success(5) -val b = exception.catch { shift(Error) } // Shift(error) +val b = exception.catch { raise(Error) } // Raise(error) val c = exception.catch { throw RuntimeException("other-failure") } // Exception(other-failure) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt index d1f053d3573..e854d89c490 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt @@ -9,8 +9,8 @@ object Error val x = effect { throw IllegalArgumentException("builder missed args") -}.catch { shift(Error) } +}.catch { raise(Error) } val y = effect { throw IllegalArgumentException("builder missed args") -}.catch { shift(Error) } +}.catch { raise(Error) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt index 2b56f3c4506..6dc03e51b22 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt @@ -11,5 +11,5 @@ object Error val error: Either = Error.left() val a: Either = error.recover { error -> User } // Either.Right(User) -val b: Either = error.recover { error -> shift("other-failure") } // Either.Left(other-failure) +val b: Either = error.recover { error -> raise("other-failure") } // Either.Left(other-failure) val c: Either = error.recover { error -> User } // Either.Right(User) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt index a0d9a3cebaa..478809b523f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt @@ -114,7 +114,7 @@ class ResourceTest : StringSpec({ install({ 1 }) { _, ex -> require(exit.complete(ex)) } - shift("error") + raise("error") } } shouldBe "error".left() exit.await().shouldBeTypeOf() From 6ec972ff4e1002d09372c06b9db91bf671556e92 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 5 Oct 2022 12:31:31 +0200 Subject: [PATCH 005/114] Remove all references to shift from new Arrow 2.0 code (#2834) * Remove all references to shift from new code * Update API files --- arrow-libs/core/arrow-core/api/arrow-core.api | 2 +- .../commonMain/kotlin/arrow/core/Either.kt | 2 +- .../kotlin/arrow/core/continuations/Fold.kt | 30 +++++++-------- .../core/continuations/EagerEffectSpec.kt | 22 +++++------ .../arrow/core/continuations/EffectSpec.kt | 24 ++++++------ .../StructuredConcurrencySpec.kt | 37 +++++++++---------- .../kotlin/arrow/fx/coroutines/PredefTest.kt | 2 +- 7 files changed, 59 insertions(+), 60 deletions(-) diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 853d7ae32db..04c5171a396 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -2619,10 +2619,10 @@ public final class arrow/core/continuations/Effect { public static final fun option (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun orNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun orNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun raisedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/continuations/DefaultRaise;)Ljava/lang/Object; public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; public static final fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; public static final fun result (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun shiftedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/continuations/DefaultRaise;)Ljava/lang/Object; public static final fun toEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun toEither (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun toIor (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index d6e84ec316d..0d9d123a44d 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -1234,7 +1234,7 @@ public sealed class Either { /** * Recover from [E] when encountering [Left]. - * You can either return a new value of [A], or short-circuit by shifting with a value of [E2]. + * You can either return a new value of [A], or short-circuit by raising with a value of [E2]. * * ```kotlin * import arrow.core.Either diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt index a287dd3051f..495e14de5fb 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt @@ -13,7 +13,7 @@ import kotlin.jvm.JvmName /** * `invoke` the [Effect] and [fold] the result: * - _success_ [transform] result of [A] to a value of [B]. - * - _shift_ [recover] from `shifted` value of [R] to a value of [B]. + * - _raised_ [recover] from `raised` value of [R] to a value of [B]. * - _exception_ [error] from [Throwable] by transforming value into [B]. * * This method should never be wrapped in `try`/`catch` as it will not throw any unexpected errors, @@ -21,12 +21,12 @@ import kotlin.jvm.JvmName */ public suspend fun Effect.fold( error: suspend (error: Throwable) -> B, - recover: suspend (shifted: R) -> B, + recover: suspend (raised: R) -> B, transform: suspend (value: A) -> B, ): B = fold({ invoke() }, { error(it) }, { recover(it) }, { transform(it) }) public suspend fun Effect.fold( - recover: suspend (shifted: R) -> B, + recover: suspend (raised: R) -> B, transform: suspend (value: A) -> B, ): B = fold({ throw it }, recover, transform) @@ -35,14 +35,14 @@ public fun EagerEffect.fold(recover: (R) -> B, transform: (A) -> public inline fun EagerEffect.fold( error: (error: Throwable) -> B, - recover: (shifted: R) -> B, + recover: (raised: R) -> B, transform: (value: A) -> B, ): B = fold({ invoke(this) }, error, recover, transform) @JvmName("_foldOrThrow") public inline fun fold( @BuilderInference program: Raise.() -> A, - recover: (shifted: R) -> B, + recover: (raised: R) -> B, transform: (value: A) -> B, ): B = fold(program, { throw it }, recover, transform) @@ -50,14 +50,14 @@ public inline fun fold( public inline fun fold( @BuilderInference program: Raise.() -> A, error: (error: Throwable) -> B, - recover: (shifted: R) -> B, + recover: (raised: R) -> B, transform: (value: A) -> B, ): B { - val shift = DefaultRaise() + val raise = DefaultRaise() return try { - transform(program(shift)) + transform(program(raise)) } catch (e: CancellationException) { - recover(e.shiftedOrRethrow(shift)) + recover(e.raisedOrRethrow(raise)) } catch (e: Throwable) { error(e.nonFatalOrThrow()) } @@ -65,16 +65,16 @@ public inline fun fold( /** Returns the shifted value, rethrows the CancellationException if not our scope */ @PublishedApi -internal fun CancellationException.shiftedOrRethrow(shift: DefaultRaise): R = - if (this is ShiftCancellationException && this.raise === shift) _shifted as R +internal fun CancellationException.raisedOrRethrow(raise: DefaultRaise): R = + if (this is RaiseCancellationException && this.raise === raise) _raised as R else throw this -/** Serves as both purposes of a scope-reference token, and a default implementation for Shift. */ +/** Serves as both purposes of a scope-reference token, and a default implementation for Raise. */ @PublishedApi internal class DefaultRaise : Raise { - override fun raise(r: Any?): B = throw ShiftCancellationException(r, this) + override fun raise(r: Any?): B = throw RaiseCancellationException(r, this) } /** CancellationException is required to cancel coroutines when shifting from within them. */ -private class ShiftCancellationException(val _shifted: Any?, val raise: Raise) : - CancellationException("Shifted Continuation") +private class RaiseCancellationException(val _raised: Any?, val raise: Raise) : + CancellationException("Raised Continuation") diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt index e7e2fbba6ff..671306bb6ac 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt @@ -19,7 +19,7 @@ import io.kotest.property.checkAll import kotlinx.coroutines.CompletableDeferred class EagerEffectSpec : StringSpec({ - "try/catch - can recover from shift" { + "try/catch - can recover from raise" { checkAll(Arb.int(), Arb.string()) { i, s -> eagerEffect { try { @@ -46,7 +46,7 @@ class EagerEffectSpec : StringSpec({ } } - "try/catch - First shift is ignored and second is returned" { + "try/catch - First raise is ignored and second is returned" { checkAll(Arb.int(), Arb.string(), Arb.string()) { i, s, s2 -> eagerEffect { val x: Int = @@ -86,7 +86,7 @@ class EagerEffectSpec : StringSpec({ } } - "attempt - shift from catch" { + "attempt - raise from catch" { checkAll(Arb.int(), Arb.long(), Arb.string()) { i, l, error -> eagerEffect { eagerEffect { @@ -109,25 +109,25 @@ class EagerEffectSpec : StringSpec({ } "ensure null in eager either computation" { - checkAll(Arb.boolean(), Arb.int(), Arb.string()) { predicate, success, shift -> + checkAll(Arb.boolean(), Arb.int(), Arb.string()) { predicate, success, raise -> either { - ensure(predicate) { shift } + ensure(predicate) { raise } success - } shouldBe if (predicate) success.right() else shift.left() + } shouldBe if (predicate) success.right() else raise.left() } } "ensureNotNull in eager either computation" { fun square(i: Int): Int = i * i - checkAll(Arb.int().orNull(), Arb.string()) { i: Int?, shift: String -> + checkAll(Arb.int().orNull(), Arb.string()) { i: Int?, raise: String -> val res = either { val ii = i - ensureNotNull(ii) { shift } + ensureNotNull(ii) { raise } square(ii) // Smart-cast by contract } - val expected = i?.let(::square)?.right() ?: shift.left() + val expected = i?.let(::square)?.right() ?: raise.left() res shouldBe expected } } @@ -151,7 +151,7 @@ class EagerEffectSpec : StringSpec({ } } - "catch - error path and re-shift" { + "catch - error path and re-raise" { checkAll(Arb.int(), Arb.string()) { int, fallback -> eagerEffect { raise(int) @@ -191,7 +191,7 @@ class EagerEffectSpec : StringSpec({ } } - "attempt - error path and re-shift" { + "attempt - error path and re-raise" { checkAll(Arb.string(), Arb.int()) { msg, fallback -> eagerEffect { throw RuntimeException(msg) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt index 9bce6d3ff39..569651f962e 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt @@ -30,7 +30,7 @@ import kotlinx.coroutines.withContext class EffectSpec : StringSpec({ - "try/catch - can recover from shift" { + "try/catch - can recover from raise" { checkAll(Arb.int().suspend(), Arb.string().suspend()) { i, s -> effect { try { @@ -57,7 +57,7 @@ class EffectSpec : } } - "try/catch - First shift is ignored and second is returned" { + "try/catch - First raise is ignored and second is returned" { checkAll(Arb.int().suspend(), Arb.string().suspend(), Arb.string().suspend()) { i, s, s2 -> effect { val x: Int = try { @@ -110,7 +110,7 @@ class EffectSpec : } } - "eagerEffect shift short-circuits effect computation" { + "eagerEffect raise short-circuits effect computation" { checkAll(Arb.string(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = eagerEffect { raise(a) } @@ -174,25 +174,25 @@ class EffectSpec : Arb.boolean().suspend(), Arb.int().suspend(), Arb.string().suspend() - ) { predicate, success, shift -> + ) { predicate, success, raise -> either { - ensure(predicate()) { shift() } + ensure(predicate()) { raise() } success() - } shouldBe if (predicate()) success().right() else shift().left() + } shouldBe if (predicate()) success().right() else raise().left() } } "ensureNotNull in either computation" { fun square(i: Int): Int = i * i - checkAll(Arb.int().orNull().suspend(), Arb.string().suspend()) { i, shift-> + checkAll(Arb.int().orNull().suspend(), Arb.string().suspend()) { i, raise-> val res = either { val ii = i() - ensureNotNull(ii) { shift() } + ensureNotNull(ii) { raise() } square(ii) // Smart-cast by contract } - val expected = i()?.let(::square)?.right() ?: shift().left() + val expected = i()?.let(::square)?.right() ?: raise().left() res shouldBe expected } } @@ -262,7 +262,7 @@ class EffectSpec : } } - "Can shift from thrown exceptions" { + "Can raise from thrown exceptions" { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> effect { effect { @@ -309,7 +309,7 @@ class EffectSpec : } } - "catch - error path and re-shift" { + "catch - error path and re-raise" { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> effect { raise(int()) @@ -349,7 +349,7 @@ class EffectSpec : } } - "attempt - error path and re-shift" { + "attempt - error path and re-raise" { checkAll(Arb.string().suspend(), Arb.int().suspend()) { msg, fallback -> effect { throw RuntimeException(msg()) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt index cb17c98dfe7..e19278b7c3e 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/StructuredConcurrencySpec.kt @@ -27,10 +27,9 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.withTimeout -@OptIn(ExperimentalTime::class) class StructuredConcurrencySpec : StringSpec({ - "async - suspendCancellableCoroutine.invokeOnCancellation is called with Shifted Continuation" { + "async - suspendCancellableCoroutine.invokeOnCancellation is called with Raised Continuation" { val started = CompletableDeferred() val cancelled = CompletableDeferred() @@ -53,7 +52,7 @@ class StructuredConcurrencySpec : }.runCont() shouldBe "hello" withTimeout(2.seconds) { - cancelled.await().shouldNotBeNull().message shouldBe "Shifted Continuation" + cancelled.await().shouldNotBeNull().message shouldBe "Raised Continuation" } } @@ -62,7 +61,7 @@ class StructuredConcurrencySpec : effect { currentContext() shouldBe parentCtx }.runCont() } - "Concurrent shift - async await" { + "Concurrent raise - async await" { checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { @@ -75,7 +74,7 @@ class StructuredConcurrencySpec : } } - "Concurrent shift - async await exit results" { + "Concurrent raise - async await exit results" { checkAll(Arb.int()) { a -> val scopeExit = CompletableDeferred() val fbExit = CompletableDeferred() @@ -119,21 +118,21 @@ class StructuredConcurrencySpec : } } - "Concurrent shift - async" { + "Concurrent raise - async" { checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { val fa = async { raise(a) } val fb = async { raise(b) } - "I will be overwritten by shift - coroutineScope waits until all async are finished" + "I will be overwritten by raise - coroutineScope waits until all async are finished" } } .fold({ fail("Async is never awaited, and thus ignored.") }, ::identity) shouldBe - "I will be overwritten by shift - coroutineScope waits until all async are finished" + "I will be overwritten by raise - coroutineScope waits until all async are finished" } } - "Concurrent shift - async exit results" { + "Concurrent raise - async exit results" { checkAll(Arb.int(), Arb.string()) { a, str -> val exitScope = CompletableDeferred() val startLatches = (0..10).map { CompletableDeferred() } @@ -170,20 +169,20 @@ class StructuredConcurrencySpec : } } - "Concurrent shift - launch" { + "Concurrent raise - launch" { checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { launch { raise(a) } launch { raise(b) } - "shift does not escape `launch`" + "raise does not escape `launch`" } } - .runCont() shouldBe "shift does not escape `launch`" + .runCont() shouldBe "raise does not escape `launch`" } } - "Concurrent shift - launch exit results" { + "Concurrent raise - launch exit results" { checkAll(Arb.int(), Arb.string()) { a, str -> val scopeExit = CompletableDeferred() val startLatches = (0..10).map { CompletableDeferred() } @@ -219,23 +218,23 @@ class StructuredConcurrencySpec : } } - // `shift` escapes `cont` block, and gets rethrown inside `coroutineScope`. + // `raise` escapes `cont` block, and gets rethrown inside `coroutineScope`. // Effectively awaiting/executing DSL code, outside of the DSL... - "async funky scenario #1 - Extract `shift` from `cont` through `async`" { + "async funky scenario #1 - Extract `raise` from `cont` through `async`" { checkAll(Arb.int(), Arb.int()) { a, b -> runCatching { coroutineScope { - val shiftedAsync = + val raiseedAsync = effect> { val fa = async { raise(a) } async { raise(b) } } - .fold({ fail("shift was never awaited, so it never took effect") }, ::identity) - shiftedAsync.await() + .fold({ fail("raise was never awaited, so it never took effect") }, ::identity) + raiseedAsync.await() } } .exceptionOrNull() - ?.message shouldBe "Shifted Continuation" + ?.message shouldBe "Raised Continuation" } } }) diff --git a/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmTest/kotlin/arrow/fx/coroutines/PredefTest.kt b/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmTest/kotlin/arrow/fx/coroutines/PredefTest.kt index 3118adfd57e..aeaf8f302d7 100644 --- a/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmTest/kotlin/arrow/fx/coroutines/PredefTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmTest/kotlin/arrow/fx/coroutines/PredefTest.kt @@ -30,7 +30,7 @@ class PredefTest : ArrowFxSpec( } } - "shift" { + "raise" { checkAll(Arb.string(), Arb.string()) { a, b -> val t0 = Thread.currentThread().name From c30621d312b032e2d45e96903100cd894a7d6ca6 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 5 Oct 2022 20:26:42 +0200 Subject: [PATCH 006/114] Fixes merge conflict between main and arrow-2 (#2835) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Resource.allocated() to decompose Resource into it's allocate and… (#2820) * [2743] Migrate internal use of CircuitBreaker double to duration (#2748) * Fix typo (#2824) * Make the server disconnect test more general (#2822) * Update NonEmptyList.fromList deprecation to suggest `toOption()` instead (#2832) * Improve Either.getOrHandle() docs (#2833) * Improve allocated, and fix knit examples Co-authored-by: Jeff Martin Co-authored-by: Martin Moore Co-authored-by: valery1707 Co-authored-by: Lukasz Kalnik <70261110+lukasz-kalnik-gcx@users.noreply.github.com> Co-authored-by: stylianosgakis --- .../NetworkEitherCallAdapterTest.kt | 4 +- .../commonMain/kotlin/arrow/core/Either.kt | 3 +- .../src/commonMain/kotlin/arrow/core/Ior.kt | 2 +- .../kotlin/arrow/core/NonEmptyList.kt | 5 +- .../api/arrow-fx-coroutines.api | 10 + .../kotlin/arrow/fx/coroutines/Bracket.kt | 5 + .../arrow/fx/coroutines/CircuitBreaker.kt | 183 +++++++++++++----- .../kotlin/arrow/fx/coroutines/Resource.kt | 48 +++++ .../arrow/fx/coroutines/CircuitBreakerTest.kt | 64 +++++- .../{ScopeSpec.kt => ResourceTest.kt} | 116 +++++++++-- .../kotlin/examples/example-resource-09.kt | 18 ++ 11 files changed, 372 insertions(+), 86 deletions(-) rename arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/{ScopeSpec.kt => ResourceTest.kt} (78%) create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt index f7705dfa5a1..90788295ec9 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt @@ -20,7 +20,7 @@ import retrofit2.Converter import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.moshi.MoshiConverterFactory -import java.net.ConnectException +import java.net.SocketException import java.net.SocketTimeoutException @ExperimentalSerializationApi @@ -96,7 +96,7 @@ private fun networkEitherCallAdapterTests( body.shouldBeInstanceOf>() .value.shouldBeInstanceOf() - .cause.shouldBeInstanceOf() + .cause.shouldBeInstanceOf() } "should return IOError when no response" { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 0d9d123a44d..7e47738d6bb 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -1311,8 +1311,7 @@ public fun Either<*, B>.orNull(): B? = orNull() /** - * Returns the value from this [Right] or allows clients to transform [Left] to [Right] while providing access to - * the value of [Left]. + * Returns the value from this [Right] or allows clients to transform the value from [Left] with the [default] lambda. * * Example: * ```kotlin diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt index a2f6b55a503..9983e985121 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt @@ -23,7 +23,7 @@ public typealias IorNel = Ior, B> * [Ior]<`A`,`B`> is similar to [Either]<`A`,`B`>, except that it can represent the simultaneous presence of * an `A` and a `B`. It is right-biased so methods such as `map` and `flatMap` operate on the * `B` value. Some methods, like `flatMap`, handle the presence of two [Ior.Both] values using a - * `[Semigroup]<`A`>, while other methods, like [toEither], ignore the `A` value in a [Ior.Both Both]. + * [Semigroup]<`A`>, while other methods, like [toEither], ignore the `A` value in a [Ior.Both Both]. * * [Ior]<`A`,`B`> is isomorphic to [Either]<[Either]<`A`,`B`>, [Pair]<`A`,`B`>>, but provides methods biased toward `B` * values, regardless of whether the `B` values appear in a [Ior.Right] or a [Ior.Both]. diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index 80e58e68eb1..d823b9fc482 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -237,10 +237,9 @@ public class NonEmptyList( @Deprecated( "Use toNonEmptyListOrNull instead", ReplaceWith( - "Option.fromNullable>(l.toNonEmptyListOrNull())", + "l.toNonEmptyListOrNull().toOption()", "import arrow.core.toNonEmptyListOrNull", - "import arrow.core.Option", - "import arrow.core.NonEmptyList" + "import arrow.core.toOption" ) ) @JvmStatic diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index fbc6e73af25..be169607705 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -81,7 +81,9 @@ public final class arrow/fx/coroutines/CircuitBreaker$State$Closed : arrow/fx/co public final class arrow/fx/coroutines/CircuitBreaker$State$HalfOpen : arrow/fx/coroutines/CircuitBreaker$State { public fun (D)V + public synthetic fun (JLkotlin/jvm/internal/DefaultConstructorMarker;)V public fun equals (Ljava/lang/Object;)Z + public final fun getResetTimeout-UwyO8pc ()J public final fun getResetTimeoutNanos ()D public fun hashCode ()I public fun toString ()Ljava/lang/String; @@ -89,8 +91,10 @@ public final class arrow/fx/coroutines/CircuitBreaker$State$HalfOpen : arrow/fx/ public final class arrow/fx/coroutines/CircuitBreaker$State$Open : arrow/fx/coroutines/CircuitBreaker$State { public fun (JD)V + public synthetic fun (JJLkotlin/jvm/internal/DefaultConstructorMarker;)V public fun equals (Ljava/lang/Object;)Z public final fun getExpiresAt ()J + public final fun getResetTimeout-UwyO8pc ()J public final fun getResetTimeoutNanos ()D public final fun getStartedAt ()J public fun hashCode ()I @@ -98,6 +102,7 @@ public final class arrow/fx/coroutines/CircuitBreaker$State$Open : arrow/fx/coro } public abstract class arrow/fx/coroutines/ExitCase { + public static final field Companion Larrow/fx/coroutines/ExitCase$Companion; } public final class arrow/fx/coroutines/ExitCase$Cancelled : arrow/fx/coroutines/ExitCase { @@ -111,6 +116,10 @@ public final class arrow/fx/coroutines/ExitCase$Cancelled : arrow/fx/coroutines/ public fun toString ()Ljava/lang/String; } +public final class arrow/fx/coroutines/ExitCase$Companion { + public final fun ExitCase (Ljava/lang/Throwable;)Larrow/fx/coroutines/ExitCase; +} + public final class arrow/fx/coroutines/ExitCase$Completed : arrow/fx/coroutines/ExitCase { public static final field INSTANCE Larrow/fx/coroutines/ExitCase$Completed; public fun toString ()Ljava/lang/String; @@ -328,6 +337,7 @@ public final class arrow/fx/coroutines/ResourceExtensionsKt { } public final class arrow/fx/coroutines/ResourceKt { + public static final fun allocated (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun asFlow (Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow; public static final fun resource (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; public static final fun resource (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt index d92e4be3343..d9273f3ef95 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt @@ -13,6 +13,11 @@ public sealed class ExitCase { public data class Cancelled(val exception: CancellationException) : ExitCase() public data class Failure(val failure: Throwable) : ExitCase() + + public companion object { + public fun ExitCase(error: Throwable): ExitCase = + if (error is CancellationException) Cancelled(error) else Failure(error) + } } /** diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt index ccc8a6cd478..81c991cde98 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt @@ -8,8 +8,9 @@ import arrow.fx.coroutines.CircuitBreaker.State.HalfOpen import arrow.fx.coroutines.CircuitBreaker.State.Open import kotlinx.coroutines.CompletableDeferred import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.nanoseconds import kotlin.time.DurationUnit -import kotlin.time.ExperimentalTime /** * A [CircuitBreaker] is used to `protect` resources or services from being overloaded @@ -129,15 +130,18 @@ public class CircuitBreaker private constructor( private val state: AtomicRef, private val maxFailures: Int, - private val resetTimeout: Double, + private val resetTimeoutNanos: Double, private val exponentialBackoffFactor: Double, - private val maxResetTimeout: Double, + private val maxResetTimeoutNanos: Double, private val onRejected: suspend () -> Unit, private val onClosed: suspend () -> Unit, private val onHalfOpen: suspend () -> Unit, private val onOpen: suspend () -> Unit ) { - + + private val resetTimeout: Duration = resetTimeoutNanos.nanoseconds + private val maxResetTimeout: Duration = maxResetTimeoutNanos.nanoseconds + /** Returns the current [CircuitBreaker.State], meant for debugging purposes. */ public suspend fun state(): State = state.get() @@ -191,10 +195,10 @@ private constructor( // task to execute, while transitioning into HalfOpen if (!state.compareAndSet( curr, - State.HalfOpen(curr.resetTimeoutNanos, curr.awaitClose) + HalfOpen(curr.resetTimeout, curr.awaitClose) ) ) protectOrThrow(fa) // retry! - else attemptReset(fa, curr.resetTimeoutNanos, curr.awaitClose, curr.startedAt) + else attemptReset(fa, curr.resetTimeout, curr.awaitClose, curr.startedAt) } else { // Open isn't expired, so we need to fail val expiresInMillis = curr.expiresAt - now @@ -234,7 +238,7 @@ private constructor( if (curr.failures + 1 < maxFailures) { // It's fine, just increment the failures count val update = Closed(curr.failures + 1) - if (!state.compareAndSet(curr, update)) markOrResetFailures(result) // retry? + if (!state.compareAndSet(curr, update)) markOrResetFailures(result) // retry? else throw result.value } else { // N.B. this could be canceled, however we don't care @@ -242,7 +246,7 @@ private constructor( // We've gone over the permitted failures threshold, // so we need to open the circuit breaker val update = Open(now, resetTimeout, CompletableDeferred()) - if (!state.compareAndSet(curr, update)) markOrResetFailures(result) // retry + if (!state.compareAndSet(curr, update)) markOrResetFailures(result) // retry else { onOpen.invoke() throw result.value @@ -268,7 +272,7 @@ private constructor( */ private suspend fun attemptReset( task: suspend () -> A, - resetTimeout: Double, + resetTimeout: Duration, awaitClose: CompletableDeferred, lastStartedAt: Long ): A = @@ -292,8 +296,8 @@ private constructor( } is ExitCase.Failure -> { // Failed reset, which means we go back in the Open state with new expiry val nextTimeout - val value: Double = (resetTimeout * exponentialBackoffFactor) - val nextTimeout: Double = + val value: Duration = (resetTimeout * exponentialBackoffFactor) + val nextTimeout: Duration = if (maxResetTimeout.isFinite() && value > maxResetTimeout) maxResetTimeout else value val ts = timeInMillis() @@ -321,9 +325,9 @@ private constructor( CircuitBreaker( state = state, maxFailures = maxFailures, - resetTimeout = resetTimeout, + resetTimeoutNanos = resetTimeout.toDouble(DurationUnit.NANOSECONDS), exponentialBackoffFactor = exponentialBackoffFactor, - maxResetTimeout = maxResetTimeout, + maxResetTimeoutNanos = maxResetTimeout.toDouble(DurationUnit.NANOSECONDS), onRejected = suspend { onRejected.invoke(); callback.invoke() }, onClosed = onClosed, onHalfOpen = onHalfOpen, @@ -347,9 +351,9 @@ private constructor( CircuitBreaker( state = state, maxFailures = maxFailures, - resetTimeout = resetTimeout, + resetTimeoutNanos = resetTimeout.toDouble(DurationUnit.NANOSECONDS), exponentialBackoffFactor = exponentialBackoffFactor, - maxResetTimeout = maxResetTimeout, + maxResetTimeoutNanos = maxResetTimeout.toDouble(DurationUnit.NANOSECONDS), onRejected = onRejected, onClosed = suspend { onClosed.invoke(); callback.invoke(); }, onHalfOpen = onHalfOpen, @@ -373,9 +377,9 @@ private constructor( CircuitBreaker( state = state, maxFailures = maxFailures, - resetTimeout = resetTimeout, + resetTimeoutNanos = resetTimeout.toDouble(DurationUnit.NANOSECONDS), exponentialBackoffFactor = exponentialBackoffFactor, - maxResetTimeout = maxResetTimeout, + maxResetTimeoutNanos = maxResetTimeout.toDouble(DurationUnit.NANOSECONDS), onRejected = onRejected, onClosed = onClosed, onHalfOpen = suspend { onHalfOpen.invoke(); callback.invoke() }, @@ -399,9 +403,9 @@ private constructor( CircuitBreaker( state = state, maxFailures = maxFailures, - resetTimeout = resetTimeout, + resetTimeoutNanos = resetTimeout.toDouble(DurationUnit.NANOSECONDS), exponentialBackoffFactor = exponentialBackoffFactor, - maxResetTimeout = maxResetTimeout, + maxResetTimeoutNanos = maxResetTimeout.toDouble(DurationUnit.NANOSECONDS), onRejected = onRejected, onClosed = onClosed, onHalfOpen = onHalfOpen, @@ -447,20 +451,50 @@ private constructor( * @param startedAt is the timestamp in milliseconds since the * epoch when the transition to [Open] happened. * - * @param resetTimeoutNanos is the current `resetTimeout` that is + * @param resetTimeout is the current `resetTimeout` that is * applied to this `Open` state, to be multiplied by the * exponential backoff factor for the next transition from * `HalfOpen` to `Open`. */ public class Open internal constructor( public val startedAt: Long, - public val resetTimeoutNanos: Double, - internal val awaitClose: CompletableDeferred + public val resetTimeout: Duration, + internal val awaitClose: CompletableDeferred, ) : State() { - + + @Deprecated( + "Prefer to use resetTimeout with kotlin.time.Duration", + ReplaceWith( + "resetTimeout.toDouble(DurationUnit.NANOSECONDS)", + "kotlin.time.DurationUnit" + ) + ) + public val resetTimeoutNanos: Double + get() = resetTimeout.toDouble(DurationUnit.NANOSECONDS) + + public constructor(startedAt: Long, resetTimeout: Duration) : this( + startedAt, + resetTimeout, + CompletableDeferred() + ) + + @Deprecated( + "This constructor will be removed in Arrow 2.0", + level = DeprecationLevel.WARNING + ) + internal constructor( + startedAt: Long, + resetTimeoutNanos: Double, + awaitClose: CompletableDeferred, + ) : this(startedAt, resetTimeoutNanos.nanoseconds, awaitClose) + + @Deprecated( + "This constructor will be removed in Arrow 2.0", + level = DeprecationLevel.WARNING + ) public constructor(startedAt: Long, resetTimeoutNanos: Double) : this( startedAt, - resetTimeoutNanos, + resetTimeoutNanos.nanoseconds, CompletableDeferred() ) @@ -470,20 +504,20 @@ private constructor( * It is calculated as: * `startedAt + resetTimeout` */ - public val expiresAt: Long = startedAt + (resetTimeoutNanos.toLong() / 1_000_000) + public val expiresAt: Long = resetTimeout.plus(startedAt.milliseconds).toLong(DurationUnit.MILLISECONDS) override fun equals(other: Any?): Boolean = if (other is Open) this.startedAt == startedAt && - this.resetTimeoutNanos == resetTimeoutNanos && + this.resetTimeout == resetTimeout && this.expiresAt == expiresAt else false override fun toString(): String = - "CircuitBreaker.State.Open(startedAt=$startedAt, resetTimeoutNanos=$resetTimeoutNanos, expiresAt=$expiresAt)" + "CircuitBreaker.State.Open(startedAt=$startedAt, resetTimeoutNanos=$resetTimeout, expiresAt=$expiresAt)" override fun hashCode(): Int { var result = startedAt.hashCode() - result = 31 * result + resetTimeoutNanos.hashCode() + result = 31 * result + resetTimeout.hashCode() result = 31 * result + expiresAt.hashCode() return result } @@ -495,26 +529,47 @@ private constructor( * - If the `test request` succeeds, then the [CircuitBreaker] is tripped back into [Closed], with the reset timeout, and the failures count also reset to their initial values. * - If the `test request` fails, then the [CircuitBreaker] is tripped back into [Open], the [resetTimeout] is multiplied by the [exponentialBackoffFactor], up to the configured [maxResetTimeout]. * - * @param resetTimeoutNanos is the current `reset timeout` that the [CircuitBreaker] has to stay in [Open] state. + * @param resetTimeout is the current `reset timeout` that the [CircuitBreaker] has to stay in [Open] state. * When the `reset timeout` lapsed, than the [CircuitBreaker] will allow a test request to go through in [HalfOpen]. - * If the test request failed, the [CircuitBreaker] will go back into [Open] and it'll multiply the [resetTimeoutNanos] with the the exponential backoff factor. + * If the test request failed, the [CircuitBreaker] will go back into [Open] and it'll multiply the [resetTimeout] with the the exponential backoff factor. */ public class HalfOpen internal constructor( - public val resetTimeoutNanos: Double, + public val resetTimeout: Duration, internal val awaitClose: CompletableDeferred ) : State() { + + @Deprecated( + "Prefer to use resetTimeout with kotlin.time.Duration", + ReplaceWith( + "resetTimeout.toDouble(DurationUnit.NANOSECONDS)", + "kotlin.time.DurationUnit" + ) + ) + public val resetTimeoutNanos: Double + get() = resetTimeout.toDouble(DurationUnit.NANOSECONDS) + + public constructor(resetTimeout: Duration) : this(resetTimeout, CompletableDeferred()) + + @Deprecated( + "This constructor will be removed in Arrow 2.0", + level = DeprecationLevel.WARNING + ) + internal constructor( + resetTimeoutNanos: Double, + awaitClose: CompletableDeferred, + ) : this(resetTimeoutNanos.nanoseconds, awaitClose) - public constructor(resetTimeoutNanos: Double) : this(resetTimeoutNanos, CompletableDeferred()) + public constructor(resetTimeoutNanos: Double) : this(resetTimeoutNanos.nanoseconds, CompletableDeferred()) override fun hashCode(): Int = - resetTimeoutNanos.hashCode() + resetTimeout.hashCode() override fun equals(other: Any?): Boolean = - if (other is HalfOpen) resetTimeoutNanos == other.resetTimeoutNanos + if (other is HalfOpen) resetTimeout == other.resetTimeout else false override fun toString(): String = - "HalfOpen(resetTimeoutNanos=$resetTimeoutNanos)" + "HalfOpen(resetTimeoutNanos=$resetTimeout)" } } @@ -535,7 +590,7 @@ private constructor( * the `resetTimeout` when in the `HalfOpen` state, in case * the attempt to `Close` fails. * - * @param maxResetTimeout is the maximum timeout the circuit breaker + * @param maxResetTimeoutNanos is the maximum timeout the circuit breaker * is allowed to use when applying the `exponentialBackoffFactor`. * * @param onRejected is a callback for signaling rejected tasks, so @@ -550,22 +605,37 @@ private constructor( * @param onOpen is a callback for signaling transitions to [CircuitBreaker.State.Open]. * */ + @Deprecated( + "Prefer the kotlin.time.Duration constructor instead", + ReplaceWith( + "of(maxFailures, resetTimeoutNanos.nanoseconds, exponentialBackoffFactor, maxResetTimeout, onRejected, onClosed, onHalfOpen, onOpen)", + "import kotlin.time.Duration.Companion.nanoseconds" + ) + ) public suspend fun of( maxFailures: Int, resetTimeoutNanos: Double, exponentialBackoffFactor: Double = 1.0, - maxResetTimeout: Double = Double.POSITIVE_INFINITY, + maxResetTimeoutNanos: Double = Double.POSITIVE_INFINITY, onRejected: suspend () -> Unit = { }, onClosed: suspend () -> Unit = { }, onHalfOpen: suspend () -> Unit = { }, - onOpen: suspend () -> Unit = { } + onOpen: suspend () -> Unit = { }, ): CircuitBreaker = CircuitBreaker( state = AtomicRef(Closed(0)), - maxFailures = requireNotNull(maxFailures.takeIf { it >= 0 }) { "maxFailures expected to be higher than 0" }, - resetTimeout = requireNotNull(resetTimeoutNanos.takeIf { it > 0 }) { "resetTimeoutNanos expected to be higher than 0" }, - exponentialBackoffFactor = requireNotNull(exponentialBackoffFactor.takeIf { it > 0 }) { "exponentialBackoffFactor expected to be higher than 0" }, - maxResetTimeout = requireNotNull(maxResetTimeout.takeIf { it > 0 }) { "maxResetTimeout expected to be higher than 0" }, + maxFailures = maxFailures + .takeIf { it >= 0 } + .let { requireNotNull(it) { "maxFailures expected to be greater than or equal to 0, but was $maxFailures" } }, + resetTimeoutNanos = resetTimeoutNanos + .takeIf { it > 0 } + .let { requireNotNull(it) { "resetTimeout expected to be greater than 0, but was $resetTimeoutNanos" } }, + exponentialBackoffFactor = exponentialBackoffFactor + .takeIf { it > 0 } + .let { requireNotNull(it) { "exponentialBackoffFactor expected to be greater than 0, but was $exponentialBackoffFactor" } }, + maxResetTimeoutNanos = maxResetTimeoutNanos + .takeIf { it > 0 } + .let { requireNotNull(it) { "maxResetTimeout expected to be greater than 0, but was $maxResetTimeoutNanos" } }, onRejected = onRejected, onClosed = onClosed, onHalfOpen = onHalfOpen, @@ -601,7 +671,6 @@ private constructor( * @param onOpen is a callback for signaling transitions to [CircuitBreaker.State.Open]. * */ - @ExperimentalTime public suspend fun of( maxFailures: Int, resetTimeout: Duration, @@ -610,17 +679,27 @@ private constructor( onRejected: suspend () -> Unit = suspend { }, onClosed: suspend () -> Unit = suspend { }, onHalfOpen: suspend () -> Unit = suspend { }, - onOpen: suspend () -> Unit = suspend { } + onOpen: suspend () -> Unit = suspend { }, ): CircuitBreaker = of( - maxFailures, - resetTimeout.toDouble(DurationUnit.NANOSECONDS), - exponentialBackoffFactor, - maxResetTimeout.toDouble(DurationUnit.NANOSECONDS), - onRejected, - onClosed, - onHalfOpen, - onOpen + maxFailures = maxFailures + .takeIf { it >= 0 } + .let { requireNotNull(it) { "maxFailures expected to be greater than or equal to 0, but was $maxFailures" } }, + resetTimeoutNanos = resetTimeout + .takeIf { it.isPositive() && it != Duration.ZERO } + .let { requireNotNull(it) { "resetTimeout expected to be greater than ${Duration.ZERO}, but was $resetTimeout" } } + .toDouble(DurationUnit.NANOSECONDS), + exponentialBackoffFactor = exponentialBackoffFactor + .takeIf { it > 0 } + .let { requireNotNull(it) { "exponentialBackoffFactor expected to be greater than 0, but was $exponentialBackoffFactor" } }, + maxResetTimeoutNanos = maxResetTimeout + .takeIf { it.isPositive() && it != Duration.ZERO } + .let { requireNotNull(it) { "maxResetTimeout expected to be greater than ${Duration.ZERO}, but was $maxResetTimeout" } } + .toDouble(DurationUnit.NANOSECONDS), + onRejected = onRejected, + onClosed = onClosed, + onHalfOpen = onHalfOpen, + onOpen = onOpen ) } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt index a3301b65ee1..399c6a76797 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt @@ -5,6 +5,8 @@ import arrow.core.continuations.update import arrow.core.identity import arrow.core.prependTo import kotlinx.coroutines.CancellationException +import arrow.fx.coroutines.ExitCase.Companion.ExitCase +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -441,6 +443,52 @@ public fun Resource.asFlow(): Flow = } } +/** + * Deconstruct [Resource] into an [A] and a `release` handler. + * The `release` action **must** always be called, if never called, then the resource [A] will leak. + * The `release` step is already made `NonCancellable` to guarantee correct invocation like `Resource` or `bracketCase`, + * and it will automatically rethrow, and compose, the exceptions as needed. + * + * ```kotlin + * import arrow.fx.coroutines.* + * import arrow.fx.coroutines.ExitCase.Companion.ExitCase + * + * val resource = + * resource({ "Acquire" }) { _, exitCase -> println("Release $exitCase") } + * + * suspend fun main(): Unit { + * val (acquired: String, release: suspend (ExitCase) -> Unit) = resource.allocated() + * try { + * /** Do something with A */ + * release(ExitCase.Completed) + * } catch(e: Throwable) { + * release(ExitCase(e)) + * } + * } + * ``` + * + * + * This is a **delicate** API. It is easy to accidentally create resource or memory leaks `allocated` is used. + * A `Resource` allocated by `allocated` is not subject to the guarantees that [Resource] makes, + * instead the caller is responsible for correctly invoking the `release` handler at the appropriate time. + * This API is useful for building inter-op APIs between [Resource] and non-suspending code, such as Java libraries. + */ +@DelicateCoroutinesApi +public suspend fun Resource.allocated(): Pair Unit> { + val effect = ResourceScopeImpl() + val allocated: A = invoke(effect) + val release: suspend (ExitCase) -> Unit = { e -> + val suppressed: Throwable? = effect.cancelAll(e) + val original: Throwable? = when(e) { + ExitCase.Completed -> null + is ExitCase.Cancelled -> e.exception + is ExitCase.Failure -> e.failure + } + Platform.composeErrors(original, suppressed)?.let { throw it } + } + return Pair(allocated, release) +} + @JvmInline private value class ResourceScopeImpl( private val finalizers: AtomicRef Unit>> = AtomicRef(emptyList()), diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt index 265b318e453..3561a4a1629 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CircuitBreakerTest.kt @@ -2,6 +2,7 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.test.stackSafeIteration +import io.kotest.assertions.asClue import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe @@ -10,9 +11,11 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.delay import kotlinx.coroutines.withContext +import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes -import kotlin.time.DurationUnit.NANOSECONDS +import kotlin.time.Duration.Companion.seconds +import kotlin.time.DurationUnit import kotlin.time.ExperimentalTime @ExperimentalTime @@ -79,7 +82,7 @@ class CircuitBreakerTest : ArrowFxSpec( when (val s = cb.state()) { is CircuitBreaker.State.Open -> { - s.resetTimeoutNanos shouldBe resetTimeout.toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout } else -> fail("Invalid state: Expect CircuitBreaker.State.Open but found $s") } @@ -106,7 +109,7 @@ class CircuitBreakerTest : ArrowFxSpec( when (val s = cb.state()) { is CircuitBreaker.State.Open -> { - s.resetTimeoutNanos shouldBe resetTimeout.toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout } else -> fail("Invalid state: Expect CircuitBreaker.State.Open but found $s") } @@ -121,7 +124,7 @@ class CircuitBreakerTest : ArrowFxSpec( when (val s = cb.state()) { is CircuitBreaker.State.Open -> { - s.resetTimeoutNanos shouldBe resetTimeout.toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout } else -> fail("Invalid state: Expect CircuitBreaker.State.Open but found $s") } @@ -143,7 +146,7 @@ class CircuitBreakerTest : ArrowFxSpec( when (val s = cb.state()) { is CircuitBreaker.State.HalfOpen -> { - s.resetTimeoutNanos shouldBe resetTimeout.toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout } else -> fail("Invalid state: Expect CircuitBreaker.State.HalfOpen but found $s") } @@ -186,7 +189,7 @@ class CircuitBreakerTest : ArrowFxSpec( when (val s = cb.state()) { is CircuitBreaker.State.Open -> { - s.resetTimeoutNanos shouldBe resetTimeout.toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout } else -> fail("Invalid state: Expect CircuitBreaker.State.Open but found $s") } @@ -201,7 +204,7 @@ class CircuitBreakerTest : ArrowFxSpec( when (val s = cb.state()) { is CircuitBreaker.State.Open -> { - s.resetTimeoutNanos shouldBe resetTimeout.toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout } else -> fail("Invalid state: Expect CircuitBreaker.State.Open but found $s") } @@ -226,7 +229,7 @@ class CircuitBreakerTest : ArrowFxSpec( when (val s = cb.state()) { is CircuitBreaker.State.HalfOpen -> { - s.resetTimeoutNanos shouldBe resetTimeout.toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout } else -> fail("Invalid state: Expect CircuitBreaker.State.HalfOpen but found $s") } @@ -243,7 +246,7 @@ class CircuitBreakerTest : ArrowFxSpec( // resetTimeout should've applied when (val s = cb.state()) { is CircuitBreaker.State.Open -> { - s.resetTimeoutNanos shouldBe (resetTimeout * exponentialBackoffFactor).toDouble(NANOSECONDS) + s.resetTimeout shouldBe resetTimeout * exponentialBackoffFactor } else -> fail("Invalid state: Expect CircuitBreaker.State.Open but found $s") } @@ -267,9 +270,52 @@ class CircuitBreakerTest : ArrowFxSpec( stackSafeIteration(), 0 ) shouldBe stackSafeIteration() } + + listOf( + ConstructorValues(maxFailures = -1), + ConstructorValues(resetTimeout = Duration.ZERO), + ConstructorValues(resetTimeout = (-1).seconds), + ConstructorValues(exponentialBackoffFactor = 0.0), + ConstructorValues(exponentialBackoffFactor = -1.0), + ConstructorValues(maxResetTimeout = Duration.ZERO), + ConstructorValues(maxResetTimeout = (-1).seconds), + ).forEach { value -> + "should require valid constructor values" { + value.asClue { (maxFailures, resetTimeout, exponentialBackoffFactor, maxResetTimeout) -> + shouldThrow { + CircuitBreaker.of(maxFailures, resetTimeout, exponentialBackoffFactor, maxResetTimeout) + } + + shouldThrow { + CircuitBreaker.of( + maxFailures, + resetTimeout.toDouble(DurationUnit.NANOSECONDS), + exponentialBackoffFactor, + maxResetTimeout.toDouble(DurationUnit.NANOSECONDS) + ) + } + + shouldThrow { + CircuitBreaker.of( + maxFailures, + resetTimeout, + exponentialBackoffFactor, + maxResetTimeout + ) + } + } + } + } } ) +private data class ConstructorValues( + val maxFailures: Int = 1, + val resetTimeout: Duration = 1.seconds, + val exponentialBackoffFactor: Double = 1.0, + val maxResetTimeout: Duration = Duration.INFINITE, +) + /** * Recurs the effect [n] times, and collects the output along the way for easy asserting. */ diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt similarity index 78% rename from arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt rename to arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt index 478809b523f..dd5dfb9d74b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScopeSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt @@ -3,27 +3,37 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.continuations.either import arrow.core.left +import arrow.fx.coroutines.ExitCase.Companion.ExitCase import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec +import io.kotest.inspectors.forAll import io.kotest.matchers.collections.shouldContainExactly +import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.matchers.types.shouldBeTypeOf import io.kotest.property.Arb +import io.kotest.property.Exhaustive import io.kotest.property.arbitrary.bool +import io.kotest.property.arbitrary.element import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list +import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.negativeInt +import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.positiveInt import io.kotest.property.checkAll import io.kotest.property.arbitrary.string +import io.kotest.property.exhaustive.collection +import io.kotest.property.exhaustive.of import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList +import kotlin.random.Random class ResourceTest : StringSpec({ @@ -131,8 +141,8 @@ class ResourceTest : StringSpec({ "parZip - success" { suspend fun ResourceScope.closeable(): CheckableAutoClose = - install({ CheckableAutoClose() } ) { a: CheckableAutoClose, _: ExitCase -> a.close() } - + install({ CheckableAutoClose() }) { a: CheckableAutoClose, _: ExitCase -> a.close() } + resourceScope { parZip({ (1..depth).map { closeable() } @@ -238,8 +248,9 @@ class ResourceTest : StringSpec({ resourceScope { parZip({ install({ - require(started.complete(Unit)) - i }, { ii: Int, ex: ExitCase -> + require(started.complete(Unit)) + i + }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) }, { @@ -269,8 +280,9 @@ class ResourceTest : StringSpec({ throw cancel }, { install({ - require(started.complete(Unit)) - i }, { ii: Int, ex: ExitCase -> + require(started.complete(Unit)) + i + }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) }) { _, _ -> } @@ -292,8 +304,9 @@ class ResourceTest : StringSpec({ resourceScope { parZip({ install({ - require(started.complete(Unit)) - i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) } + require(started.complete(Unit)) + i + }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) } ) }, { started.await() @@ -322,7 +335,8 @@ class ResourceTest : StringSpec({ }, { install({ require(started.complete(Unit)) - i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) } + i + }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) } ) }) { _, _ -> } fail("It should never reach here") @@ -345,7 +359,7 @@ class ResourceTest : StringSpec({ parZip({ install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) }, { - install({ }, { _: Unit, _: ExitCase -> throw cancel }) + install({ }, { _: Unit, _: ExitCase -> throw cancel }) }) { _, _ -> } } } @@ -364,7 +378,7 @@ class ResourceTest : StringSpec({ shouldThrow { resourceScope { parZip({ - install({ }, { _: Unit, _: ExitCase -> throw cancel }) + install({ }, { _: Unit, _: ExitCase -> throw cancel }) }, { install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) }) { _, _ -> } @@ -386,7 +400,7 @@ class ResourceTest : StringSpec({ parZip({ install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) }, { - install({ }, { _: Unit, _: ExitCase -> throw throwable }) + install({ }, { _: Unit, _: ExitCase -> throw throwable }) }) { _, _ -> } } } shouldBe throwable @@ -404,7 +418,7 @@ class ResourceTest : StringSpec({ shouldThrow { resourceScope { parZip({ - install({ }, { _: Unit, _: ExitCase -> throw throwable }) + install({ }, { _: Unit, _: ExitCase -> throw throwable }) }, { install({ i }, { ii: Int, ex: ExitCase -> require(released.complete(ii to ex)) }) }) { _, _ -> } @@ -425,9 +439,9 @@ class ResourceTest : StringSpec({ shouldThrow { resourceScope { parZip({ - install({ a } ) { aa: Int, ex: ExitCase -> require(releasedA.complete(aa to ex)) } + install({ a }) { aa: Int, ex: ExitCase -> require(releasedA.complete(aa to ex)) } }, { - install({ b } ) { bb: Int, ex: ExitCase -> require(releasedB.complete(bb to ex)) } + install({ b }) { bb: Int, ex: ExitCase -> require(releasedB.complete(bb to ex)) } }) { _, _ -> } throw throwable } @@ -451,9 +465,9 @@ class ResourceTest : StringSpec({ shouldThrow { resourceScope { parZip({ - install({ a } ) { aa: Int, ex: ExitCase -> require(releasedA.complete(aa to ex)) } + install({ a }) { aa: Int, ex: ExitCase -> require(releasedA.complete(aa to ex)) } }, { - install({ b } ) { bb: Int, ex: ExitCase -> require(releasedB.complete(bb to ex)) } + install({ b }) { bb: Int, ex: ExitCase -> require(releasedB.complete(bb to ex)) } }) { _, _ -> } throw CancellationException("") } @@ -505,4 +519,72 @@ class ResourceTest : StringSpec({ released.await().shouldBeTypeOf() } } + + "allocated" { + checkAll(Arb.int()) { seed -> + val released = CompletableDeferred() + val (allocate, release) = resource({ seed }) { _, exitCase -> released.complete(exitCase) } + .allocated() + + allocate shouldBe seed + release(ExitCase.Completed) + released.await() shouldBe ExitCase.Completed + } + } + + "allocated - suppressed exception" { + checkAll( + Arb.int(), + Arb.string().map(::RuntimeException), + Arb.string().map(::IllegalStateException) + ) { seed, original, suppressed -> + val released = CompletableDeferred() + val (allocate, release) = + resource({ seed }) { _, exitCase -> + released.complete(exitCase) + throw suppressed + }.allocated() + + val exception = shouldThrow { + try { + allocate shouldBe seed + throw original + } catch (e: Throwable) { + release(ExitCase(e)) + } + } + + exception shouldBe original + exception.suppressedExceptions.firstOrNull().shouldNotBeNull() shouldBe suppressed + released.await().shouldBeTypeOf() + } + } + + "allocated - cancellation exception" { + checkAll( + Arb.int(), + Arb.string().map { CancellationException(it, null) }, + Arb.string().map(::IllegalStateException) + ) { seed, cancellation, suppressed -> + val released = CompletableDeferred() + val (allocate, release) = + resource({ seed }) { _, exitCase -> + released.complete(exitCase) + throw suppressed + }.allocated() + + val exception = shouldThrow { + try { + allocate shouldBe seed + throw cancellation + } catch (e: Throwable) { + release(ExitCase(e)) + } + } + + exception shouldBe cancellation + exception.suppressedExceptions.firstOrNull().shouldNotBeNull() shouldBe suppressed + released.await().shouldBeTypeOf() + } + } }) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt new file mode 100644 index 00000000000..c2642bb90dd --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt @@ -0,0 +1,18 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource09 + +import arrow.fx.coroutines.* +import arrow.fx.coroutines.ExitCase.Companion.ExitCase + +val resource = + resource({ "Acquire" }) { _, exitCase -> println("Release $exitCase") } + +suspend fun main(): Unit { + val (acquired: String, release: suspend (ExitCase) -> Unit) = resource.allocated() + try { + /** Do something with A */ + release(ExitCase.Completed) + } catch(e: Throwable) { + release(ExitCase(e)) + } +} From f4054c70ee10963fc1ed4905f4baa235f4944dec Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Thu, 17 Nov 2022 10:26:05 +0100 Subject: [PATCH 007/114] Add Atomic module, and StateShift (#2817) * Two small deprecations * Add Atomic module, and StateShift. Implement ior through StateShift * Fix build * Fix atomic knit * Fix knit attempt #2 * Update API files * Remove references to shift --- .../core/arrow-atomic/api/arrow-atomic.api | 20 + arrow-libs/core/arrow-atomic/build.gradle.kts | 47 +++ .../core/arrow-atomic/gradle.properties | 4 + arrow-libs/core/arrow-atomic/knit.properties | 5 + .../commonMain/kotlin/arrow/atomic/Atomic.kt | 74 ++++ .../src/jsMain/kotlin/arrow/atomic/Atomic.kt | 38 ++ .../src/jvmMain/kotlin/arrow/atomic/Atomic.kt | 26 ++ .../kotlin/examples/example-atomic-01.kt | 10 +- .../nativeMain/kotlin/arrow/atomic/Atomic.kt | 35 ++ arrow-libs/core/arrow-core/api/arrow-core.api | 59 ++- arrow-libs/core/arrow-core/build.gradle.kts | 1 + .../arrow/core/continuations/AtomicRef.kt | 52 --- .../arrow/core/continuations/Builders.kt | 39 +- .../kotlin/arrow/core/continuations/Effect.kt | 2 +- .../arrow/core/continuations/ErrorHandlers.kt | 10 +- .../kotlin/arrow/core/continuations/Fold.kt | 4 +- .../arrow/core/continuations/Mappers.kt | 12 +- .../kotlin/arrow/core/continuations/Raise.kt | 10 +- .../arrow/core/continuations/StateRaise.kt | 39 ++ .../kotlin/arrow/core/memoization.kt | 8 +- .../arrow/core/continuations/AtomicRef.kt | 30 -- .../arrow/core/continuations/AtomicRef.kt | 7 - .../arrow/core/continuations/AtomicRef.kt | 30 -- .../arrow/fx/coroutines/predef-test-jvm.kt | 6 +- .../api/arrow-fx-coroutines.api | 30 +- .../kotlin/arrow/fx/coroutines/Atomic.kt | 367 ------------------ .../arrow/fx/coroutines/CircuitBreaker.kt | 24 +- .../kotlin/arrow/fx/coroutines/Resource.kt | 8 +- .../kotlin/arrow/fx/coroutines/AtomicTest.kt | 127 ------ .../fx/coroutines/ParTraverseEitherTest.kt | 4 +- .../fx/coroutines/ParTraverseResultTest.kt | 4 +- .../arrow/fx/coroutines/ParTraverseTest.kt | 8 +- .../fx/coroutines/ParTraverseValidatedTest.kt | 4 +- .../arrow/fx/coroutines/ScheduleTest.kt | 4 +- .../fx/coroutines/parMapN/ParMap2Test.kt | 7 +- .../fx/coroutines/parMapN/ParMap3Test.kt | 7 +- .../fx/coroutines/parMapN/ParMap4Test.kt | 7 +- .../fx/coroutines/parMapN/ParMap5Test.kt | 7 +- .../fx/coroutines/parMapN/ParMap6Test.kt | 7 +- .../fx/coroutines/parMapN/ParMap7Test.kt | 7 +- .../fx/coroutines/parMapN/ParMap8Test.kt | 7 +- .../kotlin/examples/example-atomic-02.kt | 24 -- .../kotlin/examples/example-atomic-03.kt | 28 -- .../kotlin/examples/example-atomic-04.kt | 12 - .../commonMain/kotlin/arrow/fx/stm/TVar.kt | 16 +- .../kotlin/arrow/fx/stm/internal/Impl.kt | 6 +- settings.gradle.kts | 3 + 47 files changed, 465 insertions(+), 821 deletions(-) create mode 100644 arrow-libs/core/arrow-atomic/api/arrow-atomic.api create mode 100644 arrow-libs/core/arrow-atomic/build.gradle.kts create mode 100644 arrow-libs/core/arrow-atomic/gradle.properties create mode 100644 arrow-libs/core/arrow-atomic/knit.properties create mode 100644 arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt create mode 100644 arrow-libs/core/arrow-atomic/src/jsMain/kotlin/arrow/atomic/Atomic.kt create mode 100644 arrow-libs/core/arrow-atomic/src/jvmMain/kotlin/arrow/atomic/Atomic.kt rename arrow-libs/{fx/arrow-fx-coroutines => core/arrow-atomic}/src/jvmTest/kotlin/examples/example-atomic-01.kt (54%) create mode 100644 arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/AtomicRef.kt create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/StateRaise.kt delete mode 100644 arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/continuations/AtomicRef.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/continuations/AtomicRef.kt delete mode 100644 arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/continuations/AtomicRef.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Atomic.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/AtomicTest.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-02.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-03.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-04.kt diff --git a/arrow-libs/core/arrow-atomic/api/arrow-atomic.api b/arrow-libs/core/arrow-atomic/api/arrow-atomic.api new file mode 100644 index 00000000000..994ac619337 --- /dev/null +++ b/arrow-libs/core/arrow-atomic/api/arrow-atomic.api @@ -0,0 +1,20 @@ +public abstract interface class arrow/atomic/Atomic { + public abstract fun compareAndSet (Ljava/lang/Object;Ljava/lang/Object;)Z + public abstract fun getAndSet (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun getValue ()Ljava/lang/Object; + public abstract fun setAndGet (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun setValue (Ljava/lang/Object;)V +} + +public final class arrow/atomic/AtomicActual { + public static final fun Atomic (Ljava/lang/Object;)Larrow/atomic/Atomic; +} + +public final class arrow/atomic/AtomicKt { + public static final fun getAndUpdate (Larrow/atomic/Atomic;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun loop (Larrow/atomic/Atomic;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; + public static final fun tryUpdate (Larrow/atomic/Atomic;Lkotlin/jvm/functions/Function1;)Z + public static final fun update (Larrow/atomic/Atomic;Lkotlin/jvm/functions/Function1;)V + public static final fun updateAndGet (Larrow/atomic/Atomic;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +} + diff --git a/arrow-libs/core/arrow-atomic/build.gradle.kts b/arrow-libs/core/arrow-atomic/build.gradle.kts new file mode 100644 index 00000000000..5ef68dd39a6 --- /dev/null +++ b/arrow-libs/core/arrow-atomic/build.gradle.kts @@ -0,0 +1,47 @@ +plugins { + id(libs.plugins.kotlin.multiplatform.get().pluginId) + alias(libs.plugins.arrowGradleConfig.kotlin) + alias(libs.plugins.arrowGradleConfig.publish) +} + +apply(plugin = "io.kotest.multiplatform") +apply(from = property("TEST_COVERAGE")) +apply(from = property("ANIMALSNIFFER_MPP")) + +val enableCompatibilityMetadataVariant = + providers.gradleProperty("kotlin.mpp.enableCompatibilityMetadataVariant") + .forUseAtConfigurationTime().orNull?.toBoolean() == true + +if (enableCompatibilityMetadataVariant) { + tasks.withType().configureEach { + exclude("**/*") + } +} + +kotlin { + sourceSets { + commonMain { + dependencies { + api(libs.kotlin.stdlibCommon) + } + } + + jvmMain { + dependencies { + implementation(libs.kotlin.stdlibJDK8) + } + } + + jvmTest { + dependencies { + implementation(projects.arrowFxCoroutines) + } + } + + jsMain { + dependencies { + implementation(libs.kotlin.stdlibJS) + } + } + } +} diff --git a/arrow-libs/core/arrow-atomic/gradle.properties b/arrow-libs/core/arrow-atomic/gradle.properties new file mode 100644 index 00000000000..e9b3987e4af --- /dev/null +++ b/arrow-libs/core/arrow-atomic/gradle.properties @@ -0,0 +1,4 @@ +# Maven publishing configuration +pom.name=Arrow Atomic +# Build configuration +kapt.incremental.apt=false diff --git a/arrow-libs/core/arrow-atomic/knit.properties b/arrow-libs/core/arrow-atomic/knit.properties new file mode 100644 index 00000000000..0927cad52c1 --- /dev/null +++ b/arrow-libs/core/arrow-atomic/knit.properties @@ -0,0 +1,5 @@ +knit.package=arrow.atomic.examples +knit.dir=src/jvmTest/kotlin/examples/ + +test.package=arrow.atomic.examples.test +test.dir=src/jvmTest/kotlin/examples/autogenerated/ diff --git a/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt new file mode 100644 index 00000000000..b4824ff0ce4 --- /dev/null +++ b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt @@ -0,0 +1,74 @@ +package arrow.atomic + +public expect fun Atomic(initialValue: A): Atomic + +/** + * [Atomic] value of [A]. + * + * ```kotlin + * import arrow.atomic.Atomic + * import arrow.atomic.update + * import arrow.fx.coroutines.parTraverse + * suspend fun main() { + * val count = Atomic(0) + * (0 until 20_000).parTraverse { + * count.update(Int::inc) + * } + * println(count.value) + * } + * ``` + * + * + * [Atomic] also offers some other interesting operators such as [loop], [update], [tryUpdate], etc. + */ +public interface Atomic { + public var value: A + public fun getAndSet(value: A): A + public fun setAndGet(value: A): A + public fun compareAndSet(expected: A, new: A): Boolean +} + +/** + * Infinite loop that reads this atomic variable and performs the specified [action] on its value. + */ +public inline fun Atomic.loop(action: (V) -> Unit): Nothing { + while (true) { + action(value) + } +} + +public fun Atomic.tryUpdate(function: (V) -> V): Boolean { + val cur = value + val upd = function(cur) + return compareAndSet(cur, upd) +} + +public inline fun Atomic.update(function: (V) -> V) { + while (true) { + val cur = value + val upd = function(cur) + if (compareAndSet(cur, upd)) return + } +} + +/** + * Updates variable atomically using the specified [function] of its value and returns its old value. + */ +public inline fun Atomic.getAndUpdate(function: (V) -> V): V { + while (true) { + val cur = value + val upd = function(cur) + if (compareAndSet(cur, upd)) return cur + } +} + +/** + * Updates variable atomically using the specified [function] of its value and returns its new value. + */ +public inline fun Atomic.updateAndGet(function: (V) -> V): V { + while (true) { + val cur = value + val upd = function(cur) + if (compareAndSet(cur, upd)) return upd + } +} diff --git a/arrow-libs/core/arrow-atomic/src/jsMain/kotlin/arrow/atomic/Atomic.kt b/arrow-libs/core/arrow-atomic/src/jsMain/kotlin/arrow/atomic/Atomic.kt new file mode 100644 index 00000000000..b39be577690 --- /dev/null +++ b/arrow-libs/core/arrow-atomic/src/jsMain/kotlin/arrow/atomic/Atomic.kt @@ -0,0 +1,38 @@ +package arrow.atomic + +public actual fun Atomic(initialValue: A): Atomic = + AtomicRef(initialValue) + +private class AtomicRef(private var internalValue: V) : Atomic { + + /** + * Compare current value with expected and set to new if they're the same. Note, 'compare' is checking + * the actual object id, not 'equals'. + */ + override fun compareAndSet(expected: V, new: V): Boolean { + return if (expected === internalValue) { + internalValue = new + true + } else { + false + } + } + + override fun getAndSet(value: V): V { + val oldValue = internalValue + internalValue = value + return oldValue + } + + override fun setAndGet(value: V): V { + this.internalValue = value + return value + } + + + override var value: V + get() = internalValue + set(value) { + internalValue = value + } +} diff --git a/arrow-libs/core/arrow-atomic/src/jvmMain/kotlin/arrow/atomic/Atomic.kt b/arrow-libs/core/arrow-atomic/src/jvmMain/kotlin/arrow/atomic/Atomic.kt new file mode 100644 index 00000000000..73b9b6a6118 --- /dev/null +++ b/arrow-libs/core/arrow-atomic/src/jvmMain/kotlin/arrow/atomic/Atomic.kt @@ -0,0 +1,26 @@ +@file:JvmName("AtomicActual") + +package arrow.atomic + +import java.util.concurrent.atomic.AtomicReference + +public actual fun Atomic(initialValue: A): Atomic = + AtomicRef(AtomicReference(initialValue)) + +private class AtomicRef constructor(private val atom: AtomicReference) : Atomic { + + override var value: A + get() = atom.get() + set(value) { + atom.set(value) + } + + override fun compareAndSet(expected: A, new: A): Boolean = atom.compareAndSet(expected, new) + + override fun getAndSet(value: A): A = atom.getAndSet(value) + + override fun setAndGet(value: A): A { + atom.set(value) + return value + } +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-01.kt b/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt similarity index 54% rename from arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-01.kt rename to arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt index b5daa8841cf..418d6c41d7a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-01.kt +++ b/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt @@ -1,13 +1,13 @@ // This file was automatically generated from Atomic.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleAtomic01 - -import arrow.fx.coroutines.* +package arrow.atomic.examples.exampleAtomic01 +import arrow.atomic.Atomic +import arrow.atomic.update +import arrow.fx.coroutines.parTraverse suspend fun main() { val count = Atomic(0) - (0 until 20_000).parTraverse { count.update(Int::inc) } - println(count.get()) + println(count.value) } diff --git a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt new file mode 100644 index 00000000000..1714904e917 --- /dev/null +++ b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt @@ -0,0 +1,35 @@ +package arrow.atomic + +import kotlin.native.concurrent.AtomicReference +import kotlin.native.concurrent.freeze +import kotlin.native.concurrent.isFrozen + +public actual fun Atomic(initialValue: A): Atomic = + AtomicRef(AtomicReference(initialValue.freeze())) + +private class AtomicRef(private val atom: AtomicReference): Atomic { + + override fun getAndSet(value: V): V { + if (atom.isFrozen) value.freeze() + while (true) { + val cur = atom.value + if (cur === value) return cur + if (atom.compareAndSwap(cur, value) === cur) return cur + } + } + + override fun compareAndSet(expected: V, new: V): Boolean = + atom.compareAndSet(expected, new.freeze()) + + override var value: V + get() = atom.value + set(value) { + atom.value = value.freeze() + } + + override fun setAndGet(value: V): V { + this.value = value + return value + } +} + diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 04c5171a396..8c684b8f59a 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -2578,13 +2578,6 @@ public final class arrow/core/computations/result { public final fun invoke-IoAF18A (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } -public final class arrow/core/continuations/AtomicRefKt { - public static final fun getAndUpdate (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun loop (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; - public static final fun update (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)V - public static final fun updateAndGet (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - public final class arrow/core/continuations/DefaultRaise : arrow/core/continuations/Raise { public fun ()V public fun bind (Larrow/core/Either;)Ljava/lang/Object; @@ -2603,6 +2596,29 @@ public final class arrow/core/continuations/DefaultRaise : arrow/core/continuati public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } +public final class arrow/core/continuations/DefaultStateRaise : arrow/atomic/Atomic, arrow/core/continuations/Raise, arrow/core/continuations/StateRaise { + public fun (Larrow/atomic/Atomic;Larrow/core/continuations/Raise;)V + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Larrow/core/Validated;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun compareAndSet (Ljava/lang/Object;Ljava/lang/Object;)Z + public fun getAndSet (Ljava/lang/Object;)Ljava/lang/Object; + public fun getValue ()Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun setAndGet (Ljava/lang/Object;)Ljava/lang/Object; + public fun setValue (Ljava/lang/Object;)V +} + public final class arrow/core/continuations/Effect { public static final fun _fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun _foldOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -2648,7 +2664,7 @@ public final class arrow/core/continuations/EffectKt { } public final class arrow/core/continuations/IorRaise : arrow/core/continuations/Raise, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/Raise;)V + public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/StateRaise;)V public fun bind (Larrow/core/Either;)Ljava/lang/Object; public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; @@ -2659,8 +2675,7 @@ public final class arrow/core/continuations/IorRaise : arrow/core/continuations/ public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun getLeftState ()Ljava/util/concurrent/atomic/AtomicReference; - public final fun invoke (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; + public final fun getEffect ()Larrow/core/continuations/StateRaise; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; @@ -2669,7 +2684,6 @@ public final class arrow/core/continuations/IorRaise : arrow/core/continuations/ public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V } public final class arrow/core/continuations/NullableRaise : arrow/core/continuations/Raise { @@ -2847,6 +2861,29 @@ public final class arrow/core/continuations/ResultRaise : arrow/core/continuatio public final synthetic fun unbox-impl ()Larrow/core/continuations/Raise; } +public abstract interface class arrow/core/continuations/StateRaise : arrow/atomic/Atomic, arrow/core/continuations/Raise { +} + +public final class arrow/core/continuations/StateRaise$DefaultImpls { + public static fun bind (Larrow/core/continuations/StateRaise;Larrow/core/Either;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/StateRaise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/StateRaise;Larrow/core/Validated;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/StateRaise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun bind (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun catch (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun catch (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun invoke (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun invoke (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun recover (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class arrow/core/continuations/StateRaiseKt { + public static final fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; +} + public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Semigroup { public static final field Companion Larrow/typeclasses/Monoid$Companion; public static fun Boolean ()Larrow/typeclasses/Monoid; diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index 5c3541f2696..c5a58b395cc 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -25,6 +25,7 @@ kotlin { commonMain { dependencies { api(projects.arrowContinuations) + api(projects.arrowAtomic) api(projects.arrowAnnotations) api(libs.kotlin.stdlibCommon) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/AtomicRef.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/AtomicRef.kt deleted file mode 100644 index fb7e6d61e6c..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/AtomicRef.kt +++ /dev/null @@ -1,52 +0,0 @@ -package arrow.core.continuations - -public expect class AtomicRef(initialValue: V) { - public fun get(): V - public fun set(value: V) - public fun getAndSet(value: V): V - - /** - * Compare current value with expected and set to new if they're the same. Note, 'compare' is checking - * the actual object id, not 'equals'. - */ - public fun compareAndSet(expected: V, new: V): Boolean -} - -/** - * Infinite loop that reads this atomic variable and performs the specified [action] on its value. - */ -public inline fun AtomicRef.loop(action: (V) -> Unit): Nothing { - while (true) { - action(get()) - } -} - -public inline fun AtomicRef.update(function: (V) -> V) { - while (true) { - val cur = get() - val upd = function(cur) - if (compareAndSet(cur, upd)) return - } -} - -/** - * Updates variable atomically using the specified [function] of its value and returns its old value. - */ -public inline fun AtomicRef.getAndUpdate(function: (V) -> V): V { - while (true) { - val cur = get() - val upd = function(cur) - if (compareAndSet(cur, upd)) return cur - } -} - -/** - * Updates variable atomically using the specified [function] of its value and returns its new value. - */ -public inline fun AtomicRef.updateAndGet(function: (V) -> V): V { - while (true) { - val cur = get() - val upd = function(cur) - if (compareAndSet(cur, upd)) return upd - } -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt index 46b8e8ea3b8..a242ac30fa0 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt @@ -4,13 +4,15 @@ package arrow.core.continuations +import arrow.atomic.updateAndGet import arrow.core.Either -import arrow.core.EmptyValue import arrow.core.Ior import arrow.core.None import arrow.core.Option import arrow.core.Some +import arrow.core.getOrElse import arrow.core.identity +import arrow.core.orElse import arrow.typeclasses.Semigroup import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @@ -32,7 +34,13 @@ public inline fun option(action: OptionRaise.() -> A): Option = fold({ action(OptionRaise(this)) }, ::identity, ::Some) public inline fun ior(semigroup: Semigroup, @BuilderInference action: IorRaise.() -> A): Ior = - fold({ IorRaise(semigroup, this).invoke(action) }, { Ior.Left(it) }, ::identity) + fold, E, A, Ior>( + None, + { action(IorRaise(semigroup, this)) }, + { _, e -> throw e }, + { state, e -> Ior.Left(state.getOrElse { e }) }, + { state, a -> state.fold({ Ior.Right(a) }, { Ior.Both(it, a) }) } + ) @JvmInline public value class NullableRaise(private val cont: Raise) : Raise { @@ -70,12 +78,12 @@ public value class OptionRaise(private val cont: Raise) : Raise { } } -public class IorRaise @PublishedApi internal constructor(semigroup: Semigroup, private val effect: Raise) : - Raise, Semigroup by semigroup { - - // TODO this is a mess... +public class IorRaise @PublishedApi internal constructor( + semigroup: Semigroup, @PublishedApi - internal var leftState: AtomicRef = AtomicRef(EmptyValue) + internal val effect: StateRaise, E>, +) : Raise, Semigroup by semigroup { + override fun raise(r: E): B = effect.raise(combine(r)) public fun Ior.bind(): B = @@ -87,18 +95,9 @@ public class IorRaise @PublishedApi internal constructor(semigroup: Semigroup rightValue } } - - @PublishedApi - internal inline operator fun invoke(action: IorRaise.() -> A): Ior { - val res = action(this) - val leftState = leftState.get() - return if (leftState === EmptyValue) Ior.Right(res) - else Ior.Both(EmptyValue.unbox(leftState), res) - } - - @Suppress("UNCHECKED_CAST") + private fun combine(other: E): E = - leftState.updateAndGet { state -> - if (state === EmptyValue) other else EmptyValue.unbox(state).combine(other) - } as E + effect.updateAndGet { state -> + state.map { e -> e.combine(other) }.orElse { Some(other) } + }.getOrElse { other } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt index dc083ce81ad..d9de40f4727 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt @@ -313,7 +313,7 @@ import kotlin.jvm.JvmMultifileClass * * Note: * Handling errors can also be done with `try/catch` but this is **not recommended**, it uses `CancellationException` which is used to cancel `Coroutine`s and is advised not to capture in Kotlin. - * The `CancellationException` from `Effect` is `ShiftCancellationException`, this a public type, thus can be distinguished from any other `CancellationException` if necessary. + * The `CancellationException` from `Effect` is `RaiseCancellationException`, this a public type, thus can be distinguished from any other `CancellationException` if necessary. * * ## Structured Concurrency * diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt index 3012d60950c..82d2e30a86b 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ErrorHandlers.kt @@ -10,9 +10,9 @@ import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName /** - * Catch the shifted value [E] of the `Effect`. + * Catch the raised value [E] of the `Effect`. * You can either return a value a new value of [A], - * or short-circuit the effect by shifting with a value of [E], + * or short-circuit the effect by raising with a value of [E], * or raise an exception into [suspend]. * * ```kotlin @@ -30,13 +30,13 @@ import kotlin.jvm.JvmName * ``` * */ -public infix fun Effect.recover(@BuilderInference resolve: suspend Raise.(shifted: E) -> A): Effect = +public infix fun Effect.recover(@BuilderInference resolve: suspend Raise.(raised: E) -> A): Effect = effect { recover(resolve) } /** * Catch any unexpected exceptions, and [resolve] them. * You can either return a value a new value of [A], - * or short-circuit the effect by shifting with a value of [E], + * or short-circuit the effect by raising with a value of [E], * or raise an exception into [suspend]. * * ```kotlin @@ -98,7 +98,7 @@ public fun Effect.catch(): Effect> = } } -public infix fun EagerEffect.recover(@BuilderInference resolve: Raise.(shifted: E) -> A): EagerEffect = +public infix fun EagerEffect.recover(@BuilderInference resolve: Raise.(raised: E) -> A): EagerEffect = eagerEffect { recover(resolve) } public infix fun EagerEffect.catch(@BuilderInference recover: Raise.(throwable: Throwable) -> A): EagerEffect = diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt index 495e14de5fb..bbae0759511 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt @@ -63,7 +63,7 @@ public inline fun fold( } } -/** Returns the shifted value, rethrows the CancellationException if not our scope */ +/** Returns the raised value, rethrows the CancellationException if not our scope */ @PublishedApi internal fun CancellationException.raisedOrRethrow(raise: DefaultRaise): R = if (this is RaiseCancellationException && this.raise === raise) _raised as R @@ -75,6 +75,6 @@ internal class DefaultRaise : Raise { override fun raise(r: Any?): B = throw RaiseCancellationException(r, this) } -/** CancellationException is required to cancel coroutines when shifting from within them. */ +/** CancellationException is required to cancel coroutines when raising from within them. */ private class RaiseCancellationException(val _raised: Any?, val raise: Raise) : CancellationException("Raised Continuation") diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt index 9df1bb9e3b6..19bd59d0fd9 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt @@ -24,7 +24,7 @@ public fun EagerEffect.toValidated(): Validated = fold({ Vali public suspend fun Effect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } public fun EagerEffect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } -/** Run the [Effect] by returning [A], or `null` if shifted with [E]. */ +/** Run the [Effect] by returning [A], or `null` if raised with [E]. */ public suspend fun Effect.orNull(): A? = fold({ _: E -> null }) { it } public fun EagerEffect.orNull(): A? = fold({ _: E -> null }) { it } @@ -32,14 +32,16 @@ public fun EagerEffect.orNull(): A? = fold({ _: E -> null }) { it } public suspend fun Effect.toOption(orElse: suspend (E) -> Option): Option = fold(orElse) { Some(it) } public fun EagerEffect.toOption(orElse: (E) -> Option): Option = fold(orElse) { Some(it) } -/** Run the [Effect] by returning [Option] of [A], or [None] if shifted with [None]. */ +/** Run the [Effect] by returning [Option] of [A], or [None] if raised with [None]. */ public suspend fun Effect.toOption(): Option = option { invoke() } public fun EagerEffect.toOption(): Option = option { invoke() } /** Run the [Effect] by returning [Result] of [A], [orElse] run the fallback lambda and returning its result of [Result] of [A]. */ -public suspend fun Effect.toResult(orElse: suspend (E) -> Result): Result = fold({ orElse(it) }, { Result.success(it) }) -public fun EagerEffect.toResult(orElse: (E) -> Result): Result = fold({ orElse(it) }, { Result.success(it) }) +public suspend fun Effect.toResult(orElse: suspend (E) -> Result): Result = + fold({ orElse(it) }, { Result.success(it) }) +public fun EagerEffect.toResult(orElse: (E) -> Result): Result = + fold({ orElse(it) }, { Result.success(it) }) -/** Run the [Effect] by returning [Result] of [A], or [Result.Failure] if shifted with [Throwable]. */ +/** Run the [Effect] by returning [Result] of [A], or [Result.Failure] if raised with [Throwable]. */ public suspend fun Effect.toResult(): Result = result { invoke() } public fun EagerEffect.toResult(): Result = result { invoke() } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt index 268951b24d3..d4f1736edfd 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt @@ -175,7 +175,7 @@ public interface Raise { * }.also(::println) * * either { - * effect { raise("failed") }.recover { str -> shift(-1) } + * effect { raise("failed") }.recover { str -> raise(-1) } * }.also(::println) * } * ``` @@ -245,12 +245,12 @@ public inline fun Raise.catch( ): A = catch(action) { t: Throwable -> if (t is T) catch(t) else throw t } @EffectDSL -public inline fun Raise.ensure(condition: Boolean, shift: () -> R): Unit = - if (condition) Unit else raise(shift()) +public inline fun Raise.ensure(condition: Boolean, raise: () -> R): Unit = + if (condition) Unit else raise(raise()) @OptIn(ExperimentalContracts::class) @EffectDSL -public inline fun Raise.ensureNotNull(value: B?, shift: () -> R): B { +public inline fun Raise.ensureNotNull(value: B?, raise: () -> R): B { contract { returns() implies (value != null) } - return value ?: raise(shift()) + return value ?: raise(raise()) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/StateRaise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/StateRaise.kt new file mode 100644 index 00000000000..20f4791cc7e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/StateRaise.kt @@ -0,0 +1,39 @@ +@file:OptIn(ExperimentalTypeInference::class) + +package arrow.core.continuations + +import arrow.atomic.Atomic +import kotlin.experimental.ExperimentalTypeInference + +/** + * Intersection of Atomic & Raise. + * Will be replaced by `context(Atomic, Raise)` later + */ +public interface StateRaise : Atomic, Raise + +public typealias StateEffect = suspend StateRaise.() -> A + +public typealias EagerStateEffect = StateRaise.() -> A + +public inline fun fold( + initial: State, + @BuilderInference program: StateRaise.() -> A, + error: (state: State, error: Throwable) -> B, + recover: (state: State, raised: R) -> B, + transform: (state: State, value: A) -> B, +): B { + val state = Atomic(initial) + return fold( + { program(DefaultStateRaise(state, this)) }, + { error(state.value, it) }, + { recover(state.value, it) }, + { transform(state.value, it) } + ) +} + +/** Default intersection boilerplate. PublishedApi to support _inline_ */ +@PublishedApi +internal class DefaultStateRaise( + state: Atomic, + raise: Raise, +) : StateRaise, Atomic by state, Raise by raise {} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt index 52d0e8d1101..89412b5eacb 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt @@ -2,8 +2,8 @@ package arrow.core -import arrow.core.continuations.AtomicRef -import arrow.core.continuations.loop +import arrow.atomic.Atomic +import arrow.atomic.loop import kotlin.jvm.JvmName /** @@ -113,9 +113,9 @@ private data class MemoizeKey5( } private class MemoizedHandler, out R>(val f: F) { - private val cache = AtomicRef(emptyMap()) + private val cache = Atomic(emptyMap()) operator fun invoke(k: K): R { - val cached = cache.get()[k] + val cached = cache.value[k] // No cached value found, compute one return if (cached == null) { val b = k(f) diff --git a/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/continuations/AtomicRef.kt b/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/continuations/AtomicRef.kt deleted file mode 100644 index d839476478d..00000000000 --- a/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/continuations/AtomicRef.kt +++ /dev/null @@ -1,30 +0,0 @@ -package arrow.core.continuations - -public actual class AtomicRef actual constructor(initialValue: V) { - private var internalValue: V = initialValue - - /** - * Compare current value with expected and set to new if they're the same. Note, 'compare' is checking - * the actual object id, not 'equals'. - */ - public actual fun compareAndSet(expected: V, new: V): Boolean { - return if (expected === internalValue) { - internalValue = new - true - } else { - false - } - } - - public actual fun getAndSet(value: V): V { - val oldValue = internalValue - internalValue = value - return oldValue - } - - public actual fun get(): V = internalValue - - public actual fun set(value: V) { - internalValue = value - } -} diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/continuations/AtomicRef.kt b/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/continuations/AtomicRef.kt deleted file mode 100644 index 564deb22311..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/continuations/AtomicRef.kt +++ /dev/null @@ -1,7 +0,0 @@ -@file:JvmName("AtomicReferenceActual") - -package arrow.core.continuations - -import java.util.concurrent.atomic.AtomicReference - -public actual typealias AtomicRef = AtomicReference diff --git a/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/continuations/AtomicRef.kt b/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/continuations/AtomicRef.kt deleted file mode 100644 index bc63616ad47..00000000000 --- a/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/continuations/AtomicRef.kt +++ /dev/null @@ -1,30 +0,0 @@ -package arrow.core.continuations - -import kotlin.native.concurrent.AtomicReference -import kotlin.native.concurrent.freeze -import kotlin.native.concurrent.isFrozen - -public actual class AtomicRef actual constructor(initialValue: V) { - private val atom = AtomicReference(initialValue.freeze()) - public actual fun get(): V = atom.value - - public actual fun set(value: V) { - atom.value = value.freeze() - } - - public actual fun getAndSet(value: V): V { - if (atom.isFrozen) value.freeze() - while (true) { - val cur = atom.value - if (cur === value) return cur - if (atom.compareAndSwap(cur, value) === cur) return cur - } - } - - /** - * Compare current value with expected and set to new if they're the same. Note, 'compare' is checking - * the actual object id, not 'equals'. - */ - public actual fun compareAndSet(expected: V, new: V): Boolean = - atom.compareAndSet(expected, new.freeze()) -} diff --git a/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmMain/kotlin/arrow/fx/coroutines/predef-test-jvm.kt b/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmMain/kotlin/arrow/fx/coroutines/predef-test-jvm.kt index b05351a74f4..76c3924dfef 100644 --- a/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmMain/kotlin/arrow/fx/coroutines/predef-test-jvm.kt +++ b/arrow-libs/fx/arrow-fx-coroutines-test/src/jvmMain/kotlin/arrow/fx/coroutines/predef-test-jvm.kt @@ -1,6 +1,6 @@ package arrow.fx.coroutines -import arrow.core.continuations.AtomicRef +import arrow.atomic.Atomic import arrow.core.test.concurrency.deprecateArrowTestModules import java.util.concurrent.ThreadFactory import kotlin.coroutines.CoroutineContext @@ -17,8 +17,8 @@ public val threadName: suspend () -> String = @Deprecated(deprecateArrowTestModules) public class NamedThreadFactory(private val mkName: (Int) -> String) : ThreadFactory { - private val count = AtomicRef(0) + private val count = Atomic(0) override fun newThread(r: Runnable): Thread = - Thread(r, mkName(count.get())) + Thread(r, mkName(count.value)) .apply { isDaemon = true } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index be169607705..ee299e3bc75 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -2,32 +2,6 @@ public final class arrow/fx/coroutines/AcquireStep { public static final field INSTANCE Larrow/fx/coroutines/AcquireStep; } -public abstract interface class arrow/fx/coroutines/Atomic { - public static final field Companion Larrow/fx/coroutines/Atomic$Companion; - public abstract fun access (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun get (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun getAndSet (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun getAndUpdate (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun lens (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Atomic; - public abstract fun modify (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun modifyGet (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun set (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun setAndGet (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun tryModify (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun tryUpdate (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun update (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun updateAndGet (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/fx/coroutines/Atomic$Companion { - public final fun invoke (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun unsafe (Ljava/lang/Object;)Larrow/fx/coroutines/Atomic; -} - -public final class arrow/fx/coroutines/Atomic$DefaultImpls { - public static fun lens (Larrow/fx/coroutines/Atomic;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Atomic; -} - public final class arrow/fx/coroutines/BracketKt { public static final fun bracket (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun bracketCase (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -44,7 +18,7 @@ public final class arrow/fx/coroutines/BuildersKt { public final class arrow/fx/coroutines/CircuitBreaker { public static final field Companion Larrow/fx/coroutines/CircuitBreaker$Companion; - public synthetic fun (Ljava/util/concurrent/atomic/AtomicReference;IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Larrow/atomic/Atomic;IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun awaitClose (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun doOnClosed (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/CircuitBreaker; public final fun doOnHalfOpen (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/CircuitBreaker; @@ -52,7 +26,7 @@ public final class arrow/fx/coroutines/CircuitBreaker { public final fun doOnRejectedTask (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/CircuitBreaker; public final fun protectEither (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun protectOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun state (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun state ()Larrow/fx/coroutines/CircuitBreaker$State; } public final class arrow/fx/coroutines/CircuitBreaker$Companion { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Atomic.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Atomic.kt deleted file mode 100644 index e8b16b27798..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Atomic.kt +++ /dev/null @@ -1,367 +0,0 @@ -package arrow.fx.coroutines - -import arrow.core.continuations.AtomicRef - -/** - * An [Atomic] with an initial value of [A]. - * - * [Atomic] wraps `atomic`, so that you can also use it on a top-level function or pass it around. - * In other languages this data type is also known as `Ref`, `IORef` or Concurrent safe Reference. - * So in case you don't need to pass around an atomic reference, or use it in top-level functions - * it's advised to use `atomic` from Atomic Fu directly. - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * suspend fun main() { - * val count = Atomic(0) - * - * (0 until 20_000).parTraverse { - * count.update(Int::inc) - * } - * println(count.get()) - * } - * ``` - * - * - * [Atomic] also offers some other interesting operators such as [modify], [tryUpdate], [access] & [lens]. - */ -public interface Atomic { - - /** - * Obtains the current value. - * Since [AtomicRef] is always guaranteed to have a value, the returned action completes immediately after being bound. - */ - public suspend fun get(): A - - /** - * Sets the current value to [a]. - * The returned action completes after the reference has been successfully set. - */ - public suspend fun set(a: A): Unit - - /** - * Replaces the current value with [a], returning the *old* value. - */ - public suspend fun getAndSet(a: A): A - - /** - * Replaces the current value with [a], returning the *new* value. - */ - public suspend fun setAndGet(a: A): A - - /** - * Updates the current value using the supplied function [f]. - * - * If another modification occurs between the time the current value is read and subsequently updated, - * the modification is retried using the new value. Hence, [f] may be invoked multiple times. - */ - public suspend fun update(f: (A) -> A): Unit - - /** - * Modifies the current value using the supplied update function and returns the *old* value. - * - * @see [update], [f] may be invoked multiple times. - */ - public suspend fun getAndUpdate(f: (A) -> A): A - - /** - * Modifies the current value using the supplied update function and returns the *new* value. - * - * @see [update], [f] may be invoked multiple times. - */ - public suspend fun updateAndGet(f: (A) -> A): A - - /** - * Modify allows to inspect the state [A] of the [AtomicRef], update it and extract a different state [B]. - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * typealias Id = Int - * data class Job(val description: String) - * - * val initialState = (0 until 10).map { i -> Pair(i, Job("Task #$i")) } - * - * suspend fun main(): Unit { - * val jobs = Atomic(initialState) - * - * val batch = jobs.modify { j -> - * val batch = j.take(5) - * Pair(j.drop(5), batch) - * } - * - * batch.forEach { (id, job) -> - * println("Going to work on $job with id $id\n") - * } - * - * println("Remaining: ${jobs.get()}") - * } - * ``` - * - */ - public suspend fun modify(f: (A) -> Pair): B - - /** - * ModifyGet allows to inspect state [A], update it and extract a different state [B]. - * In contrast to [modify], it returns a [Pair] of the updated state [A] and the extracted state [B]. - * - * @see [modify] for an example - */ - public suspend fun modifyGet(f: (A) -> Pair): Pair - - /** - * Attempts to modify the current value once, in contrast to [update] which calls [f] until it succeeds. - * - * @returns `false` if concurrent modification completes between the time the variable is read and the time it is set. - */ - public suspend fun tryUpdate(f: (A) -> A): Boolean - - /** - * Attempts to inspect the state, uptade it, and extract a different state. - * - * [tryModify] behaves as [tryUpdate] but allows the update function to return an output value of type [B]. - * - * @returns `null` if the update fails and [B] otherwise. - */ - public suspend fun tryModify(f: (A) -> Pair): B? - - /** - * Obtains a snapshot of the current value, and a setter for updating it. - * - * This is useful when you need to execute effects with the original result while still ensuring an atomic update. - * - * The setter will return `false` if another concurrent call invalidated the snapshot (modified the value). - * It will return `true` if setting the value was successful. - * - * Once it has returned `false` or been used once, a setter never succeeds again. - */ - public suspend fun access(): Pair Boolean> - - /** - * Creates an [AtomicRef] for [B] based on provided a [get] and [set] operation. - * - * This is useful when you have an [AtomicRef] of a `data class` - * and need to work with with certain properties individually, - * or want to hide parts of your domain from a dependency. - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * data class Preference(val isEnabled: Boolean) - * data class User(val name: String, val age: Int, val preference: Preference) - * data class ViewState(val user: User) - * - * suspend fun main(): Unit { - * //sampleStart - * val state: Atomic = Atomic(ViewState(User("Simon", 27, Preference(false)))) - * val isEnabled: Atomic = - * state.lens( - * { it.user.preference.isEnabled }, - * { state, isEnabled -> - * state.copy( - * user = - * state.user.copy( - * preference = - * state.user.preference.copy(isEnabled = isEnabled) - * ) - * ) - * } - * ) - * isEnabled.set(true) - * println(state.get()) - * } - * ``` - * - */ - public fun lens(get: (A) -> B, set: (A, B) -> A): arrow.fx.coroutines.Atomic = - LensAtomic(this, get, set) - - public companion object { - - /** - * Creates an [AtomicRef] with an initial value of [A]. - * - * Data type on top of [atomic] to use in parallel functions. - * - * ```kotlin - * import arrow.fx.coroutines.* - * - * suspend fun main() { - * val count = Atomic(0) - * (0 until 20_000).parTraverse { - * count.update(Int::inc) - * } - * println(count.get()) - * } - * ``` - * - */ - public suspend operator fun invoke(a: A): arrow.fx.coroutines.Atomic = unsafe(a) - public fun unsafe(a: A): arrow.fx.coroutines.Atomic = DefaultAtomic(a) - } -} - -private class DefaultAtomic(a: A) : arrow.fx.coroutines.Atomic { - - private val ar = AtomicRef(a) - - public override suspend fun get(): A = - ar.get() - - public override suspend fun set(a: A): Unit { - ar.set(a) - } - - public override suspend fun getAndSet(a: A): A = - ar.getAndSet(a) - - public override suspend fun setAndGet(a: A): A { - ar.set(a) - return a - } - - public override suspend fun getAndUpdate(f: (A) -> A): A { - while (true) { - val cur = get() - val upd = f(cur) - if (ar.compareAndSet(cur, upd)) return cur - } - } - - public override suspend fun updateAndGet(f: (A) -> A): A { - while (true) { - val cur = ar.get() - val upd = f(cur) - if (ar.compareAndSet(cur, upd)) return upd - } - } - - public override suspend fun access(): Pair Boolean> { - val snapshot = ar.get() - val hasBeenCalled = AtomicRef(false) - val setter: suspend (A) -> Boolean = { a: A -> - hasBeenCalled.compareAndSet(false, true) && ar.compareAndSet(snapshot, a) - } - - return Pair(snapshot, setter) - } - - public override suspend fun tryUpdate(f: (A) -> A): Boolean = - tryModify { a -> Pair(f(a), Unit) } != null - - public override suspend fun tryModify(f: (A) -> Pair): B? { - val a = ar.get() - val (u, b) = f(a) - return if (ar.compareAndSet(a, u)) b - else null - } - - public override suspend fun update(f: (A) -> A): Unit = - modify { a -> Pair(f(a), Unit) } - - public override suspend fun modify(f: (A) -> Pair): B { - tailrec fun go(): B { - val a = ar.get() - val (u, b) = f(a) - return if (!ar.compareAndSet(a, u)) go() else b - } - - return go() - } - - public override suspend fun modifyGet(f: (A) -> Pair): Pair { - tailrec fun go(): Pair { - val a = ar.get() - val res = f(a) - return if (!ar.compareAndSet(a, res.first)) go() else res - } - - return go() - } -} - -private class LensAtomic( - private val underlying: arrow.fx.coroutines.Atomic, - private val lensGet: (A) -> B, - private val lensSet: (A, B) -> A -) : arrow.fx.coroutines.Atomic { - - public override suspend fun setAndGet(a: B): B = - underlying.modify { old -> - Pair(lensModify(old) { a }, a) - } - - public override suspend fun getAndUpdate(f: (B) -> B): B = - underlying.modify { old -> - Pair(lensModify(old, f), lensGet(old)) - } - - public override suspend fun updateAndGet(f: (B) -> B): B = - underlying.modify { old -> - val new = lensModify(old, f) - Pair(new, lensGet(new)) - } - - public override suspend fun get(): B = - lensGet(underlying.get()) - - public override suspend fun set(a: B) { - underlying.update { old -> lensModify(old) { a } } - } - - public override suspend fun getAndSet(a: B): B = - underlying.modify { old -> - Pair(lensModify(old) { a }, lensGet(old)) - } - - public override suspend fun update(f: (B) -> B) = - underlying.update { old -> lensModify(old, f) } - - public override suspend fun modify(f: (B) -> Pair): C = - underlying.modify { old -> - val oldB = lensGet(old) - val (b, c) = f(oldB) - Pair(lensSet(old, b), c) - } - - public override suspend fun modifyGet(f: (B) -> Pair): Pair = - underlying.modifyGet { old -> - val oldB = lensGet(old) - val (b, c) = f(oldB) - Pair(lensSet(old, b), c) - }.let { (a, c) -> Pair(lensGet(a), c) } - - public override suspend fun tryUpdate(f: (B) -> B): Boolean = - tryModify { b -> Pair(f(b), Unit) } != null - - public override suspend fun tryModify(f: (B) -> Pair): C? = - underlying.tryModify { a -> - val oldB = lensGet(a) - val (b, result) = f(oldB) - Pair(lensSet(a, b), result) - } - - public override suspend fun access(): Pair Boolean> { - val snapshotA = underlying.get() - val snapshotB = lensGet(snapshotA) - - val setter: suspend (B) -> Boolean = { b: B -> - val hasBeenCalled = AtomicRef(false) - - suspend { - val called = hasBeenCalled.compareAndSet(false, true) - - underlying.tryModify { a -> - if (called && lensGet(a) == snapshotA) Pair(lensSet(a, b), true) - else Pair(a, false) - } ?: false - }.invoke() - } - - return Pair(snapshotB, setter) - } - - private fun lensModify(s: A, f: (B) -> B): A = - lensSet(s, f(lensGet(s))) -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt index 81c991cde98..cbefde26406 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt @@ -1,7 +1,7 @@ package arrow.fx.coroutines import arrow.core.Either -import arrow.core.continuations.AtomicRef +import arrow.atomic.Atomic import arrow.core.identity import arrow.fx.coroutines.CircuitBreaker.State.Closed import arrow.fx.coroutines.CircuitBreaker.State.HalfOpen @@ -128,7 +128,7 @@ import kotlin.time.DurationUnit */ public class CircuitBreaker private constructor( - private val state: AtomicRef, + private val state: Atomic, private val maxFailures: Int, private val resetTimeoutNanos: Double, private val exponentialBackoffFactor: Double, @@ -144,7 +144,7 @@ private constructor( /** Returns the current [CircuitBreaker.State], meant for debugging purposes. */ - public suspend fun state(): State = state.get() + public fun state(): State = state.value /** * Awaits for this `CircuitBreaker` to be [CircuitBreaker.State.Closed]. @@ -155,10 +155,10 @@ private constructor( * state again. */ public suspend fun awaitClose(): Unit = - when (val curr = state.get()) { + when (val curr = state.value) { is Closed -> Unit is Open -> curr.awaitClose.await() - is State.HalfOpen -> curr.awaitClose.await() + is HalfOpen -> curr.awaitClose.await() } /** @@ -179,7 +179,7 @@ private constructor( * If an exception in [fa] occurs it will be rethrown */ public tailrec suspend fun protectOrThrow(fa: suspend () -> A): A = - when (val curr = state.get()) { + when (val curr = state.value) { is Closed -> { val attempt = try { Either.Right(fa.invoke()) @@ -209,7 +209,7 @@ private constructor( ) } } - is State.HalfOpen -> { + is HalfOpen -> { // CircuitBreaker is in HalfOpen state, which means we still reject all // tasks, while waiting to see if our reset attempt succeeds or fails onRejected.invoke() @@ -221,7 +221,7 @@ private constructor( * triggering the `Open` state if necessary. */ private tailrec suspend fun markOrResetFailures(result: Either): A = - when (val curr = state.get()) { + when (val curr = state.value) { is Closed -> { when (result) { is Either.Right -> { @@ -284,13 +284,13 @@ private constructor( is ExitCase.Cancelled -> { // We need to return to Open state // otherwise we get stuck in Half-Open (see https://github.com/monix/monix/issues/1080 ) - state.set(Open(lastStartedAt, resetTimeout, awaitClose)) + state.value = Open(lastStartedAt, resetTimeout, awaitClose) onOpen.invoke() } ExitCase.Completed -> { // While in HalfOpen only a reset attempt is allowed to update // the state, so setting this directly is safe - state.set(Closed(0)) + state.value = Closed(0) awaitClose.complete(Unit) onClosed.invoke() } @@ -301,7 +301,7 @@ private constructor( if (maxResetTimeout.isFinite() && value > maxResetTimeout) maxResetTimeout else value val ts = timeInMillis() - state.set(Open(ts, nextTimeout, awaitClose)) + state.value = Open(ts, nextTimeout, awaitClose) onOpen.invoke() } } @@ -623,7 +623,7 @@ private constructor( onOpen: suspend () -> Unit = { }, ): CircuitBreaker = CircuitBreaker( - state = AtomicRef(Closed(0)), + state = Atomic(Closed(0)), maxFailures = maxFailures .takeIf { it >= 0 } .let { requireNotNull(it) { "maxFailures expected to be greater than or equal to 0, but was $maxFailures" } }, diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt index 399c6a76797..4b4dd18d038 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt @@ -1,7 +1,7 @@ package arrow.fx.coroutines -import arrow.core.continuations.AtomicRef -import arrow.core.continuations.update +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.identity import arrow.core.prependTo import kotlinx.coroutines.CancellationException @@ -491,7 +491,7 @@ public suspend fun Resource.allocated(): Pair Un @JvmInline private value class ResourceScopeImpl( - private val finalizers: AtomicRef Unit>> = AtomicRef(emptyList()), + private val finalizers: Atomic Unit>> = Atomic(emptyList()), ) : ResourceScope { override suspend fun Resource.bind(): A = invoke(this@ResourceScopeImpl) @@ -514,7 +514,7 @@ private value class ResourceScopeImpl( suspend fun cancelAll( exitCase: ExitCase, first: Throwable? = null, - ): Throwable? = finalizers.get().fold(first) { acc, finalizer -> + ): Throwable? = finalizers.value.fold(first) { acc, finalizer -> val other = kotlin.runCatching { finalizer(exitCase) }.exceptionOrNull() other?.let { acc?.apply { addSuppressed(other) } ?: other diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/AtomicTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/AtomicTest.kt deleted file mode 100644 index 19c36f48dd1..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/AtomicTest.kt +++ /dev/null @@ -1,127 +0,0 @@ -package arrow.fx.coroutines - -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import kotlin.coroutines.Continuation -import kotlin.coroutines.EmptyCoroutineContext -import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn - -class AtomicTest : ArrowFxSpec( - spec = { - - "set get - successful" { - checkAll(Arb.int(), Arb.int()) { x, y -> - val r = Atomic(x) - r.set(y) - r.get() shouldBe y - } - } - - "getAndSet - successful" { - checkAll(Arb.int(), Arb.int()) { x, y -> - val ref = Atomic(x) - ref.getAndSet(y) shouldBe x - ref.get() shouldBe y - } - } - - "access - successful" { - checkAll(Arb.int(), Arb.int()) { x, y -> - val ref = Atomic(x) - val (_, setter) = ref.access() - setter(y) shouldBe true - ref.get() shouldBe y - } - } - - "access - setter should fail if value is modified before setter is called" { - checkAll(Arb.int(), Arb.int()) { x, z -> - val ref = Atomic(x) - val (_, setter) = ref.access() - ref.update { it + 1 } - setter(z) shouldBe false - ref.get() shouldBe x + 1 - } - } - - "access - setter should fail if called twice" { - checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int()) { w, x, y, z -> - val ref = Atomic(w) - val (_, setter) = ref.access() - setter(x) shouldBe true - ref.set(y) - setter(z) shouldBe false - ref.get() shouldBe y - } - } - - "tryUpdate - modification occurs successfully" { - checkAll(Arb.int()) { x -> - val ref = Atomic(x) - ref.tryUpdate { it + 1 } - ref.get() shouldBe x + 1 - } - } - - "tryUpdate - should fail to update if modification has occurred" { - checkAll(Arb.int()) { x -> - val ref = Atomic(x) - ref.tryUpdate { - suspend { ref.update(Int::inc) } - .startCoroutineUninterceptedOrReturn(Continuation(EmptyCoroutineContext) { }) - it + 1 - } shouldBe false - } - } - - "consistent set update" { - checkAll(Arb.int(), Arb.int()) { x, y -> - val set = suspend { - val r = Atomic(x) - r.set(y) - r.get() - } - - val update = suspend { - val r = Atomic(x) - r.update { y } - r.get() - } - - set() shouldBe update() - } - } - - "access id" { - checkAll(Arb.int()) { x -> - val r = Atomic(x) - val (a, _) = r.access() - r.get() shouldBe a - } - } - - "consistent access tryUpdate" { - checkAll(Arb.int()) { x -> - val acccessMap = suspend { - val r = Atomic(x) - val (a, setter) = r.access() - setter(a + 1) - } - val tryUpdate = suspend { - val r = Atomic(x) - r.tryUpdate { it + 1 } - } - - acccessMap() shouldBe tryUpdate() - } - } - - "concurrent modifications" { - val finalValue = 50_000 - val r = Atomic(0) - (0 until finalValue).parTraverse { r.update { it + 1 } } - r.get() shouldBe finalValue - } - } -) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt index 7cdd933e762..f6c67ed496f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt @@ -1,5 +1,7 @@ package arrow.fx.coroutines +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.left import arrow.core.right @@ -18,7 +20,7 @@ class ParTraverseEitherTest : ArrowFxSpec( (0 until 100).parTraverseEither { ref.update { it + 1 }.right() } - ref.get() shouldBe 100 + ref.value shouldBe 100 } "parTraverseEither runs in parallel" { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt index 32c4a0aade7..6bab1da436c 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt @@ -1,5 +1,7 @@ package arrow.fx.coroutines +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.sequence import arrow.core.test.generators.result @@ -19,7 +21,7 @@ class ParTraverseResultTest : ArrowFxSpec( (0 until 100).parTraverseResult { Result.success(ref.update { it + 1 }) } - ref.get() shouldBe 100 + ref.value shouldBe 100 } "parTraverseResult runs in parallel" { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt index 2b8ea17480d..9cb6b47207e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseTest.kt @@ -1,5 +1,7 @@ package arrow.fx.coroutines +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import io.kotest.matchers.should import io.kotest.matchers.shouldBe @@ -20,7 +22,7 @@ class ParTraverseTest : ArrowFxSpec( (0 until 100).parTraverse { ref.update { it + 1 } } - ref.get() shouldBe 100 + ref.value shouldBe 100 } "parTraverse runs in parallel" { @@ -75,7 +77,7 @@ class ParTraverseTest : ArrowFxSpec( (0 until 100).parTraverseN(5) { ref.update { it + 1 } } - ref.get() shouldBe 100 + ref.value shouldBe 100 } "parTraverseN(3) runs in (3) parallel" { @@ -154,7 +156,7 @@ class ParTraverseTest : ArrowFxSpec( .map { suspend { ref.update { it + 1 } } } .parSequenceN(5) - ref.get() shouldBe 100 + ref.value shouldBe 100 } } ) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt index 26be83f0a61..133e1ffa30d 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt @@ -1,5 +1,7 @@ package arrow.fx.coroutines +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.Validated @@ -21,7 +23,7 @@ class ParTraverseValidatedTest : ArrowFxSpec( (0 until 100).parTraverseValidated(Semigroup.nonEmptyList()) { ref.update { it + 1 }.validNel() } - ref.get() shouldBe 100 + ref.value shouldBe 100 } "parTraverseValidated runs in parallel" { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt index 4ae2907d34c..6cf8689212d 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt @@ -1,5 +1,7 @@ package arrow.fx.coroutines +import arrow.atomic.Atomic +import arrow.atomic.updateAndGet import arrow.core.Either import arrow.core.Eval import io.kotest.assertions.fail @@ -255,7 +257,7 @@ class ScheduleTest : ArrowFxSpec( } l should leftException(exception) - count.get() shouldBe 20_001 + count.value shouldBe 20_001 } "retry succeeds if no exception is thrown" { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt index 9f8ef59c261..92b980fffa5 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap2Test.kt @@ -1,8 +1,9 @@ package arrow.fx.coroutines.parMapN +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.guaranteeCase @@ -40,14 +41,14 @@ class ParMap2Test : ArrowFxSpec( r.update { i -> "$i$a" } }, { - r.set("$b") + r.value = "$b" modifyGate.complete(0) } ) { _a, _b -> Pair(_a, _b) } - r.get() shouldBe "$b$a" + r.value shouldBe "$b$a" } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt index cd2fce7349a..5afbf9d040f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap3Test.kt @@ -1,8 +1,9 @@ package arrow.fx.coroutines.parMapN +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException @@ -40,14 +41,14 @@ class ParMap3Test : ArrowFxSpec( modifyGate2.complete(Unit) }, { - r.set("$c") + r.value ="$c" modifyGate1.complete(Unit) } ) { _a, _b, _c -> Triple(_a, _b, _c) } - r.get() shouldBe "$c$b$a" + r.value shouldBe "$c$b$a" } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt index b3cbc921b31..103b68d6ec8 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap4Test.kt @@ -1,9 +1,10 @@ package arrow.fx.coroutines.parMapN +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.Tuple4 import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException @@ -47,14 +48,14 @@ class ParMap4Test : ArrowFxSpec( modifyGate3.complete(Unit) }, { - r.set("$d") + r.value = "$d" modifyGate1.complete(Unit) } ) { _a, _b, _c, _d -> Tuple4(_a, _b, _c, _d) } - r.get() shouldBe "$d$c$b$a" + r.value shouldBe "$d$c$b$a" } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt index 6ceeb1a7519..cbcc393acde 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap5Test.kt @@ -1,9 +1,10 @@ package arrow.fx.coroutines.parMapN +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.Tuple5 import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException @@ -53,14 +54,14 @@ class ParMap5Test : ArrowFxSpec( modifyGate4.complete(Unit) }, { - r.set("$e") + r.value = "$e" modifyGate1.complete(Unit) } ) { _a, _b, _c, _d, _e -> Tuple5(_a, _b, _c, _d, _e) } - r.get() shouldBe "$e$d$c$b$a" + r.value shouldBe "$e$d$c$b$a" } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt index 78982a64066..2f474145a46 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap6Test.kt @@ -1,9 +1,10 @@ package arrow.fx.coroutines.parMapN +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.Tuple6 import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException @@ -59,14 +60,14 @@ class ParMap6Test : ArrowFxSpec( modifyGate5.complete(Unit) }, { - r.set("$f") + r.value = "$f" modifyGate1.complete(Unit) } ) { _a, _b, _c, _d, _e, _f -> Tuple6(_a, _b, _c, _d, _e, _f) } - r.get() shouldBe "$f$e$d$c$b$a" + r.value shouldBe "$f$e$d$c$b$a" } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt index 9d77f712eed..a14f36ea24a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap7Test.kt @@ -1,9 +1,10 @@ package arrow.fx.coroutines.parMapN +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.Tuple7 import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException @@ -65,14 +66,14 @@ class ParMap7Test : ArrowFxSpec( modifyGate6.complete(Unit) }, { - r.set("$g") + r.value = "$g" modifyGate1.complete(Unit) } ) { _a, _b, _c, _d, _e, _f, _g -> Tuple7(_a, _b, _c, _d, _e, _f, _g) } - r.get() shouldBe "$g$f$e$d$c$b$a" + r.value shouldBe "$g$f$e$d$c$b$a" } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt index 471acc0990c..6452c9c850c 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/parMapN/ParMap8Test.kt @@ -1,9 +1,10 @@ package arrow.fx.coroutines.parMapN +import arrow.atomic.Atomic +import arrow.atomic.update import arrow.core.Either import arrow.core.Tuple8 import arrow.fx.coroutines.ArrowFxSpec -import arrow.fx.coroutines.Atomic import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException @@ -71,14 +72,14 @@ class ParMap8Test : ArrowFxSpec( modifyGate7.complete(Unit) }, { - r.set("$h") + r.value = "$h" modifyGate1.complete(Unit) } ) { _a, _b, _c, _d, _e, _f, _g, _h -> Tuple8(_a, _b, _c, _d, _e, _f, _g, _h) } - r.get() shouldBe "$h$g$f$e$d$c$b$a" + r.value shouldBe "$h$g$f$e$d$c$b$a" } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-02.kt deleted file mode 100644 index 4c1c9f2cbde..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-02.kt +++ /dev/null @@ -1,24 +0,0 @@ -// This file was automatically generated from Atomic.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleAtomic02 - -import arrow.fx.coroutines.* - -typealias Id = Int -data class Job(val description: String) - -val initialState = (0 until 10).map { i -> Pair(i, Job("Task #$i")) } - -suspend fun main(): Unit { - val jobs = Atomic(initialState) - - val batch = jobs.modify { j -> - val batch = j.take(5) - Pair(j.drop(5), batch) - } - - batch.forEach { (id, job) -> - println("Going to work on $job with id $id\n") - } - - println("Remaining: ${jobs.get()}") -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-03.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-03.kt deleted file mode 100644 index 4431588c459..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-03.kt +++ /dev/null @@ -1,28 +0,0 @@ -// This file was automatically generated from Atomic.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleAtomic03 - -import arrow.fx.coroutines.* - -data class Preference(val isEnabled: Boolean) -data class User(val name: String, val age: Int, val preference: Preference) -data class ViewState(val user: User) - -suspend fun main(): Unit { - //sampleStart - val state: Atomic = Atomic(ViewState(User("Simon", 27, Preference(false)))) - val isEnabled: Atomic = - state.lens( - { it.user.preference.isEnabled }, - { state, isEnabled -> - state.copy( - user = - state.user.copy( - preference = - state.user.preference.copy(isEnabled = isEnabled) - ) - ) - } - ) - isEnabled.set(true) - println(state.get()) -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-04.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-04.kt deleted file mode 100644 index ea357dcf2df..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-atomic-04.kt +++ /dev/null @@ -1,12 +0,0 @@ -// This file was automatically generated from Atomic.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.exampleAtomic04 - -import arrow.fx.coroutines.* - -suspend fun main() { - val count = Atomic(0) - (0 until 20_000).parTraverse { - count.update(Int::inc) - } - println(count.get()) -} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt index 01224173376..ca32614ec5e 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt @@ -1,8 +1,8 @@ package arrow.fx.stm -import arrow.core.continuations.AtomicRef -import arrow.core.continuations.update -import arrow.core.continuations.updateAndGet +import arrow.atomic.Atomic +import arrow.atomic.update +import arrow.atomic.updateAndGet import arrow.fx.stm.internal.STMFrame import arrow.fx.stm.internal.STMTransaction import kotlin.coroutines.resume @@ -128,10 +128,10 @@ public class TVar internal constructor(a: A) { * This is used to implement locking. Reading threads have to loop until the value is released by a * transaction. */ - private val ref = AtomicRef(a as Any?) + private val ref = Atomic(a as Any?) internal val value - get() = ref.get() + get() = ref.value /** * Each TVar has a unique id which is used to get a total ordering of variables to ensure that locks @@ -147,7 +147,7 @@ public class TVar internal constructor(a: A) { * Changes are pushed to waiting transactions via [notify] */ // TODO Use a set here, and preferably something that uses sharing to avoid gc pressure from copying... - private val waiting = AtomicRef>>(emptyList()) + private val waiting = Atomic>>(emptyList()) override fun hashCode(): Int = id.hashCode() @@ -167,7 +167,7 @@ public class TVar internal constructor(a: A) { */ internal fun readI(): A { while (true) { - ref.get().let { + ref.value.let { if (it !is STMFrame) return@readI it as A } } @@ -251,4 +251,4 @@ public class TVar internal constructor(a: A) { } } -internal val globalC: AtomicRef = AtomicRef(0L) +internal val globalC: Atomic = Atomic(0L) diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt index 327d6a68173..544890c9c7d 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt @@ -1,6 +1,6 @@ package arrow.fx.stm.internal -import arrow.core.continuations.AtomicRef +import arrow.atomic.Atomic import arrow.fx.stm.STM import arrow.fx.stm.TVar import kotlinx.coroutines.suspendCancellableCoroutine @@ -163,7 +163,7 @@ public expect object RetryException : Throwable * Keeps the continuation that [TVar]'s use to resume this transaction. */ internal class STMTransaction(val f: STM.() -> A) { - private val cont = AtomicRef?>(null) + private val cont = Atomic?>(null) /** * Any one resumptions is enough, because we enqueue on all read variables this might be called multiple times. @@ -189,7 +189,7 @@ internal class STMTransaction(val f: STM.() -> A) { val registered = mutableListOf>() suspendCancellableCoroutine susp@{ k -> - cont.set(k) + cont.value = k frame.accessMap .forEach { (tv, entry) -> diff --git a/settings.gradle.kts b/settings.gradle.kts index 3836a82132c..51c02774a74 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -31,6 +31,9 @@ project(":arrow-annotations").projectDir = file("arrow-libs/core/arrow-annotatio include("arrow-core") project(":arrow-core").projectDir = file("arrow-libs/core/arrow-core") +include("arrow-atomic") +project(":arrow-atomic").projectDir = file("arrow-libs/core/arrow-atomic") + val enableCompatibilityMetadataVariant = providers.gradleProperty("kotlin.mpp.enableCompatibilityMetadataVariant") .forUseAtConfigurationTime().orNull?.toBoolean() == true From 47b06a609b5fa51bea2864e5dbc25bef0029f68d Mon Sep 17 00:00:00 2001 From: Sam Cooper <54266448+roomscape@users.noreply.github.com> Date: Thu, 17 Nov 2022 14:11:17 +0000 Subject: [PATCH 008/114] Change return type of raise to Nothing (#2839) * Change return type of raise to Nothing Implements #2805 * Update public api with ./gradlew apiDump * Suppress warnings for unreachable calls to fail in tests The test is verifying that no code will be executed after a call to raise, so it's actually testing the very behaviour that the compiler is warning us about. Co-authored-by: Alejandro Serrano --- arrow-libs/core/arrow-core/api/arrow-core.api | 26 +++++++++---------- .../arrow/core/continuations/Builders.kt | 10 +++---- .../kotlin/arrow/core/continuations/Effect.kt | 6 ++--- .../kotlin/arrow/core/continuations/Fold.kt | 2 +- .../kotlin/arrow/core/continuations/Raise.kt | 2 +- .../core/continuations/EagerEffectSpec.kt | 11 +++++--- .../arrow/core/continuations/EffectSpec.kt | 13 ++++++---- .../kotlin/examples/example-effect-05.kt | 2 +- .../kotlin/examples/example-effect-07.kt | 2 +- .../kotlin/examples/example-effect-09.kt | 2 +- 10 files changed, 41 insertions(+), 35 deletions(-) diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 74b2b6921da..222f4ec7e2b 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -2598,7 +2598,7 @@ public final class arrow/core/continuations/DefaultRaise : arrow/core/continuati public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2619,7 +2619,7 @@ public final class arrow/core/continuations/DefaultStateRaise : arrow/atomic/Ato public fun getValue ()Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2688,7 +2688,7 @@ public final class arrow/core/continuations/IorRaise : arrow/core/continuations/ public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2726,9 +2726,9 @@ public final class arrow/core/continuations/NullableRaise : arrow/core/continuat public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Object; - public fun raise (Ljava/lang/Void;)Ljava/lang/Object; - public static fun raise-impl (Larrow/core/continuations/Raise;Ljava/lang/Void;)Ljava/lang/Object; + public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; + public fun raise (Ljava/lang/Void;)Ljava/lang/Void; + public static fun raise-impl (Larrow/core/continuations/Raise;Ljava/lang/Void;)Ljava/lang/Void; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2771,9 +2771,9 @@ public final class arrow/core/continuations/OptionRaise : arrow/core/continuatio public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun raise (Larrow/core/None;)Ljava/lang/Object; - public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Object; - public static fun raise-impl (Larrow/core/continuations/Raise;Larrow/core/None;)Ljava/lang/Object; + public fun raise (Larrow/core/None;)Ljava/lang/Void; + public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; + public static fun raise-impl (Larrow/core/continuations/Raise;Larrow/core/None;)Ljava/lang/Void; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2796,7 +2796,7 @@ public abstract interface class arrow/core/continuations/Raise { public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun raise (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun raise (Ljava/lang/Object;)Ljava/lang/Void; public abstract fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2855,9 +2855,9 @@ public final class arrow/core/continuations/ResultRaise : arrow/core/continuatio public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun invoke-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Object; - public fun raise (Ljava/lang/Throwable;)Ljava/lang/Object; - public static fun raise-impl (Larrow/core/continuations/Raise;Ljava/lang/Throwable;)Ljava/lang/Object; + public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; + public fun raise (Ljava/lang/Throwable;)Ljava/lang/Void; + public static fun raise-impl (Larrow/core/continuations/Raise;Ljava/lang/Throwable;)Ljava/lang/Void; public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt index a242ac30fa0..99d730a44bb 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Builders.kt @@ -46,7 +46,7 @@ public inline fun ior(semigroup: Semigroup, @BuilderInference action: public value class NullableRaise(private val cont: Raise) : Raise { @EffectDSL public fun ensure(value: Boolean): Unit = ensure(value) { null } - override fun raise(r: Nothing?): B = cont.raise(r) + override fun raise(r: Nothing?): Nothing = cont.raise(r) public fun Option.bind(): B = bind { raise(null) } public fun B?.bind(): B { @@ -62,13 +62,13 @@ public value class NullableRaise(private val cont: Raise) : Raise) : Raise { - override fun raise(r: Throwable): B = cont.raise(r) + override fun raise(r: Throwable): Nothing = cont.raise(r) public fun Result.bind(): B = fold(::identity) { raise(it) } } @JvmInline public value class OptionRaise(private val cont: Raise) : Raise { - override fun raise(r: None): B = cont.raise(r) + override fun raise(r: None): Nothing = cont.raise(r) public fun Option.bind(): B = bind { raise(None) } public fun ensure(value: Boolean): Unit = ensure(value) { None } @@ -83,8 +83,8 @@ public class IorRaise @PublishedApi internal constructor( @PublishedApi internal val effect: StateRaise, E>, ) : Raise, Semigroup by semigroup { - - override fun raise(r: E): B = effect.raise(combine(r)) + + override fun raise(r: E): Nothing = effect.raise(combine(r)) public fun Ior.bind(): B = when (this) { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt index d9de40f4727..3130b5cd28c 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt @@ -355,7 +355,7 @@ import kotlin.jvm.JvmMultifileClass * val error = "Error" * val exit = CompletableDeferred() * effect { - * parZip({ awaitExitCase(exit) }, { raise(error) }) { a, b -> a + b } + * parZip({ awaitExitCase(exit) }, { raise(error) }) { a: Int, b: Int -> a + b } * }.fold({ it shouldBe error }, { fail("Int can never be the result") }) * exit.await().shouldBeTypeOf() * } @@ -425,7 +425,7 @@ import kotlin.jvm.JvmMultifileClass * val error = "Error" * val exit = CompletableDeferred() * effect { - * raceN({ awaitExitCase(exit) }) { raise(error) } + * raceN({ awaitExitCase(exit) }) { raise(error) } * .merge() // Flatten Either result from race into Int * }.fold({ msg -> msg shouldBe error }, { fail("Int can never be the result") }) * // It's possible not all parallel task got launched, and in those cases awaitCancellation never ran @@ -497,7 +497,7 @@ import kotlin.jvm.JvmMultifileClass * resourceScope { * effect { * val reader = bufferedReader("build.gradle.kts") - * raise(error) + * raise(error) * reader.lineSequence().count() * }.fold({ it shouldBe error }, { fail("Int can never be the result") }) * } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt index bbae0759511..40580116d5e 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt @@ -72,7 +72,7 @@ internal fun CancellationException.raisedOrRethrow(raise: DefaultRaise): R = /** Serves as both purposes of a scope-reference token, and a default implementation for Raise. */ @PublishedApi internal class DefaultRaise : Raise { - override fun raise(r: Any?): B = throw RaiseCancellationException(r, this) + override fun raise(r: Any?): Nothing = throw RaiseCancellationException(r, this) } /** CancellationException is required to cancel coroutines when raising from within them. */ diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt index d4f1736edfd..e72e8e5df3b 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt @@ -61,7 +61,7 @@ public annotation class EffectDSL public interface Raise { /** Raise a _logical failure_ of type [R] */ - public fun raise(r: R): A + public fun raise(r: R): Nothing /** * Invoke an [EagerEffect] inside `this` [Raise] context. diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt index 671306bb6ac..8286e614132 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EagerEffectSpec.kt @@ -36,7 +36,7 @@ class EagerEffectSpec : StringSpec({ val promise = CompletableDeferred() eagerEffect { try { - raise(s) + raise(s) } finally { require(promise.complete(i)) } @@ -141,31 +141,34 @@ class EagerEffectSpec : StringSpec({ } } + @Suppress("UNREACHABLE_CODE") "catch - error path and recover" { checkAll(Arb.int(), Arb.string()) { int, fallback -> eagerEffect { - raise(int) + raise(int) fail("It should never reach this point") }.recover { fallback } .runCont() shouldBe fallback } } + @Suppress("UNREACHABLE_CODE") "catch - error path and re-raise" { checkAll(Arb.int(), Arb.string()) { int, fallback -> eagerEffect { - raise(int) + raise(int) fail("It should never reach this point") }.recover { raise(fallback) } .runCont() shouldBe fallback } } + @Suppress("UNREACHABLE_CODE") "catch - error path and throw" { checkAll(Arb.int(), Arb.string()) { int, msg -> shouldThrow { eagerEffect { - raise(int) + raise(int) fail("It should never reach this point") }.recover { throw RuntimeException(msg) } .runCont() diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt index 569651f962e..eb4b91b8c5c 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt @@ -47,7 +47,7 @@ class EffectSpec : val promise = CompletableDeferred() effect { try { - raise(s().suspend()) + raise(s().suspend()) } finally { require(promise.complete(i())) } @@ -132,7 +132,7 @@ class EffectSpec : "short-circuit" { checkAll(Arb.string().suspend()) { msg -> effect { - raise(msg()) + raise(msg()) }.runCont() shouldBe msg() } } @@ -299,31 +299,34 @@ class EffectSpec : } } + @Suppress("UNREACHABLE_CODE") "catch - error path and recover" { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> effect { - raise(int()) + raise(int()) fail("It should never reach this point") }.recover { fallback() } .runCont() shouldBe fallback() } } + @Suppress("UNREACHABLE_CODE") "catch - error path and re-raise" { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> effect { - raise(int()) + raise(int()) fail("It should never reach this point") }.recover { raise(fallback()) } .runCont() shouldBe fallback() } } + @Suppress("UNREACHABLE_CODE") "catch - error path and throw" { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, msg -> shouldThrow { effect { - raise(int()) + raise(int()) fail("It should never reach this point") }.recover { throw RuntimeException(msg()) } .runCont() diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt index c17af634fe8..09cd2ef8212 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-05.kt @@ -19,7 +19,7 @@ suspend fun awaitExitCase(exit: CompletableDeferred): A = val error = "Error" val exit = CompletableDeferred() effect { - parZip({ awaitExitCase(exit) }, { raise(error) }) { a, b -> a + b } + parZip({ awaitExitCase(exit) }, { raise(error) }) { a: Int, b: Int -> a + b } }.fold({ it shouldBe error }, { fail("Int can never be the result") }) exit.await().shouldBeTypeOf() } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt index 33f4a45af98..8d9295d3545 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-07.kt @@ -23,7 +23,7 @@ suspend fun main() { val error = "Error" val exit = CompletableDeferred() effect { - raceN({ awaitExitCase(exit) }) { raise(error) } + raceN({ awaitExitCase(exit) }) { raise(error) } .merge() // Flatten Either result from race into Int }.fold({ msg -> msg shouldBe error }, { fail("Int can never be the result") }) // It's possible not all parallel task got launched, and in those cases awaitCancellation never ran diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt index e3426a5911b..97083577588 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-09.kt @@ -26,7 +26,7 @@ suspend fun main() { resourceScope { effect { val reader = bufferedReader("build.gradle.kts") - raise(error) + raise(error) reader.lineSequence().count() }.fold({ it shouldBe error }, { fail("Int can never be the result") }) } From a9271633e61d70b449f36b72bbdee79ef71b6333 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Sun, 4 Dec 2022 21:06:09 +0100 Subject: [PATCH 009/114] Update API files --- arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api | 1 + 1 file changed, 1 insertion(+) diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index 093b5fb9ee0..e95ad9ad80a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -99,6 +99,7 @@ public final class arrow/fx/coroutines/ExitCase$Cancelled : arrow/fx/coroutines/ public final class arrow/fx/coroutines/ExitCase$Companion { public final fun ExitCase (Ljava/lang/Throwable;)Larrow/fx/coroutines/ExitCase; + public final fun fromError (Ljava/lang/Throwable;)Larrow/fx/coroutines/ExitCase; } public final class arrow/fx/coroutines/ExitCase$Completed : arrow/fx/coroutines/ExitCase { From b39de7c7c2dba7fb60a76e91f1922b4d0f53be52 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Mon, 5 Dec 2022 08:59:46 +0100 Subject: [PATCH 010/114] Increase timeout --- .github/workflows/pull_request.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index df8631d4e13..2e6e20f4572 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -8,7 +8,7 @@ env: jobs: ios_watchos: runs-on: macos-latest - timeout-minutes: 60 + timeout-minutes: 90 steps: - uses: actions/checkout@v3 @@ -38,7 +38,7 @@ jobs: macos_tvos: runs-on: macos-latest - timeout-minutes: 60 + timeout-minutes: 90 steps: - uses: actions/checkout@v3 @@ -65,7 +65,7 @@ jobs: windows: runs-on: windows-latest - timeout-minutes: 60 + timeout-minutes: 90 steps: - uses: actions/checkout@v3 @@ -92,7 +92,7 @@ jobs: ubuntu: runs-on: ubuntu-latest - timeout-minutes: 60 + timeout-minutes: 90 steps: - uses: actions/checkout@v3 @@ -129,7 +129,7 @@ jobs: update_api: runs-on: ubuntu-latest - timeout-minutes: 60 + timeout-minutes: 90 steps: - uses: actions/checkout@v3 From cf45dadc4d5f4231d4e4929835a886104582bf21 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Mon, 5 Dec 2022 12:01:16 +0100 Subject: [PATCH 011/114] Fix compiler bug with nested inline + while + return --- .../kotlin/arrow/fx/coroutines/ScheduleTest.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt index 6cf8689212d..b1fc0ad1871 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt @@ -1,7 +1,5 @@ package arrow.fx.coroutines -import arrow.atomic.Atomic -import arrow.atomic.updateAndGet import arrow.core.Either import arrow.core.Eval import io.kotest.assertions.fail @@ -248,16 +246,16 @@ class ScheduleTest : ArrowFxSpec( } "retry is stack-safe" { - val count = Atomic(0) + var count = 0 val l = Either.catch { Schedule.recurs(20_000).retry { - count.updateAndGet { it + 1 } + count++ throw exception } } l should leftException(exception) - count.value shouldBe 20_001 + count shouldBe 20_001 } "retry succeeds if no exception is thrown" { @@ -329,16 +327,16 @@ private tailrec suspend fun go( } private suspend fun checkRepeat(schedule: Schedule, expected: B): Unit { - val count = Atomic(0) + var count = 0 schedule.repeat { - count.updateAndGet { it + 1 } + ++count } shouldBe expected } private suspend fun checkRepeatAsFlow(schedule: Schedule, expected: Flow): Unit { - val count = Atomic(0) + var count = 0 schedule.repeatAsFlow { - count.updateAndGet { it + 1 } + ++count }.zip(expected, ::Pair) .collect { (a, b) -> a shouldBe b } } From 7a472b832ae4b86a353dfc5075750a9509659048 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Mon, 5 Dec 2022 13:01:20 +0100 Subject: [PATCH 012/114] Clean up ExitCase.fromError --- .../src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt | 3 --- .../commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt index 547d5d37a11..d9273f3ef95 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt @@ -17,9 +17,6 @@ public sealed class ExitCase { public companion object { public fun ExitCase(error: Throwable): ExitCase = if (error is CancellationException) Cancelled(error) else Failure(error) - - public fun fromError(error: Throwable): ExitCase = - if (error is CancellationException) Cancelled(error) else Failure(error) } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt index 8094e9882ab..4e39ae0f125 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt @@ -3,6 +3,7 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.left import arrow.core.continuations.either +import arrow.fx.coroutines.ExitCase.Companion.ExitCase import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -543,7 +544,7 @@ class ResourceTest : StringSpec({ allocate shouldBe seed throw original } catch (e: Throwable) { - release(ExitCase.fromError(e)) + release(ExitCase(e)) } } @@ -571,7 +572,7 @@ class ResourceTest : StringSpec({ allocate shouldBe seed throw cancellation } catch (e: Throwable) { - release(ExitCase.fromError(e)) + release(ExitCase(e)) } } From 48c7bd592e6997f785944d74c30f11cc6f569515 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Mon, 5 Dec 2022 13:36:50 +0100 Subject: [PATCH 013/114] Update API files@ --- arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api | 1 - 1 file changed, 1 deletion(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index e95ad9ad80a..093b5fb9ee0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -99,7 +99,6 @@ public final class arrow/fx/coroutines/ExitCase$Cancelled : arrow/fx/coroutines/ public final class arrow/fx/coroutines/ExitCase$Companion { public final fun ExitCase (Ljava/lang/Throwable;)Larrow/fx/coroutines/ExitCase; - public final fun fromError (Ljava/lang/Throwable;)Larrow/fx/coroutines/ExitCase; } public final class arrow/fx/coroutines/ExitCase$Completed : arrow/fx/coroutines/ExitCase { From fbba669996f2279d177404f07fd6d19525162737 Mon Sep 17 00:00:00 2001 From: Marc Moreno Ferrer Date: Mon, 5 Dec 2022 15:34:10 +0100 Subject: [PATCH 014/114] Feature/remove validated (#2795) Co-authored-by: Simon Vergauwen Co-authored-by: Alejandro Serrano --- README.md | 2 +- .../commonMain/kotlin/arrow/atomic/Atomic.kt | 1 + .../kotlin/examples/example-atomic-01.kt | 1 + .../kotlin/arrow/continuations/Reset.kt | 2 +- .../continuations/generic/ControlThrowable.kt | 2 +- .../continuations/generic/ControlThrowable.kt | 2 +- .../continuations/generic/ControlThrowable.kt | 2 +- .../generic/ControlThrowable.kt | 2 +- .../arrow-core-test/api/arrow-core-test.api | 1 - .../arrow/core/test/generators/Generators.kt | 5 - arrow-libs/core/arrow-core/api/arrow-core.api | 337 +------ .../commonMain/kotlin/arrow/core/Either.kt | 391 ++------ .../commonMain/kotlin/arrow/core/EitherZip.kt | 382 ++++++++ .../src/commonMain/kotlin/arrow/core/Ior.kt | 353 ++------ .../commonMain/kotlin/arrow/core/Iterable.kt | 220 ++--- .../kotlin/arrow/core/NonEmptyList.kt | 95 -- .../commonMain/kotlin/arrow/core/Option.kt | 65 -- .../commonMain/kotlin/arrow/core/Sequence.kt | 128 +-- .../commonMain/kotlin/arrow/core/Validated.kt | 856 ------------------ .../kotlin/arrow/core/computations/either.kt | 7 - .../kotlin/arrow/core/computations/result.kt | 73 +- .../arrow/core/continuations/EagerEffect.kt | 0 .../kotlin/arrow/core/continuations/Effect.kt | 9 +- .../arrow/core/continuations/Mappers.kt | 5 - .../kotlin/arrow/core/continuations/Raise.kt | 7 - .../src/commonMain/kotlin/arrow/core/map.kt | 82 -- .../commonMain/kotlin/arrow/core/predef.kt | 8 +- .../kotlin/arrow/typeclasses/Monoid.kt | 63 +- .../kotlin/arrow/typeclasses/Semigroup.kt | 55 +- .../kotlin/arrow/core/EitherTest.kt | 138 +-- .../kotlin/arrow/core/EitherZipTest.kt | 117 +++ .../commonTest/kotlin/arrow/core/IorTest.kt | 148 +-- .../kotlin/arrow/core/IterableTest.kt | 234 +---- .../commonTest/kotlin/arrow/core/MapKTest.kt | 87 +- .../kotlin/arrow/core/NonEmptyListTest.kt | 136 +-- .../kotlin/arrow/core/OptionTest.kt | 39 - .../kotlin/arrow/core/SequenceKTest.kt | 65 -- .../kotlin/arrow/core/ValidatedTest.kt | 519 ----------- .../arrow/core/computations/ResultTest.kt | 1 + .../jvmTest/java/arrow/core/DeadlockTest.kt | 14 - .../java/arrow/core/ValidatedUsage.java | 19 - .../arrow/typeclasses/MonoidUsageTest.java | 3 - .../arrow/typeclasses/SemigroupUsageTest.java | 1 - .../kotlin/examples/example-effect-02.kt | 3 - .../kotlin/examples/example-either-02.kt | 6 +- .../kotlin/examples/example-either-03.kt | 7 +- .../kotlin/examples/example-either-04.kt | 4 +- .../kotlin/examples/example-either-05.kt | 14 +- .../kotlin/examples/example-either-06.kt | 18 +- .../kotlin/examples/example-either-07.kt | 18 +- .../kotlin/examples/example-either-08.kt | 20 +- .../kotlin/examples/example-either-09.kt | 16 +- .../kotlin/examples/example-either-10.kt | 31 +- .../kotlin/examples/example-either-11.kt | 19 +- .../kotlin/examples/example-either-12.kt | 35 +- .../kotlin/examples/example-either-13.kt | 73 +- .../kotlin/examples/example-either-14.kt | 80 +- .../kotlin/examples/example-either-15.kt | 10 +- .../kotlin/examples/example-either-16.kt | 9 +- .../kotlin/examples/example-either-17.kt | 8 +- .../kotlin/examples/example-either-18.kt | 9 +- .../kotlin/examples/example-either-19.kt | 10 +- .../kotlin/examples/example-either-20.kt | 6 +- .../kotlin/examples/example-either-21.kt | 9 +- .../kotlin/examples/example-either-22.kt | 2 +- .../kotlin/examples/example-either-23.kt | 7 +- .../kotlin/examples/example-either-24.kt | 6 +- .../kotlin/examples/example-either-25.kt | 13 +- .../kotlin/examples/example-either-26.kt | 17 +- .../kotlin/examples/example-either-27.kt | 8 +- .../kotlin/examples/example-either-28.kt | 4 +- .../kotlin/examples/example-either-29.kt | 5 +- .../kotlin/examples/example-either-30.kt | 2 +- .../kotlin/examples/example-either-31.kt | 4 +- .../kotlin/examples/example-either-32.kt | 2 +- .../kotlin/examples/example-either-33.kt | 14 +- .../kotlin/examples/example-either-34.kt | 8 +- .../kotlin/examples/example-either-35.kt | 4 +- .../kotlin/examples/example-either-36.kt | 4 +- .../kotlin/examples/example-either-37.kt | 3 +- .../kotlin/examples/example-either-38.kt | 2 +- .../kotlin/examples/example-either-39.kt | 10 +- .../kotlin/examples/example-either-40.kt | 11 +- .../kotlin/examples/example-either-41.kt | 6 +- .../kotlin/examples/example-either-42.kt | 12 +- .../kotlin/examples/example-either-43.kt | 7 +- .../kotlin/examples/example-either-44.kt | 8 - .../kotlin/examples/example-either-45.kt | 12 + .../kotlin/examples/example-either-46.kt | 20 +- .../kotlin/examples/example-either-47.kt | 9 +- .../kotlin/examples/example-either-48.kt | 10 +- .../kotlin/examples/example-either-49.kt | 5 +- .../kotlin/examples/example-either-50.kt | 13 +- .../kotlin/examples/example-either-51.kt | 19 +- .../kotlin/examples/example-either-52.kt | 18 +- .../kotlin/examples/example-either-53.kt | 13 +- .../kotlin/examples/example-either-54.kt | 9 +- .../kotlin/examples/example-either-55.kt | 12 +- .../kotlin/examples/example-either-56.kt | 13 - .../jvmTest/kotlin/examples/example-ior-12.kt | 8 +- .../jvmTest/kotlin/examples/example-ior-13.kt | 15 +- .../jvmTest/kotlin/examples/example-ior-14.kt | 13 - .../example-result-computations-01.kt | 2 +- .../kotlin/examples/example-validated-01.kt | 14 - .../kotlin/examples/example-validated-02.kt | 12 - .../kotlin/examples/example-validated-03.kt | 9 - .../kotlin/examples/example-validated-04.kt | 9 - .../kotlin/examples/example-validated-05.kt | 13 - .../kotlin/examples/example-validated-06.kt | 11 - .../kotlin/examples/test/EitherKnitTest.kt | 24 +- .../api/arrow-fx-coroutines-test.api | 2 - .../kotlin/arrow/fx/coroutines/predef-test.kt | 20 - .../api/arrow-fx-coroutines.api | 18 - .../arrow/fx/coroutines/ParTraverseResult.kt | 8 +- .../fx/coroutines/ParTraverseValidated.kt | 210 ----- .../fx/coroutines/ParTraverseEitherTest.kt | 7 +- .../fx/coroutines/ParTraverseResultTest.kt | 6 +- .../fx/coroutines/ParTraverseValidatedTest.kt | 89 -- .../coroutines/ParTraverseValidatedJvmTest.kt | 26 - .../example-partraversevalidated-01.kt | 21 - .../example-partraversevalidated-02.kt | 26 - .../optics/arrow-optics/api/arrow-optics.api | 8 - .../commonMain/kotlin/arrow/optics/Fold.kt | 16 +- .../src/commonMain/kotlin/arrow/optics/Iso.kt | 37 - .../commonMain/kotlin/arrow/optics/predef.kt | 2 +- .../kotlin/arrow/optics/std/EitherTest.kt | 25 - .../kotlin/arrow/optics/std/ValidatedTest.kt | 27 - arrow-site/docs/_code/fx-home-code.md | 6 +- arrow-site/docs/_data/sidebar-core.yml | 3 - arrow-site/docs/docs/core/README.md | 7 +- .../docs/docs/datatypes/intro/README.md | 2 - .../docs/patterns/errorhandling/README.md | 40 +- .../docs/docs/patterns/monads/README.md | 2 +- arrow-site/docs/docs/quickstart/README.md | 2 +- 134 files changed, 1325 insertions(+), 4809 deletions(-) create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/EitherZip.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt create mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffect.kt create mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/ValidatedUsage.java delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-56.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-14.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-03.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-04.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-05.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-06.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-partraversevalidated-01.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-partraversevalidated-02.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/EitherTest.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ValidatedTest.kt diff --git a/README.md b/README.md index b432f390580..ce858aa92b9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Arrow aims to provide a [*lingua franca*](https://en.wikipedia.org/wiki/Lingua_franca) of interfaces and abstractions across Kotlin libraries. For this, it includes the most popular data types such -as `Option`, `Either`, `Validated` etc and functional operators such as `traverse` and computation +as `Option`, `Either` etc and functional operators such as `traverse` and computation blocks to empower users to write pure FP apps and libraries built atop higher order abstractions. Use the list below to learn more about Λrrow's main features. diff --git a/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt index b4824ff0ce4..a0b2ab1631c 100644 --- a/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt +++ b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt @@ -9,6 +9,7 @@ public expect fun Atomic(initialValue: A): Atomic * import arrow.atomic.Atomic * import arrow.atomic.update * import arrow.fx.coroutines.parTraverse + * * suspend fun main() { * val count = Atomic(0) * (0 until 20_000).parTraverse { diff --git a/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt b/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt index 418d6c41d7a..5bf7a24ce01 100644 --- a/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt +++ b/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt @@ -4,6 +4,7 @@ package arrow.atomic.examples.exampleAtomic01 import arrow.atomic.Atomic import arrow.atomic.update import arrow.fx.coroutines.parTraverse + suspend fun main() { val count = Atomic(0) (0 until 20_000).parTraverse { diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt index cd620c38fa7..c6a4dab39d7 100644 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt +++ b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt @@ -20,7 +20,7 @@ internal object Reset { * The usage of `try { ... } catch(e: Throwable) { ... }` will catch the [ShortCircuit] error, * and will lead to recover of short-circuiting. * You should always prefer to catch the most specific exception class, or - * use `Either.catch`, `Validated.catch` etc or `e.nonFatalOrThrow()` + * use `Either.catch` etc or `e.nonFatalOrThrow()` * to ensure you're not catching `ShortCircuit`. */ @Deprecated(deprecateArrowContinuation) 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 index 4ddbfe07b65..234953e85a9 100644 --- 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 @@ -4,7 +4,7 @@ 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]. + * Thus by extension `Either.catch` also don't catch [ControlThrowable]. */ @Deprecated(deprecateArrowContinuation) public expect open class ControlThrowable() : Throwable diff --git a/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt b/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt index 83e3ef54c08..aab29577711 100644 --- a/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt +++ b/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt @@ -4,7 +4,7 @@ package arrow.continuations.generic * A [Throwable] class intended for control flow. * 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.kt]. + * Thus by extension `Either.catch` also don't catch [ControlThrowable.kt]. */ @Deprecated(deprecateArrowContinuation) public actual open class ControlThrowable : Throwable() 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 5b773b30a7d..46bf67112e5 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 @@ -5,7 +5,7 @@ package arrow.continuations.generic * A [Throwable] class intended for control flow. * 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.kt]. + * Thus by extension `Either.catch` also don't catch [ControlThrowable.kt]. */ @Deprecated(deprecateArrowContinuation) public actual open class ControlThrowable : Throwable() { diff --git a/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt b/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt index dedc2b8463c..839dc4043ba 100644 --- a/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt +++ b/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt @@ -4,7 +4,7 @@ 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]. + * Thus by extension `Either.catch` also don't catch [ControlThrowable]. */ @Deprecated(deprecateArrowContinuation) public actual open class ControlThrowable : Throwable() diff --git a/arrow-libs/core/arrow-core-test/api/arrow-core-test.api b/arrow-libs/core/arrow-core-test/api/arrow-core-test.api index 1d009c7d92f..edddd74f650 100644 --- a/arrow-libs/core/arrow-core-test/api/arrow-core-test.api +++ b/arrow-libs/core/arrow-core-test/api/arrow-core-test.api @@ -101,7 +101,6 @@ public final class arrow/core/test/generators/GeneratorsKt { public static final fun tuple8 (Lio/kotest/property/Arb$Companion;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;)Lio/kotest/property/Arb; public static final fun tuple9 (Lio/kotest/property/Arb$Companion;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;Lio/kotest/property/Arb;)Lio/kotest/property/Arb; public static final fun unit (Lio/kotest/property/Arb$Companion;)Lio/kotest/property/Arb; - public static final fun validated (Lio/kotest/property/Arb$Companion;Lio/kotest/property/Arb;Lio/kotest/property/Arb;)Lio/kotest/property/Arb; } public final class arrow/core/test/generators/UtilsKt { diff --git a/arrow-libs/core/arrow-core-test/src/commonMain/kotlin/arrow/core/test/generators/Generators.kt b/arrow-libs/core/arrow-core-test/src/commonMain/kotlin/arrow/core/test/generators/Generators.kt index 49c19601228..06b2caee06e 100644 --- a/arrow-libs/core/arrow-core-test/src/commonMain/kotlin/arrow/core/test/generators/Generators.kt +++ b/arrow-libs/core/arrow-core-test/src/commonMain/kotlin/arrow/core/test/generators/Generators.kt @@ -13,7 +13,6 @@ import arrow.core.Tuple6 import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 -import arrow.core.Validated import arrow.core.left import arrow.core.right import arrow.core.test.concurrency.deprecateArrowTestModules @@ -220,10 +219,6 @@ public fun Arb.Companion.either(arbE: Arb, arbA: Arb): Arb Arb.or(arbA: Arb): Arb> = Arb.either(this, arbA) -@Deprecated(deprecateArrowTestModules) -public fun Arb.Companion.validated(arbE: Arb, arbA: Arb): Arb> = - Arb.either(arbE, arbA).map { Validated.fromEither(it) } - @Deprecated(deprecateArrowTestModules) public fun Arb.Companion.unit(): Arb = Arb.constant(Unit) diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index a6fc6341ea9..cc1e8a88fda 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -155,10 +155,6 @@ public abstract class arrow/core/Either { public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun bitraverseValidated (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun conditionally (ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public final fun exists (Lkotlin/jvm/functions/Function1;)Z public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -186,14 +182,6 @@ public abstract class arrow/core/Either { public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public final fun tapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public fun toString ()Ljava/lang/String; - public final fun toValidated ()Larrow/core/Validated; - public final fun toValidatedNel ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public static final fun tryCatchAndFlatten (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; @@ -246,10 +234,6 @@ public final class arrow/core/Either$Right$Companion { public final class arrow/core/EitherKt { public static final field NicheAPI Ljava/lang/String; public static final field RedundantAPI Ljava/lang/String; - public static final fun bisequence (Larrow/core/Either;)Ljava/util/List; - public static final fun bisequenceNullable (Larrow/core/Either;)Larrow/core/Either; - public static final fun bisequenceOption (Larrow/core/Either;)Larrow/core/Option; - public static final fun bisequenceValidated (Larrow/core/Either;)Larrow/core/Validated; public static final fun combine (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Either;)Larrow/core/Either; public static final fun combineAll (Ljava/lang/Iterable;Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/core/Either; public static final fun combineK (Larrow/core/Either;Larrow/core/Either;)Larrow/core/Either; @@ -277,15 +261,9 @@ public final class arrow/core/EitherKt { public static final fun right (Ljava/lang/Object;)Larrow/core/Either; public static final fun rightIfNotNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public static final fun rightIfNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Either;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Either;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Either;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Either;)Ljava/util/List; - public static final fun sequenceNullable (Larrow/core/Either;)Larrow/core/Either; - public static final fun sequenceOption (Larrow/core/Either;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/Either;)Larrow/core/Validated; + public static final fun toEitherNel (Larrow/core/Either;)Larrow/core/Either; + public static final fun toEitherNel (Ljava/lang/Object;)Larrow/core/Either; public static final fun widen (Larrow/core/Either;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;)Larrow/core/Either; public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function10;)Larrow/core/Either; public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function9;)Larrow/core/Either; public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function8;)Larrow/core/Either; @@ -295,10 +273,29 @@ public final class arrow/core/EitherKt { public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function4;)Larrow/core/Either; public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function3;)Larrow/core/Either; public static final fun zip (Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function10;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function9;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function8;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function7;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function6;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function5;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function4;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function3;)Larrow/core/Either; + public static final fun zip (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function10;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function9;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function8;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function7;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function6;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function5;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function4;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function3;)Larrow/core/Either; + public static final fun zipNonEmptyList (Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; } public final class arrow/core/EmptyValue { public static final field INSTANCE Larrow/core/EmptyValue; + public final fun combine (Ljava/lang/Object;Ljava/lang/Object;Larrow/typeclasses/Semigroup;)Ljava/lang/Object; public final fun unbox (Ljava/lang/Object;)Ljava/lang/Object; } @@ -429,11 +426,6 @@ public abstract class arrow/core/Ior { public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun bitraverseValidated (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun bothNel (Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Ior; public final fun crosswalk (Lkotlin/jvm/functions/Function1;)Ljava/util/List; public final fun crosswalkMap (Lkotlin/jvm/functions/Function1;)Ljava/util/Map; @@ -460,15 +452,6 @@ public abstract class arrow/core/Ior { public final fun swap ()Larrow/core/Ior; public final fun toEither ()Larrow/core/Either; public fun toString ()Ljava/lang/String; - public final fun toValidated ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public final fun unwrap ()Larrow/core/Either; public final fun void ()Larrow/core/Ior; } @@ -535,11 +518,6 @@ public final class arrow/core/Ior$Right$Companion { } public final class arrow/core/IorKt { - public static final fun bisequence (Larrow/core/Ior;)Ljava/util/List; - public static final fun bisequenceEither (Larrow/core/Ior;)Larrow/core/Either; - public static final fun bisequenceNullable (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun bisequenceOption (Larrow/core/Ior;)Larrow/core/Option; - public static final fun bisequenceValidated (Larrow/core/Ior;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun bothIor (Lkotlin/Pair;)Larrow/core/Ior; public static final fun combine (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Ior;)Larrow/core/Ior; public static final fun compareTo (Larrow/core/Ior;Larrow/core/Ior;)I @@ -551,15 +529,6 @@ public final class arrow/core/IorKt { public static final fun replicate (Larrow/core/Ior;Larrow/typeclasses/Semigroup;I)Larrow/core/Ior; public static final fun replicate (Larrow/core/Ior;Larrow/typeclasses/Semigroup;ILarrow/typeclasses/Monoid;)Larrow/core/Ior; public static final fun rightIor (Ljava/lang/Object;)Larrow/core/Ior; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Ior;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Ior;)Larrow/core/Either; - public static final fun sequenceNullable (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun sequenceOption (Larrow/core/Ior;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/Ior;)Larrow/core/Validated; public static final fun widen (Larrow/core/Ior;)Larrow/core/Ior; public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;)Larrow/core/Ior; public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function10;)Larrow/core/Ior; @@ -597,6 +566,8 @@ public final class arrow/core/IterableKt { public static final fun lastOrNone (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun leftPadZip (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List; public static final fun leftPadZip (Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun mapOrAccumulate (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; + public static final fun mapOrAccumulate (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; public static final fun padZip (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List; public static final fun padZip (Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun prependTo (Ljava/lang/Object;Ljava/lang/Iterable;)Ljava/util/List; @@ -608,39 +579,13 @@ public final class arrow/core/IterableKt { public static final fun rightPadZip (Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun salign (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Ljava/lang/Iterable;)Ljava/lang/Iterable; public static final fun separateEither (Ljava/lang/Iterable;)Lkotlin/Pair; - public static final fun separateValidated (Ljava/lang/Iterable;)Lkotlin/Pair; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Either; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Validated; - public static final fun sequence (Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun sequence (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun sequence (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Ljava/lang/Iterable;)Larrow/core/Either; - public static final fun sequenceNullable (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun sequenceOption (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun sequenceResult (Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun sequenceValidated (Ljava/lang/Iterable;)Larrow/core/Validated; - public static final fun sequenceValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun singleOrNone (Ljava/lang/Iterable;)Larrow/core/Option; public static final fun singleOrNone (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun split (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun tail (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun traverse (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public static final fun traverseEither (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseNullable (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public static final fun traverseOption (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseResult (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun traverseValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverseValidated (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun unalign (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun uniteEither (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun uniteValidated (Ljava/lang/Iterable;)Ljava/util/List; public static final fun unweave (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun unzip (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun unzip (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; @@ -670,18 +615,6 @@ public final class arrow/core/MapKt { public static final fun padZip (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public static final fun padZip (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function3;)Ljava/util/Map; public static final fun salign (Ljava/util/Map;Larrow/typeclasses/Semigroup;Ljava/util/Map;)Ljava/util/Map; - public static final fun sequence (Ljava/util/Map;)Larrow/core/Either; - public static final fun sequence (Ljava/util/Map;)Larrow/core/Option; - public static final fun sequence (Ljava/util/Map;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Ljava/util/Map;)Larrow/core/Either; - public static final fun sequenceOption (Ljava/util/Map;)Larrow/core/Option; - public static final fun sequenceValidated (Ljava/util/Map;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun traverse (Ljava/util/Map;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Ljava/util/Map;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Ljava/util/Map;)Lkotlin/Pair; public static final fun unalign (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun unzip (Ljava/util/Map;)Lkotlin/Pair; @@ -763,20 +696,8 @@ public final class arrow/core/NonEmptyListKt { public static final fun minBy (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun nel (Ljava/lang/Object;)Larrow/core/NonEmptyList; public static final fun nonEmptyListOf (Ljava/lang/Object;[Ljava/lang/Object;)Larrow/core/NonEmptyList; - public static final fun sequence (Larrow/core/NonEmptyList;)Larrow/core/Either; - public static final fun sequence (Larrow/core/NonEmptyList;)Larrow/core/Option; - public static final fun sequence (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Larrow/core/NonEmptyList;)Larrow/core/Either; - public static final fun sequenceOption (Larrow/core/NonEmptyList;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun toNonEmptyListOrNone (Ljava/lang/Iterable;)Larrow/core/Option; public static final fun toNonEmptyListOrNull (Ljava/lang/Iterable;)Larrow/core/NonEmptyList; - public static final fun traverse (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unzip (Larrow/core/NonEmptyList;)Lkotlin/Pair; public static final fun unzip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; } @@ -848,11 +769,6 @@ public abstract class arrow/core/Option { public final fun toEither (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public final fun toList ()Ljava/util/List; public fun toString ()Ljava/lang/String; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public static final fun tryCatchOrNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public final fun void ()Larrow/core/Option; @@ -896,12 +812,6 @@ public final class arrow/core/OptionKt { public static final fun rethrow (Larrow/core/Option;)Larrow/core/Option; public static final fun salign (Larrow/core/Option;Larrow/typeclasses/Semigroup;Larrow/core/Option;)Larrow/core/Option; public static final fun separateEither (Larrow/core/Option;)Lkotlin/Pair; - public static final fun separateValidated (Larrow/core/Option;)Lkotlin/Pair; - public static final fun sequence (Larrow/core/Option;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Option;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Option;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Option;)Larrow/core/Either; - public static final fun sequenceValidated (Larrow/core/Option;)Larrow/core/Validated; public static final fun some (Ljava/lang/Object;)Larrow/core/Option; public static final fun toMap (Larrow/core/Option;)Ljava/util/Map; public static final fun toOption (Ljava/lang/Object;)Larrow/core/Option; @@ -909,7 +819,6 @@ public final class arrow/core/OptionKt { public static final fun unalign (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun unite (Larrow/core/Option;Larrow/typeclasses/Monoid;)Larrow/core/Option; public static final fun uniteEither (Larrow/core/Option;)Larrow/core/Option; - public static final fun uniteValidated (Larrow/core/Option;)Larrow/core/Option; public static final fun unzip (Larrow/core/Option;)Lkotlin/Pair; public static final fun unzip (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun widen (Larrow/core/Option;)Larrow/core/Option; @@ -1471,26 +1380,12 @@ public final class arrow/core/SequenceKt { public static final fun rightPadZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; public static final fun salign (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun separateEither (Lkotlin/sequences/Sequence;)Lkotlin/Pair; - public static final fun separateValidated (Lkotlin/sequences/Sequence;)Lkotlin/Pair; - public static final fun sequence (Lkotlin/sequences/Sequence;)Larrow/core/Either; - public static final fun sequence (Lkotlin/sequences/Sequence;)Larrow/core/Option; - public static final fun sequence (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Lkotlin/sequences/Sequence;)Larrow/core/Either; - public static final fun sequenceOption (Lkotlin/sequences/Sequence;)Larrow/core/Option; - public static final fun sequenceValidated (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun some (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun split (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun tail (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; - public static final fun traverse (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun unalign (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun uniteEither (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; - public static final fun uniteValidated (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun unweave (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; public static final fun unzip (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun unzip (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; @@ -2312,164 +2207,14 @@ public final class arrow/core/UtilsKt { public static final fun mapNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public abstract class arrow/core/Validated { - public static final field Companion Larrow/core/Validated$Companion; - public final fun all (Lkotlin/jvm/functions/Function1;)Z - public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun catchNel (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun exist (Lkotlin/jvm/functions/Function1;)Z - public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun foldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun fromEither (Larrow/core/Either;)Larrow/core/Validated; - public static final fun fromNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun fromOption (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun isEmpty ()Z - public final fun isInvalid ()Z - public final fun isNotEmpty ()Z - public final fun isValid ()Z - public static final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun mapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun swap ()Larrow/core/Validated; - public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun tapInvalid (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun toEither ()Larrow/core/Either; - public final fun toList ()Ljava/util/List; - public final fun toOption ()Larrow/core/Option; - public fun toString ()Ljava/lang/String; - public final fun toValidatedNel ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun void ()Larrow/core/Validated; - public final fun withEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; -} - -public final class arrow/core/Validated$Companion { - public final fun catchNel (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun fromEither (Larrow/core/Either;)Larrow/core/Validated; - public final fun fromNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun fromOption (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; -} - -public final class arrow/core/Validated$Invalid : arrow/core/Validated { - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Validated$Invalid; - public static synthetic fun copy$default (Larrow/core/Validated$Invalid;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Validated$Invalid; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Validated$Valid : arrow/core/Validated { - public static final field Companion Larrow/core/Validated$Valid$Companion; - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Validated$Valid; - public static synthetic fun copy$default (Larrow/core/Validated$Valid;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Validated$Valid; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Validated$Valid$Companion { - public final fun getUnit ()Larrow/core/Validated; -} - -public final class arrow/core/ValidatedKt { - public static final fun andThen (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun attempt (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun bisequence (Larrow/core/Validated;)Ljava/util/List; - public static final fun bisequenceEither (Larrow/core/Validated;)Larrow/core/Either; - public static final fun bisequenceNullable (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun bisequenceOption (Larrow/core/Validated;)Larrow/core/Option; - public static final fun combine (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun combineAll (Larrow/core/Validated;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun combineK (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun compareTo (Larrow/core/Validated;Larrow/core/Validated;)I - public static final fun findValid (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun fold (Larrow/core/Validated;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun getOrElse (Larrow/core/Validated;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static final fun handleError (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun handleErrorWith (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun invalid (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun leftWiden (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun merge (Larrow/core/Validated;)Ljava/lang/Object; - public static final fun orElse (Larrow/core/Validated;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun orNone (Larrow/core/Validated;)Larrow/core/Option; - public static final fun orNull (Larrow/core/Validated;)Ljava/lang/Object; - public static final fun redeem (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun replicate (Larrow/core/Validated;Larrow/typeclasses/Semigroup;I)Larrow/core/Validated; - public static final fun replicate (Larrow/core/Validated;Larrow/typeclasses/Semigroup;ILarrow/typeclasses/Monoid;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Validated;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Validated;)Larrow/core/Either; - public static final fun sequenceNullable (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun sequenceOption (Larrow/core/Validated;)Larrow/core/Option; - public static final fun toIor (Larrow/core/Validated;)Larrow/core/Ior; - public static final fun valid (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun valueOr (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun widen (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function10;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function9;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function8;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function7;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function6;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function5;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function4;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function3;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function2;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function10;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function9;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function8;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function7;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function6;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function5;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function4;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function3;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Lkotlin/jvm/functions/Function2;)Larrow/core/Validated; -} - public abstract interface class arrow/core/computations/EitherEffect : arrow/continuations/Effect { public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public final class arrow/core/computations/EitherEffect$DefaultImpls { public static fun bind (Larrow/core/computations/EitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/EitherEffect;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind (Larrow/core/computations/EitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun ensure (Larrow/core/computations/EitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } @@ -2521,7 +2266,6 @@ public abstract interface class arrow/core/computations/RestrictedEitherEffect : public final class arrow/core/computations/RestrictedEitherEffect$DefaultImpls { public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun ensure (Larrow/core/computations/RestrictedEitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } @@ -2553,10 +2297,14 @@ public final class arrow/core/computations/RestrictedOptionEffect$DefaultImpls { public final class arrow/core/computations/ResultEffect { public static final field INSTANCE Larrow/core/computations/ResultEffect; public final fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Validated;)Ljava/lang/Object; public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; } +public final class arrow/core/computations/ResultEffect$result { + public static final field INSTANCE Larrow/core/computations/ResultEffect$result; + public final fun invoke-IoAF18A (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +} + public final class arrow/core/computations/either { public static final field INSTANCE Larrow/core/computations/either; public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Either; @@ -2581,16 +2329,10 @@ public final class arrow/core/computations/option { public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class arrow/core/computations/result { - public static final field INSTANCE Larrow/core/computations/result; - public final fun invoke-IoAF18A (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - public final class arrow/core/continuations/DefaultRaise : arrow/core/continuations/Raise { public fun ()V public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2608,7 +2350,6 @@ public final class arrow/core/continuations/DefaultStateRaise : arrow/atomic/Ato public fun (Larrow/atomic/Atomic;Larrow/core/continuations/Raise;)V public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2659,8 +2400,6 @@ public final class arrow/core/continuations/Effect { public static final fun toResult (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun toValidated (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public abstract interface annotation class arrow/core/continuations/EffectDSL : java/lang/annotation/Annotation { @@ -2673,10 +2412,10 @@ public final class arrow/core/continuations/EffectKt { public final class arrow/core/continuations/IorRaise : arrow/core/continuations/Raise, arrow/typeclasses/Semigroup { public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/StateRaise;)V + public fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2697,14 +2436,12 @@ public final class arrow/core/continuations/IorRaise : arrow/core/continuations/ public final class arrow/core/continuations/NullableRaise : arrow/core/continuations/Raise { public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -2743,14 +2480,12 @@ public final class arrow/core/continuations/NullableRaise : arrow/core/continuat public final class arrow/core/continuations/OptionRaise : arrow/core/continuations/Raise { public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2788,7 +2523,6 @@ public final class arrow/core/continuations/OptionRaise : arrow/core/continuatio public abstract interface class arrow/core/continuations/Raise { public abstract fun bind (Larrow/core/Either;)Ljava/lang/Object; public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;)Ljava/lang/Object; public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2805,7 +2539,6 @@ public abstract interface class arrow/core/continuations/Raise { public final class arrow/core/continuations/Raise$DefaultImpls { public static fun bind (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2829,13 +2562,11 @@ public final class arrow/core/continuations/RaiseKt { public final class arrow/core/continuations/ResultRaise : arrow/core/continuations/Raise { public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Either;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/Raise;Larrow/core/Validated;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/continuations/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -2875,7 +2606,6 @@ public abstract interface class arrow/core/continuations/StateRaise : arrow/atom public final class arrow/core/continuations/StateRaise$DefaultImpls { public static fun bind (Larrow/core/continuations/StateRaise;Larrow/core/Either;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/StateRaise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/StateRaise;Larrow/core/Validated;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/StateRaise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind (Larrow/core/continuations/StateRaise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2913,7 +2643,6 @@ public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Sem public static fun pair (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public static fun sequence ()Larrow/typeclasses/Monoid; public static fun string ()Larrow/typeclasses/Monoid; - public static fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; } public final class arrow/typeclasses/Monoid$Companion { @@ -2931,10 +2660,10 @@ public final class arrow/typeclasses/Monoid$Companion { public final fun pair (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final fun sequence ()Larrow/typeclasses/Monoid; public final fun string ()Larrow/typeclasses/Monoid; - public final fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; } public final class arrow/typeclasses/Monoid$DefaultImpls { + public static fun combine (Larrow/typeclasses/Monoid;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun combineAll (Larrow/typeclasses/Monoid;Ljava/util/Collection;)Ljava/lang/Object; public static fun combineAll (Larrow/typeclasses/Monoid;Ljava/util/List;)Ljava/lang/Object; public static fun fold (Larrow/typeclasses/Monoid;Ljava/util/Collection;)Ljava/lang/Object; @@ -2950,6 +2679,7 @@ public abstract interface class arrow/typeclasses/Semigroup { public static fun Integer ()Larrow/typeclasses/Semigroup; public static fun Long ()Larrow/typeclasses/Semigroup; public static fun Short ()Larrow/typeclasses/Semigroup; + public abstract fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun constant (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public static fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; @@ -2964,7 +2694,6 @@ public abstract interface class arrow/typeclasses/Semigroup { public abstract fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun sequence ()Larrow/typeclasses/Semigroup; public static fun string ()Larrow/typeclasses/Semigroup; - public static fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; } public final class arrow/typeclasses/Semigroup$Companion { @@ -2984,11 +2713,12 @@ public final class arrow/typeclasses/Semigroup$Companion { public final fun pair (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public final fun sequence ()Larrow/typeclasses/Semigroup; public final fun string ()Larrow/typeclasses/Semigroup; - public final fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; } public final class arrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup : arrow/typeclasses/Semigroup { public static final field INSTANCE Larrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup; + public fun append (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public synthetic fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun combine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public synthetic fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public fun maybeCombine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; @@ -2998,6 +2728,7 @@ public final class arrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup : } public final class arrow/typeclasses/Semigroup$DefaultImpls { + public static fun combine (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun maybeCombine (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun plus (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index da0d73775b6..628bd817272 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -1,16 +1,19 @@ +@file:JvmMultifileClass +@file:JvmName("EitherKt") package arrow.core import arrow.core.Either.Companion.resolve import arrow.core.Either.Left import arrow.core.Either.Right +import arrow.core.EmptyValue.combine as emptyCombine import arrow.core.continuations.Raise import arrow.core.continuations.either import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract -import kotlin.experimental.ExperimentalTypeInference import kotlin.js.JsName +import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic @@ -47,25 +50,6 @@ import kotlin.jvm.JvmStatic * * How then do we communicate an error? By making it explicit in the data type we return. * - * ## Either vs Validated - * - * In general, `Validated` is used to accumulate errors, while `Either` is used to short-circuit a computation - * upon the first error. For more information, see the `Validated` vs `Either` section of the `Validated` documentation. - * - * By convention, the right side of an `Either` is used to hold successful values. - * - * ```kotlin - * import arrow.core.Either - * - * val right: Either = - * //sampleStart - * Either.Right(5) - * //sampleEnd - * fun main() { - * println(right) - * } - * ``` - * * * ```kotlin * import arrow.core.Either @@ -78,7 +62,7 @@ import kotlin.jvm.JvmStatic * println(left) * } * ``` - * + * * * Because `Either` is right-biased, it is possible to define a Monad instance for it. * @@ -99,7 +83,7 @@ import kotlin.jvm.JvmStatic * println("value = $value") * } * ``` - * + * * * ```kotlin * import arrow.core.Either @@ -113,7 +97,7 @@ import kotlin.jvm.JvmStatic * println("value = $value") * } * ``` - * + * * * ## Using Either instead of exceptions * @@ -141,7 +125,7 @@ import kotlin.jvm.JvmStatic * fun stringify(d: Double): String = d.toString() * //sampleEnd * ``` - * + * * * Instead, let's make the fact that some of our functions can fail explicit in the return type. * @@ -167,7 +151,7 @@ import kotlin.jvm.JvmStatic * parse(s).flatMap { reciprocal(it) }.map { stringify(it) } * //sampleEnd * ``` - * + * * * These calls to `parse` return a [Left] and [Right] value * @@ -187,7 +171,7 @@ import kotlin.jvm.JvmStatic * println("number2 = $number2") * } * ``` - * + * * * Now, using combinators like `flatMap` and `map`, we can compose our functions together. * @@ -219,7 +203,7 @@ import kotlin.jvm.JvmStatic * println("magicNotANumber = $magicNotANumber") * } * ``` - * + * * * In the following exercise, we pattern-match on every case in which the `Either` returned by `magic` can be in. * Note the `when` clause in the [Left] - the compiler will complain if we leave that out because it knows that, @@ -260,7 +244,7 @@ import kotlin.jvm.JvmStatic * println("value = $value") * } * ``` - * + * * * Instead of using exceptions as our error value, let's instead enumerate explicitly the things that * can go wrong in our program. @@ -290,7 +274,7 @@ import kotlin.jvm.JvmStatic * parse(s).flatMap{reciprocal(it)}.map{ stringify(it) } * //sampleEnd * ``` - * + * * * For our little module, we enumerate any and all errors that can occur. Then, instead of using * exception classes as error values, we use one of the enumerated cases. Now, when we pattern match, @@ -333,7 +317,7 @@ import kotlin.jvm.JvmStatic * println("value = $value") * } * ``` - * + * * * ## Either.catch exceptions * @@ -358,7 +342,7 @@ import kotlin.jvm.JvmStatic * object SpecificError : Error() * } * ``` - * + * * * ## Resolve Either into one type of value * In some cases you can not use Either as a value. For instance, when you need to respond to an HTTP request. To resolve Either into one type of value, you can use the resolve function. @@ -448,7 +432,7 @@ import kotlin.jvm.JvmStatic * data class ErrorResponse(val errorMessage: String) * enum class Level { INFO, WARN, ERROR } * ``` - * + * * * There are far more use cases for the resolve function, the HTTP endpoint example is just one of them. * @@ -470,7 +454,7 @@ import kotlin.jvm.JvmStatic * println("leftMapLeft = $leftMapLeft") * } * ``` - * + * * * `Either` can be transformed to `Either` using the `swap()` method. * @@ -486,7 +470,7 @@ import kotlin.jvm.JvmStatic * println("swapped = $swapped") * } * ``` - * + * * * For using Either's syntax on arbitrary data types. * This will make possible to use the `left()`, `right()`, `contains()`, `getOrElse()` and `getOrHandle()` methods: @@ -502,7 +486,7 @@ import kotlin.jvm.JvmStatic * println(right7) * } * ``` - * + * * * ```kotlin * import arrow.core.left @@ -515,7 +499,7 @@ import kotlin.jvm.JvmStatic * println(leftHello) * } * ``` - * + * * * ```kotlin * import arrow.core.right @@ -529,7 +513,7 @@ import kotlin.jvm.JvmStatic * println("contains7 = $contains7") * } * ``` - * + * * * ```kotlin * import arrow.core.left @@ -543,7 +527,7 @@ import kotlin.jvm.JvmStatic * println("getOr7 = $getOr7") * } * ``` - * + * * * ```kotlin * import arrow.core.left @@ -557,7 +541,7 @@ import kotlin.jvm.JvmStatic * println("value = $value") * } * ``` - * + * * * For creating Either instance based on a predicate, use `Either.conditionally()` method. It will evaluate an expression * passed as first parameter, in case the expression evaluates to `false` it will give an `Either.Left` build from the second parameter. @@ -574,7 +558,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * ```kotlin * import arrow.core.Either @@ -587,7 +571,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * Another operation is `fold`. This operation will extract the value from the Either, or provide a default if the value is [Left] * @@ -603,7 +587,7 @@ import kotlin.jvm.JvmStatic * println("fold = $fold") * } * ``` - * + * * * ```kotlin * import arrow.core.Either @@ -617,7 +601,7 @@ import kotlin.jvm.JvmStatic * println("fold = $fold") * } * ``` - * + * * * The `getOrHandle()` operation allows the transformation of an `Either.Left` value to a `Either.Right` using * the value of [Left]. This can be useful when mapping to a single result type is required like `fold()`, but without @@ -642,7 +626,7 @@ import kotlin.jvm.JvmStatic * println("httpStatusCode = $httpStatusCode") * } * ``` - * + * * * The ```leftIfNull``` operation transforms a null `Either.Right` value to the specified ```Either.Left``` value. * If the value is non-null, the value wrapped into a non-nullable ```Either.Right``` is returned (very useful to @@ -663,7 +647,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * ```kotlin * import arrow.core.Either.Right @@ -677,7 +661,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * ```kotlin * import arrow.core.Either.Left @@ -691,7 +675,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * Another useful operation when working with null is `rightIfNotNull`. * If the value is null, it will be transformed to the specified `Either.Left` and, if it's not null, the type will @@ -710,7 +694,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * ```kotlin * import arrow.core.rightIfNotNull @@ -723,7 +707,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * The inverse of `rightIfNotNull`, `rightIfNull`. * If the value is null it will be transformed to the specified `Either.right` and the type will be `Nothing?`. @@ -742,7 +726,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * ```kotlin * import arrow.core.rightIfNull @@ -755,7 +739,7 @@ import kotlin.jvm.JvmStatic * println(value) * } * ``` - * + * * * Arrow contains `Either` instances for many useful typeclasses that allows you to use and transform right values. * Option does not require a type parameter with the following functions, but it is specifically used for Either.Left @@ -814,7 +798,7 @@ public sealed class Either { * .fold({ -1 }, { fail("Cannot be right") }) shouldBe -1 * } * ``` - * + * * * * @param ifLeft transform the [Either.Left] type [A] to [C]. @@ -867,7 +851,7 @@ public sealed class Either { * Either.Right("right").swap() shouldBe Either.Left("right") * } * ``` - * + * * */ public fun swap(): Either = @@ -885,7 +869,7 @@ public sealed class Either { * Either.Left(12).map { _: Nothing -> "flower" } shouldBe Either.Left(12) * } * ``` - * + * * */ public inline fun map(f: (right: B) -> C): Either = @@ -903,7 +887,7 @@ public sealed class Either { * Either.Left(12).mapLeft { _: Int -> "flower" } shouldBe Either.Left("flower") * } * ``` - * + * * */ public inline fun mapLeft(f: (A) -> C): Either = @@ -935,7 +919,7 @@ public sealed class Either { * Either.Right(1).onRight(::println) shouldBe Either.Right(1) * } * ``` - * + * * */ public inline fun onRight(action: (right: B) -> Unit): Either = @@ -953,7 +937,7 @@ public sealed class Either { * Either.Left(2).onLeft(::println) shouldBe Either.Left(2) * } * ``` - * + * * */ public inline fun onLeft(action: (left: A) -> Unit): Either = @@ -986,7 +970,7 @@ public sealed class Either { * left.exists { it > 10 } // Result: false * } * ``` - * + * */ @Deprecated( NicheAPI + "Prefer when or fold instead", @@ -1033,7 +1017,7 @@ public sealed class Either { * Either.Left(12).getOrNull() shouldBe null * } * ``` - * + * * */ public fun getOrNull(): B? = getOrElse { null } @@ -1056,7 +1040,7 @@ public sealed class Either { * Either.Left(12).getOrNone() shouldBe None * } * ``` - * + * * */ public fun getOrNone(): Option = fold({ None }, { Some(it) }) @@ -1066,81 +1050,12 @@ public sealed class Either { ReplaceWith("if (n <= 0) Right(emptyList()) else map { b -> List(n) { b } }") ) public fun replicate(n: Int): Either> = - if (n <= 0) Right(emptyList()) else map { b -> List(n) { b } } - - @Deprecated( - NicheAPI + "Prefer using the Either DSL, or explicit fold or when", - ReplaceWith("fold({ emptyList() }, { fa(it).map(::Right) })") - ) - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Iterable): List> = - fold({ emptyList() }, { fa(it).map(::Right) }) - - @Deprecated( - NicheAPI + "Prefer using the Either DSL, or explicit fold or when", - ReplaceWith("fold({ None }, { right -> fa(right).map(::Right) })") - ) - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Option): Option> = - fold({ None }, { right -> fa(right).map(::Right) }) - - @Deprecated("traverseOption is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseOption(fa: (B) -> Option): Option> = - traverse(fa) - - @Deprecated( - RedundantAPI + "Use orNull() and Kotlin nullable types", - ReplaceWith("orNull()?.let(fa)?.right()") - ) - public inline fun traverseNullable(fa: (B) -> C?): Either? = - getOrNull()?.let(fa)?.right() - - // TODO will be renamed to mapAccumulating in 2.x.x. Backport, and deprecate in 1.x.x - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Validated): Validated> = - when (this) { - is Right -> fa(this.value).map(::Right) - is Left -> this.valid() + if (n <= 0) emptyList().right() + else when (this) { + is Left -> this + is Right -> List(n) { this.value }.right() } - @Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseValidated(fa: (B) -> Validated): Validated> = - traverse(fa) - - @Deprecated( - NicheAPI + "Prefer explicit fold instead", - ReplaceWith("fold({ fe(it).map { aa -> Left(aa) } }, { fa(it).map { c -> Right(c) } })") - ) - public inline fun bitraverse(fe: (A) -> Iterable, fa: (B) -> Iterable): List> = - fold({ fe(it).map { aa -> Left(aa) } }, { fa(it).map { c -> Right(c) } }) - - @Deprecated( - NicheAPI + "Prefer explicit fold instead", - ReplaceWith("fold({ fl(it).map(::Left) }, { fr(it).map(::Right) })") - ) - public inline fun bitraverseOption(fl: (A) -> Option, fr: (B) -> Option): Option> = - fold({ fl(it).map(::Left) }, { fr(it).map(::Right) }) - - @Deprecated( - NicheAPI + "Prefer explicit fold instead", - ReplaceWith("fold({ fl(it)?.let(::Left) }, { fr(it)?.let(::Right) })") - ) - public inline fun bitraverseNullable(fl: (A) -> AA?, fr: (B) -> C?): Either? = - fold({ fl(it)?.let(::Left) }, { fr(it)?.let(::Right) }) - - @Deprecated( - NicheAPI + "Prefer explicit fold instead", - ReplaceWith("fold({ fe(it).map { Left(it) } }, { fa(it).map { Right(it) } })") - ) - public inline fun bitraverseValidated( - fe: (A) -> Validated, - fa: (B) -> Validated, - ): Validated> = - fold({ fe(it).map { Left(it) } }, { fa(it).map { Right(it) } }) - @Deprecated( NicheAPI + "Prefer Kotlin nullable syntax instead", ReplaceWith("orNull()?.takeIf(predicate)") @@ -1161,7 +1076,7 @@ public sealed class Either { * Either.Right("foo").isEmpty() // Result: false * } * ``` - * + * */ @Deprecated( RedundantAPI + "Use `is Either.Left<*>`, `when`, or `fold` instead", @@ -1183,7 +1098,7 @@ public sealed class Either { * //sampleEnd * } * ``` - * + * */ @Deprecated( RedundantAPI + "Use `is Either.Right<*>`, `when`, or `fold` instead", @@ -1200,6 +1115,7 @@ public sealed class Either { ReplaceWith("(this is Either.Left<*>)") ) override val isLeft = true + @Deprecated( RedundantAPI + "Use `is Either.Right<*>`, `when`, or `fold` instead", ReplaceWith("(this is Either.Right<*>)") @@ -1224,6 +1140,7 @@ public sealed class Either { ReplaceWith("(this is Either.Left<*>)") ) override val isLeft = false + @Deprecated( RedundantAPI + "Use `is Either.Right<*>`, `when`, or `fold` instead", ReplaceWith("(this is Either.Right<*>)") @@ -1244,12 +1161,6 @@ public sealed class Either { { "Either.Right($it)" } ) - public fun toValidatedNel(): ValidatedNel = - fold({ Validated.invalidNel(it) }, ::Valid) - - public fun toValidated(): Validated = - fold({ it.invalid() }, { it.valid() }) - public companion object { @Deprecated( @@ -1331,9 +1242,9 @@ public sealed class Either { }.recover { t: Throwable -> throwable(t).bind() }.getOrElse { t: Throwable -> - unrecoverableState(t) - throw t - } + unrecoverableState(t) + throw t + } /** * Lifts a function `(B) -> C` to the [Either] structure returning a polymorphic function @@ -1351,7 +1262,7 @@ public sealed class Either { * println(result) * } * ``` - * + * */ @JvmStatic @Deprecated( @@ -1396,7 +1307,7 @@ public sealed class Either { * val b: Either = error.recover { error -> raise("other-failure") } // Either.Left(other-failure) * val c: Either = error.recover { error -> User } // Either.Right(User) * ``` - * + * */ public inline fun Either.recover(recover: Raise.(E) -> A): Either = when (this) { @@ -1434,7 +1345,7 @@ public fun Either>.flatten(): Either = * Left(12).getOrElse { 17 } // Result: 17 * } * ``` - * + * */ @Deprecated( RedundantAPI + "This API is overloaded with an API with a single argument", @@ -1456,7 +1367,7 @@ public inline fun Either<*, B>.getOrElse(default: () -> B): B = * Either.Left(12).getOrElse { it + 5 } shouldBe 17 * } * ``` - * + * * */ public inline fun Either.getOrElse(default: (A) -> B): B = @@ -1475,7 +1386,7 @@ public inline fun Either.getOrElse(default: (A) -> B): B = * Left(12).orNull() // Result: null * } * ``` - * + * */ @Deprecated( "Duplicated API. Please use Either's member function orNull. This will be removed towards Arrow 2.0", @@ -1498,7 +1409,7 @@ public fun Either<*, B>.orNull(): B? = * Left(12).getOrHandle { it + 5 } // Result: 17 * } * ``` - * + * */ @Deprecated( RedundantAPI + "Use other getOrElse signature", @@ -1530,7 +1441,7 @@ public inline fun Either.getOrHandle(default: (A) -> B): B = * left.filterOrElse({ it > 10 }, { -1 }) // Result: Left(12) * } * ``` - * + * */ @Deprecated( RedundantAPI + "Prefer if-else statement inside either DSL, or replace with explicit flatMap", @@ -1567,7 +1478,7 @@ public inline fun Either.filterOrElse(predicate: (B) -> Boolean, de * //sampleEnd * } * ``` - * + * */ @Deprecated( RedundantAPI + "Prefer if-else statement inside either DSL, or replace with explicit flatMap", @@ -1590,7 +1501,7 @@ public inline fun Either.filterOrOther(predicate: (B) -> Boolean, d * Left(12).merge() // Result: 12 * } * ``` - * + * * */ public inline fun Either.merge(): A = @@ -1616,7 +1527,7 @@ public inline fun Either.merge(): A = * Left(12).leftIfNull({ -1 }) // Result: Left(12) * } * ``` - * + * */ @Deprecated( RedundantAPI + "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit flatMap", @@ -1677,7 +1588,7 @@ public fun A.right(): Either = Right(this) * null.rightIfNotNull { "left" } // Left(a="left") * } * ``` - * + * */ @Deprecated( RedundantAPI + "Prefer Kotlin nullable syntax", @@ -1750,7 +1661,7 @@ public fun Iterable>.combineAll(MA: Monoid, MB: Monoid fold(Monoid.either(MA, MB)) /** - * Given [B] is a sub type of [C], re-type this value from Either to Either + * Given [B] is a subtype of [C], re-type this value from Either to Either * * ```kotlin * import arrow.core.* @@ -1764,7 +1675,7 @@ public fun Iterable>.combineAll(MA: Monoid, MB: Monoid * println(chars) * } * ``` - * + * */ public fun Either.widen(): Either = this @@ -1772,98 +1683,6 @@ public fun Either.widen(): Either = public fun Either.leftWiden(): Either = this -// TODO this will be completely breaking from 1.x.x -> 2.x.x. Only _real_ solution is `inline fun either { }` -public fun Either.zip(fb: Either, f: (B, C) -> D): Either = - either { f(bind(), fb.bind()) } - -public fun Either.zip(fb: Either): Either> = - either { Pair(bind(), fb.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - map: (B, C, D) -> E, -): Either = - either { map(bind(), c.bind(), d.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - e: Either, - map: (B, C, D, E) -> F, -): Either = - either { map(bind(), c.bind(), d.bind(), e.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - e: Either, - f: Either, - map: (B, C, D, E, F) -> G, -): Either = - either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - e: Either, - f: Either, - g: Either, - map: (B, C, D, E, F, G) -> H, -): Either = - either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - e: Either, - f: Either, - g: Either, - h: Either, - map: (B, C, D, E, F, G, H) -> I, -): Either = - either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - e: Either, - f: Either, - g: Either, - h: Either, - i: Either, - map: (B, C, D, E, F, G, H, I) -> J, -): Either = - either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - e: Either, - f: Either, - g: Either, - h: Either, - i: Either, - j: Either, - map: (B, C, D, E, F, G, H, I, J) -> K, -): Either = - either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind()) } - -public inline fun Either.zip( - c: Either, - d: Either, - e: Either, - f: Either, - g: Either, - h: Either, - i: Either, - j: Either, - k: Either, - map: (B, C, D, E, F, G, H, I, J, K) -> L -): Either = either { - map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind(), k.bind()) -} - @Deprecated( NicheAPI + "Prefer using the Either DSL, or map", ReplaceWith("if (n <= 0) Right(MB.empty()) else map { b -> List(n) { b }.fold(MB) }") @@ -1885,80 +1704,6 @@ public inline fun Either.ensure(error: () -> A, predicate: (B) -> B public inline fun Either.redeemWith(fa: (A) -> Either, fb: (B) -> Either): Either = fold(fa, fb) -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "fold({ emptyList() }, { iterable -> iterable.map { it.right() } })", - "arrow.core.right", - ) -) -public fun Either>.sequence(): List> = - fold({ emptyList() }, { iterable -> iterable.map { it.right() } }) - -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "fold({ emptyList() }, { iterable -> iterable.map { it.right() } })", - "arrow.core.right", - ) -) -public fun Either>.sequenceOption(): Option> = - sequence() - -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "orNull()?.orNull()?.right().toOption()", - "arrow.core.toOption", - "arrow.core.right", - "arrow.core.left" - ) -) -public fun Either>.sequence(): Option> = - getOrNull()?.orNull()?.right().toOption() - -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "fold({ it.left() }, { it.orNull()?.right() }).toOption()", - "arrow.core.toOption", - "arrow.core.right", - "arrow.core.left" - ) -) -public fun Either.sequenceNullable(): Either? = - sequence() - -@Deprecated( - "Prefer Kotlin nullable syntax", - ReplaceWith("orNull()?.right()", "arrow.core.right") -) -public fun Either.sequence(): Either? = - getOrNull()?.right() - -@Deprecated( - "sequenceValidated is being renamed to sequence to simplify the Arrow API", - ReplaceWith("sequence()", "arrow.core.sequence") -) -public fun Either>.sequenceValidated(): Validated> = - sequence() - -// TODO deprecate for mapAccumulating after back-port. -public fun Either>.sequence(): Validated> = - traverse(::identity) - -public fun Either, Iterable>.bisequence(): List> = - bitraverse(::identity, ::identity) - -public fun Either, Option>.bisequenceOption(): Option> = - bitraverseOption(::identity, ::identity) - -public fun Either.bisequenceNullable(): Either? = - bitraverseNullable(::identity, ::identity) - -public fun Either, Validated>.bisequenceValidated(): Validated> = - bitraverseValidated(::identity, ::identity) - public const val NicheAPI: String = "This API is niche and will be removed in the future. If this method is crucial for you, please let us know on the Arrow Github. Thanks!\n https://github.com/arrow-kt/arrow/issues\n" diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/EitherZip.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/EitherZip.kt new file mode 100644 index 00000000000..a9770ae8217 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/EitherZip.kt @@ -0,0 +1,382 @@ +@file:JvmMultifileClass +@file:JvmName("EitherKt") +package arrow.core + +import arrow.typeclasses.Semigroup +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName + +@PublishedApi +internal val unit: Either = Either.Right(Unit) + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + transform: (A, B) -> Z, +): Either = zip(combine, b, unit, unit, unit, unit, unit, unit, unit, unit) { a, bb, _, _, _, _, _, _, _, _ -> + transform(a, bb) +} + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + transform: (A, B, C) -> Z, +): Either = zip(combine, b, c, unit, unit, unit, unit, unit, unit, unit) { a, bb, cc, _, _, _, _, _, _, _ -> + transform(a, bb, cc) +} + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + d: Either, + transform: (A, B, C, D) -> Z, +): Either = zip(combine, b, c, d, unit, unit, unit, unit, unit, unit) { a, bb, cc, dd, _, _, _, _, _, _ -> + transform(a, bb, cc, dd) +} + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + d: Either, + e: Either, + transform: (A, B, C, D, EE) -> Z, +): Either = zip(combine, b, c, d, e, unit, unit, unit, unit, unit) { a, bb, cc, dd, ee, _, _, _, _, _ -> + transform(a, bb, cc, dd, ee) +} + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + transform: (A, B, C, D, EE, FF) -> Z, +): Either = zip(combine, b, c, d, e, f, unit, unit, unit, unit) { a, bb, cc, dd, ee, ff, _, _, _, _ -> + transform(a, bb, cc, dd, ee, ff) +} + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + transform: (A, B, C, D, EE, F, G) -> Z, +): Either = zip(combine, b, c, d, e, f, g, unit, unit, unit) { a, bb, cc, dd, ee, ff, gg, _, _, _ -> + transform(a, bb, cc, dd, ee, ff, gg) +} + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + h: Either, + transform: (A, B, C, D, EE, F, G, H) -> Z, +): Either = zip(combine, b, c, d, e, f, g, h, unit, unit) { a, bb, cc, dd, ee, ff, gg, hh, _, _ -> + transform(a, bb, cc, dd, ee, ff, gg, hh) +} + +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + h: Either, + i: Either, + transform: (A, B, C, D, EE, F, G, H, I) -> Z, +): Either = zip(combine, b, c, d, e, f, g, h, i, unit) { a, bb, cc, dd, ee, ff, gg, hh, ii, _ -> + transform(a, bb, cc, dd, ee, ff, gg, hh, ii) +} + +@Suppress("DuplicatedCode") +public inline fun Either.zip( + combine: Semigroup, + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + h: Either, + i: Either, + j: Either, + transform: (A, B, C, D, EE, F, G, H, I, J) -> Z, +): Either = + if (this is Either.Right && b is Either.Right && c is Either.Right && d is Either.Right && e is Either.Right && f is Either.Right && g is Either.Right && h is Either.Right && i is Either.Right && j is Either.Right) { + Either.Right(transform(this.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value, j.value)) + } else { + var accumulatedError: Any? = EmptyValue + accumulatedError = if (this@zip is Either.Left) this@zip.value else accumulatedError + accumulatedError = if (b is Either.Left) EmptyValue.combine(accumulatedError, b.value, combine) else accumulatedError + accumulatedError = if (c is Either.Left) EmptyValue.combine(accumulatedError, c.value, combine) else accumulatedError + accumulatedError = if (d is Either.Left) EmptyValue.combine(accumulatedError, d.value, combine) else accumulatedError + accumulatedError = if (e is Either.Left) EmptyValue.combine(accumulatedError, e.value, combine) else accumulatedError + accumulatedError = if (f is Either.Left) EmptyValue.combine(accumulatedError, f.value, combine) else accumulatedError + accumulatedError = if (g is Either.Left) EmptyValue.combine(accumulatedError, g.value, combine) else accumulatedError + accumulatedError = if (h is Either.Left) EmptyValue.combine(accumulatedError, h.value, combine) else accumulatedError + accumulatedError = if (i is Either.Left) EmptyValue.combine(accumulatedError, i.value, combine) else accumulatedError + accumulatedError = if (j is Either.Left) EmptyValue.combine(accumulatedError, j.value, combine) else accumulatedError + + @Suppress("UNCHECKED_CAST") + (Either.Left(accumulatedError as E)) + } + +public inline fun Either.zip( + b: Either, + transform: (A, B) -> Z, +): Either, Z> = zip(b, unit, unit, unit, unit, unit, unit, unit, unit) { a, bb, _, _, _, _, _, _, _, _ -> + transform(a, bb) +} + +public inline fun Either.zip( + b: Either, + c: Either, + transform: (A, B, C) -> Z, +): Either, Z> = zip(b, c, unit, unit, unit, unit, unit, unit, unit) { a, bb, cc, _, _, _, _, _, _, _ -> + transform(a, bb, cc) +} + +public inline fun Either.zip( + b: Either, + c: Either, + d: Either, + transform: (A, B, C, D) -> Z, +): Either, Z> = zip(b, c, d, unit, unit, unit, unit, unit, unit) { a, bb, cc, dd, _, _, _, _, _, _ -> + transform(a, bb, cc, dd) +} + +public inline fun Either.zip( + b: Either, + c: Either, + d: Either, + e: Either, + transform: (A, B, C, D, EE) -> Z, +): Either, Z> = zip(b, c, d, e, unit, unit, unit, unit, unit) { a, bb, cc, dd, ee, _, _, _, _, _ -> + transform(a, bb, cc, dd, ee) +} + +public inline fun Either.zip( + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + transform: (A, B, C, D, EE, FF) -> Z, +): Either, Z> = zip(b, c, d, e, f, unit, unit, unit, unit) { a, bb, cc, dd, ee, ff, _, _, _, _ -> + transform(a, bb, cc, dd, ee, ff) +} + +public inline fun Either.zip( + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + transform: (A, B, C, D, EE, F, G) -> Z, +): Either, Z> = zip(b, c, d, e, f, g, unit, unit, unit) { a, bb, cc, dd, ee, ff, gg, _, _, _ -> + transform(a, bb, cc, dd, ee, ff, gg) +} + +public inline fun Either.zip( + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + h: Either, + transform: (A, B, C, D, EE, F, G, H) -> Z, +): Either, Z> = zip(b, c, d, e, f, g, h, unit, unit) { a, bb, cc, dd, ee, ff, gg, hh, _, _ -> + transform(a, bb, cc, dd, ee, ff, gg, hh) +} + +public inline fun Either.zip( + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + h: Either, + i: Either, + transform: (A, B, C, D, EE, F, G, H, I) -> Z, +): Either, Z> = zip(b, c, d, e, f, g, h, i, unit) { a, bb, cc, dd, ee, ff, gg, hh, ii, _ -> + transform(a, bb, cc, dd, ee, ff, gg, hh, ii) +} + +@Suppress("DuplicatedCode") +public inline fun Either.zip( + b: Either, + c: Either, + d: Either, + e: Either, + f: Either, + g: Either, + h: Either, + i: Either, + j: Either, + transform: (A, B, C, D, EE, F, G, H, I, J) -> Z, +): Either, Z> = + if (this is Either.Right && b is Either.Right && c is Either.Right && d is Either.Right && e is Either.Right && f is Either.Right && g is Either.Right && h is Either.Right && i is Either.Right && j is Either.Right) { + Either.Right(transform(this.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value, j.value)) + } else { + val list = buildList(9) { + if (this@zip is Either.Left) add(this@zip.value) + if (b is Either.Left) add(b.value) + if (c is Either.Left) add(c.value) + if (d is Either.Left) add(d.value) + if (e is Either.Left) add(e.value) + if (f is Either.Left) add(f.value) + if (g is Either.Left) add(g.value) + if (h is Either.Left) add(h.value) + if (i is Either.Left) add(i.value) + if (j is Either.Left) add(j.value) + } + Either.Left(NonEmptyList(list[0], list.drop(1))) + } + +public typealias EitherNel = Either, A> + +public fun Either.toEitherNel(): EitherNel = + mapLeft { nonEmptyListOf(it) } + +public fun E.toEitherNel(): EitherNel = + nonEmptyListOf(this).left() + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + transform: (A, B) -> Z, +): EitherNel = zip(b, unit, unit, unit, unit, unit, unit, unit, unit) { a, bb, _, _, _, _, _, _, _, _ -> + transform(a, bb) +} + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + transform: (A, B, C) -> Z, +): EitherNel = zip(b, c, unit, unit, unit, unit, unit, unit, unit) { a, bb, cc, _, _, _, _, _, _, _ -> + transform(a, bb, cc) +} + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + d: EitherNel, + transform: (A, B, C, D) -> Z, +): EitherNel = zip(b, c, d, unit, unit, unit, unit, unit, unit) { a, bb, cc, dd, _, _, _, _, _, _ -> + transform(a, bb, cc, dd) +} + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + d: EitherNel, + e: EitherNel, + transform: (A, B, C, D, EE) -> Z, +): EitherNel = zip(b, c, d, e, unit, unit, unit, unit, unit) { a, bb, cc, dd, ee, _, _, _, _, _ -> + transform(a, bb, cc, dd, ee) +} + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + d: EitherNel, + e: EitherNel, + f: EitherNel, + transform: (A, B, C, D, EE, FF) -> Z, +): EitherNel = zip(b, c, d, e, f, unit, unit, unit, unit) { a, bb, cc, dd, ee, ff, _, _, _, _ -> + transform(a, bb, cc, dd, ee, ff) +} + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + d: EitherNel, + e: EitherNel, + f: EitherNel, + g: EitherNel, + transform: (A, B, C, D, EE, F, G) -> Z, +): EitherNel = zip(b, c, d, e, f, g, unit, unit, unit) { a, bb, cc, dd, ee, ff, gg, _, _, _ -> + transform(a, bb, cc, dd, ee, ff, gg) +} + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + d: EitherNel, + e: EitherNel, + f: EitherNel, + g: EitherNel, + h: EitherNel, + transform: (A, B, C, D, EE, F, G, H) -> Z, +): EitherNel = zip(b, c, d, e, f, g, h, unit, unit) { a, bb, cc, dd, ee, ff, gg, hh, _, _ -> + transform(a, bb, cc, dd, ee, ff, gg, hh) +} + +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + d: EitherNel, + e: EitherNel, + f: EitherNel, + g: EitherNel, + h: EitherNel, + i: EitherNel, + transform: (A, B, C, D, EE, F, G, H, I) -> Z, +): EitherNel = zip(b, c, d, e, f, g, h, i, unit) { a, bb, cc, dd, ee, ff, gg, hh, ii, _ -> + transform(a, bb, cc, dd, ee, ff, gg, hh, ii) +} + +@Suppress("DuplicatedCode") +@JvmName("zipNonEmptyList") +public inline fun EitherNel.zip( + b: EitherNel, + c: EitherNel, + d: EitherNel, + e: EitherNel, + f: EitherNel, + g: EitherNel, + h: EitherNel, + i: EitherNel, + j: EitherNel, + transform: (A, B, C, D, EE, F, G, H, I, J) -> Z, +): EitherNel = + if (this is Either.Right && b is Either.Right && c is Either.Right && d is Either.Right && e is Either.Right && f is Either.Right && g is Either.Right && h is Either.Right && i is Either.Right && j is Either.Right) { + Either.Right(transform(this.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value, j.value)) + } else { + val list = buildList { + if (this@zip is Either.Left) addAll(this@zip.value) + if (b is Either.Left) addAll(b.value) + if (c is Either.Left) addAll(c.value) + if (d is Either.Left) addAll(d.value) + if (e is Either.Left) addAll(e.value) + if (f is Either.Left) addAll(f.value) + if (g is Either.Left) addAll(g.value) + if (h is Either.Left) addAll(h.value) + if (i is Either.Left) addAll(i.value) + if (j is Either.Left) addAll(j.value) + } + Either.Left(NonEmptyList(list[0], list.drop(1))) + } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt index 9983e985121..233292c80aa 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt @@ -1,11 +1,9 @@ package arrow.core -import arrow.core.Ior.Both -import arrow.core.Ior.Left -import arrow.core.Ior.Right +import arrow.core.Ior.* +import arrow.core.Ior.Right.Companion.unit import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup -import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmStatic public typealias IorNel = Ior, B> @@ -30,7 +28,7 @@ public typealias IorNel = Ior, B> * The isomorphic Either form can be accessed via the [unwrap] method. */ public sealed class Ior { - + /** * Returns `true` if this is a [Right], `false` otherwise. * @@ -48,7 +46,7 @@ public sealed class Ior { * */ public abstract val isRight: Boolean - + /** * Returns `true` if this is a [Left], `false` otherwise. * @@ -63,10 +61,10 @@ public sealed class Ior { * Ior.Both("venus", "fly-trap").isLeft // Result: false * } * ``` - * + * */ public abstract val isLeft: Boolean - + /** * Returns `true` if this is a [Both], `false` otherwise. * @@ -80,10 +78,10 @@ public sealed class Ior { * Ior.Both("venus", "fly-trap").isBoth // Result: true * } * ``` - * + * */ public abstract val isBoth: Boolean - + public companion object { /** * Create an [Ior] from two nullables if at least one of them is defined. @@ -101,18 +99,19 @@ public sealed class Ior { true -> Both(a, b) false -> Left(a) } + false -> when (b != null) { true -> Right(b) false -> null } } - + @JvmStatic public fun leftNel(a: A): IorNel = Left(nonEmptyListOf(a)) - + @JvmStatic public fun bothNel(a: A, b: B): IorNel = Both(nonEmptyListOf(a), b) - + /** * Lifts a function `(B) -> C` to the [Ior] structure returning a polymorphic function * that can be applied over all [Ior] values in the shape of Ior @@ -133,12 +132,12 @@ public sealed class Ior { @JvmStatic public fun lift(f: (B) -> C): (Ior) -> Ior = { it.map(f) } - + @JvmStatic public fun lift(fa: (A) -> C, fb: (B) -> D): (Ior) -> Ior = { it.bimap(fa, fb) } } - + /** * Applies `fa` if this is a [Left], `fb` if this is a [Right] or `fab` if this is a [Both] * @@ -153,21 +152,21 @@ public sealed class Ior { is Right -> fb(value) is Both -> fab(leftValue, rightValue) } - + public inline fun foldLeft(c: C, f: (C, B) -> C): C = fold({ c }, { f(c, it) }, { _, b -> f(c, b) }) - + public inline fun foldMap(MN: Monoid, f: (B) -> C): C = MN.run { foldLeft(MN.empty()) { b, a -> b.combine(f(a)) } } - + public inline fun bifoldLeft(c: C, f: (C, A) -> C, g: (C, B) -> C): C = fold({ f(c, it) }, { g(c, it) }, { a, b -> g(f(c, a), b) }) - + public inline fun bifoldMap(MN: Monoid, f: (A) -> C, g: (B) -> C): C = MN.run { bifoldLeft(MN.empty(), { c, a -> c.combine(f(a)) }, { c, b -> c.combine(g(b)) }) } - + /** * The given function is applied if this is a [Right] or [Both] to `B`. * @@ -181,7 +180,7 @@ public sealed class Ior { * Ior.Both(12, "power").map { "flower $it" } // Result: Both(12, "flower power") * } * ``` - * + * */ public inline fun map(f: (B) -> D): Ior = when (this) { @@ -189,7 +188,7 @@ public sealed class Ior { is Right -> Right(f(value)) is Both -> Both(leftValue, f(rightValue)) } - + /** * Apply `fa` if this is a [Left] or [Both] to `A` * and apply `fb` if this is [Right] or [Both] to `B` @@ -204,14 +203,14 @@ public sealed class Ior { * Ior.Both(12, "power").bimap ({ it * 2 }, { b -> "flower $b" }) // Result: Both("flower power", 24) * } * ``` - * + * */ public inline fun bimap(fa: (A) -> C, fb: (B) -> D): Ior = fold( { Left(fa(it)) }, { Right(fb(it)) }, { a, b -> Both(fa(a), fb(b)) } ) - + /** * The given function is applied if this is a [Left] or [Both] to `A`. * @@ -232,7 +231,7 @@ public sealed class Ior { ::Right, { a, b -> Both(fa(a), b) } ) - + /** * If this is a [Left], then return the left value in [Right] or vice versa, * when this is [Both] , left and right values are swap @@ -247,14 +246,14 @@ public sealed class Ior { * Ior.Both("left", "right").swap() // Result: Both("right", "left") * } * ``` - * + * */ public fun swap(): Ior = fold( { Right(it) }, { Left(it) }, { a, b -> Both(b, a) } ) - + /** * Return the isomorphic [Either] of this [Ior] */ @@ -263,7 +262,7 @@ public sealed class Ior { { Either.Left(Either.Right(it)) }, { a, b -> Either.Right(Pair(a, b)) } ) - + /** * Return this [Ior] as [Pair] of nullables] * @@ -281,14 +280,14 @@ public sealed class Ior { * println("both = $both") * } * ``` - * + * */ public fun padNull(): Pair = fold( { Pair(it, null) }, { Pair(null, it) }, { a, b -> Pair(a, b) } ) - + /** * Returns a [Either.Right] containing the [Right] value or `B` if this is [Right] or [Both] * and [Either.Left] if this is a [Left]. @@ -303,11 +302,11 @@ public sealed class Ior { * Ior.Both("power", 12).toEither() // Result: Either.Right(12) * } * ``` - * + * */ public fun toEither(): Either = fold({ Either.Left(it) }, { Either.Right(it) }, { _, b -> Either.Right(b) }) - + /** * Returns the [Right] value or `B` if this is [Right] or [Both] * and [null] if this is a [Left]. @@ -326,11 +325,11 @@ public sealed class Ior { * println("both = $both") * } * ``` - * + * */ public fun orNull(): B? = fold({ null }, { it }, { _, b -> b }) - + /** * Returns the [Left] value or `A` if this is [Left] or [Both] * and [null] if this is a [Right]. @@ -348,170 +347,103 @@ public sealed class Ior { * println("both = $both") * } * ``` - * + * */ public fun leftOrNull(): A? = fold({ it }, { null }, { a, _ -> a }) - - /** - * Returns a [Validated.Valid] containing the [Right] value or `B` if this is [Right] or [Both] - * and [Validated.Invalid] if this is a [Left]. - * - * Example: - * ```kotlin - * import arrow.core.Ior - * - * fun main() { - * Ior.Right(12).toValidated() // Result: Valid(12) - * Ior.Left(12).toValidated() // Result: Invalid(12) - * Ior.Both(12, "power").toValidated() // Result: Valid("power") - * } - * ``` - * - */ - public fun toValidated(): Validated = - fold({ Invalid(it) }, { Valid(it) }, { _, b -> Valid(b) }) - + public data class Left(val value: A) : Ior() { override val isRight: Boolean get() = false override val isLeft: Boolean get() = true override val isBoth: Boolean get() = false - + override fun toString(): String = "Ior.Left($value)" - + public companion object } - + public data class Right(val value: B) : Ior() { override val isRight: Boolean get() = true override val isLeft: Boolean get() = false override val isBoth: Boolean get() = false - + override fun toString(): String = "Ior.Right($value)" - + public companion object { @PublishedApi internal val unit: Ior = Right(Unit) } } - + public data class Both(val leftValue: A, val rightValue: B) : Ior() { override val isRight: Boolean get() = false override val isLeft: Boolean get() = false override val isBoth: Boolean get() = true - + override fun toString(): String = "Ior.Both($leftValue, $rightValue)" } - + override fun toString(): String = fold( { "Ior.Left($it" }, { "Ior.Right($it)" }, { a, b -> "Ior.Both($a, $b)" } ) - + public inline fun bicrosswalk( fa: (A) -> Iterable, - fb: (B) -> Iterable + fb: (B) -> Iterable, ): List> = fold( { a -> fa(a).map { it.leftIor() } }, { b -> fb(b).map { it.rightIor() } }, { a, b -> fa(a).align(fb(b)) } ) - + public inline fun bicrosswalkMap( fa: (A) -> Map, - fb: (B) -> Map + fb: (B) -> Map, ): Map> = fold( { a -> fa(a).mapValues { it.value.leftIor() } }, { b -> fb(b).mapValues { it.value.rightIor() } }, { a, b -> fa(a).align(fb(b)) } ) - + public inline fun bicrosswalkNull( fa: (A) -> C?, - fb: (B) -> D? + fb: (B) -> D?, ): Ior? = fold( { a -> fa(a)?.let { Left(it) } }, { b -> fb(b)?.let { Right(it) } }, { a, b -> fromNullables(fa(a), fb(b)) } ) - - public inline fun bitraverse(fa: (A) -> Iterable, fb: (B) -> Iterable): List> = - fold( - { a -> fa(a).map { Left(it) } }, - { b -> fb(b).map { Right(it) } }, - { a, b -> fa(a).zip(fb(b)) { aa, c -> Both(aa, c) } } - ) - - public inline fun bitraverseEither( - fa: (A) -> Either, - fb: (B) -> Either - ): Either> = - fold( - { a -> fa(a).map { Left(it) } }, - { b -> fb(b).map { Right(it) } }, - { a, b -> fa(a).zip(fb(b)) { aa, c -> Both(aa, c) } } - ) - - public inline fun bitraverseOption( - fa: (A) -> Option, - fb: (B) -> Option - ): Option> = - fold( - { fa(it).map { Left(it) } }, - { fb(it).map { Right(it) } }, - { a, b -> fa(a).zip(fb(b)) { aa, c -> Both(aa, c) } } - ) - - public inline fun bitraverseNullable( - fa: (A) -> C?, - fb: (B) -> D? - ): Ior? = - fold( - { a -> fa(a)?.let { Left(it) } }, - { b -> fb(b)?.let { Right(it) } }, - { a, b -> Nullable.zip(fa(a), fb(b)) { aa, c -> Both(aa, c) } } - ) - - public inline fun bitraverseValidated( - SA: Semigroup, - fa: (A) -> Validated, - fb: (B) -> Validated - ): Validated> = - fold( - { a -> fa(a).map { Left(it) } }, - { b -> fb(b).map { Right(it) } }, - { a, b -> fa(a).zip(SA, fb(b)) { aa, c -> Both(aa, c) } } - ) - + public inline fun crosswalk(fa: (B) -> Iterable): List> = fold( { emptyList() }, { b -> fa(b).map { Right(it) } }, { a, b -> fa(b).map { Both(a, it) } } ) - + public inline fun crosswalkMap(fa: (B) -> Map): Map> = fold( { emptyMap() }, { b -> fa(b).mapValues { Right(it.value) } }, { a, b -> fa(b).mapValues { Both(a, it.value) } } ) - + public inline fun crosswalkNull(ior: Ior, fa: (B) -> C?): Ior? = ior.fold( { a -> Left(a) }, { b -> fa(b)?.let { Right(it) } }, { a, b -> fa(b)?.let { Both(a, it) } } ) - + public inline fun all(predicate: (B) -> Boolean): Boolean = fold({ true }, predicate, { _, b -> predicate(b) }) - + /** * Returns `false` if [Left] or returns the result of the application of * the given predicate to the [Right] value. @@ -528,77 +460,22 @@ public sealed class Ior { * left.exists { it > 10 } // Result: false * } * ``` - * + * */ public inline fun exists(predicate: (B) -> Boolean): Boolean = fold({ false }, predicate, { _, b -> predicate(b) }) - + public inline fun findOrNull(predicate: (B) -> Boolean): B? = when (this) { is Left -> null is Right -> if (predicate(this.value)) this.value else null is Both -> if (predicate(this.rightValue)) this.rightValue else null } - + public fun isEmpty(): Boolean = isLeft - + public fun isNotEmpty(): Boolean = !isLeft - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Iterable): List> = - fold( - { a -> listOf(Left(a)) }, - { b -> fa(b).map { Right(it) } }, - { a, b -> fa(b).map { Both(a, it) } } - ) - - @Deprecated("traverseEither is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseEither(fa: (B) -> Either): Either> = - traverse(fa) - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Either): Either> = - fold( - { a -> Either.Right(Left(a)) }, - { b -> fa(b).map { Right(it) } }, - { a, b -> fa(b).map { Both(a, it) } } - ) - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Option): Option> = - fold( - { a -> Some(Left(a)) }, - { b -> fa(b).map { Right(it) } }, - { a, b -> fa(b).map { Both(a, it) } } - ) - - @Deprecated("traverseOption is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseOption(fa: (B) -> Option): Option> = - traverse(fa) - - public inline fun traverseNullable(fa: (B) -> C?): Ior? = - fold( - { a -> Left(a) }, - { b -> fa(b)?.let { Right(it) } }, - { a, b -> fa(b)?.let { Both(a, it) } } - ) - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Validated): Validated> = - fold( - { a -> Valid(Left(a)) }, - { b -> fa(b).map { Right(it) } }, - { a, b -> fa(b).map { Both(a, it) } } - ) - - @Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseValidated(fa: (B) -> Validated): Validated> = - traverse(fa) - + public fun void(): Ior = map { Unit } } @@ -630,21 +507,6 @@ public fun A.leftIor(): Ior = Ior.Left(this) public fun A.rightIor(): Ior = Ior.Right(this) -public fun Ior, Iterable>.bisequence(): List> = - bitraverse(::identity, ::identity) - -public fun Ior, Either>.bisequenceEither(): Either> = - bitraverseEither(::identity, ::identity) - -public fun Ior, Option>.bisequenceOption(): Option> = - bitraverseOption(::identity, ::identity) - -public fun Ior.bisequenceNullable(): Ior? = - bitraverseNullable(::identity, ::identity) - -public fun Ior, Validated>.bisequenceValidated(SA: Semigroup): Validated> = - bitraverseValidated(SA, ::identity, ::identity) - public fun Ior.combine(SA: Semigroup, SB: Semigroup, other: Ior): Ior = with(SA) { with(SB) { @@ -654,11 +516,13 @@ public fun Ior.combine(SA: Semigroup, SB: Semigroup, other: I is Ior.Right -> Ior.Both(a.value, other.value) is Ior.Both -> Ior.Both(a.value + other.leftValue, other.rightValue) } + is Ior.Right -> when (other) { is Ior.Left -> Ior.Both(other.value, a.value) is Ior.Right -> Ior.Right(a.value + other.value) is Ior.Both -> Ior.Both(other.leftValue, a.value + other.rightValue) } + is Ior.Both -> when (other) { is Ior.Left -> Ior.Both(a.leftValue + other.value, a.rightValue) is Ior.Right -> Ior.Both(a.leftValue, a.rightValue + other.value) @@ -694,37 +558,6 @@ public fun Ior.replicate(SA: Semigroup, n: Int, MB: Monoid): ) } -public fun Ior>.sequence(): List> = - traverse(::identity) - -@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Ior>.sequenceEither(): Either> = - sequence() - -public fun Ior>.sequence(): Either> = - traverse(::identity) - -@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Ior>.sequenceOption(): Option> = - sequence() - -public fun Ior>.sequence(): Option> = - traverse(::identity) - -@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Ior.sequenceNullable(): Ior? = - sequence() - -public fun Ior.sequence(): Ior? = - traverseNullable(::identity) - -@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Ior>.sequenceValidated(): Validated> = - sequence() - -public fun Ior>.sequence(): Validated> = - traverse(::identity) - /** * Given [B] is a sub type of [C], re-type this value from Ior to Ior * @@ -740,7 +573,7 @@ public fun Ior>.sequence(): Validated> * println(chars) * } * ``` - * + * */ public fun Ior.widen(): Ior = this @@ -754,26 +587,28 @@ public fun Ior.zip(SA: Semigroup, fb: Ior): Ior Ior.zip( SA: Semigroup, c: Ior, - map: (B, C) -> D + map: (B, C) -> D, ): Ior = - zip(SA, c, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit) { b, c, _, _, _, _, _, _, _, _ -> map(b, c) } + zip(SA, c, unit, unit, unit, unit, unit, unit, unit, unit) { b, c, _, _, _, _, _, _, _, _ -> + map(b, c) + } public inline fun Ior.zip( SA: Semigroup, c: Ior, d: Ior, - map: (B, C, D) -> E + map: (B, C, D) -> E, ): Ior = - zip(SA, c, d, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit) { b, c, d, _, _, _, _, _, _, _ -> map(b, c, d) } + zip(SA, c, d, unit, unit, unit, unit, unit, unit, unit) { b, c, d, _, _, _, _, _, _, _ -> map(b, c, d) } public inline fun Ior.zip( SA: Semigroup, c: Ior, d: Ior, e: Ior, - map: (B, C, D, E) -> F + map: (B, C, D, E) -> F, ): Ior = - zip(SA, c, d, e, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit) { b, c, d, e, _, _, _, _, _, _ -> map(b, c, d, e) } + zip(SA, c, d, e, unit, unit, unit, unit, unit, unit) { b, c, d, e, _, _, _, _, _, _ -> map(b, c, d, e) } public inline fun Ior.zip( SA: Semigroup, @@ -781,9 +616,9 @@ public inline fun Ior.zip( d: Ior, e: Ior, f: Ior, - map: (B, C, D, E, F) -> G + map: (B, C, D, E, F) -> G, ): Ior = - zip(SA, c, d, e, f, Right.unit, Right.unit, Right.unit, Right.unit, Right.unit) { b, c, d, e, f, _, _, _, _, _ -> map(b, c, d, e, f) } + zip(SA, c, d, e, f, unit, unit, unit, unit, unit) { b, c, d, e, f, _, _, _, _, _ -> map(b, c, d, e, f) } public inline fun Ior.zip( SA: Semigroup, @@ -792,9 +627,9 @@ public inline fun Ior.zip( e: Ior, f: Ior, g: Ior, - map: (B, C, D, E, F, G) -> H + map: (B, C, D, E, F, G) -> H, ): Ior = - zip(SA, c, d, e, f, g, Right.unit, Right.unit, Right.unit, Right.unit) { b, c, d, e, f, g, _, _, _, _ -> map(b, c, d, e, f, g) } + zip(SA, c, d, e, f, g, unit, unit, unit, unit) { b, c, d, e, f, g, _, _, _, _ -> map(b, c, d, e, f, g) } public inline fun Ior.zip( SA: Semigroup, @@ -804,9 +639,9 @@ public inline fun Ior.zip( f: Ior, g: Ior, h: Ior, - map: (B, C, D, E, F, G, H) -> I + map: (B, C, D, E, F, G, H) -> I, ): Ior = - zip(SA, c, d, e, f, g, h, Right.unit, Right.unit, Right.unit) { b, c, d, e, f, g, h, _, _, _ -> map(b, c, d, e, f, g, h) } + zip(SA, c, d, e, f, g, h, unit, unit, unit) { b, c, d, e, f, g, h, _, _, _ -> map(b, c, d, e, f, g, h) } public inline fun Ior.zip( SA: Semigroup, @@ -817,9 +652,9 @@ public inline fun Ior.zip( g: Ior, h: Ior, i: Ior, - map: (B, C, D, E, F, G, H, I) -> J + map: (B, C, D, E, F, G, H, I) -> J, ): Ior = - zip(SA, c, d, e, f, g, h, i, Right.unit, Right.unit) { b, c, d, e, f, g, h, i, _, _ -> map(b, c, d, e, f, g, h, i) } + zip(SA, c, d, e, f, g, h, i, unit, unit) { b, c, d, e, f, g, h, i, _, _ -> map(b, c, d, e, f, g, h, i) } public inline fun Ior.zip( SA: Semigroup, @@ -831,9 +666,9 @@ public inline fun Ior.zip( h: Ior, i: Ior, j: Ior, - map: (B, C, D, E, F, G, H, I, J) -> K + map: (B, C, D, E, F, G, H, I, J) -> K, ): Ior = - zip(SA, c, d, e, f, g, h, i, j, Right.unit) { b, c, d, e, f, g, h, i, j, _ -> map(b, c, d, e, f, g, h, i, j) } + zip(SA, c, d, e, f, g, h, i, j, unit) { b, c, d, e, f, g, h, i, j, _ -> map(b, c, d, e, f, g, h, i, j) } public inline fun Ior.zip( SA: Semigroup, @@ -846,7 +681,7 @@ public inline fun Ior.zip( i: Ior, j: Ior, k: Ior, - map: (B, C, D, E, F, G, H, I, J, K) -> L + map: (B, C, D, E, F, G, H, I, J, K) -> L, ): Ior { // If any of the values is Right or Both then we can calculate L otherwise it results in MY_NULL val rightValue: Any? = if ( @@ -874,44 +709,44 @@ public inline fun Ior.zip( k.orNull() as K ) } else EmptyValue - + val leftValue: Any? = SA.run { var accumulatedLeft: Any? = EmptyValue - + if (this@zip is Left) return@zip Left(this@zip.value) accumulatedLeft = if (this@zip is Both) this@zip.leftValue else accumulatedLeft - + if (c is Left) return@zip Left(emptyCombine(accumulatedLeft, c.value)) accumulatedLeft = if (c is Both) emptyCombine(accumulatedLeft, c.leftValue) else accumulatedLeft - + if (d is Left) return@zip Left(emptyCombine(accumulatedLeft, d.value)) accumulatedLeft = if (d is Both) emptyCombine(accumulatedLeft, d.leftValue) else accumulatedLeft - + if (e is Left) return@zip Left(emptyCombine(accumulatedLeft, e.value)) accumulatedLeft = if (e is Both) emptyCombine(accumulatedLeft, e.leftValue) else accumulatedLeft - + if (f is Left) return@zip Left(emptyCombine(accumulatedLeft, f.value)) accumulatedLeft = if (f is Both) emptyCombine(accumulatedLeft, f.leftValue) else accumulatedLeft - + if (g is Left) return@zip Left(emptyCombine(accumulatedLeft, g.value)) accumulatedLeft = if (g is Both) emptyCombine(accumulatedLeft, g.leftValue) else accumulatedLeft - + if (h is Left) return@zip Left(emptyCombine(accumulatedLeft, h.value)) accumulatedLeft = if (h is Both) emptyCombine(accumulatedLeft, h.leftValue) else accumulatedLeft - + if (i is Left) return@zip Left(emptyCombine(accumulatedLeft, i.value)) accumulatedLeft = if (i is Both) emptyCombine(accumulatedLeft, i.leftValue) else accumulatedLeft - + if (j is Left) return@zip Left(emptyCombine(accumulatedLeft, j.value)) accumulatedLeft = if (j is Both) emptyCombine(accumulatedLeft, j.leftValue) else accumulatedLeft - + if (k is Left) return@zip Left(emptyCombine(accumulatedLeft, k.value)) accumulatedLeft = if (k is Both) emptyCombine(accumulatedLeft, k.leftValue) else accumulatedLeft - + accumulatedLeft } - + return when { rightValue != EmptyValue && leftValue == EmptyValue -> Right(rightValue as L) rightValue != EmptyValue && leftValue != EmptyValue -> Both(leftValue as A, rightValue as L) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt index c3bd1d2f16d..2326ace09bf 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt @@ -4,9 +4,10 @@ package arrow.core import arrow.core.Either.Left import arrow.core.Either.Right +import arrow.core.continuations.Raise +import arrow.core.continuations.either import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup -import kotlin.Result.Companion.success import kotlin.experimental.ExperimentalTypeInference public inline fun Iterable.zip( @@ -283,154 +284,57 @@ public inline fun Iterable.zip( internal fun Iterable.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default -@Deprecated("traverseEither is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) -public inline fun Iterable.traverseEither(f: (A) -> Either): Either> = - traverse(f) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> Either): Either> { - val destination = ArrayList(collectionSizeOrDefault(10)) - for (item in this) { - when (val res = f(item)) { - is Right -> destination.add(res.value) - is Left -> return res - } - } - return destination.right() -} - -@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Iterable>.sequenceEither(): Either> = - traverse(::identity) - -public fun Iterable>.sequence(): Either> = - traverse(::identity) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> Result): Result> { - val destination = ArrayList(collectionSizeOrDefault(10)) - for (item in this) { - f(item).fold(destination::add) { throwable -> - return@traverse Result.failure(throwable) - } - } - return success(destination) -} - -@Deprecated("traverseResult is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) -public inline fun Iterable.traverseResult(f: (A) -> Result): Result> = - traverse(f) - -@Deprecated("sequenceResult is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Iterable>.sequenceResult(): Result> = - sequence() - -public fun Iterable>.sequence(): Result> = - traverse(::identity) - -@Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(semigroup, f)", "arrow.core.traverse")) -public inline fun Iterable.traverseValidated( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - traverse(semigroup, f) - +/** + * Returns [Either] a [List] containing the results of applying the given [transform] function + * to each element in the original collection, + * **or** accumulate all the _logical errors_ that were _raised_ while transforming the collection. + * The [semigroup] is used to accumulate all the _logical errors_. + */ @OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - semigroup.run { - fold(Valid(ArrayList(collectionSizeOrDefault(10))) as Validated>) { acc, a -> - when (val res = f(a)) { - is Validated.Valid -> when (acc) { - is Valid -> acc.also { it.value.add(res.value) } - is Invalid -> acc - } - is Validated.Invalid -> when (acc) { - is Valid -> res - is Invalid -> Invalid(acc.value.combine(res.value)) - } +public inline fun Iterable.mapOrAccumulate( + semigroup: Semigroup, + @BuilderInference transform: Raise.(A) -> B, +): Either> = + fold>>(Right(ArrayList(collectionSizeOrDefault(10)))) { acc, a -> + when (val res = either { transform(a) }) { + is Right -> when (acc) { + is Right -> acc.also { acc.value.add(res.value) } + is Left -> acc + } + + is Left -> when (acc) { + is Right -> res + is Left -> Left(semigroup.append(acc.value, res.value)) } } } -@Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) -public inline fun Iterable.traverseValidated(f: (A) -> ValidatedNel): ValidatedNel> = - traverse(f) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> ValidatedNel): ValidatedNel> = - traverse(Semigroup.nonEmptyList(), f) - -@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence(semigroup)", "arrow.core.sequence")) -public fun Iterable>.sequenceValidated(semigroup: Semigroup): Validated> = - sequence(semigroup) - -public fun Iterable>.sequence(semigroup: Semigroup): Validated> = - traverse(semigroup, ::identity) - -@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Iterable>.sequenceValidated(): ValidatedNel> = - sequence() - -public fun Iterable>.sequence(): ValidatedNel> = - traverse(Semigroup.nonEmptyList(), ::identity) - -@Deprecated("traverseOption is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) -public inline fun Iterable.traverseOption(f: (A) -> Option): Option> = - traverse(f) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> Option): Option> { - val destination = ArrayList(collectionSizeOrDefault(10)) - for (item in this) { - when (val res = f(item)) { - is Some -> destination.add(res.value) - is None -> return res - } - } - return destination.some() -} - -@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Iterable>.sequenceOption(): Option> = - sequence() - -public fun Iterable>.sequence(): Option> = - traverse(::identity) - -@Deprecated("traverseNullable is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) -public inline fun Iterable.traverseNullable(f: (A) -> B?): List? = - traverse(f) - +/** + * Returns [Either] a [List] containing the results of applying the given [transform] function + * to each element in the original collection, + * **or** accumulate all the _logical errors_ into a [NonEmptyList] that were _raised_ while applying the [transform] function. + */ @OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> B?): List? { - val acc = mutableListOf() - forEach { a -> - val res = f(a) - if (res != null) { - acc.add(res) - } else { - return res +public inline fun Iterable.mapOrAccumulate( + @BuilderInference transform: Raise.(A) -> B, +): Either, List> { + val buffer = mutableListOf() + val res = fold, ArrayList>>(Right(ArrayList(collectionSizeOrDefault(10)))) { acc, a -> + when (val res = either { transform(a) }) { + is Right -> when (acc) { + is Right -> acc.also { acc.value.add(res.value) } + is Left -> acc + } + + is Left -> when (acc) { + is Right -> Left(buffer.also { it.add(res.value) }) + is Left -> Left(buffer.also { it.add(res.value) }) + } } } - return acc.toList() + return res.mapLeft { NonEmptyList(it[0], it.drop(1)) } } -@Deprecated("sequenceNullable is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Iterable.sequenceNullable(): List? = - sequence() - -public fun Iterable.sequence(): List? = - traverse(::identity) - public fun Iterable.void(): List = map { } @@ -665,11 +569,11 @@ private fun alignRec(ls: Iterable, rs: Iterable): List> { } /** - * aligns two structures and combine them with the given [Semigroup.combine] + * aligns two structures and combine them with the given [Semigroup.append] */ public fun Iterable.salign( SG: Semigroup, - other: Iterable + other: Iterable, ): Iterable = SG.run { align(other) { it.fold(::identity, ::identity) { a, b -> @@ -783,6 +687,7 @@ public fun Iterable.firstOrNone(): Option = } else { None } + else -> { iterator().nextOrNone() } @@ -816,6 +721,7 @@ public fun Iterable.singleOrNone(): Option = 1 -> firstOrNone() else -> None } + else -> { iterator().run { nextOrNone().filter { !hasNext() } } } @@ -847,6 +753,7 @@ public fun Iterable.lastOrNone(): Option = } else { None } + else -> iterator().run { if (hasNext()) { var last: T @@ -881,6 +788,7 @@ public fun Iterable.elementAtOrNone(index: Int): Option = in indices -> Some(elementAt(index)) else -> None } + else -> iterator().skip(index).nextOrNone() } @@ -890,6 +798,7 @@ private tailrec fun Iterator.skip(count: Int): Iterator = next() skip(count - 1) } + else -> this } @@ -987,48 +896,25 @@ public inline fun Iterable.ifThen(fb: Iterable, ffa: (A) -> Iterabl public fun Iterable>.uniteEither(): List = mapNotNull { it.orNull() } -@Deprecated("Use mapNotNull and orNull instead.", ReplaceWith("mapNotNull { it.orNull() }", "arrow.core.orNull")) -public fun Iterable>.uniteValidated(): List = - mapNotNull { it.orNull() } - /** * Separate the inner [Either] values into the [Either.Left] and [Either.Right]. * - * @receiver Iterable of Validated + * @receiver Iterable of Either * @return a tuple containing List with [Either.Left] and another List with its [Either.Right] values. */ public fun Iterable>.separateEither(): Pair, List> { val left = ArrayList(collectionSizeOrDefault(10)) val right = ArrayList(collectionSizeOrDefault(10)) - + for (either in this) when (either) { is Left -> left.add(either.value) is Right -> right.add(either.value) } - + return Pair(left, right) } -/** - * Separate the inner [Validated] values into the [Validated.Invalid] and [Validated.Valid]. - * - * @receiver Iterable of Validated - * @return a tuple containing List with [Validated.Invalid] and another List with its [Validated.Valid] values. - */ -public fun Iterable>.separateValidated(): Pair, List> { - val invalids = ArrayList(collectionSizeOrDefault(10)) - val valids = ArrayList(collectionSizeOrDefault(10)) - - for (validated in this) - when (validated) { - is Invalid -> invalids.add(validated.value) - is Valid -> valids.add(validated.value) - } - - return Pair(invalids, valids) -} - public fun Iterable>.flatten(): List = flatMap(::identity) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index 41ea03aced8..4f10a35ba14 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -1,9 +1,6 @@ package arrow.core -import arrow.core.Either.Left -import arrow.core.Either.Right import arrow.typeclasses.Semigroup -import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmStatic public typealias Nel = NonEmptyList @@ -409,98 +406,6 @@ public fun NonEmptyList.unzip(f: (C) -> Pair): Pair NonEmptyList.traverseEither(f: (A) -> Either): Either> = - traverse(f) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun NonEmptyList.traverse(f: (A) -> Either): Either> = - f(head).map { newHead -> - val acc = mutableListOf() - tail.forEach { a -> - when (val res = f(a)) { - is Right -> acc.add(res.value) - is Left -> return@traverse res - } - } - NonEmptyList(newHead, acc) - } - -@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun NonEmptyList>.sequenceEither(): Either> = - sequence() - -public fun NonEmptyList>.sequence(): Either> = - traverse(::identity) - -@Deprecated( - "traverseValidated is being renamed to traverse to simplify the Arrow API", - ReplaceWith("traverse(semigroup, f)", "arrow.core.traverse") -) -public inline fun NonEmptyList.traverseValidated( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - traverse(semigroup, f) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun NonEmptyList.traverse( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - fold>>(mutableListOf().valid()) { acc, a -> - when (val res = f(a)) { - is Valid -> when (acc) { - is Valid -> acc.also { it.value.add(res.value) } - is Invalid -> acc - } - is Invalid -> when (acc) { - is Valid -> res - is Invalid -> semigroup.run { Invalid(acc.value.combine(res.value)) } - } - } - }.map { requireNotNull(it.toNonEmptyListOrNull()) } - -@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun NonEmptyList>.sequenceValidated(semigroup: Semigroup): Validated> = - sequence(semigroup) - -public fun NonEmptyList>.sequence(semigroup: Semigroup): Validated> = - traverse(semigroup, ::identity) - -@Deprecated( - "traverseOption is being renamed to traverse to simplify the Arrow API", - ReplaceWith("traverse(f)", "arrow.core.traverse") -) -public inline fun NonEmptyList.traverseOption(f: (A) -> Option): Option> = - traverse(f) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun NonEmptyList.traverse(f: (A) -> Option): Option> = - f(head).map { newHead -> - val acc = mutableListOf() - tail.forEach { a -> - when (val res = f(a)) { - is Some -> acc.add(res.value) - is None -> return@traverse res - } - } - NonEmptyList(newHead, acc) - } - -@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun NonEmptyList>.sequenceOption(): Option> = - sequence() - -public fun NonEmptyList>.sequence(): Option> = - traverse(::identity) - public fun Iterable.toNonEmptyListOrNull(): NonEmptyList? = firstOrNull()?.let { NonEmptyList(it, drop(1)) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 0c86bd2ccbe..6fe6dbaaf87 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -1,9 +1,7 @@ package arrow.core -import arrow.core.Either.Right import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup -import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic @@ -813,35 +811,6 @@ public sealed class Option { public fun replicate(n: Int): Option> = if (n <= 0) Some(emptyList()) else map { a -> List(n) { a } } - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (A) -> Iterable): List> = - fold({ emptyList() }, { a -> fa(a).map { Some(it) } }) - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (A) -> Either): Either> = - when (this) { - is Some -> fa(value).map { Some(it) } - is None -> Right(this) - } - - @Deprecated("traverseEither is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseEither(fa: (A) -> Either): Either> = - traverse(fa) - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (A) -> Validated): Validated> = - when (this) { - is Some -> fa(value).map { Some(it) } - is None -> Valid(this) - } - - @Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseValidated(fa: (A) -> Validated): Validated> = - traverse(fa) - public inline fun toEither(ifEmpty: () -> L): Either = fold({ ifEmpty().left() }, { it.right() }) @@ -991,35 +960,6 @@ public fun Option>.separateEither(): Pair, Option< return asep to bsep } -/** - * Separate the inner [Validated] value into the [Validated.Invalid] and [Validated.Valid]. - * - * @receiver Option of Either - * @return a tuple containing Option of [Validated.Invalid] and another Option of its [Validated.Valid] value. - */ -public fun Option>.separateValidated(): Pair, Option> { - val asep = flatMap { gab -> gab.fold({ Some(it) }, { None }) } - val bsep = flatMap { gab -> gab.fold({ None }, { Some(it) }) } - return asep to bsep -} - -public fun Option>.sequence(): List> = - traverse(::identity) - -@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Option>.sequenceEither(): Either> = - sequence() - -public fun Option>.sequence(): Either> = - traverse(::identity) - -@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Option>.sequenceValidated(): Validated> = - sequence() - -public fun Option>.sequence(): Validated> = - traverse(::identity) - public fun Option>.unalign(): Pair, Option> = unalign(::identity) @@ -1043,11 +983,6 @@ public fun Option>.uniteEither(): Option = either.fold({ None }, { b -> Some(b) }) } -public fun Option>.uniteValidated(): Option = - flatMap { validated -> - validated.fold({ None }, { b -> Some(b) }) - } - public fun Option>.unzip(): Pair, Option> = unzip(::identity) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt index 7f67780684d..fc2ffe650b8 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt @@ -4,7 +4,6 @@ import arrow.core.Either.Left import arrow.core.Either.Right import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup -import kotlin.experimental.ExperimentalTypeInference public fun Sequence.zip( c: Sequence, @@ -574,7 +573,7 @@ public fun Sequence.rightPadZip(other: Sequence): Sequence a to b } /** - * aligns two structures and combine them with the given [Semigroup.combine] + * aligns two structures and combine them with the given [Semigroup.append] */ public fun Sequence.salign( SG: Semigroup, @@ -590,7 +589,7 @@ public fun Sequence.salign( /** * Separate the inner [Either] values into the [Either.Left] and [Either.Right]. * - * @receiver Iterable of Validated + * @receiver Iterable of Either * @return a tuple containing Sequence with [Either.Left] and another Sequence with its [Either.Right] values. */ public fun Sequence>.separateEither(): Pair, Sequence> = @@ -601,49 +600,6 @@ public fun Sequence>.separateEither(): Pair, Seq } } -/** - * Separate the inner [Validated] values into the [Validated.Invalid] and [Validated.Valid]. - * - * @receiver Iterable of Validated - * @return a tuple containing Sequence with [Validated.Invalid] and another Sequence with its [Validated.Valid] values. - */ -public fun Sequence>.separateValidated(): Pair, Sequence> = - fold(sequenceOf() to sequenceOf()) { (invalids, valids), validated -> - when (validated) { - is Valid -> invalids to valids + validated.value - is Invalid -> invalids + validated.value to valids - } - } - -public fun Sequence>.sequence(): Either> = - traverse(::identity) - -@Deprecated( - "sequenceEither is being renamed to sequence to simplify the Arrow API", - ReplaceWith("sequence().map { it.asSequence() }", "arrow.core.sequence") -) -public fun Sequence>.sequenceEither(): Either> = - sequence().map { it.asSequence() } - -public fun Sequence>.sequence(): Option> = - traverse(::identity) - -@Deprecated( - "sequenceOption is being renamed to sequence to simplify the Arrow API", - ReplaceWith("sequence().map { it.asSequence() }", "arrow.core.sequence") -) -public fun Sequence>.sequenceOption(): Option> = - sequence().map { it.asSequence() } - -public fun Sequence>.sequence(semigroup: Semigroup): Validated> = - traverse(semigroup, ::identity) - -@Deprecated( - "sequenceValidated is being renamed to sequence to simplify the Arrow API", - ReplaceWith("sequence(semigroup).map { it.asSequence() }", "arrow.core.sequence") -) -public fun Sequence>.sequenceValidated(semigroup: Semigroup): Validated> = - sequence(semigroup).map { it.asSequence() } @Deprecated("some is being deprecated in favor of map", ReplaceWith("map { generateSequence { this } }")) public fun Sequence.some(): Sequence> = @@ -673,81 +629,6 @@ public fun Sequence.split(): Pair, A>? = public fun Sequence.tail(): Sequence = drop(1) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public fun Sequence.traverse(f: (A) -> Either): Either> { - // Note: Using a mutable list here avoids the stackoverflows one can accidentally create when using - // Sequence.plus instead. But we don't convert the sequence to a list beforehand to avoid - // forcing too much of the sequence to be evaluated. - val acc = mutableListOf() - forEach { a -> - when (val res = f(a)) { - is Right -> acc.add(res.value) - is Left -> return@traverse res - } - } - return acc.toList().right() -} - -@Deprecated( - "traverseEither is being renamed to traverse to simplify the Arrow API", - ReplaceWith("traverse(f).map { it.asSequence() }", "arrow.core.traverse") -) -public fun Sequence.traverseEither(f: (A) -> Either): Either> = - traverse(f).map { it.asSequence() } - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public fun Sequence.traverse(f: (A) -> Option): Option> { - // Note: Using a mutable list here avoids the stackoverflows one can accidentally create when using - // Sequence.plus instead. But we don't convert the sequence to a list beforehand to avoid - // forcing too much of the sequence to be evaluated. - val acc = mutableListOf() - forEach { a -> - when (val res = f(a)) { - is Some -> acc.add(res.value) - is None -> return@traverse res - } - } - return Some(acc) -} - -@Deprecated( - "traverseOption is being renamed to traverse to simplify the Arrow API", - ReplaceWith("traverse(f).map { it.asSequence() }", "arrow.core.traverse") -) -public fun Sequence.traverseOption(f: (A) -> Option): Option> = - traverse(f).map { it.asSequence() } - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public fun Sequence.traverse( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - fold(mutableListOf().valid() as Validated>) { acc, a -> - when (val res = f(a)) { - is Valid -> when (acc) { - is Valid -> acc.also { it.value.add(res.value) } - is Invalid -> acc - } - is Invalid -> when (acc) { - is Valid -> res - is Invalid -> semigroup.run { acc.value.combine(res.value).invalid() } - } - } - } - -@Deprecated( - "traverseValidated is being renamed to traverse to simplify the Arrow API", - ReplaceWith("traverse(semigroup, f).map { it.asSequence() }", "arrow.core.traverse") -) -public fun Sequence.traverseValidated( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - traverse(semigroup, f).map { it.asSequence() } - /** * splits an union into its component parts. * @@ -798,11 +679,6 @@ public fun Sequence>.uniteEither(): Sequence = either.fold({ emptySequence() }, { b -> sequenceOf(b) }) } -public fun Sequence>.uniteValidated(): Sequence = - flatMap { validated -> - validated.fold({ emptySequence() }, { b -> sequenceOf(b) }) - } - /** * Fair conjunction. Similarly to interleave * diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt deleted file mode 100644 index cf668335f19..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt +++ /dev/null @@ -1,856 +0,0 @@ -package arrow.core - -import arrow.typeclasses.Monoid -import arrow.typeclasses.Semigroup -import arrow.core.Either.Left -import arrow.core.Either.Right -import kotlin.experimental.ExperimentalTypeInference -import kotlin.jvm.JvmName -import kotlin.jvm.JvmStatic - -public typealias ValidatedNel = Validated, A> -public typealias Valid = Validated.Valid -public typealias Invalid = Validated.Invalid - -public sealed class Validated { - - public companion object { - - @JvmStatic - public fun invalidNel(e: E): ValidatedNel = Invalid(nonEmptyListOf(e)) - - @JvmStatic - public fun validNel(a: A): ValidatedNel = Valid(a) - - /** - * Converts an `Either` to a `Validated`. - */ - @JvmStatic - public fun fromEither(e: Either): Validated = e.fold({ Invalid(it) }, { Valid(it) }) - - /** - * Converts an `Option` to a `Validated`, where the provided `ifNone` output value is returned as [Invalid] - * when the specified `Option` is `None`. - */ - @JvmStatic - public inline fun fromOption(o: Option, ifNone: () -> E): Validated = - o.fold( - { Invalid(ifNone()) }, - { Valid(it) } - ) - - /** - * Converts a nullable `A?` to a `Validated`, where the provided `ifNull` output value is returned as [Invalid] - * when the specified value is null. - */ - @JvmStatic - public inline fun fromNullable(value: A?, ifNull: () -> E): Validated = - value?.let(::Valid) ?: Invalid(ifNull()) - - @JvmStatic - @JvmName("tryCatch") - public inline fun catch(f: () -> A): Validated = - try { - f().valid() - } catch (e: Throwable) { - e.nonFatalOrThrow().invalid() - } - - @JvmStatic - @JvmName("tryCatch") - public inline fun catch(recover: (Throwable) -> E, f: () -> A): Validated = - catch(f).mapLeft(recover) - - @JvmStatic - public inline fun catchNel(f: () -> A): ValidatedNel = - try { - f().validNel() - } catch (e: Throwable) { - e.nonFatalOrThrow().invalidNel() - } - - @JvmStatic - public inline fun lift(crossinline f: (A) -> B): (Validated) -> Validated = - { fa -> fa.map(f) } - - /** - * Lifts two functions to the Bifunctor type. - * - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * //sampleStart - * val f = Validated.lift(String::toUpperCase, Int::inc) - * val res1 = f("test".invalid()) - * val res2 = f(1.valid()) - * //sampleEnd - * println("res1: $res1") - * println("res2: $res2") - * } - * ``` - * - */ - @JvmStatic - public inline fun lift( - crossinline fl: (A) -> C, - crossinline fr: (B) -> D - ): (Validated) -> Validated = - { fa -> fa.bimap(fl, fr) } - } - - /** - * Discards the [A] value inside [Validated] signaling this container may be pointing to a noop - * or an effect whose return value is deliberately ignored. The singleton value [Unit] serves as signal. - * - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * val result = - * //sampleStart - * "Hello World".valid().void() - * //sampleEnd - * println(result) - * } - * ``` - * - */ - public fun void(): Validated = - map { Unit } - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (A) -> Iterable): List> = - fold({ emptyList() }, { a -> fa(a).map { Valid(it) } }) - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (A) -> Either): Either> = - when (this) { - is Valid -> fa(this.value).map { Valid(it) } - is Invalid -> this.right() - } - - @Deprecated("traverseEither is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseEither(fa: (A) -> Either): Either> = - traverse(fa) - - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (A) -> Option): Option> = - when (this) { - is Valid -> fa(this.value).map { Valid(it) } - is Invalid -> None - } - - @Deprecated("traverseOption is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseOption(fa: (A) -> Option): Option> = - traverse(fa) - - public inline fun traverseNullable(fa: (A) -> B?): Validated? = - when (this) { - is Valid -> fa(this.value)?.let { Valid(it) } - is Invalid -> null - } - - public inline fun bifoldLeft( - c: B, - fe: (B, E) -> B, - fa: (B, A) -> B - ): B = - fold({ fe(c, it) }, { fa(c, it) }) - - public inline fun bifoldMap(MN: Monoid, g: (E) -> B, f: (A) -> B): B = MN.run { - bifoldLeft(MN.empty(), { c, b -> c.combine(g(b)) }) { c, a -> c.combine(f(a)) } - } - - public inline fun bitraverse(fe: (E) -> Iterable, fa: (A) -> Iterable): List> = - fold({ fe(it).map { Invalid(it) } }, { fa(it).map { Valid(it) } }) - - public inline fun bitraverseEither( - fe: (E) -> Either, - fa: (A) -> Either - ): Either> = - fold({ fe(it).map { Invalid(it) } }, { fa(it).map { Valid(it) } }) - - public inline fun bitraverseOption( - fe: (E) -> Option, - fa: (A) -> Option - ): Option> = - fold({ fe(it).map(::Invalid) }, { fa(it).map(::Valid) }) - - public inline fun bitraverseNullable( - fe: (E) -> B?, - fa: (A) -> C? - ): Validated? = - fold({ fe(it)?.let(::Invalid) }, { fa(it)?.let(::Valid) }) - - public inline fun foldMap(MB: Monoid, f: (A) -> B): B = - fold({ MB.empty() }, f) - - override fun toString(): String = fold( - { "Validated.Invalid($it)" }, - { "Validated.Valid($it)" } - ) - - public data class Valid(val value: A) : Validated() { - override fun toString(): String = "Validated.Valid($value)" - - public companion object { - @PublishedApi - internal val unit: Validated = - Validated.Valid(Unit) - } - } - - public data class Invalid(val value: E) : Validated() { - override fun toString(): String = "Validated.Invalid($value)" - } - - public inline fun fold(fe: (E) -> B, fa: (A) -> B): B = - when (this) { - is Valid -> fa(value) - is Invalid -> (fe(value)) - } - - public val isValid: Boolean = - fold({ false }, { true }) - public val isInvalid: Boolean = - fold({ true }, { false }) - - /** - * Is this Valid and matching the given predicate - */ - public inline fun exist(predicate: (A) -> Boolean): Boolean = - fold({ false }, predicate) - - public inline fun findOrNull(predicate: (A) -> Boolean): A? = - when (this) { - is Valid -> if (predicate(this.value)) this.value else null - is Invalid -> null - } - - public inline fun all(predicate: (A) -> Boolean): Boolean = - fold({ true }, predicate) - - public fun isEmpty(): Boolean = isInvalid - - public fun isNotEmpty(): Boolean = isValid - - /** - * Converts the value to an Either - */ - public fun toEither(): Either = - fold(::Left, ::Right) - - /** - * Returns Valid values wrapped in Some, and None for Invalid values - */ - public fun toOption(): Option = - fold({ None }, ::Some) - - /** - * Convert this value to a single element List if it is Valid, - * otherwise return an empty List - */ - public fun toList(): List = - fold({ listOf() }, ::listOf) - - /** Lift the Invalid value into a NonEmptyList. */ - public fun toValidatedNel(): ValidatedNel = - fold({ invalidNel(it) }, ::Valid) - - /** - * Convert to an Either, apply a function, convert back. This is handy - * when you want to use the Monadic properties of the Either type. - */ - public inline fun withEither(f: (Either) -> Either): Validated = - fromEither(f(toEither())) - - /** - * From [arrow.typeclasses.Bifunctor], maps both types of this Validated. - * - * Apply a function to an Invalid or Valid value, returning a new Invalid or Valid value respectively. - */ - public inline fun bimap(fe: (E) -> EE, fa: (A) -> B): Validated = - fold({ Invalid(fe(it)) }, { Valid(fa(it)) }) - - /** - * Apply a function to a Valid value, returning a new Valid value - */ - public inline fun map(f: (A) -> B): Validated = - bimap(::identity, f) - - /** - * Apply a function to an Invalid value, returning a new Invalid value. - * Or, if the original valid was Valid, return it. - */ - public inline fun mapLeft(f: (E) -> EE): Validated = - bimap(f, ::identity) - - /** - * The given function is applied as a fire and forget effect - * if this is `Invalid`. - * When applied the result is ignored and the original - * Validated value is returned - * - * Example: - * ```kotlin - * import arrow.core.Validated - * - * fun main() { - * Validated.Valid(12).tapInvalid { println("flower") } // Result: Valid(12) - * Validated.Invalid(12).tapInvalid { println("flower") } // Result: prints "flower" and returns: Invalid(12) - * } - * ``` - * - */ - public inline fun tapInvalid(f: (E) -> Unit): Validated = - when (this) { - is Invalid -> { - f(this.value) - this - } - is Valid -> this - } - - /** - * The given function is applied as a fire and forget effect - * if this is `Valid`. - * When applied the result is ignored and the original - * Validated value is returned - * - * Example: - * ```kotlin - * import arrow.core.Validated - * - * fun main() { - * Validated.Valid(12).tap { println("flower") } // Result: prints "flower" and returns: Valid(12) - * Validated.Invalid(12).tap { println("flower") } // Result: Invalid(12) - * } - * ``` - * - */ - public inline fun tap(f: (A) -> Unit): Validated = - when (this) { - is Invalid -> this - is Valid -> { - f(this.value) - this - } - } - - /** - * apply the given function to the value with the given B when - * valid, otherwise return the given B - */ - public inline fun foldLeft(b: B, f: (B, A) -> B): B = - fold({ b }, { f(b, it) }) - - public fun swap(): Validated = - fold(::Valid, ::Invalid) -} - -public fun Validated.zip(SE: Semigroup, fb: Validated): Validated> = - zip(SE, fb, ::Pair) - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - f: (A, B) -> Z -): Validated = - zip( - SE, - b, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit - ) { a, b, _, _, _, _, _, _, _, _ -> - f(a, b) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - f: (A, B, C) -> Z -): Validated = - zip( - SE, - b, - c, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit - ) { a, b, c, _, _, _, _, _, _, _ -> - f(a, b, c) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - d: Validated, - f: (A, B, C, D) -> Z -): Validated = - zip( - SE, - b, - c, - d, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit - ) { a, b, c, d, _, _, _, _, _, _ -> - f(a, b, c, d) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - d: Validated, - e: Validated, - f: (A, B, C, D, EE) -> Z -): Validated = - zip( - SE, - b, - c, - d, - e, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit - ) { a, b, c, d, e, _, _, _, _, _ -> - f(a, b, c, d, e) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - d: Validated, - e: Validated, - ff: Validated, - f: (A, B, C, D, EE, FF) -> Z -): Validated = - zip( - SE, - b, - c, - d, - e, - ff, - Valid.unit, - Valid.unit, - Valid.unit, - Valid.unit - ) { a, b, c, d, e, ff, _, _, _, _ -> - f(a, b, c, d, e, ff) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - d: Validated, - e: Validated, - ff: Validated, - g: Validated, - f: (A, B, C, D, EE, F, G) -> Z -): Validated = - zip(SE, b, c, d, e, ff, g, Valid.unit, Valid.unit, Valid.unit) { a, b, c, d, e, ff, g, _, _, _ -> - f(a, b, c, d, e, ff, g) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - d: Validated, - e: Validated, - ff: Validated, - g: Validated, - h: Validated, - f: (A, B, C, D, EE, F, G, H) -> Z -): Validated = - zip(SE, b, c, d, e, ff, g, h, Valid.unit, Valid.unit) { a, b, c, d, e, ff, g, h, _, _ -> - f(a, b, c, d, e, ff, g, h) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - d: Validated, - e: Validated, - ff: Validated, - g: Validated, - h: Validated, - i: Validated, - f: (A, B, C, D, EE, F, G, H, I) -> Z -): Validated = - zip(SE, b, c, d, e, ff, g, h, i, Valid.unit) { a, b, c, d, e, ff, g, h, i, _ -> - f(a, b, c, d, e, ff, g, h, i) - } - -public inline fun Validated.zip( - SE: Semigroup, - b: Validated, - c: Validated, - d: Validated, - e: Validated, - ff: Validated, - g: Validated, - h: Validated, - i: Validated, - j: Validated, - f: (A, B, C, D, EE, F, G, H, I, J) -> Z -): Validated = - if (this is Validated.Valid && b is Validated.Valid && c is Validated.Valid && d is Validated.Valid && e is Validated.Valid && ff is Validated.Valid && g is Validated.Valid && h is Validated.Valid && i is Validated.Valid && j is Validated.Valid) { - Validated.Valid(f(this.value, b.value, c.value, d.value, e.value, ff.value, g.value, h.value, i.value, j.value)) - } else SE.run { - var accumulatedError: Any? = EmptyValue - accumulatedError = - if (this@zip is Validated.Invalid) this@zip.value else accumulatedError - accumulatedError = - if (b is Validated.Invalid) emptyCombine(accumulatedError, b.value) else accumulatedError - accumulatedError = - if (c is Validated.Invalid) emptyCombine(accumulatedError, c.value) else accumulatedError - accumulatedError = - if (d is Validated.Invalid) emptyCombine(accumulatedError, d.value) else accumulatedError - accumulatedError = - if (e is Validated.Invalid) emptyCombine(accumulatedError, e.value) else accumulatedError - accumulatedError = - if (ff is Validated.Invalid) emptyCombine(accumulatedError, ff.value) else accumulatedError - accumulatedError = - if (g is Validated.Invalid) emptyCombine(accumulatedError, g.value) else accumulatedError - accumulatedError = - if (h is Validated.Invalid) emptyCombine(accumulatedError, h.value) else accumulatedError - accumulatedError = - if (i is Validated.Invalid) emptyCombine(accumulatedError, i.value) else accumulatedError - accumulatedError = - if (j is Validated.Invalid) emptyCombine(accumulatedError, j.value) else accumulatedError - - Validated.Invalid(accumulatedError as E) - } - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - f: (A, B) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - f: (A, B, C) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - d: ValidatedNel, - f: (A, B, C, D) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, d, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - d: ValidatedNel, - e: ValidatedNel, - f: (A, B, C, D, EE) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, d, e, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - d: ValidatedNel, - e: ValidatedNel, - ff: ValidatedNel, - f: (A, B, C, D, EE, FF) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, d, e, ff, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - d: ValidatedNel, - e: ValidatedNel, - ff: ValidatedNel, - g: ValidatedNel, - f: (A, B, C, D, EE, F, G) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, d, e, ff, g, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - d: ValidatedNel, - e: ValidatedNel, - ff: ValidatedNel, - g: ValidatedNel, - h: ValidatedNel, - f: (A, B, C, D, EE, F, G, H) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, d, e, ff, g, h, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - d: ValidatedNel, - e: ValidatedNel, - ff: ValidatedNel, - g: ValidatedNel, - h: ValidatedNel, - i: ValidatedNel, - f: (A, B, C, D, EE, F, G, H, I) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, d, e, ff, g, h, i, f) - -public inline fun ValidatedNel.zip( - b: ValidatedNel, - c: ValidatedNel, - d: ValidatedNel, - e: ValidatedNel, - ff: ValidatedNel, - g: ValidatedNel, - h: ValidatedNel, - i: ValidatedNel, - j: ValidatedNel, - f: (A, B, C, D, EE, F, G, H, I, J) -> Z -): ValidatedNel = - zip(Semigroup.nonEmptyList(), b, c, d, e, ff, g, h, i, j, f) - -/** - * Given [A] is a sub type of [B], re-type this value from Validated to Validated - * - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * //sampleStart - * val string: Validated = "Hello".valid() - * val chars: Validated = - * string.widen() - * //sampleEnd - * println(chars) - * } - * ``` - * - */ -public fun Validated.widen(): Validated = - this - -public fun Validated.leftWiden(): Validated = - this - -public fun Validated.replicate(SE: Semigroup, n: Int): Validated> = - if (n <= 0) emptyList().valid() - else this.zip(SE, replicate(SE, n - 1)) { a, xs -> listOf(a) + xs } - -public fun Validated.replicate(SE: Semigroup, n: Int, MA: Monoid): Validated = - if (n <= 0) MA.empty().valid() - else this@replicate.zip(SE, replicate(SE, n - 1, MA)) { a, xs -> MA.run { a + xs } } - -public fun Validated, Iterable>.bisequence(): List> = - bitraverse(::identity, ::identity) - -public fun Validated, Either>.bisequenceEither(): Either> = - bitraverseEither(::identity, ::identity) - -public fun Validated, Option>.bisequenceOption(): Option> = - bitraverseOption(::identity, ::identity) - -public fun Validated.bisequenceNullable(): Validated? = - bitraverseNullable(::identity, ::identity) - -public fun Validated.fold(MA: Monoid): A = MA.run { - foldLeft(empty()) { acc, a -> acc.combine(a) } -} - -@Deprecated("use fold instead", ReplaceWith("fold(MA)", "arrow.core.fold")) -public fun Validated.combineAll(MA: Monoid): A = - fold(MA) - -public fun Validated>.sequence(): List> = - traverse(::identity) - -@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Validated>.sequenceEither(): Either> = - sequence() - -public fun Validated>.sequence(): Either> = - traverse(::identity) - -@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Validated>.sequenceOption(): Option> = - sequence() - -public fun Validated>.sequence(): Option> = - traverse(::identity) - -@Deprecated("sequenceNullable is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Validated.sequenceNullable(): Validated? = - sequence() - -public fun Validated.sequence(): Validated? = - traverseNullable(::identity) - -public operator fun , A : Comparable> Validated.compareTo(other: Validated): Int = - fold( - { l1 -> other.fold({ l2 -> l1.compareTo(l2) }, { -1 }) }, - { r1 -> other.fold({ 1 }, { r2 -> r1.compareTo(r2) }) } - ) - -/** - * Return the Valid value, or the default if Invalid - */ -public inline fun Validated.getOrElse(default: () -> A): A = - fold({ default() }, ::identity) - -/** - * Return the Valid value, or null if Invalid - */ -public fun Validated.orNull(): A? = - getOrElse { null } - -public fun Validated.orNone(): Option = - fold({ None }, { Some(it) }) - -/** - * Return the Valid value, or the result of f if Invalid - */ -public inline fun Validated.valueOr(f: (E) -> A): A = - fold({ f(it) }, ::identity) - -/** - * If `this` is valid return `this`, otherwise if `that` is valid return `that`, otherwise combine the failures. - * This is similar to [orElse] except that here failures are accumulated. - */ -public inline fun Validated.findValid(SE: Semigroup, that: () -> Validated): Validated = - fold( - { e -> - that().fold( - { ee -> Invalid(SE.run { e.combine(ee) }) }, - { Valid(it) } - ) - }, - { Valid(it) } - ) - -/** - * Apply a function to a Valid value, returning a new Validation that may be valid or invalid - * - * Example: - * ```kotlin - * import arrow.core.Validated - * import arrow.core.andThen - * - * fun main() { - * Validated.Valid(5).andThen { Validated.Valid(10) } // Result: Valid(10) - * Validated.Valid(5).andThen { Validated.Invalid(10) } // Result: Invalid(10) - * Validated.Invalid(5).andThen { Validated.Valid(10) } // Result: Invalid(5) - * } - * ``` - * - */ -public inline fun Validated.andThen(f: (A) -> Validated): Validated = - when (this) { - is Validated.Valid -> f(value) - is Validated.Invalid -> this - } - -/** - * Return this if it is Valid, or else fall back to the given default. - * The functionality is similar to that of [findValid] except for failure accumulation, - * where here only the error on the right is preserved and the error on the left is ignored. - */ -public inline fun Validated.orElse(default: () -> Validated): Validated = - fold( - { default() }, - { Valid(it) } - ) - -public inline fun Validated.handleErrorWith(f: (E) -> Validated): Validated = - when (this) { - is Validated.Valid -> this - is Validated.Invalid -> f(this.value) - } - -public inline fun Validated.handleError(f: (E) -> A): Validated = - when (this) { - is Validated.Valid -> this - is Validated.Invalid -> Valid(f(this.value)) - } - -public inline fun Validated.redeem(fe: (E) -> B, fa: (A) -> B): Validated = - when (this) { - is Validated.Valid -> map(fa) - is Validated.Invalid -> Valid(fe(this.value)) - } - -public fun Validated.attempt(): Validated> = - map { Right(it) }.handleError { Left(it) } - -public inline fun Validated.merge(): A = - fold(::identity, ::identity) - -public fun Validated.combine( - SE: Semigroup, - SA: Semigroup, - y: Validated -): Validated = - when { - this is Valid && y is Valid -> Valid(SA.run { value.combine(y.value) }) - this is Invalid && y is Invalid -> Invalid(SE.run { value.combine(y.value) }) - this is Invalid -> this - else -> y - } - -public fun Validated.combineK(SE: Semigroup, y: Validated): Validated { - return when (this) { - is Valid -> this - is Invalid -> when (y) { - is Invalid -> Invalid(SE.run { this@combineK.value.combine(y.value) }) - is Valid -> y - } - } -} - -/** - * Converts the value to an Ior - */ -public fun Validated.toIor(): Ior = - fold({ Ior.Left(it) }, { Ior.Right(it) }) - -public inline fun A.valid(): Validated = - Valid(this) - -public inline fun E.invalid(): Validated = - Invalid(this) - -public inline fun A.validNel(): ValidatedNel = - Validated.validNel(this) - -public inline fun E.invalidNel(): ValidatedNel = - Validated.invalidNel(this) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt index ffeaccf5db9..4939b08d7ad 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt @@ -3,7 +3,6 @@ package arrow.core.computations import arrow.continuations.Effect import arrow.core.Either import arrow.core.Either.Left -import arrow.core.Validated import arrow.core.identity import arrow.core.left import arrow.core.right @@ -20,12 +19,6 @@ public fun interface EitherEffect : Effect> { is Left -> control().shift(this@bind) } - public suspend fun Validated.bind(): B = - when (this) { - is Validated.Valid -> value - is Validated.Invalid -> control().shift(Left(value)) - } - public suspend fun Result.bind(transform: (Throwable) -> E): B = fold(::identity) { throwable -> control().shift(transform(throwable).left()) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt index 68061797952..f2893377b91 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt @@ -1,7 +1,6 @@ package arrow.core.computations import arrow.core.Either -import arrow.core.Validated import arrow.core.identity /** @@ -18,43 +17,39 @@ public object ResultEffect { public fun Either.bind(): A = fold({ throw it }, ::identity) - @Deprecated("$deprecatedInFavorOfEagerEffectScope\nThis object introduces dangerous behavior and will be removed in the next version: https://github.com/arrow-kt/arrow/issues/2547") - public fun Validated.bind(): A = - fold({ throw it }, ::identity) -} - -@Deprecated(deprecateInFavorOfEffectOrEagerEffect, ReplaceWith("result", "arrow.core.continuations.result")) -@Suppress("ClassName") -public object result { + @Deprecated(deprecateInFavorOfEffectOrEagerEffect, ReplaceWith("result", "arrow.core.continuations.result")) + @Suppress("ClassName") + public object result { - /** - * Provides a computation block for [Result] which is build on top of Kotlin's Result Std operations. - * - * ```kotlin - * import arrow.core.* - * import arrow.core.computations.result - * - * fun main() { - * result { // We can safely use assertion based operation inside blocks - * kotlin.require(false) { "Boom" } - * } // Result.Failure(IllegalArgumentException("Boom")) - * - * result { - * Result.failure(RuntimeException("Boom")) - * .recover { 1 } - * .bind() - * } // Result.Success(1) - * - * result { - * val x = Result.success(1).bind() - * val y = Result.success(x + 1).bind() - * x + y - * } // Result.Success(3) - * } - * ``` - * - */ - @Deprecated(deprecateInFavorOfEffect, ReplaceWith("result.eager(block)", "arrow.core.continuations.result")) - public inline operator fun invoke(block: ResultEffect.() -> A): Result = - kotlin.runCatching { block(ResultEffect) } + /** + * Provides a computation block for [Result] which is build on top of Kotlin's Result Std operations. + * + * ```kotlin + * import arrow.core.* + * import arrow.core.computations.ResultEffect.result + * + * fun main() { + * result { // We can safely use assertion based operation inside blocks + * kotlin.require(false) { "Boom" } + * } // Result.Failure(IllegalArgumentException("Boom")) + * + * result { + * Result.failure(RuntimeException("Boom")) + * .recover { 1 } + * .bind() + * } // Result.Success(1) + * + * result { + * val x = Result.success(1).bind() + * val y = Result.success(x + 1).bind() + * x + y + * } // Result.Success(3) + * } + * ``` + * + */ + @Deprecated(deprecateInFavorOfEffect, ReplaceWith("result.eager(block)", "arrow.core.continuations.result")) + public inline operator fun invoke(block: ResultEffect.() -> A): Result = + kotlin.runCatching { block(ResultEffect) } + } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/EagerEffect.kt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt index 3130b5cd28c..915179cc561 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt @@ -21,7 +21,7 @@ import kotlin.jvm.JvmMultifileClass * [Structured Concurrency](#structured-concurrency) * [Arrow Fx Coroutines](#arrow-fx-coroutines) * [parZip](#parzip) - * [parTraverse](#partraverse) + * [parMap](#parmap) * [raceN](#racen) * [bracketCase / Resource](#bracketcase--resource) * [KotlinX](#kotlinx) @@ -78,12 +78,10 @@ import kotlin.jvm.JvmMultifileClass * import arrow.core.Either * import arrow.core.Ior * import arrow.core.None - * import arrow.core.Validated * import arrow.core.continuations.Effect * import arrow.core.continuations.effect * import arrow.core.continuations.fold * import arrow.core.continuations.toEither - * import arrow.core.continuations.toValidated * import arrow.core.continuations.toIor * import arrow.core.continuations.toOption * import arrow.core.continuations.ensureNotNull @@ -134,7 +132,6 @@ import kotlin.jvm.JvmMultifileClass * ```kotlin * suspend fun main() { * readFile("").toEither() shouldBe Either.Left(EmptyPath) - * readFile("knit.properties").toValidated() shouldBe Validated.Invalid(FileNotFound("knit.properties")) * readFile("gradle.properties").toIor() shouldBe Ior.Left(FileNotFound("gradle.properties")) * readFile("README.MD").toOption { None } shouldBe None * @@ -362,7 +359,7 @@ import kotlin.jvm.JvmMultifileClass * ``` * * - * #### parTraverse + * #### parMap * * - * `parTraverse` will launch 5 tasks, for every element in `1..5`. + * `parMap` will launch 5 tasks, for every element in `1..5`. * The last task to get scheduled will `raise` with "error", and it will cancel the other launched tasks before returning. * * #### raceN diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt index 19bd59d0fd9..3d816c315dd 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Mappers.kt @@ -8,7 +8,6 @@ import arrow.core.Ior import arrow.core.None import arrow.core.Option import arrow.core.Some -import arrow.core.Validated import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -16,10 +15,6 @@ import kotlin.jvm.JvmName public suspend fun Effect.toEither(): Either = either { invoke() } public fun EagerEffect.toEither(): Either = either { invoke() } -/** Run the [Effect] by returning [Validated.Valid] of [A], or [Validated.Invalid] of [E]. */ -public suspend fun Effect.toValidated(): Validated = fold({ Validated.Invalid(it) }) { Validated.Valid(it) } -public fun EagerEffect.toValidated(): Validated = fold({ Validated.Invalid(it) }) { Validated.Valid(it) } - /** Run the [Effect] by returning [Ior.Right] of [A], or [Ior.Left] of [E]. */ public suspend fun Effect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } public fun EagerEffect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt index e72e8e5df3b..999d6f995d6 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Raise.kt @@ -6,7 +6,6 @@ import arrow.core.Either import arrow.core.None import arrow.core.Option import arrow.core.Some -import arrow.core.Validated import arrow.core.identity import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @@ -106,12 +105,6 @@ public interface Raise { is Either.Right -> value } - /* Will be removed in subsequent PRs for Arrow 2.x.x */ - public fun Validated.bind(): A = when (this) { - is Validated.Invalid -> raise(value) - is Validated.Valid -> value - } - /** * Extract the [Result.success] value out of [Result], * because [Result] works with [Throwable] as its error type you need to [transform] [Throwable] to [R]. diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt index 1265ec598c6..2dadbc549a7 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt @@ -1,10 +1,7 @@ package arrow.core -import arrow.core.Either.Left -import arrow.core.Either.Right import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup -import kotlin.experimental.ExperimentalTypeInference import kotlin.collections.flatMap as _flatMap /** @@ -235,85 +232,6 @@ public fun Map.flatMap(f: (Map.Entry) -> Map): Map Map.traverse(f: (A) -> Either): Either> { - val acc = mutableMapOf() - forEach { (k, v) -> - when (val res = f(v)) { - is Right -> acc[k] = res.value - is Left -> return@traverse res - } - } - return acc.right() -} - -@Deprecated("traverseEither is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) -public inline fun Map.traverseEither(f: (A) -> Either): Either> = - traverse(f) - -public fun Map>.sequence(): Either> = - traverse(::identity) - -@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Map>.sequenceEither(): Either> = - sequence() - -@Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(semigroup, f)", "arrow.core.traverse")) -public inline fun Map.traverseValidated( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - traverse(semigroup, f) - -public inline fun Map.traverse( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - foldLeft(mutableMapOf().valid() as Validated>) { acc, (k, v) -> - when (val res = f(v)) { - is Valid -> when (acc) { - is Valid -> acc.also { it.value[k] = res.value } - is Invalid -> acc - } - is Invalid -> when (acc) { - is Valid -> res - is Invalid -> semigroup.run { acc.value.combine(res.value).invalid() } - } - } - } - -@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence(semigroup)", "arrow.core.sequence")) -public fun Map>.sequenceValidated(semigroup: Semigroup): Validated> = - sequence(semigroup) - -public fun Map>.sequence(semigroup: Semigroup): Validated> = - traverse(semigroup, ::identity) - -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Map.traverse(f: (A) -> Option): Option> { - val acc = mutableMapOf() - forEach { (k, v) -> - when (val res = f(v)) { - is Some -> acc[k] = res.value - is None -> return@traverse res - } - } - return acc.some() -} - -@Deprecated("traverseOption is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) -public inline fun Map.traverseOption(f: (A) -> Option): Option> = - traverse(f) - -@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) -public fun Map>.sequenceOption(): Option> = - sequence() - -public fun Map>.sequence(): Option> = - traverse(::identity) - public fun Map.void(): Map = mapValues { Unit } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt index dfb8be55ccc..f1f1ceb2a6e 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt @@ -13,8 +13,11 @@ public inline fun identity(a: A): A = a @PublishedApi internal object EmptyValue { @Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE") - public inline fun unbox(value: Any?): A = + inline fun unbox(value: Any?): A = if (value === this) null as A else value as A + + inline fun combine(first: Any?, second: T, s: Semigroup): T = + if (first === EmptyValue) second else s.append(first as T, second) } /** @@ -22,4 +25,5 @@ internal object EmptyValue { */ @PublishedApi internal fun Semigroup.emptyCombine(first: Any?, second: T): T = - if (first == EmptyValue) second else (first as T).combine(second) + if (first === EmptyValue) second else (first as T).combine(second) + diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt index 6b88f4152c7..f875cf919e1 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt @@ -5,7 +5,6 @@ import arrow.core.Either import arrow.core.Endo import arrow.core.None import arrow.core.Option -import arrow.core.Validated import arrow.core.combine import arrow.core.compose import arrow.core.flatten @@ -83,7 +82,7 @@ public interface Monoid : Semigroup { public fun endo(): Monoid> = object : Monoid> { override fun empty(): Endo = Endo(::identity) - override fun Endo.combine(g: Endo): Endo = Endo(f.compose(g.f)) + override fun append(a: Endo, b: Endo): Endo = Endo(a.f.compose(b.f)) } @JvmStatic @@ -91,7 +90,8 @@ public interface Monoid : Semigroup { public fun const(MA: Monoid): Monoid> = object : Monoid> { override fun empty(): Const = Const(MA.empty()) - override fun Const.combine(b: Const): Const = this.combine(MA, b) + override fun append(a: Const, b: Const): Const = + a.combine(MA, b) } @JvmStatic @@ -102,31 +102,17 @@ public interface Monoid : Semigroup { public fun option(MA: Semigroup): Monoid> = OptionMonoid(MA) - @JvmStatic - public fun validated(SE: Semigroup, MA: Monoid): Monoid> = - ValidatedMonoid(SE, MA) - @JvmStatic public fun pair(MA: Monoid, MB: Monoid): Monoid> = PairMonoid(MA, MB) - private class ValidatedMonoid( - private val SA: Semigroup, - private val MB: Monoid - ) : Monoid> { - private val empty = Validated.Valid(MB.empty()) - override fun empty(): Validated = empty - override fun Validated.combine(b: Validated): Validated = - combine(SA, MB, b) - } - private class OptionMonoid( private val MA: Semigroup ) : Monoid> { - - override fun Option.combine(b: Option): Option = - combine(MA, b) - + + override fun append(a: Option, b: Option): Option = + a.combine(MA, b) + override fun Option.maybeCombine(b: Option?): Option = b?.let { combine(MA, it) } ?: this @@ -135,59 +121,59 @@ public interface Monoid : Semigroup { private class MapMonoid(private val SG: Semigroup) : Monoid> { override fun empty(): Map = emptyMap() - - override fun Map.combine(b: Map): Map = - combine(SG, b) + + override fun append(a: Map, b: Map): Map = + a.combine(SG, b) } private object AndMonoid : Monoid { - override fun Boolean.combine(b: Boolean): Boolean = this && b + override fun append(a: Boolean, b: Boolean): Boolean = a && b override fun empty(): Boolean = true } private object ByteMonoid : Monoid { override fun empty(): Byte = 0 - override fun Byte.combine(b: Byte): Byte = (this + b).toByte() + override fun append(a: Byte, b: Byte): Byte = (a + b).toByte() } private object DoubleMonoid : Monoid { override fun empty(): Double = .0 - override fun Double.combine(b: Double): Double = this + b + override fun append(a: Double, b: Double): Double = a + b } private object IntMonoid : Monoid { override fun empty(): Int = 0 - override fun Int.combine(b: Int): Int = this + b + override fun append(a: Int, b: Int): Int = a + b } private object LongMonoid : Monoid { override fun empty(): Long = 0L - override fun Long.combine(b: Long): Long = this + b + override fun append(a: Long, b: Long): Long = a + b } private object ShortMonoid : Monoid { override fun empty(): Short = 0 - override fun Short.combine(b: Short): Short = (this + b).toShort() + override fun append(a: Short, b: Short): Short = (a + b).toShort() } private object FloatMonoid : Monoid { override fun empty(): Float = 0f - override fun Float.combine(b: Float): Float = this + b + override fun append(a: Float, b: Float): Float = a + b } private object StringMonoid : Monoid { - override fun String.combine(b: String): String = "${this}$b" + override fun append(a: String, b: String): String = "${a}$b" override fun empty(): String = "" } private object ListMonoid : Monoid> { override fun empty(): List = emptyList() - override fun List.combine(b: List): List = this._plus(b) + override fun append(a: List, b: List): List = a._plus(b) } private object SequenceMonoid : Monoid> { override fun empty(): Sequence = emptySequence() - override fun Sequence.combine(b: Sequence): Sequence = sequenceOf(this, b).flatten() + override fun append(a: Sequence, b: Sequence): Sequence = sequenceOf(a, b).flatten() } private class EitherMonoid( @@ -195,9 +181,9 @@ public interface Monoid : Semigroup { private val MOR: Monoid ) : Monoid> { override fun empty(): Either = Either.Right(MOR.empty()) - - override fun Either.combine(b: Either): Either = - combine(SGOL, MOR, b) + + override fun append(a: Either, b: Either): Either = + a.combine(SGOL, MOR, b) override fun Collection>.fold(): Either = fold(either(SGOL, MOR)) @@ -214,7 +200,8 @@ public interface Monoid : Semigroup { private val MB: Monoid ) : Monoid> { override fun empty(): Pair = Pair(MA.empty(), MB.empty()) - override fun Pair.combine(b: Pair): Pair = combine(MA, MB, b) + override fun append(a: Pair, b: Pair): Pair = + a.combine(MA, MB, b) } } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt index 2de78ae1f4d..dbaa26d1c72 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt @@ -6,23 +6,27 @@ import arrow.core.Endo import arrow.core.Ior import arrow.core.NonEmptyList import arrow.core.Option -import arrow.core.Validated import arrow.core.combine import arrow.core.compose import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic public fun interface Semigroup { + + // TODO: think of better name + public fun append(a: A, b: A): A + /** * Combine two [A] values. */ - public fun A.combine(b: A): A + public fun A.combine(b: A): A = + append(this, b) public operator fun A.plus(b: A): A = - this.combine(b) + append(this, b) public fun A.maybeCombine(b: A?): A = - b?.let { combine(it) } ?: this + b?.let { append(this, it) } ?: this public companion object { @JvmStatic @@ -64,17 +68,12 @@ public fun interface Semigroup { @JvmStatic public fun endo(): Semigroup> = - object : Semigroup> { - override fun Endo.combine(g: Endo): Endo = Endo(f.compose(g.f)) - } + Semigroup { f, g -> Endo(f.f.compose(g.f)) } @JvmStatic @JvmName("constant") public fun const(SA: Semigroup): Semigroup> = - object : Semigroup> { - override fun Const.combine(b: Const): Const = - this.combine(SA, b) - } + Semigroup { a, b -> a.combine(SA, b) } @JvmStatic public fun map(SG: Semigroup): Semigroup> = @@ -84,10 +83,6 @@ public fun interface Semigroup { public fun option(SGA: Semigroup): Semigroup> = OptionSemigroup(SGA) - @JvmStatic - public fun validated(SE: Semigroup, SA: Semigroup): Semigroup> = - ValidatedSemigroup(SE, SA) - @Suppress("UNCHECKED_CAST") @JvmStatic public fun nonEmptyList(): Semigroup> = @@ -101,36 +96,28 @@ public fun interface Semigroup { private val SA: Semigroup, private val SB: Semigroup ) : Semigroup> { - override fun Pair.combine(b: Pair): Pair = combine(SA, SB, b) + override fun append(a: Pair, b: Pair): Pair = a.combine(SA, SB, b) } public object NonEmptyListSemigroup : Semigroup> { - override fun NonEmptyList.combine(b: NonEmptyList): NonEmptyList = - NonEmptyList(this.head, this.tail.plus(b)) - } - - private open class ValidatedSemigroup( - private val SA: Semigroup, - private val SB: Semigroup - ) : Semigroup> { - override fun Validated.combine(b: Validated): Validated = - combine(SA, SB, b) + override fun append(a: NonEmptyList, b: NonEmptyList): NonEmptyList = + NonEmptyList(a.head, a.tail.plus(b)) } private class OptionSemigroup( private val SGA: Semigroup ) : Semigroup> { - override fun Option.combine(b: Option): Option = - combine(SGA, b) + override fun append(a: Option, b: Option): Option = + a.combine(SGA, b) override fun Option.maybeCombine(b: Option?): Option = b?.let { combine(SGA, it) } ?: this } private class MapSemigroup(private val SG: Semigroup) : Semigroup> { - override fun Map.combine(b: Map): Map = - combine(SG, b) + override fun append(a: Map, b: Map): Map = + a.combine(SG, b) } private open class EitherSemigroup( @@ -138,8 +125,8 @@ public fun interface Semigroup { private val SGR: Semigroup ) : Semigroup> { - override fun Either.combine(b: Either): Either = - combine(SGL, SGR, b) + override fun append(a: Either, b: Either): Either = + a.combine(SGL, SGR, b) override fun Either.maybeCombine(b: Either?): Either = b?.let { combine(SGL, SGR, it) } ?: this @@ -150,8 +137,8 @@ public fun interface Semigroup { private val SGB: Semigroup ) : Semigroup> { - override fun Ior.combine(b: Ior): Ior = - combine(SGA, SGB, b) + override fun append(a: Ior, b: Ior): Ior = + a.combine(SGA, SGB, b) override fun Ior.maybeCombine(b: Ior?): Ior = b?.let { combine(SGA, SGB, it) } ?: this diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt index 9c2c6b3b472..6665f030415 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt @@ -12,6 +12,7 @@ import arrow.core.test.generators.suspendFunThatReturnsEitherAnyOrAnyOrThrows import arrow.core.test.generators.suspendFunThatThrows import arrow.core.test.laws.MonoidLaws import arrow.typeclasses.Monoid +import arrow.typeclasses.Semigroup import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe @@ -321,8 +322,6 @@ class EitherTest : UnitSpec() { val expected: Either> = Right(emptyList()) Right(a).replicate(n) shouldBe expected - - Left(a).replicate(n) shouldBe expected } } @@ -337,18 +336,6 @@ class EitherTest : UnitSpec() { } } - "traverse should return list of Right when Right and empty list when Left" { - checkAll( - Arb.int(), - Arb.int(), - Arb.int() - ) { a: Int, b: Int, c: Int -> - Right(a).traverse { emptyList() } shouldBe emptyList() - Right(a).traverse { listOf(b, c) } shouldBe listOf(Right(b), Right(c)) - Left(a).traverse { listOf(b, c) } shouldBe emptyList() - } - } - "flatMap should map right instance only" { checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> val right: Either = Right(a) @@ -458,129 +445,6 @@ class EitherTest : UnitSpec() { } } } - - "traverse should return list if either is right" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.traverse { listOf(it, 2, 3) } shouldBe listOf(Right(1), Right(2), Right(3)) - left.traverse { listOf(it, 2, 3) } shouldBe emptyList() - } - - "sequence should be consistent with traverse" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.map { listOf(it) }.sequence() shouldBe either.traverse { listOf(it) } - } - } - - "traverseNullable should return non-nullable if either is right" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.traverseNullable { it } shouldBe Right(1) - right.traverseNullable { null } shouldBe null - left.traverseNullable { it } shouldBe null - } - - "sequence for Nullable should be consistent with traverseNullable" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.map { it }.sequence() shouldBe either.traverseNullable { it } - either.map { null }.sequence() shouldBe null - } - } - - "traverse for Option should return option if either is right" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.traverse { Some(it) } shouldBe Some(Right(1)) - left.traverse { Some(it) } shouldBe None - } - - "sequence for Option should be consistent with traverseOption" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.map { Some(it) }.sequence() shouldBe either.traverse { Some(it) } - } - } - - "traverse for Validated should return validated of either" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.traverse { it.valid() } shouldBe Valid(Right(1)) - left.traverse { it.valid() } shouldBe Valid(Left("foo")) - } - - "sequence for Validated should be consistent with traverseValidated" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.map { it.valid() }.sequence() shouldBe either.traverse { it.valid() } - } - } - - "bitraverse should wrap either in a list" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.bitraverse({ listOf(it, "bar", "baz") }, { listOf(it, 2, 3) }) shouldBe listOf(Right(1), Right(2), Right(3)) - left.bitraverse({ listOf(it, "bar", "baz") }, { listOf(it, 2, 3) }) shouldBe - listOf(Left("foo"), Left("bar"), Left("baz")) - } - - "bisequence should be consistent with bitraverse" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.bimap({ listOf(it) }, { listOf(it) }).bisequence() shouldBe either.bitraverse( - { listOf(it) }, - { listOf(it) }) - } - } - - "bitraverseNullable should wrap either in a nullable" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.bitraverseNullable({ it }, { it.toString() }) shouldBe Right("1") - left.bitraverseNullable({ it }, { it.toString() }) shouldBe Left("foo") - - right.bitraverseNullable({ it }, { null }) shouldBe null - left.bitraverseNullable({ null }, { it.toString() }) shouldBe null - } - - "bisequenceNullable should be consistent with bitraverseNullable" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.bimap({ it }, { it }).bisequenceNullable() shouldBe - either.bitraverseNullable({ it }, { it }) - } - } - - "bitraverseOption should wrap either in an option" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.bitraverseOption({ Some(it) }, { Some(it.toString()) }) shouldBe Some(Right("1")) - left.bitraverseOption({ Some(it) }, { Some(it.toString()) }) shouldBe Some(Left("foo")) - } - - "bisequenceOption should be consistent with bitraverseOption" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.bimap({ Some(it) }, { Some(it) }).bisequenceOption() shouldBe - either.bitraverseOption({ Some(it) }, { Some(it) }) - } - } - - "bitraverseValidated should return validated of either" { - val right: Either = Right(1) - val left: Either = Left("foo") - - right.bitraverseValidated({ it.invalid() }, { it.valid() }) shouldBe Valid(Right(1)) - left.bitraverseValidated({ it.invalid() }, { it.valid() }) shouldBe Invalid("foo") - } - - "bisequenceValidated should be consistent with bitraverseValidated" { - checkAll(Arb.either(Arb.string(), Arb.int())) { either -> - either.bimap({ it.invalid() }, { it.valid() }).bisequenceValidated() shouldBe - either.bitraverseValidated({ it.invalid() }, { it.valid() }) - } - } } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt new file mode 100644 index 00000000000..1c2f4b29367 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt @@ -0,0 +1,117 @@ +package arrow.core + +import arrow.core.test.generators.either +import arrow.typeclasses.Semigroup +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe +import io.kotest.property.Arb +import io.kotest.property.arbitrary.boolean +import io.kotest.property.arbitrary.byte +import io.kotest.property.arbitrary.char +import io.kotest.property.arbitrary.double +import io.kotest.property.arbitrary.float +import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.list +import io.kotest.property.arbitrary.long +import io.kotest.property.arbitrary.map +import io.kotest.property.arbitrary.short +import io.kotest.property.arbitrary.string +import io.kotest.property.checkAll + +class EitherZipTest : StringSpec({ + "zip results in all Right transformed, or all Left combined according to combine" { + checkAll( + Arb.either(Arb.string(), Arb.short()), + Arb.either(Arb.string(), Arb.byte()), + Arb.either(Arb.string(), Arb.int()), + Arb.either(Arb.string(), Arb.long()), + Arb.either(Arb.string(), Arb.float()), + Arb.either(Arb.string(), Arb.double()), + Arb.either(Arb.string(), Arb.char()), + Arb.either(Arb.string(), Arb.string()), + Arb.either(Arb.string(), Arb.boolean()), + Arb.either(Arb.string(), Arb.boolean()) + ) { a, b, c, d, e, f, g, h, i, j -> + val res = a.zip({ e1, e2 -> "$e1$e2" }, b, c, d, e, f, g, h, i, j, ::Tuple10) + val all = listOf(a, b, c, d, e, f, g, h, i, j) + + val expected = if (all.any { it.isLeft() }) { + all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() + } else { + all.filterIsInstance>().map { it.value }.let { + Tuple10(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8], it[9]).right() + } + } + + res shouldBe expected + } + } + + "zip without Semigroup results in all Right transformed, or all Left in a NonEmptyList" { + checkAll( + Arb.either(Arb.string(), Arb.short()), + Arb.either(Arb.string(), Arb.byte()), + Arb.either(Arb.string(), Arb.int()), + Arb.either(Arb.string(), Arb.long()), + Arb.either(Arb.string(), Arb.float()), + Arb.either(Arb.string(), Arb.double()), + Arb.either(Arb.string(), Arb.char()), + Arb.either(Arb.string(), Arb.string()), + Arb.either(Arb.string(), Arb.boolean()), + Arb.either(Arb.string(), Arb.boolean()) + ) { a, b, c, d, e, f, g, h, i, j -> + val res = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) + val all = listOf(a, b, c, d, e, f, g, h, i, j) + + val expected = if (all.any { it.isLeft() }) { + all.filterIsInstance>().map { it.value }.toNonEmptyListOrNull()!!.left() + } else { + all.filterIsInstance>().map { it.value }.let { + Tuple10(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8], it[9]).right() + } + } + + res shouldBe expected + } + } + + "zipping EitherNel results in all Right transformed, or all Left in a NonEmptyList" { + fun Arb.Companion.nonEmptyList(arb: Arb): Arb> = + Arb.list(arb, 1..100).map { it.toNonEmptyListOrNull()!! } + + checkAll( + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.short()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.byte()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.int()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.long()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.float()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.double()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.char()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.string()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.boolean()), + Arb.either(Arb.nonEmptyList(Arb.string()), Arb.boolean()) + ) { a, b, c, d, e, f, g, h, i, j -> + val res = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) + val all = listOf(a, b, c, d, e, f, g, h, i, j) + + val expected = if (all.any { it.isLeft() }) { + all.filterIsInstance>>() + .flatMap { it.value } + .toNonEmptyListOrNull()!!.left() + } else { + all.filterIsInstance>().map { it.value }.let { + Tuple10(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8], it[9]).right() + } + } + + res shouldBe expected + } + } + + "Can use Semigroup as combine function" { + Either.Left(10).zip( + Semigroup.int(), + Either.Right(5) + ) { a, b -> a + b } shouldBe Either.Left(10) + } +}) \ No newline at end of file diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt index 4b83bc15750..70d25d9c74b 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt @@ -23,10 +23,8 @@ class IorTest : UnitSpec() { SemigroupLaws.laws(Semigroup.ior(Semigroup.string(), Semigroup.int()), ARB) ) - val nullableLongSemigroup = object : Semigroup { - override fun Long?.combine(b: Long?): Long? = - Nullable.zip(this, b) { a, bb -> a + bb } - } + val nullableLongSemigroup = + Semigroup { a, b -> Nullable.zip(a, b) { aa, bb -> aa + bb } } "zip identity" { checkAll(Arb.ior(Arb.long().orNull(), Arb.int().orNull())) { ior -> @@ -153,14 +151,6 @@ class IorTest : UnitSpec() { } } - "toValidated() should convert values into a valid Validated" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - Ior.Left(a).toValidated() shouldBe Invalid(a) - Ior.Right(b).toValidated() shouldBe Valid(b) - Ior.Both(a, b).toValidated() shouldBe Valid(b) - } - } - "fromNullables() should build a correct Ior" { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.fromNullables(a, null) shouldBe Ior.Left(a) @@ -202,139 +192,5 @@ class IorTest : UnitSpec() { } } - "traverse should wrap ior in a list" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val iorL: Ior = a.leftIor() - val iorR: Ior = b.rightIor() - val iorBoth: Ior = (a to b).bothIor() - - iorL.traverse { listOf(it) } shouldBe listOf(Ior.Left(a)) - iorR.traverse { listOf(it) } shouldBe listOf(Ior.Right(b)) - iorBoth.traverse { listOf(it) } shouldBe listOf(Ior.Both(a, b)) - } - } - - "sequence should be consistent with traverse" { - checkAll(Arb.ior(Arb.int(), Arb.string())) { ior -> - ior.map { listOf(it) }.sequence() shouldBe ior.traverse { listOf(it) } - } - } - - "traverseNullable should wrap ior in a nullable" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val iorL: Ior = a.leftIor() - val iorR: Ior = b.rightIor() - val iorBoth: Ior = (a to b).bothIor() - - iorL.traverseNullable { it } shouldBe Ior.Left(a) - iorR.traverseNullable { it } shouldBe Ior.Right(b) - iorBoth.traverseNullable { it } shouldBe Ior.Both(a, b) - - iorL.traverseNullable { null } shouldBe Ior.Left(a) - iorR.traverseNullable { null } shouldBe null - iorBoth.traverseNullable { null } shouldBe null - } - } - - "sequence for Nullable should be consistent with traverseNullable" { - checkAll(Arb.ior(Arb.int(), Arb.string())) { ior -> - ior.map { it }.sequence() shouldBe ior.traverseNullable { it } - ior.map { null }.sequence() shouldBe ior.traverseNullable { null } - } - } - - "traverseOption should wrap ior in an Option" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val iorL: Ior = a.leftIor() - val iorR: Ior = b.rightIor() - val iorBoth: Ior = (a to b).bothIor() - - iorL.traverse { Some(it) } shouldBe Some(Ior.Left(a)) - iorR.traverse { Some(it) } shouldBe Some(Ior.Right(b)) - iorBoth.traverse { Some(it) } shouldBe Some(Ior.Both(a, b)) - } - } - - "sequenceOption should be consistent with traverseOption" { - checkAll(Arb.ior(Arb.int(), Arb.string())) { ior -> - ior.map { Some(it) }.sequence() shouldBe ior.traverse { Some(it) } - } - } - - "traverseEither should wrap ior in an Option" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val iorL: Ior = a.leftIor() - val iorR: Ior = b.rightIor() - val iorBoth: Ior = (a to b).bothIor() - - iorL.traverse { it.right() } shouldBe Either.Right(Ior.Left(a)) - iorR.traverse { it.right() } shouldBe Either.Right(Ior.Right(b)) - iorBoth.traverse { it.right() } shouldBe Either.Right(Ior.Both(a, b)) - } - } - - "sequenceEither should be consistent with traverseEither" { - checkAll(Arb.ior(Arb.int(), Arb.string())) { ior -> - ior.map { it.right() }.sequence() shouldBe ior.traverse { it.right() } - } - } - - "bitraverse should wrap ior in a list" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val iorL: Ior = a.leftIor() - val iorR: Ior = b.rightIor() - val iorBoth: Ior = (a to b).bothIor() - - iorL.bitraverse({ listOf(it, 2, 3) }, { listOf(it) }) shouldBe listOf(Ior.Left(a), Ior.Left(2), Ior.Left(3)) - iorR.bitraverse({ listOf(it, 2, 3) }, { listOf(it) }) shouldBe listOf(Ior.Right(b)) - iorBoth.bitraverse({ listOf(it, 2, 3) }, { listOf(it, 4, 5) }) shouldBe - listOf(Ior.Both(a, b), Ior.Both(2, 4), Ior.Both(3, 5)) - } - } - - "bisequence should be consistent with bitraverse" { - checkAll(Arb.ior(Arb.int(), Arb.string())) { ior -> - ior.bimap({ listOf(it) }, { listOf(it) }).bisequence() shouldBe - ior.bitraverse({ listOf(it) }, { listOf(it) }) - } - } - - "bitraverseOption should wrap ior in an Option" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val iorL: Ior = a.leftIor() - val iorR: Ior = b.rightIor() - val iorBoth: Ior = (a to b).bothIor() - - iorL.bitraverseOption({ None }, { Some(it) }) shouldBe None - iorR.bitraverseOption({ None }, { Some(it) }) shouldBe Some(Ior.Right(b)) - iorBoth.bitraverseOption({ None }, { Some(it) }) shouldBe None - } - } - - "bisequenceOption should be consistent with bitraverseOption" { - checkAll(Arb.ior(Arb.int(), Arb.string())) { ior -> - ior.bimap({ None }, { Some(it) }).bisequenceOption() shouldBe - ior.bitraverseOption({ None }, { Some(it) }) - } - } - - "bitraverseEither should wrap ior in an Either" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val iorL: Ior = a.leftIor() - val iorR: Ior = b.rightIor() - val iorBoth: Ior = (a to b).bothIor() - - iorL.bitraverseEither({ it.left() }, { it.right() }) shouldBe Either.Left(a) - iorR.bitraverseEither({ it.left() }, { it.right() }) shouldBe Either.Right(Ior.Right(b)) - iorBoth.bitraverseEither({ it.left() }, { it.right() }) shouldBe Either.Left(a) - } - } - - "bisequenceEither should be consistent with bitraverseEither" { - checkAll(Arb.ior(Arb.int(), Arb.string())) { ior -> - ior.bimap({ it.left() }, { it.right() }).bisequenceEither() shouldBe - ior.bitraverseEither({ it.left() }, { it.right() }) - } - } } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index 02b1d88edd3..5e6b43c3a19 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -1,229 +1,43 @@ package arrow.core import arrow.core.test.UnitSpec -import arrow.core.test.generators.either -import arrow.core.test.generators.functionAToB import arrow.core.test.generators.option import arrow.typeclasses.Semigroup -import io.kotest.matchers.collections.shouldBeEmpty -import io.kotest.matchers.collections.shouldContainExactly -import io.kotest.matchers.nulls.shouldBeNull -import io.kotest.matchers.nulls.shouldNotBeNull -import io.kotest.matchers.should -import io.kotest.property.Arb import io.kotest.matchers.shouldBe +import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.orNull -import io.kotest.property.arbitrary.string import kotlin.math.max import kotlin.math.min class IterableTest : UnitSpec() { init { - "traverse Either stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).traverse { a -> - acc.add(a) - Either.Right(a) - } - res shouldBe Either.Right(acc) - res shouldBe Either.Right((0..20_000).toList()) - } - - "traverse Either short-circuit" { - checkAll(Arb.list(Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - if (it % 2 == 0) { - acc.add(it) - Either.Right(it) - } else Either.Left(it) - } - acc shouldBe ints.takeWhile { it % 2 == 0 } - when (evens) { - is Either.Right -> evens.value shouldBe ints - is Either.Left -> evens.value shouldBe ints.first { it % 2 != 0 } - } - } - } - - "sequenceEither should be consistent with traverse Either" { - checkAll(Arb.list(Arb.int())) { ints -> - ints.map { it.right() }.sequence() shouldBe ints.traverse { it.right() } - } - } - - "traverse Result stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).traverse { a -> - acc.add(a) - Result.success(a) - } - res shouldBe Result.success(acc) - res shouldBe Result.success((0..20_000).toList()) - } - - "traverse Result short-circuit" { - checkAll(Arb.list(Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - if (it % 2 == 0) { - acc.add(it) - Result.success(it) - } else Result.failure(RuntimeException()) - } - acc shouldBe ints.takeWhile { it % 2 == 0 } - evens.fold( - { it shouldBe ints }, - { } - ) - } - } - - "sequence Result should be consistent with traverse Result" { - checkAll(Arb.list(Arb.int())) { ints -> - ints.map { Result.success(it) }.sequence() shouldBe ints.traverse { Result.success(it) } - } - } - - "traverse Option is stack-safe" { - // also verifies result order and execution order (l to r) + "mapAccumulating stack-safe, and runs in original order" { val acc = mutableListOf() - val res = (0..20_000).traverse { a: Int -> - acc.add(a) - Some(a) - } - res shouldBe Some(acc) - res shouldBe Some((0..20_000).toList()) - } - - "traverse Option short-circuits" { - checkAll(Arb.list(Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - (it % 2 == 0).maybe { - acc.add(it) - it - } - } - acc shouldBe ints.takeWhile { it % 2 == 0 } - evens.fold({ Unit }) { it shouldBe ints } - } - } - - "sequence Option yields some when all entries in the list are some" { - checkAll(Arb.list(Arb.int())) { ints -> - val evens = ints.map { (it % 2 == 0).maybe { it } }.sequence() - evens.fold({ Unit }) { it shouldBe ints } - } - } - - "sequence Option should be consistent with traverse Option" { - checkAll(Arb.list(Arb.int())) { ints -> - ints.map { Some(it) }.sequence() shouldBe ints.traverse { Some(it) } - } - } - - "traverse Nullable is stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).traverse { a: Int -> - acc.add(a) - a - } - res.shouldNotBeNull() shouldBe acc - res.shouldNotBeNull() shouldBe (0..20_000).toList() - } - - "traverse Nullable short-circuits" { - checkAll(Arb.list(Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - if (it % 2 == 0) { - acc.add(it) - it - } else { - null - } - } - - val expected = ints.takeWhile { it % 2 == 0 } - acc shouldBe expected - - if (ints.any { it % 2 != 0 }) { - evens.shouldBeNull() - } else { - evens.shouldNotBeNull() shouldContainExactly expected - } - } - } - - "sequence Nullable yields some when all entries in the list are not null" { - checkAll(Arb.list(Arb.int())) { ints -> - val evens = ints.map { if (it % 2 == 0) it else null }.sequence() - - if (ints.any { it % 2 != 0 }) { - evens.shouldBeNull() - } else { - evens.shouldNotBeNull() shouldContainExactly ints.takeWhile { it % 2 == 0 } - } - } - } - - "sequence Nullable should be consistent with travers Nullable" { - checkAll(Arb.list(Arb.int())) { ints -> - ints.map { it as Int? }.sequence() shouldBe ints.traverse { it as Int? } - } - } - - "traverse Validated stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).traverse(Semigroup.string()) { + val res = (0..20_000).mapOrAccumulate(Semigroup.string()) { acc.add(it) - Validated.Valid(it) + it } - res shouldBe Validated.Valid(acc) - res shouldBe Validated.Valid((0..20_000).toList()) + res shouldBe acc.right() + res shouldBe (0..20_000).toList().right() } - - "traverse Validated acumulates" { + + "mapAccumulating accumulates" { checkAll(Arb.list(Arb.int())) { ints -> - val res: ValidatedNel> = - ints.map { i -> if (i % 2 == 0) Valid(i) else Invalid(nonEmptyListOf(i)) } - .sequence() - - val expected: ValidatedNel> = ints.filterNot { it % 2 == 0 } - .toNonEmptyListOrNull()?.invalid() ?: Valid(ints.filter { it % 2 == 0 }) - + val res: Either, List> = + ints.mapOrAccumulate { i -> if (i % 2 == 0) i else raise(i) } + + val expected: Either, List> = ints.filterNot { it % 2 == 0 } + .toNonEmptyListOrNull()?.left() ?: ints.filter { it % 2 == 0 }.right() + res shouldBe expected } } - - "sequence Validated should be consistent with traverse Validated" { - checkAll(Arb.list(Arb.int())) { ints -> - ints.map { it.valid() }.sequence(Semigroup.string()) shouldBe - ints.traverse(Semigroup.string()) { it.valid() } - } - } - - "sequence Either traverse Nullable interoperate - and proof map + sequence equality with traverse" { - checkAll( - Arb.list(Arb.int()), - Arb.functionAToB?>(Arb.either(Arb.string(), Arb.int()).orNull()) - ) { ints, f -> - - val res: Either>? = - ints.traverse(f)?.sequence() - - val expected: Either>? = - ints.map(f).sequence()?.sequence() - - res shouldBe expected - } + + "mapAccumulating with String::plus" { + listOf(1, 2, 3).mapOrAccumulate(String::plus) { i -> + raise("fail") + } shouldBe Either.Left("failfailfail") } "zip3" { @@ -489,15 +303,5 @@ class IterableTest : UnitSpec() { list.separateEither() shouldBe ints.partition { it % 2 == 0 } } } - - "separateValidated" { - checkAll(Arb.list(Arb.int())) { ints -> - val list = ints.map { - if (it % 2 == 0) it.invalid() - else it.valid() - } - list.separateValidated() shouldBe ints.partition { it % 2 == 0 } - } - } } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt index 478062cae4b..c744c808536 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt @@ -6,10 +6,9 @@ import arrow.core.test.generators.longSmall import arrow.core.test.laws.MonoidLaws import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup -import io.kotest.property.Arb import io.kotest.matchers.shouldBe +import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.string @@ -23,90 +22,6 @@ class MapKTest : UnitSpec() { ) ) - "traverseEither is stacksafe" { - val acc = mutableListOf() - val res = (0..20_000).map { it to it }.toMap().traverse { v -> - acc.add(v) - Either.Right(v) - } - res shouldBe acc.map { it to it }.toMap().right() - res shouldBe (0..20_000).map { it to it }.toMap().right() - } - - "traverseEither short-circuit" { - checkAll(Arb.map(Arb.int(), Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - if (it % 2 == 0) { - acc.add(it) - Either.Right(it) - } else Either.Left(it) - } - acc shouldBe ints.values.takeWhile { it % 2 == 0 } - when (evens) { - is Either.Right -> evens.value shouldBe ints - is Either.Left -> evens.value shouldBe ints.values.first { it % 2 != 0 } - } - } - } - - "traverseOption is stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).map { it to it }.toMap().traverse { a -> - acc.add(a) - Some(a) - } - res shouldBe Some(acc.map { it to it }.toMap()) - res shouldBe Some((0..20_000).map { it to it }.toMap()) - } - - "traverseOption short-circuits" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - (it % 2 == 0).maybe { - acc.add(it) - it - } - } - acc shouldBe ints.takeWhile { it % 2 == 0 } - evens.fold({ Unit }) { it shouldBe ints } - } - } - - "sequenceOption yields some when all entries in the list are some" { - checkAll(Arb.list(Arb.int())) { ints -> - val evens = ints.map { (it % 2 == 0).maybe { it } }.sequence() - evens.fold({ Unit }) { it shouldBe ints } - } - } - - "traverseValidated is stacksafe" { - val acc = mutableListOf() - val res = (0..20_000).map { it to it }.toMap().traverse(Semigroup.string()) { v -> - acc.add(v) - Validated.Valid(v) - } - res shouldBe acc.map { it to it }.toMap().valid() - res shouldBe (0..20_000).map { it to it }.toMap().valid() - } - - "traverseValidated acummulates" { - checkAll(Arb.map(Arb.int(), Arb.int())) { ints -> - val res: ValidatedNel> = - ints.traverse(Semigroup.nonEmptyList()) { i -> if (i % 2 == 0) i.validNel() else i.invalidNel() } - - val expected: ValidatedNel> = - Option.fromNullable(ints.values.filterNot { it % 2 == 0 }.toNonEmptyListOrNull()) - .fold( - { ints.entries.filter { (_, v) -> v % 2 == 0 }.map { (k, v) -> k to v }.toMap().validNel() }, - { it.invalid() }) - - res shouldBe expected - } - } - "can align maps" { // aligned keySet is union of a's and b's keys checkAll(Arb.map(Arb.long(), Arb.boolean()), Arb.map(Arb.long(), Arb.boolean())) { a, b -> diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index 67b1c14ddf5..e989f8d40dd 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -17,7 +17,7 @@ class NonEmptyListTest : UnitSpec() { init { testLaws(SemigroupLaws.laws(Semigroup.nonEmptyList(), Arb.nonEmptyList(Arb.int()))) - + "iterable.toNonEmptyListOrNull should round trip" { checkAll(Arb.nonEmptyList(Arb.int())) { nonEmptyList -> nonEmptyList.all.toNonEmptyListOrNull().shouldNotBeNull() shouldBe nonEmptyList @@ -29,110 +29,36 @@ class NonEmptyListTest : UnitSpec() { nonEmptyList.all.toNonEmptyListOrNone() shouldBe nonEmptyList.some() } } - - "traverse for Either stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).toNonEmptyListOrNull()?.traverse { a -> - acc.add(a) - Either.Right(a) - } - res shouldBe Either.Right(acc.toNonEmptyListOrNull()) - res shouldBe Either.Right((0..20_000).toNonEmptyListOrNull()) - } - - "traverse for Either short-circuit" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - if (it % 2 == 0) { - acc.add(it) - Either.Right(it) - } else Either.Left(it) - } - acc shouldBe ints.takeWhile { it % 2 == 0 } - when (evens) { - is Either.Right -> evens.value shouldBe ints - is Either.Left -> evens.value shouldBe ints.first { it % 2 != 0 } - } - } - } - - "sequence for Either should be consistent with traverseEither" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - ints.map { Either.conditionally(it % 2 == 0, { it }, { it }) }.sequence() shouldBe - ints.traverse { Either.conditionally(it % 2 == 0, { it }, { it }) } - } - } - - "traverse for Option is stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).toNonEmptyListOrNull()?.traverse { a -> - acc.add(a) - Some(a) - } - res shouldBe Some(acc.toNonEmptyListOrNull()) - res shouldBe Some((0..20_000).toNonEmptyListOrNull()) - } - - "traverse for Option short-circuits" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - val acc = mutableListOf() - val evens = ints.traverse { - (it % 2 == 0).maybe { - acc.add(it) - it - } - } - acc shouldBe ints.takeWhile { it % 2 == 0 } - evens.fold({ Unit }) { it shouldBe ints } - } - } - - "sequence for Option yields some when all entries in the list are some" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - val evens = ints.map { (it % 2 == 0).maybe { it } }.sequence() - evens.fold({ Unit }) { it shouldBe ints } - } - } - - "sequence for Option should be consistent with traverseOption" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - ints.map { (it % 2 == 0).maybe { it } }.sequence() shouldBe - ints.traverse { (it % 2 == 0).maybe { it } } - } - } - - "traverse for Validated stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).traverse(Semigroup.string()) { - acc.add(it) - Validated.Valid(it) - } - res shouldBe Validated.Valid(acc) - res shouldBe Validated.Valid((0..20_000).toList()) - } - - "traverse for Validated acummulates" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - val res: ValidatedNel> = - ints.traverse(Semigroup.nonEmptyList()) { i: Int -> if (i % 2 == 0) i.validNel() else i.invalidNel() } - - val expected: ValidatedNel> = - ints.filterNot { it % 2 == 0 }.toNonEmptyListOrNull()?.invalid() ?: ints.filter { it % 2 == 0 }.toNonEmptyListOrNull()!!.valid() - - res shouldBe expected - } - } - - "sequence for Validated should be consistent with traverseValidated" { - checkAll(Arb.nonEmptyList(Arb.int())) { ints -> - ints.map { if (it % 2 == 0) Valid(it) else Invalid(it) }.sequence(Semigroup.int()) shouldBe - ints.traverse(Semigroup.int()) { if (it % 2 == 0) Valid(it) else Invalid(it) } - } - } + + // "traverse for Validated stack-safe" { + // // also verifies result order and execution order (l to r) + // val acc = mutableListOf() + // val res = (0..20_000).traverse(Semigroup.string()) { + // acc.add(it) + // Validated.Valid(it) + // } + // res shouldBe Validated.Valid(acc) + // res shouldBe Validated.Valid((0..20_000).toList()) + // } + // + // "traverse for Validated acummulates" { + // checkAll(Arb.nonEmptyList(Arb.int())) { ints -> + // val res: ValidatedNel> = + // ints.traverse(Semigroup.nonEmptyList()) { i: Int -> if (i % 2 == 0) i.validNel() else i.invalidNel() } + // + // val expected: ValidatedNel> = + // ints.filterNot { it % 2 == 0 }.toNonEmptyListOrNull()?.invalid() ?: ints.filter { it % 2 == 0 }.toNonEmptyListOrNull()!!.valid() + // + // res shouldBe expected + // } + // } + // + // "sequence for Validated should be consistent with traverseValidated" { + // checkAll(Arb.nonEmptyList(Arb.int())) { ints -> + // ints.map { if (it % 2 == 0) Valid(it) else Invalid(it) }.sequence(Semigroup.int()) shouldBe + // ints.traverse(Semigroup.int()) { if (it % 2 == 0) Valid(it) else Invalid(it) } + // } + // } "can align lists with different lengths" { checkAll(Arb.nonEmptyList(Arb.boolean()), Arb.nonEmptyList(Arb.boolean())) { a, b -> diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt index d01efef505f..5ba149a4d84 100755 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt @@ -365,45 +365,6 @@ class OptionTest : UnitSpec() { none.toMap() shouldBe emptyMap() } - "traverse should yield list of option" { - val some: Option = Some("value") - val none: Option = None - some.traverse { listOf(it) } shouldBe listOf(Some("value")) - none.traverse { listOf(it) } shouldBe emptyList() - } - - "sequence should be consistent with traverse" { - checkAll(Arb.option(Arb.int())) { option -> - option.map { listOf(it) }.sequence() shouldBe option.traverse { listOf(it) } - } - } - - "traverseEither should yield either of option" { - val some: Option = Some("value") - val none: Option = None - some.traverse { it.right() } shouldBe some.right() - none.traverse { it.right() } shouldBe none.right() - } - - "sequenceEither should be consistent with traverseEither" { - checkAll(Arb.option(Arb.int())) { option -> - option.map { it.right() }.sequence() shouldBe option.traverse{ it.right() } - } - } - - "traverseValidated should yield validated of option" { - val some: Option = Some("value") - val none: Option = None - some.traverse { it.valid() } shouldBe some.valid() - none.traverse { it.valid() } shouldBe none.valid() - } - - "sequenceValidated should be consistent with traverseValidated" { - checkAll(Arb.option(Arb.int())) { option -> - option.map { it.valid() }.sequence() shouldBe option.traverse { it.valid() } - } - } - "catch should return Some(result) when f does not throw" { val recover: (Throwable) -> Option = { _ -> None} Option.catch(recover) { 1 } shouldBe Some(1) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt index 8e77cffad6f..d85f0b0e998 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt @@ -21,58 +21,6 @@ class SequenceKTest : UnitSpec() { testLaws(MonoidLaws.laws(Monoid.sequence(), Arb.sequence(Arb.int())) { s1, s2 -> s1.toList() == s2.toList() }) - "traverse for Either stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = generateSequence(0) { it + 1 }.traverse { a -> - if (a > 20_000) { - Either.Left(Unit) - } else { - acc.add(a) - Either.Right(a) - } - } - acc shouldBe (0..20_000).toList() - res shouldBe Either.Left(Unit) - } - - "traverse for Option stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = generateSequence(0) { it + 1 }.traverse { a -> - (a <= 20_000).maybe { - acc.add(a) - a - } - } - acc shouldBe (0..20_000).toList() - res shouldBe None - } - - "traverse for Validated stack-safe" { - // also verifies result order and execution order (l to r) - val acc = mutableListOf() - val res = (0..20_000).asSequence().traverse(Semigroup.string()) { - acc.add(it) - Validated.Valid(it) - }.map { it.toList() } - res shouldBe Validated.Valid(acc) - res shouldBe Validated.Valid((0..20_000).toList()) - } - - "traverse for Validated acummulates" { - checkAll(Arb.sequence(Arb.int())) { ints -> - val res: ValidatedNel> = ints.map { i -> if (i % 2 == 0) i.validNel() else i.invalidNel() } - .sequence(Semigroup.nonEmptyList()) - - val expected: ValidatedNel> = - ints.filterNot { it % 2 == 0 }.toList() - .toNonEmptyListOrNull()?.invalid() ?: ints.filter { it % 2 == 0 }.validNel() - - res.map { it.toList() } shouldBe expected.map { it.toList() } - } - } - "zip3" { checkAll(Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), Arb.sequence(Arb.int())) { a, b, c -> val result = a.zip(b, c, ::Triple) @@ -320,18 +268,5 @@ class SequenceKTest : UnitSpec() { lefts.toList() to rights.toList() shouldBe ints.partition { it % 2 == 0 } } } - - "separateValidated" { - checkAll(Arb.sequence(Arb.int())) { ints -> - val sequence = ints.map { - if (it % 2 == 0) it.invalid() - else it.valid() - } - - val (invalids, valids) = sequence.separateValidated() - - invalids.toList() to valids.toList() shouldBe ints.partition { it % 2 == 0 } - } - } } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt deleted file mode 100644 index 0dca116a255..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt +++ /dev/null @@ -1,519 +0,0 @@ -package arrow.core - -import arrow.core.Either.Left -import arrow.core.Either.Right -import arrow.core.test.UnitSpec -import arrow.typeclasses.Monoid -import arrow.typeclasses.Semigroup -import arrow.core.test.generators.validated -import io.kotest.assertions.fail -import io.kotest.matchers.nulls.shouldBeNull -import io.kotest.property.Arb -import io.kotest.matchers.shouldBe -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.long -import io.kotest.property.arbitrary.orNull -import io.kotest.property.arbitrary.string - -@Suppress("RedundantSuspendModifier") -class ValidatedTest : UnitSpec() { - - init { - - "fold should call function on Invalid" { - val exception = Exception("My Exception") - val result: Validated = Invalid(exception) - result.fold( - { e -> e.message + " Checked" }, - { fail("Some should not be called") } - ) shouldBe "My Exception Checked" - } - - "fold should call function on Valid" { - val value = "Some value" - val result: Validated = Valid(value) - result.fold( - { fail("None should not be called") }, - { a -> "$a processed" } - ) shouldBe "$value processed" - } - - "leftMap should modify error" { - Valid(10).mapLeft { fail("None should not be called") } shouldBe Valid(10) - Invalid(13).mapLeft { i -> "$i is Coming soon!" } shouldBe Invalid("13 is Coming soon!") - } - - "exist should return false if is Invalid" { - Invalid(13).exist { fail("None should not be called") } shouldBe false - } - - "exist should return the value of predicate if is Valid" { - Valid(13).exist { v -> v > 10 } shouldBe true - Valid(13).exist { v -> v < 10 } shouldBe false - } - - "swap should return Valid(e) if is Invalid and Invalid(v) otherwise" { - Valid(13).swap() shouldBe Invalid(13) - Invalid(13).swap() shouldBe Valid(13) - } - - "getOrElse should return value if is Valid or default otherwise" { - Valid(13).getOrElse { fail("None should not be called") } shouldBe 13 - Invalid(13).getOrElse { "defaultValue" } shouldBe "defaultValue" - } - - "orNull should return value if is Valid or null otherwise" { - Valid(13).orNull() shouldBe 13 - val invalid: Validated = Invalid(13) - invalid.orNull() shouldBe null - } - - "orNone should return value if is Valid or None otherwise" { - Valid(13).orNone() shouldBe Some(13) - val invalid: Validated = Invalid(13) - invalid.orNone() shouldBe None - } - - "valueOr should return value if is Valid or the the result of f otherwise" { - Valid(13).valueOr { fail("None should not be called") } shouldBe 13 - Invalid(13).valueOr { e -> "$e is the defaultValue" } shouldBe "13 is the defaultValue" - } - - "orElse should return Valid(value) if is Valid or the result of default otherwise" { - Valid(13).orElse { fail("None should not be called") } shouldBe Valid(13) - Invalid(13).orElse { Valid("defaultValue") } shouldBe Valid("defaultValue") - Invalid(13).orElse { Invalid("defaultValue") } shouldBe Invalid("defaultValue") - } - - "foldLeft should return b when is Invalid" { - Invalid(13).foldLeft("Coming soon!") { _, _ -> fail("None should not be called") } shouldBe "Coming soon!" - } - - "foldLeft should return f processed when is Valid" { - Valid(10).foldLeft("Tennant") { b, a -> "$a is $b" } shouldBe "10 is Tennant" - } - - "toEither should return Either.Right(value) if is Valid or Either.Left(error) otherwise" { - Valid(10).toEither() shouldBe Right(10) - Invalid(13).toEither() shouldBe Left(13) - } - - "toIor should return Ior.Right(value) if is Valid or Ior.Left(error) otherwise" { - Valid(10).toIor() shouldBe Ior.Right(10) - Invalid(13).toIor() shouldBe Ior.Left(13) - } - - "toOption should return Some(value) if is Valid or None otherwise" { - Valid(10).toOption() shouldBe Some(10) - Invalid(13).toOption() shouldBe None - } - - "toList should return listOf(value) if is Valid or empty list otherwise" { - Valid(10).toList() shouldBe listOf(10) - Invalid(13).toList() shouldBe listOf() - } - - "toValidatedNel should return Valid(value) if is Valid or Invalid, A>(error) otherwise" { - Valid(10).toValidatedNel() shouldBe Valid(10) - Invalid(13).toValidatedNel() shouldBe Invalid(NonEmptyList(13, listOf())) - } - - "findValid should return the first Valid value or combine or Invalid values otherwise" { - Valid(10).findValid(Semigroup.int()) { fail("None should not be called") } shouldBe Valid(10) - Invalid(10).findValid(Semigroup.int()) { Valid(5) } shouldBe Valid(5) - Invalid(10).findValid(Semigroup.int()) { Invalid(5) } shouldBe Invalid(15) - } - - val nullableLongSemigroup = object : Monoid { - override fun empty(): Long? = 0 - override fun Long?.combine(b: Long?): Long? = - Nullable.zip(this@combine, b) { a, bb -> a + bb } - } - - "zip identity" { - checkAll(Arb.validated(Arb.long().orNull(), Arb.int().orNull())) { validated -> - val res = validated.zip(nullableLongSemigroup, Valid(Unit)) { a, _ -> a } - res shouldBe validated - } - } - - "tap applies effects returning the original value" { - checkAll(Arb.validated(Arb.long(), Arb.int())) { validated -> - var effect = 0 - val res = validated.tap { effect += 1 } - val expected = when (validated) { - is Validated.Valid -> 1 - is Validated.Invalid -> 0 - } - effect shouldBe expected - res shouldBe validated - } - } - - "tapInvalid applies effects returning the original value" { - checkAll(Arb.validated(Arb.long(), Arb.int())) { validated -> - var effect = 0 - val res = validated.tapInvalid { effect += 1 } - val expected = when (validated) { - is Validated.Valid -> 0 - is Validated.Invalid -> 1 - } - effect shouldBe expected - res shouldBe validated - } - } - - "zip is derived from flatMap" { - checkAll( - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()), - Arb.validated(Arb.long().orNull(), Arb.int().orNull()) - ) { a, b, c, d, e, f, g, h, i, j -> - val res = a.zip( - nullableLongSemigroup, - b, c, d, e, f, g, h, i, j - ) { a, b, c, d, e, f, g, h, i, j -> - Nullable.zip( - a, - b, - c, - d, - e, - f, - g, - h, - i, - j - ) { a, b, c, d, e, f, g, h, i, j -> a + b + c + d + e + f + g + h + i + j } - } - - val all = listOf(a, b, c, d, e, f, g, h, i, j) - val isValid = all.all { it.isValid } - val expected: Validated = - if (isValid) Valid(all.fold, Int?>(0) { acc, validated -> - Nullable.zip( - acc, - validated.orNull() - ) { a, b -> a + b } - }) - else Invalid( - all.filterIsInstance>().map { it.value }.fold(nullableLongSemigroup) - ) - - res shouldBe expected - } - } - - "zip should return Valid(f(a)) if both are Valid" { - Valid(10).zip(Semigroup.int(), Valid { a: Int -> a + 5 }) { a, ff -> ff(a) } shouldBe Valid(15) - } - - "zip should return first Invalid found if is unique or combine both otherwise" { - Invalid(10).zip(Semigroup.int(), Valid { a: Int -> a + 5 }) { a, ff -> ff(a) } shouldBe Invalid(10) - Valid(10).zip Int, Int>(Semigroup.int(), Invalid(5)) { a, ff -> ff(a) } shouldBe Invalid(5) - Invalid(10).zip Int, Int>(Semigroup.int(), Invalid(5)) { a, ff -> ff(a) } shouldBe Invalid(15) - } - - data class MyException(val msg: String) : Exception() - - "fromEither should return Valid if is Either.Right or Failure otherwise" { - Validated.fromEither(Right(10)) shouldBe Valid(10) - Validated.fromEither(Left(10)) shouldBe Invalid(10) - } - - "fromOption should return Valid if is Some or Invalid otherwise" { - Validated.fromOption(Some(10)) { fail("should not be called") } shouldBe Valid(10) - Validated.fromOption(None) { 5 } shouldBe Invalid(5) - } - - "fromNullable should return Valid if is not-null or Invalid otherwise" { - Validated.fromNullable(10) { fail("should not be called") } shouldBe Valid(10) - Validated.fromNullable(null) { 5 } shouldBe Invalid(5) - } - - "invalidNel should return a Invalid>" { - Validated.invalidNel(10) shouldBe Invalid(NonEmptyList(10, listOf())) - } - - "withEither should return Valid(result) if f return Right" { - Valid(10).withEither { it.map { it + 5 } } shouldBe Valid(15) - Invalid(10).withEither { Right(5) } shouldBe Valid(5) - } - - "withEither should return Invalid(result) if f return Left" { - Valid(10).withEither { Left(5) } shouldBe Invalid(5) - Invalid(10).withEither(::identity) shouldBe Invalid(10) - } - - "catch should return Valid(result) when f does not throw" { - suspend fun loadFromNetwork(): Int = 1 - Validated.catch { loadFromNetwork() } shouldBe Valid(1) - } - - "catch should return Invalid(result) when f throws" { - val exception = MyException("Boom!") - suspend fun loadFromNetwork(): Int = throw exception - Validated.catch { loadFromNetwork() } shouldBe Invalid(exception) - } - - "catchNel should return Valid(result) when f does not throw" { - suspend fun loadFromNetwork(): Int = 1 - Validated.catchNel { loadFromNetwork() } shouldBe Valid(1) - } - - "catchNel should return Invalid(Nel(result)) when f throws" { - val exception = MyException("Boom!") - suspend fun loadFromNetwork(): Int = throw exception - Validated.catchNel { loadFromNetwork() } shouldBe Invalid(nonEmptyListOf(exception)) - } - - "Cartesian builder should build products over homogeneous Validated" { - Valid("11th").zip( - Semigroup.string(), - Valid("Doctor"), - Valid("Who") - ) { a, b, c -> "$a $b $c" } shouldBe Valid("11th Doctor Who") - } - - "Cartesian builder should build products over heterogeneous Validated" { - Valid(13).zip( - Semigroup.string(), - Valid("Doctor"), - Valid(false) - ) { a, b, c -> "${a}th $b is $c" } shouldBe Valid("13th Doctor is false") - } - - "Cartesian builder should build products over Invalid Validated" { - Invalid("fail1").zip( - Semigroup.string(), - Invalid("fail2"), - Valid("Who") - ) { _, _, _ -> "success!" } shouldBe Invalid("fail1fail2") - } - - "Cartesian builder for nel doesn't need semigroup parameter" { - "fail1".invalidNel().zip( - "fail2".invalidNel() - ) { _, _ -> "success!" } shouldBe Invalid(nonEmptyListOf("fail1", "fail2")) - } - - "CombineK should combine Valid Validated" { - val valid = Valid("Who") - - valid.combineK(Semigroup.string(), valid) shouldBe (Valid("Who")) - } - - "CombineK should combine Valid and Invalid Validated" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.combineK(Semigroup.string(), invalid) shouldBe (Valid("Who")) - } - - "CombineK should combine Invalid Validated" { - val invalid = Invalid("Nope") - - invalid.combineK(Semigroup.string(), invalid) shouldBe (Invalid("NopeNope")) - } - - "Combine should combine Valid Validated" { - val valid: Validated = Valid("Who") - - valid.combine(Monoid.string(), Monoid.string(), valid) shouldBe (Valid("WhoWho")) - } - - "Combine should combine Valid and Invalid Validated" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.combine(Monoid.string(), Monoid.string(), invalid) shouldBe (Invalid("Nope")) - } - - "Combine should combine Invalid Validated" { - val invalid: Validated = Invalid("Nope") - - invalid.combine(Monoid.string(), Monoid.string(), invalid) shouldBe (Invalid("NopeNope")) - } - - "traverse should yield list when validated is valid" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.traverse { listOf(it) } shouldBe listOf(Valid("Who")) - invalid.traverse { listOf(it) } shouldBe emptyList() - } - - "sequence should yield consistent result with traverse" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val valid = Valid(a) - val invalid = Invalid(b) - - valid.traverse { listOf(it) } shouldBe valid.map { listOf(it) }.sequence() - invalid.traverse { listOf(it) } shouldBe invalid.map { listOf(it) }.sequence() - } - } - - "traverse for Option should yield option when validated is valid" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.traverse { Some(it) } shouldBe Some(Valid("Who")) - invalid.traverse { Some(it) } shouldBe None - } - - "sequence for Option should yield consistent result with traverseOption" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val valid = Valid(a) - val invalid = Invalid(b) - - valid.traverse { Some(it) } shouldBe valid.map { Some(it) }.sequence() - invalid.traverse { Some(it) } shouldBe invalid.map { Some(it) }.sequence() - } - } - - "traverseNullable should yield non-null object when validated is valid" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.traverseNullable { it } shouldBe Valid("Who") - valid.traverseNullable { null }.shouldBeNull() - invalid.traverseNullable { it }.shouldBeNull() - } - - "sequence for Nullable should yield consistent result with traverseNullable" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val valid = Valid(a) - val invalid = Invalid(b) - - valid.traverseNullable { it } shouldBe valid.map { it }.sequence() - valid.traverseNullable { null } shouldBe valid.map { null }.sequence() - invalid.traverseNullable { it } shouldBe invalid.map { it }.sequence() - } - } - - "traverse for Either should wrap validated in either" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.traverse { it.right() } shouldBe Valid("Who").right() - invalid.traverse { it.right() } shouldBe Invalid("Nope").right() - } - - "sequence for Either should yield consistent result with traverseEither" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val valid = Valid(a) - val invalid = Invalid(b) - - valid.traverse { Right(it) } shouldBe valid.map { Right(it) }.sequence() - invalid.traverse { Right(it) } shouldBe invalid.map { Right(it) }.sequence() - } - } - - "bitraverse should wrap valid or invalid in a list" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.bitraverse({ listOf(it) }, { listOf(it) }) shouldBe listOf(Valid("Who")) - invalid.bitraverse({ listOf(it) }, { listOf(it) }) shouldBe listOf(Invalid("Nope")) - } - - "bisequence should yield consistent result with bitraverse" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val valid: Validated = Valid(a) - val invalid: Validated = Invalid(b) - - valid.bimap({ listOf(it) }, { listOf(it) }).bisequence() shouldBe valid.bitraverse( - { listOf(it) }, - { listOf(it) }) - invalid.bimap({ listOf(it) }, { listOf(it) }).bisequence() shouldBe invalid.bitraverse( - { listOf(it) }, - { listOf(it) }) - } - } - - "bitraverseOption should wrap valid or invalid in an option" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.bitraverseOption({ Some(it) }, { Some(it) }) shouldBe Some(Valid("Who")) - invalid.bitraverseOption({ Some(it) }, { Some(it) }) shouldBe Some(Invalid("Nope")) - } - - "bisequenceOption should yield consistent result with bitraverseOption" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val valid: Validated = Valid(a) - val invalid: Validated = Invalid(b) - - valid.bimap({ Some(it) }, { Some(it) }).bisequenceOption() shouldBe - valid.bitraverseOption({ Some(it) }, { Some(it) }) - invalid.bimap({ Some(it) }, { Some(it) }).bisequenceOption() shouldBe - invalid.bitraverseOption({ Some(it) }, { Some(it) }) - } - } - - "bisequenceNullable should yield consistent result with bitraverseNullable" { - checkAll(Arb.string().orNull(), Arb.string().orNull()) { a: String?, b: String? -> - val valid: Validated = Valid(a) - val invalid: Validated = Invalid(b) - - valid.bimap({ it }, { it }).bisequenceNullable() shouldBe - valid.bitraverseNullable({ it }, { it }) - invalid.bimap({ it }, { it }).bisequenceNullable() shouldBe - invalid.bitraverseNullable({ it }, { it }) - } - } - - "bitraverseNullable should wrap valid or invalid in a nullable" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.bitraverseNullable({ it }, { it }) shouldBe Valid("Who") - invalid.bitraverseNullable({ it }, { it }) shouldBe Invalid("Nope") - } - - "bitraverseEither should wrap valid or invalid in an either" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.bitraverseEither({ it.left() }, { it.right() }) shouldBe Valid("Who").right() - invalid.bitraverseEither({ it.left() }, { it.right() }) shouldBe "Nope".left() - } - - "bisequenceEither should yield consistent result with bitraverseEither" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val valid: Validated = Valid(a) - val invalid: Validated = Invalid(b) - - valid.bimap({ it.left() }, { it.right() }).bisequenceEither() shouldBe - valid.bitraverseEither({ it.left() }, { it.right() }) - invalid.bimap({ it.left() }, { it.right() }).bisequenceEither() shouldBe - invalid.bitraverseEither({ it.left() }, { it.right() }) - } - } - - "andThen should return Valid(result) if f return Valid" { - checkAll(Arb.int(), Arb.int()) { x, y -> - Valid(x).andThen { Valid(it + y) } shouldBe Valid(x + y) - } - } - - "andThen should only run f on valid instances " { - checkAll(Arb.int(), Arb.int()) { x, y -> - Invalid(x).andThen { Valid(y) } shouldBe Invalid(x) - } - } - - "andThen should return Invalid(result) if f return Invalid " { - checkAll(Arb.int(), Arb.int()) { x, y -> - Valid(x).andThen { Invalid(it + y) } shouldBe Invalid(x + y) - } - } - } -} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt index 301ffb7a5d9..ca710afcac0 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt @@ -3,6 +3,7 @@ package arrow.core.computations import arrow.core.Eval import arrow.core.Tuple10 import arrow.core.composeErrors +import arrow.core.computations.ResultEffect.result import arrow.core.flatMap import arrow.core.handleErrorWith import arrow.core.redeemWith diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt index b55d4d20084..c6fd971e03d 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt @@ -10,20 +10,6 @@ class DeadlockTest : UnitSpec() { init { - "classloader should not deadlock Validated initialization" { - runBlocking { - (0..10).map { i -> - GlobalScope.launch { - if (i % 2 == 0) { - Validated.Invalid(Unit) - } else { - Validated.Valid(null) - } - } - }.joinAll() - } - } - "classloader should not deadlock Either initialization" { runBlocking { (0..10).map { i -> diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/ValidatedUsage.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/ValidatedUsage.java deleted file mode 100644 index 26b63fdb4b4..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/ValidatedUsage.java +++ /dev/null @@ -1,19 +0,0 @@ -package arrow.core; - -import kotlin.Unit; -import kotlin.jvm.functions.Function1; - -public class ValidatedUsage { - - public void testUsage() { - Validated throwableIntegerValidated = Validated.tryCatch(() -> 1); - Validated stringIntegerValidated = Validated.tryCatch((throwable) -> throwable.getMessage(), () -> 1); - Function1, Validated> lift = Validated.lift((b) -> b + 1); - Function1, Validated> lift1 = Validated.lift((a) -> a.toUpperCase(), (b) -> b + 1); - Validated unitIntegerValidated = Validated.fromNullable(1, () -> Unit.INSTANCE); - Validated unitIntegerValidated1 = Validated.fromOption(Option.invoke(1), () -> Unit.INSTANCE); - Validated unitIntegerValidated2 = Validated.fromEither(Either.fromNullable(1)); - Validated, Integer> nonEmptyListIntegerValidated = Validated.validNel(1); - Validated, Integer> nonEmptyListObjectValidated = Validated.invalidNel("1"); - } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java index 13bdafaea2c..41821542af6 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java @@ -3,7 +3,6 @@ import arrow.core.Either; import arrow.core.Endo; import arrow.core.Option; -import arrow.core.Validated; import kotlin.Pair; import kotlin.sequences.Sequence; @@ -17,7 +16,6 @@ public void testUsage() { Monoid aShort = Monoid.Short(); Monoid bool = Monoid.Boolean(); Monoid integer = Monoid.Integer(); - Monoid string = Monoid.string(); Monoid> list = Monoid.list(); Monoid> sequence = Monoid.sequence(); @@ -25,7 +23,6 @@ public void testUsage() { Monoid> endo = Monoid.endo(); Monoid> map = Monoid.map(Semigroup.Integer()); Monoid> option = Monoid.option(Semigroup.Integer()); - Monoid> validated = Monoid.validated(Semigroup.Integer(), Monoid.Boolean()); Monoid> pair = Monoid.pair(Monoid.Boolean(), Monoid.Integer()); Monoid.constant(Monoid.Integer()); diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java index 57d4320f09c..3485ee812ec 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java @@ -20,7 +20,6 @@ public void testUsage() { Semigroup> endo = Semigroup.endo(); Semigroup> map = Semigroup.map(Semigroup.Integer()); Semigroup> option = Semigroup.option(Semigroup.Integer()); - Semigroup> validated = Semigroup.validated(Semigroup.Boolean(), Semigroup.Integer()); Semigroup> nonEmptyList = Semigroup.nonEmptyList(); Semigroup> pair = Semigroup.pair(Semigroup.Boolean(), Semigroup.Integer()); Semigroup> constant = Semigroup.constant(Semigroup.Integer()); diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt index 323e8b6fa0f..ddf5ecb4896 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-02.kt @@ -4,12 +4,10 @@ package arrow.core.examples.exampleEffect02 import arrow.core.Either import arrow.core.Ior import arrow.core.None -import arrow.core.Validated import arrow.core.continuations.Effect import arrow.core.continuations.effect import arrow.core.continuations.fold import arrow.core.continuations.toEither -import arrow.core.continuations.toValidated import arrow.core.continuations.toIor import arrow.core.continuations.toOption import arrow.core.continuations.ensureNotNull @@ -45,7 +43,6 @@ fun readFile(path: String?): Effect = effect { suspend fun main() { readFile("").toEither() shouldBe Either.Left(EmptyPath) - readFile("knit.properties").toValidated() shouldBe Validated.Invalid(FileNotFound("knit.properties")) readFile("gradle.properties").toIor() shouldBe Ior.Left(FileNotFound("gradle.properties")) readFile("README.MD").toOption { None } shouldBe None diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt index 3050e4d988b..d9f0dfa712f 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt @@ -3,8 +3,8 @@ package arrow.core.examples.exampleEither02 import arrow.core.Either -val right: Either = - Either.Right(5) +val left: Either = + Either.Left("Something went wrong") fun main() { - println(right) + println(left) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt index a30a54e9643..32c1b919271 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt @@ -2,9 +2,10 @@ package arrow.core.examples.exampleEither03 import arrow.core.Either +import arrow.core.flatMap -val left: Either = - Either.Left("Something went wrong") +val right: Either = Either.Right(5) +val value = right.flatMap{ Either.Right(it + 1) } fun main() { - println(left) + println("value = $value") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt index 86bf1302c74..002655609b2 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt @@ -4,8 +4,8 @@ package arrow.core.examples.exampleEither04 import arrow.core.Either import arrow.core.flatMap -val right: Either = Either.Right(5) -val value = right.flatMap{ Either.Right(it + 1) } +val left: Either = Either.Left("Something went wrong") +val value = left.flatMap{ Either.Right(it + 1) } fun main() { println("value = $value") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt index 28c39f3df3f..90c14927889 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt @@ -4,8 +4,12 @@ package arrow.core.examples.exampleEither05 import arrow.core.Either import arrow.core.flatMap -val left: Either = Either.Left("Something went wrong") -val value = left.flatMap{ Either.Right(it + 1) } -fun main() { - println("value = $value") -} +fun parse(s: String): Int = + if (s.matches(Regex("-?[0-9]+"))) s.toInt() + else throw NumberFormatException("$s is not a valid integer.") + +fun reciprocal(i: Int): Double = + if (i == 0) throw IllegalArgumentException("Cannot take reciprocal of 0.") + else 1.0 / i + +fun stringify(d: Double): String = d.toString() diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt index 67df2d4b8cb..3bcaf31e093 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt @@ -3,13 +3,19 @@ package arrow.core.examples.exampleEither06 import arrow.core.Either import arrow.core.flatMap +import arrow.core.left +import arrow.core.right -fun parse(s: String): Int = - if (s.matches(Regex("-?[0-9]+"))) s.toInt() - else throw NumberFormatException("$s is not a valid integer.") +// Either Style +fun parse(s: String): Either = + if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) + else Either.Left(NumberFormatException("$s is not a valid integer.")) -fun reciprocal(i: Int): Double = - if (i == 0) throw IllegalArgumentException("Cannot take reciprocal of 0.") - else 1.0 / i +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0.")) + else Either.Right(1.0 / i) fun stringify(d: Double): String = d.toString() + +fun magic(s: String): Either = + parse(s).flatMap { reciprocal(it) }.map { stringify(it) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt index 6565442240c..71cf5d27d22 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt @@ -2,20 +2,14 @@ package arrow.core.examples.exampleEither07 import arrow.core.Either -import arrow.core.flatMap -import arrow.core.left -import arrow.core.right -// Either Style fun parse(s: String): Either = if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) else Either.Left(NumberFormatException("$s is not a valid integer.")) -fun reciprocal(i: Int): Either = - if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0.")) - else Either.Right(1.0 / i) - -fun stringify(d: Double): String = d.toString() - -fun magic(s: String): Either = - parse(s).flatMap { reciprocal(it) }.map { stringify(it) } +val notANumber = parse("Not a number") +val number2 = parse("2") +fun main() { + println("notANumber = $notANumber") + println("number2 = $number2") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt index e25b8aaf693..67c0390ef19 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt @@ -2,14 +2,26 @@ package arrow.core.examples.exampleEither08 import arrow.core.Either +import arrow.core.flatMap fun parse(s: String): Either = if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) else Either.Left(NumberFormatException("$s is not a valid integer.")) -val notANumber = parse("Not a number") -val number2 = parse("2") +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0.")) + else Either.Right(1.0 / i) + +fun stringify(d: Double): String = d.toString() + +fun magic(s: String): Either = + parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } + +val magic0 = magic("0") +val magic1 = magic("1") +val magicNotANumber = magic("Not a number") fun main() { - println("notANumber = $notANumber") - println("number2 = $number2") + println("magic0 = $magic0") + println("magic1 = $magic1") + println("magicNotANumber = $magicNotANumber") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt index 6e01423972f..824832efff8 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt @@ -17,11 +17,15 @@ fun stringify(d: Double): String = d.toString() fun magic(s: String): Either = parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } -val magic0 = magic("0") -val magic1 = magic("1") -val magicNotANumber = magic("Not a number") +val x = magic("2") +val value = when(x) { + is Either.Left -> when (x.value) { + is NumberFormatException -> "Not a number!" + is IllegalArgumentException -> "Can't take reciprocal of 0!" + else -> "Unknown error" + } + is Either.Right -> "Got reciprocal: ${x.value}" +} fun main() { - println("magic0 = $magic0") - println("magic1 = $magic1") - println("magicNotANumber = $magicNotANumber") + println("value = $value") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt index 84d23516808..fc1ae99d530 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt @@ -3,29 +3,22 @@ package arrow.core.examples.exampleEither10 import arrow.core.Either import arrow.core.flatMap +// Either with ADT Style -fun parse(s: String): Either = +sealed class Error { + object NotANumber : Error() + object NoZeroReciprocal : Error() +} + +fun parse(s: String): Either = if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) - else Either.Left(NumberFormatException("$s is not a valid integer.")) + else Either.Left(Error.NotANumber) -fun reciprocal(i: Int): Either = - if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0.")) +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(Error.NoZeroReciprocal) else Either.Right(1.0 / i) fun stringify(d: Double): String = d.toString() -fun magic(s: String): Either = - parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } - -val x = magic("2") -val value = when(x) { - is Either.Left -> when (x.value) { - is NumberFormatException -> "Not a number!" - is IllegalArgumentException -> "Can't take reciprocal of 0!" - else -> "Unknown error" - } - is Either.Right -> "Got reciprocal: ${x.value}" -} -fun main() { - println("value = $value") -} +fun magic(s: String): Either = + parse(s).flatMap{reciprocal(it)}.map{ stringify(it) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt index 3b4172abc69..86ee196c7b6 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt @@ -3,11 +3,10 @@ package arrow.core.examples.exampleEither11 import arrow.core.Either import arrow.core.flatMap -// Either with ADT Style sealed class Error { - object NotANumber : Error() - object NoZeroReciprocal : Error() + object NotANumber : Error() + object NoZeroReciprocal : Error() } fun parse(s: String): Either = @@ -21,4 +20,16 @@ fun reciprocal(i: Int): Either = fun stringify(d: Double): String = d.toString() fun magic(s: String): Either = - parse(s).flatMap{reciprocal(it)}.map{ stringify(it) } + parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } + +val x = magic("2") +val value = when(x) { + is Either.Left -> when (x.value) { + is Error.NotANumber -> "Not a number!" + is Error.NoZeroReciprocal -> "Can't take reciprocal of 0!" + } + is Either.Right -> "Got reciprocal: ${x.value}" +} +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt index bca693c137c..7dbf4740624 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt @@ -2,34 +2,15 @@ package arrow.core.examples.exampleEither12 import arrow.core.Either -import arrow.core.flatMap -sealed class Error { - object NotANumber : Error() - object NoZeroReciprocal : Error() -} - -fun parse(s: String): Either = - if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) - else Either.Left(Error.NotANumber) - -fun reciprocal(i: Int): Either = - if (i == 0) Either.Left(Error.NoZeroReciprocal) - else Either.Right(1.0 / i) +fun potentialThrowingCode(): String = throw RuntimeException("Blow up!") -fun stringify(d: Double): String = d.toString() - -fun magic(s: String): Either = - parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } - -val x = magic("2") -val value = when(x) { - is Either.Left -> when (x.value) { - is Error.NotANumber -> "Not a number!" - is Error.NoZeroReciprocal -> "Can't take reciprocal of 0!" - } - is Either.Right -> "Got reciprocal: ${x.value}" +suspend fun makeSureYourLogicDoesNotHaveSideEffects(): Either = + Either.catch { potentialThrowingCode() }.mapLeft { Error.SpecificError } +suspend fun main() { + println("makeSureYourLogicDoesNotHaveSideEffects().isLeft() = ${makeSureYourLogicDoesNotHaveSideEffects().isLeft()}") } -fun main() { - println("value = $value") + +sealed class Error { + object SpecificError : Error() } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt index 868a711873d..39facde74d0 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt @@ -2,15 +2,78 @@ package arrow.core.examples.exampleEither13 import arrow.core.Either +import arrow.core.flatMap +import arrow.core.left +import arrow.core.right -fun potentialThrowingCode(): String = throw RuntimeException("Blow up!") - -suspend fun makeSureYourLogicDoesNotHaveSideEffects(): Either = - Either.catch { potentialThrowingCode() }.mapLeft { Error.SpecificError } +suspend fun httpEndpoint(request: String = "Hello?") = + Either.resolve( + f = { + if (request == "Hello?") "HELLO WORLD!".right() + else Error.SpecificError.left() + }, + success = { a -> handleSuccess({ a: Any -> log(Level.INFO, "This is a: $a") }, a) }, + error = { e -> handleError({ e: Any -> log(Level.WARN, "This is e: $e") }, e) }, + throwable = { throwable -> handleThrowable({ throwable: Throwable -> log(Level.ERROR, "Log the throwable: $throwable.") }, throwable) }, + unrecoverableState = { _ -> Unit.right() } + ) suspend fun main() { - println("makeSureYourLogicDoesNotHaveSideEffects().isLeft() = ${makeSureYourLogicDoesNotHaveSideEffects().isLeft()}") + println("httpEndpoint().status = ${httpEndpoint().status}") +} + +@Suppress("UNUSED_PARAMETER") +suspend fun handleSuccess(log: suspend (a: A) -> Either, a: A): Either = + Either.catch { + Response.Builder(HttpStatus.OK) + .header(CONTENT_TYPE, CONTENT_TYPE_APPLICATION_JSON) + .body(a) + .build() + } + +@Suppress("UNUSED_PARAMETER") +suspend fun handleError(log: suspend (e: E) -> Either, e: E): Either = + createErrorResponse(HttpStatus.NOT_FOUND, ErrorResponse("$ERROR_MESSAGE_PREFIX $e")) + +suspend fun handleThrowable(log: suspend (throwable: Throwable) -> Either, throwable: Throwable): Either = + log(throwable) + .flatMap { createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ErrorResponse("$THROWABLE_MESSAGE_PREFIX $throwable")) } + +suspend fun createErrorResponse(httpStatus: HttpStatus, errorResponse: ErrorResponse): Either = + Either.catch { + Response.Builder(httpStatus) + .header(CONTENT_TYPE, CONTENT_TYPE_APPLICATION_JSON) + .body(errorResponse) + .build() + } + +suspend fun log(level: Level, message: String): Either = + Unit.right() // Should implement logging. + +enum class HttpStatus(val value: Int) { OK(200), NOT_FOUND(404), INTERNAL_SERVER_ERROR(500) } + +class Response private constructor( + val status: HttpStatus, + val headers: Map, + val body: Any? +) { + + data class Builder( + val status: HttpStatus, + var headers: Map = emptyMap(), + var body: Any? = null + ) { + fun header(key: String, value: String) = apply { this.headers = this.headers + mapOf(key to value) } + fun body(body: Any?) = apply { this.body = body } + fun build() = Response(status, headers, body) + } } +val CONTENT_TYPE = "Content-Type" +val CONTENT_TYPE_APPLICATION_JSON = "application/json" +val ERROR_MESSAGE_PREFIX = "An error has occurred. The error is:" +val THROWABLE_MESSAGE_PREFIX = "An exception was thrown. The exception is:" sealed class Error { object SpecificError : Error() } +data class ErrorResponse(val errorMessage: String) +enum class Level { INFO, WARN, ERROR } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt index e4aefdd6134..a1b3c01b74b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt @@ -2,78 +2,12 @@ package arrow.core.examples.exampleEither14 import arrow.core.Either -import arrow.core.flatMap -import arrow.core.left -import arrow.core.right -suspend fun httpEndpoint(request: String = "Hello?") = - Either.resolve( - f = { - if (request == "Hello?") "HELLO WORLD!".right() - else Error.SpecificError.left() - }, - success = { a -> handleSuccess({ a: Any -> log(Level.INFO, "This is a: $a") }, a) }, - error = { e -> handleError({ e: Any -> log(Level.WARN, "This is e: $e") }, e) }, - throwable = { throwable -> handleThrowable({ throwable: Throwable -> log(Level.ERROR, "Log the throwable: $throwable.") }, throwable) }, - unrecoverableState = { _ -> Unit.right() } - ) -suspend fun main() { - println("httpEndpoint().status = ${httpEndpoint().status}") +val r : Either = Either.Right(7) +val rightMapLeft = r.mapLeft {it + 1} +val l: Either = Either.Left(7) +val leftMapLeft = l.mapLeft {it + 1} +fun main() { + println("rightMapLeft = $rightMapLeft") + println("leftMapLeft = $leftMapLeft") } - -@Suppress("UNUSED_PARAMETER") -suspend fun handleSuccess(log: suspend (a: A) -> Either, a: A): Either = - Either.catch { - Response.Builder(HttpStatus.OK) - .header(CONTENT_TYPE, CONTENT_TYPE_APPLICATION_JSON) - .body(a) - .build() - } - -@Suppress("UNUSED_PARAMETER") -suspend fun handleError(log: suspend (e: E) -> Either, e: E): Either = - createErrorResponse(HttpStatus.NOT_FOUND, ErrorResponse("$ERROR_MESSAGE_PREFIX $e")) - -suspend fun handleThrowable(log: suspend (throwable: Throwable) -> Either, throwable: Throwable): Either = - log(throwable) - .flatMap { createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ErrorResponse("$THROWABLE_MESSAGE_PREFIX $throwable")) } - -suspend fun createErrorResponse(httpStatus: HttpStatus, errorResponse: ErrorResponse): Either = - Either.catch { - Response.Builder(httpStatus) - .header(CONTENT_TYPE, CONTENT_TYPE_APPLICATION_JSON) - .body(errorResponse) - .build() - } - -suspend fun log(level: Level, message: String): Either = - Unit.right() // Should implement logging. - -enum class HttpStatus(val value: Int) { OK(200), NOT_FOUND(404), INTERNAL_SERVER_ERROR(500) } - -class Response private constructor( - val status: HttpStatus, - val headers: Map, - val body: Any? -) { - - data class Builder( - val status: HttpStatus, - var headers: Map = emptyMap(), - var body: Any? = null - ) { - fun header(key: String, value: String) = apply { this.headers = this.headers + mapOf(key to value) } - fun body(body: Any?) = apply { this.body = body } - fun build() = Response(status, headers, body) - } -} - -val CONTENT_TYPE = "Content-Type" -val CONTENT_TYPE_APPLICATION_JSON = "application/json" -val ERROR_MESSAGE_PREFIX = "An error has occurred. The error is:" -val THROWABLE_MESSAGE_PREFIX = "An exception was thrown. The exception is:" -sealed class Error { - object SpecificError : Error() -} -data class ErrorResponse(val errorMessage: String) -enum class Level { INFO, WARN, ERROR } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt index 02ba7e88a61..59aab0f8a32 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt @@ -1,13 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither15 +import arrow.core.Either.Left import arrow.core.Either -val r : Either = Either.Right(7) -val rightMapLeft = r.mapLeft {it + 1} -val l: Either = Either.Left(7) -val leftMapLeft = l.mapLeft {it + 1} +val r: Either = Either.Right(7) +val swapped = r.swap() fun main() { - println("rightMapLeft = $rightMapLeft") - println("leftMapLeft = $leftMapLeft") + println("swapped = $swapped") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt index 20f29c59fcf..cd71592aeab 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt @@ -1,11 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither16 -import arrow.core.Either.Left -import arrow.core.Either +import arrow.core.right -val r: Either = Either.Right(7) -val swapped = r.swap() +val right7 = + 7.right() fun main() { - println("swapped = $swapped") + println(right7) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt index 4a9e9269241..f820c3c1392 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt @@ -1,10 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither17 -import arrow.core.right +import arrow.core.left -val right7 = - 7.right() + val leftHello = + "hello".left() fun main() { - println(right7) + println(leftHello) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt index 61b4cfa3593..42bb4561126 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt @@ -1,10 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither18 -import arrow.core.left +import arrow.core.right +import arrow.core.contains - val leftHello = - "hello".left() +val x = 7.right() +val contains7 = x.contains(7) fun main() { - println(leftHello) + println("contains7 = $contains7") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt index 6d1ea1331b2..8aedf5ce5c5 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt @@ -1,11 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither19 -import arrow.core.right -import arrow.core.contains +import arrow.core.left +import arrow.core.getOrElse -val x = 7.right() -val contains7 = x.contains(7) +val x = "hello".left() +val getOr7 = x.getOrElse { 7 } fun main() { - println("contains7 = $contains7") + println("getOr7 = $getOr7") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt index 2dd4aae24ad..9eb763740c5 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt @@ -2,10 +2,10 @@ package arrow.core.examples.exampleEither20 import arrow.core.left -import arrow.core.getOrElse +import arrow.core.getOrHandle val x = "hello".left() -val getOr7 = x.getOrElse { 7 } +val value = x.getOrHandle { "$it world!" } fun main() { - println("getOr7 = $getOr7") + println("value = $value") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt index 67e7eb953bf..097a73f6ebe 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt @@ -1,11 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither21 -import arrow.core.left -import arrow.core.getOrHandle +import arrow.core.Either -val x = "hello".left() -val value = x.getOrHandle { "$it world!" } +val value = + Either.conditionally(true, { "Error" }, { 42 }) fun main() { - println("value = $value") + println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt index f9cfa9ae33c..71cec73792c 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt @@ -4,7 +4,7 @@ package arrow.core.examples.exampleEither22 import arrow.core.Either val value = - Either.conditionally(true, { "Error" }, { 42 }) + Either.conditionally(false, { "Error" }, { 42 }) fun main() { println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt index 177ba8a52d7..6dd2e13d6c8 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt @@ -2,9 +2,10 @@ package arrow.core.examples.exampleEither23 import arrow.core.Either +import arrow.core.right -val value = - Either.conditionally(false, { "Error" }, { 42 }) +val x : Either = 7.right() +val fold = x.fold({ 1 }, { it + 3 }) fun main() { - println(value) + println("fold = $fold") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt index 540212da3d0..13ae7406ca9 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt @@ -2,10 +2,10 @@ package arrow.core.examples.exampleEither24 import arrow.core.Either -import arrow.core.right +import arrow.core.left -val x : Either = 7.right() -val fold = x.fold({ 1 }, { it + 3 }) +val y : Either = 7.left() +val fold = y.fold({ 1 }, { it + 3 }) fun main() { println("fold = $fold") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt index f212f13b69e..afa8209d5ff 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt @@ -2,10 +2,15 @@ package arrow.core.examples.exampleEither25 import arrow.core.Either -import arrow.core.left +import arrow.core.getOrHandle -val y : Either = 7.left() -val fold = y.fold({ 1 }, { it + 3 }) +val r: Either = Either.Left(NumberFormatException()) +val httpStatusCode = r.getOrHandle { + when(it) { + is NumberFormatException -> 400 + else -> 500 + } +} fun main() { - println("fold = $fold") + println("httpStatusCode = $httpStatusCode") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt index 2efc6e305d4..44146180023 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt @@ -1,16 +1,13 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither26 -import arrow.core.Either -import arrow.core.getOrHandle +import arrow.core.Either.Right +import arrow.core.leftIfNull -val r: Either = Either.Left(NumberFormatException()) -val httpStatusCode = r.getOrHandle { - when(it) { - is NumberFormatException -> 400 - else -> 500 - } -} fun main() { - println("httpStatusCode = $httpStatusCode") + val value = + //sampleStart + Right(12).leftIfNull({ -1 }) + //sampleEnd + println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt index c446a01405f..a5790b4af2e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt @@ -4,10 +4,8 @@ package arrow.core.examples.exampleEither27 import arrow.core.Either.Right import arrow.core.leftIfNull +val value = + Right(null).leftIfNull({ -1 }) fun main() { - val value = - //sampleStart - Right(12).leftIfNull({ -1 }) - //sampleEnd - println(value) + println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt index 9ce8328c1a1..b28c90bf578 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt @@ -1,11 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither28 -import arrow.core.Either.Right +import arrow.core.Either.Left import arrow.core.leftIfNull val value = - Right(null).leftIfNull({ -1 }) + Left(12).leftIfNull({ -1 }) fun main() { println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt index b260eb2681a..d26ce296458 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt @@ -1,11 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither29 -import arrow.core.Either.Left -import arrow.core.leftIfNull +import arrow.core.rightIfNotNull val value = - Left(12).leftIfNull({ -1 }) + "value".rightIfNotNull { "left" } fun main() { println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt index b68274ffcc6..41ee5901fd8 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt @@ -4,7 +4,7 @@ package arrow.core.examples.exampleEither30 import arrow.core.rightIfNotNull val value = - "value".rightIfNotNull { "left" } + null.rightIfNotNull { "left" } fun main() { println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt index 2a73a11a0fd..f28c329b18a 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt @@ -1,10 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither31 -import arrow.core.rightIfNotNull +import arrow.core.rightIfNull val value = - null.rightIfNotNull { "left" } + "value".rightIfNull { "left" } fun main() { println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt index 2fe7fe4f955..5303f1e0a28 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt @@ -4,7 +4,7 @@ package arrow.core.examples.exampleEither32 import arrow.core.rightIfNull val value = - "value".rightIfNull { "left" } + null.rightIfNull { "left" } fun main() { println(value) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt index bcf492a1a31..4fdf5863ad1 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt @@ -1,10 +1,14 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither33 -import arrow.core.rightIfNull +import arrow.core.Either +import io.kotest.matchers.shouldBe +import io.kotest.assertions.fail -val value = - null.rightIfNull { "left" } -fun main() { - println(value) +fun test() { + Either.Right(1) + .fold({ fail("Cannot be left") }, { it + 1 }) shouldBe 2 + + Either.Left(RuntimeException("Boom!")) + .fold({ -1 }, { fail("Cannot be right") }) shouldBe -1 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt index f48d72dacdd..20367ece978 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt @@ -3,12 +3,8 @@ package arrow.core.examples.exampleEither34 import arrow.core.Either import io.kotest.matchers.shouldBe -import io.kotest.assertions.fail fun test() { - Either.Right(1) - .fold({ fail("Cannot be left") }, { it + 1 }) shouldBe 2 - - Either.Left(RuntimeException("Boom!")) - .fold({ -1 }, { fail("Cannot be right") }) shouldBe -1 + Either.Left("left").swap() shouldBe Either.Right("left") + Either.Right("right").swap() shouldBe Either.Left("right") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt index 2161775ad0a..b3c57be1b56 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt @@ -5,6 +5,6 @@ import arrow.core.Either import io.kotest.matchers.shouldBe fun test() { - Either.Left("left").swap() shouldBe Either.Right("left") - Either.Right("right").swap() shouldBe Either.Left("right") + Either.Right(12).map { _: Int ->"flower" } shouldBe Either.Right("flower") + Either.Left(12).map { _: Nothing -> "flower" } shouldBe Either.Left(12) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt index f248f131e99..a6ad1b661f4 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt @@ -5,6 +5,6 @@ import arrow.core.Either import io.kotest.matchers.shouldBe fun test() { - Either.Right(12).map { _: Int ->"flower" } shouldBe Either.Right("flower") - Either.Left(12).map { _: Nothing -> "flower" } shouldBe Either.Left(12) + Either.Right(12).mapLeft { _: Nothing -> "flower" } shouldBe Either.Right(12) + Either.Left(12).mapLeft { _: Int -> "flower" } shouldBe Either.Left("flower") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt index dd86132c740..0895bcb4335 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt @@ -5,6 +5,5 @@ import arrow.core.Either import io.kotest.matchers.shouldBe fun test() { - Either.Right(12).mapLeft { _: Nothing -> "flower" } shouldBe Either.Right(12) - Either.Left(12).mapLeft { _: Int -> "flower" } shouldBe Either.Left("flower") + Either.Right(1).onRight(::println) shouldBe Either.Right(1) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-38.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-38.kt index 22f3f2e0d31..83ccbf67399 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-38.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-38.kt @@ -5,5 +5,5 @@ import arrow.core.Either import io.kotest.matchers.shouldBe fun test() { - Either.Right(1).onRight(::println) shouldBe Either.Right(1) + Either.Left(2).onLeft(::println) shouldBe Either.Left(2) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-39.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-39.kt index cce818e44c3..1c5d5a73ea5 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-39.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-39.kt @@ -2,8 +2,12 @@ package arrow.core.examples.exampleEither39 import arrow.core.Either -import io.kotest.matchers.shouldBe +import arrow.core.Either.Left -fun test() { - Either.Left(2).onLeft(::println) shouldBe Either.Left(2) +fun main() { + Either.Right(12).exists { it > 10 } // Result: true + Either.Right(7).exists { it > 10 } // Result: false + + val left: Either = Left(12) + left.exists { it > 10 } // Result: false } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-40.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-40.kt index 3ec2b39bfa5..5222f325036 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-40.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-40.kt @@ -2,12 +2,9 @@ package arrow.core.examples.exampleEither40 import arrow.core.Either -import arrow.core.Either.Left +import io.kotest.matchers.shouldBe -fun main() { - Either.Right(12).exists { it > 10 } // Result: true - Either.Right(7).exists { it > 10 } // Result: false - - val left: Either = Left(12) - left.exists { it > 10 } // Result: false +fun test() { + Either.Right(12).getOrNull() shouldBe 12 + Either.Left(12).getOrNull() shouldBe null } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-41.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-41.kt index 2343f3aecdc..9e1833e18ca 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-41.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-41.kt @@ -2,9 +2,11 @@ package arrow.core.examples.exampleEither41 import arrow.core.Either +import arrow.core.Some +import arrow.core.None import io.kotest.matchers.shouldBe fun test() { - Either.Right(12).getOrNull() shouldBe 12 - Either.Left(12).getOrNull() shouldBe null + Either.Right(12).getOrNone() shouldBe Some(12) + Either.Left(12).getOrNone() shouldBe None } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-42.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-42.kt index 49dff50b172..cd9256c06b2 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-42.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-42.kt @@ -1,12 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither42 -import arrow.core.Either -import arrow.core.Some -import arrow.core.None -import io.kotest.matchers.shouldBe +import arrow.core.* -fun test() { - Either.Right(12).getOrNone() shouldBe Some(12) - Either.Left(12).getOrNone() shouldBe None + fun main(args: Array) { + //sampleStart + Either.Left("foo").isEmpty() // Result: true + Either.Right("foo").isEmpty() // Result: false } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-43.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-43.kt index 31d6b07320e..e98eda5328a 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-43.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-43.kt @@ -1,10 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither43 -import arrow.core.* + import arrow.core.* fun main(args: Array) { //sampleStart - Either.Left("foo").isEmpty() // Result: true - Either.Right("foo").isEmpty() // Result: false + Either.Left("foo").isNotEmpty() // Result: false + Either.Right("foo").isNotEmpty() // Result: true + //sampleEnd } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-44.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-44.kt index 002f7f0f5a1..27ed105719f 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-44.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-44.kt @@ -1,11 +1,3 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither44 - import arrow.core.* - - fun main(args: Array) { - //sampleStart - Either.Left("foo").isNotEmpty() // Result: false - Either.Right("foo").isNotEmpty() // Result: true - //sampleEnd -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt index 3a3f71679f4..6dc03e51b22 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-45.kt @@ -1,3 +1,15 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither45 +import arrow.core.Either +import arrow.core.left +import arrow.core.recover + +object User +object Error + +val error: Either = Error.left() + +val a: Either = error.recover { error -> User } // Either.Right(User) +val b: Either = error.recover { error -> raise("other-failure") } // Either.Left(other-failure) +val c: Either = error.recover { error -> User } // Either.Right(User) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt index d1ab410df5d..0de140e5df0 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-46.kt @@ -1,15 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither46 -import arrow.core.Either -import arrow.core.left -import arrow.core.recover - -object User -object Error - -val error: Either = Error.left() - -val a: Either = error.recover { error -> User } // Either.Right(User) -val b: Either = error.recover { error -> raise("other-failure") } // Either.Left(other-failure) -val c: Either = error.recover { error -> User } // Either.Right(User) +import arrow.core.Either.Right +import arrow.core.Either.Left +import arrow.core.getOrElse + +fun main() { + Right(12).getOrElse { 17 } // Result: 12 + Left(12).getOrElse { 17 } // Result: 17 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt index 28860545c61..46b0999a119 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-47.kt @@ -1,11 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither47 -import arrow.core.Either.Right -import arrow.core.Either.Left +import arrow.core.Either import arrow.core.getOrElse +import io.kotest.matchers.shouldBe -fun main() { - Right(12).getOrElse { 17 } // Result: 12 - Left(12).getOrElse { 17 } // Result: 17 +fun test() { + Either.Left(12).getOrElse { it + 5 } shouldBe 17 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt index 9ae9a4fa129..ff3e62a29c2 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-48.kt @@ -1,10 +1,10 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither48 -import arrow.core.Either -import arrow.core.getOrElse -import io.kotest.matchers.shouldBe +import arrow.core.Either.Right +import arrow.core.Either.Left -fun test() { - Either.Left(12).getOrElse { it + 5 } shouldBe 17 +fun main() { + Right(12).orNull() // Result: 12 + Left(12).orNull() // Result: null } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt index 6ce0f21c435..38db9474435 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-49.kt @@ -3,8 +3,9 @@ package arrow.core.examples.exampleEither49 import arrow.core.Either.Right import arrow.core.Either.Left +import arrow.core.getOrHandle fun main() { - Right(12).orNull() // Result: 12 - Left(12).orNull() // Result: null + Right(12).getOrHandle { 17 } // Result: 12 + Left(12).getOrHandle { it + 5 } // Result: 17 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt index 75e9c042f2e..2b49927eb6a 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-50.kt @@ -1,11 +1,14 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither50 -import arrow.core.Either.Right -import arrow.core.Either.Left -import arrow.core.getOrHandle +import arrow.core.Either.* +import arrow.core.Either +import arrow.core.filterOrElse fun main() { - Right(12).getOrHandle { 17 } // Result: 12 - Left(12).getOrHandle { it + 5 } // Result: 17 + Right(12).filterOrElse({ it > 10 }, { -1 }) // Result: Right(12) + Right(7).filterOrElse({ it > 10 }, { -1 }) // Result: Left(-1) + + val left: Either = Left(12) + left.filterOrElse({ it > 10 }, { -1 }) // Result: Left(12) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt index bc0e11db6d6..8560381bf73 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-51.kt @@ -1,14 +1,17 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither51 -import arrow.core.Either.* -import arrow.core.Either -import arrow.core.filterOrElse +import arrow.core.* -fun main() { - Right(12).filterOrElse({ it > 10 }, { -1 }) // Result: Right(12) - Right(7).filterOrElse({ it > 10 }, { -1 }) // Result: Left(-1) +suspend fun main(): Unit { + //sampleStart + Either.Right(7).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) + .let(::println) // Either.Left(Value '7' is not equal to 10") - val left: Either = Left(12) - left.filterOrElse({ it > 10 }, { -1 }) // Result: Left(12) + Either.Right(10).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) + .let(::println) // Either.Right(10) + + Either.Left(12).filterOrOther({ str: String -> str.contains("impossible") }, { -1 }) + .let(::println) // Either.Left(12) + //sampleEnd } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt index cdb403a4abe..c2719fe2091 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-52.kt @@ -1,17 +1,11 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither52 -import arrow.core.* +import arrow.core.Either.Left +import arrow.core.Either.Right +import arrow.core.merge -suspend fun main(): Unit { - //sampleStart - Either.Right(7).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) - .let(::println) // Either.Left(Value '7' is not equal to 10") - - Either.Right(10).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) - .let(::println) // Either.Right(10) - - Either.Left(12).filterOrOther({ str: String -> str.contains("impossible") }, { -1 }) - .let(::println) // Either.Left(12) - //sampleEnd +fun test() { + Right(12).merge() // Result: 12 + Left(12).merge() // Result: 12 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt index 2f98374614c..17db0b7f08f 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-53.kt @@ -1,11 +1,12 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither53 -import arrow.core.Either.Left -import arrow.core.Either.Right -import arrow.core.merge +import arrow.core.Either.* +import arrow.core.leftIfNull -fun test() { - Right(12).merge() // Result: 12 - Left(12).merge() // Result: 12 +fun main() { + Right(12).leftIfNull({ -1 }) // Result: Right(12) + Right(null).leftIfNull({ -1 }) // Result: Left(-1) + + Left(12).leftIfNull({ -1 }) // Result: Left(12) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt index 84f02542120..89b224ff078 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-54.kt @@ -1,12 +1,9 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither54 -import arrow.core.Either.* -import arrow.core.leftIfNull +import arrow.core.rightIfNotNull fun main() { - Right(12).leftIfNull({ -1 }) // Result: Right(12) - Right(null).leftIfNull({ -1 }) // Result: Left(-1) - - Left(12).leftIfNull({ -1 }) // Result: Left(12) + "value".rightIfNotNull { "left" } // Right(b="value") + null.rightIfNotNull { "left" } // Left(a="left") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-55.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-55.kt index cf8307ed2fd..71b721f7906 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-55.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-55.kt @@ -1,9 +1,13 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither55 -import arrow.core.rightIfNotNull +import arrow.core.* -fun main() { - "value".rightIfNotNull { "left" } // Right(b="value") - null.rightIfNotNull { "left" } // Left(a="left") +fun main(args: Array) { + //sampleStart + val string: Either = "Hello".right() + val chars: Either = + string.widen() + //sampleEnd + println(chars) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-56.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-56.kt deleted file mode 100644 index c461bd28af6..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-56.kt +++ /dev/null @@ -1,13 +0,0 @@ -// This file was automatically generated from Either.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEither56 - -import arrow.core.* - -fun main(args: Array) { - //sampleStart - val string: Either = "Hello".right() - val chars: Either = - string.widen() - //sampleEnd - println(chars) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt index 036dce24083..97e7f426fa1 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt @@ -4,7 +4,9 @@ package arrow.core.examples.exampleIor12 import arrow.core.Ior fun main() { - Ior.Right(12).toValidated() // Result: Valid(12) - Ior.Left(12).toValidated() // Result: Invalid(12) - Ior.Both(12, "power").toValidated() // Result: Valid("power") + Ior.Both(5, 12).exists { it > 10 } // Result: true + Ior.Right(12).exists { it > 10 } // Result: true + Ior.Right(7).exists { it > 10 } // Result: false + val left: Ior = Ior.Left(12) + left.exists { it > 10 } // Result: false } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-13.kt index bc719ff8273..197b2a4a17e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-13.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-13.kt @@ -1,12 +1,13 @@ // This file was automatically generated from Ior.kt by Knit tool. Do not edit. package arrow.core.examples.exampleIor13 -import arrow.core.Ior +import arrow.core.* -fun main() { - Ior.Both(5, 12).exists { it > 10 } // Result: true - Ior.Right(12).exists { it > 10 } // Result: true - Ior.Right(7).exists { it > 10 } // Result: false - val left: Ior = Ior.Left(12) - left.exists { it > 10 } // Result: false +fun main(args: Array) { + //sampleStart + val string: Ior = Ior.Right("Hello") + val chars: Ior = + string.widen() + //sampleEnd + println(chars) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-14.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-14.kt deleted file mode 100644 index 78ff26a2ff5..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-14.kt +++ /dev/null @@ -1,13 +0,0 @@ -// This file was automatically generated from Ior.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleIor14 - -import arrow.core.* - -fun main(args: Array) { - //sampleStart - val string: Ior = Ior.Right("Hello") - val chars: Ior = - string.widen() - //sampleEnd - println(chars) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt index 66f22e58f7f..20281fe4a0e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt @@ -2,7 +2,7 @@ package arrow.core.examples.exampleResultComputations01 import arrow.core.* -import arrow.core.computations.result +import arrow.core.computations.ResultEffect.result fun main() { result { // We can safely use assertion based operation inside blocks diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-01.kt deleted file mode 100644 index fc02b28723c..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-01.kt +++ /dev/null @@ -1,14 +0,0 @@ -// This file was automatically generated from Validated.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleValidated01 - -import arrow.core.* - -fun main(args: Array) { - //sampleStart - val f = Validated.lift(String::toUpperCase, Int::inc) - val res1 = f("test".invalid()) - val res2 = f(1.valid()) - //sampleEnd - println("res1: $res1") - println("res2: $res2") -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-02.kt deleted file mode 100644 index 68849d20db2..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-02.kt +++ /dev/null @@ -1,12 +0,0 @@ -// This file was automatically generated from Validated.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleValidated02 - -import arrow.core.* - -fun main(args: Array) { - val result = - //sampleStart - "Hello World".valid().void() - //sampleEnd - println(result) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-03.kt deleted file mode 100644 index e5b5f1336cf..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-03.kt +++ /dev/null @@ -1,9 +0,0 @@ -// This file was automatically generated from Validated.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleValidated03 - -import arrow.core.Validated - -fun main() { - Validated.Valid(12).tapInvalid { println("flower") } // Result: Valid(12) - Validated.Invalid(12).tapInvalid { println("flower") } // Result: prints "flower" and returns: Invalid(12) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-04.kt deleted file mode 100644 index c13fa930955..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-04.kt +++ /dev/null @@ -1,9 +0,0 @@ -// This file was automatically generated from Validated.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleValidated04 - -import arrow.core.Validated - -fun main() { - Validated.Valid(12).tap { println("flower") } // Result: prints "flower" and returns: Valid(12) - Validated.Invalid(12).tap { println("flower") } // Result: Invalid(12) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-05.kt deleted file mode 100644 index af73083b797..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-05.kt +++ /dev/null @@ -1,13 +0,0 @@ -// This file was automatically generated from Validated.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleValidated05 - -import arrow.core.* - -fun main(args: Array) { - //sampleStart - val string: Validated = "Hello".valid() - val chars: Validated = - string.widen() - //sampleEnd - println(chars) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-06.kt deleted file mode 100644 index 4cf01a61751..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-validated-06.kt +++ /dev/null @@ -1,11 +0,0 @@ -// This file was automatically generated from Validated.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleValidated06 - -import arrow.core.Validated -import arrow.core.andThen - -fun main() { - Validated.Valid(5).andThen { Validated.Valid(10) } // Result: Valid(10) - Validated.Valid(5).andThen { Validated.Invalid(10) } // Result: Invalid(10) - Validated.Invalid(5).andThen { Validated.Valid(10) } // Result: Invalid(5) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt index f95fdbfd8da..5069292af50 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt @@ -4,8 +4,12 @@ package arrow.core.examples.test import io.kotest.core.spec.style.StringSpec class EitherKnitTest : StringSpec({ - "ExampleEither34" { - arrow.core.examples.exampleEither34.test() + "ExampleEither33" { + arrow.core.examples.exampleEither33.test() + } + + "ExampleEither35" { + arrow.core.examples.exampleEither35.test() } "ExampleEither36" { @@ -20,24 +24,20 @@ class EitherKnitTest : StringSpec({ arrow.core.examples.exampleEither38.test() } - "ExampleEither39" { - arrow.core.examples.exampleEither39.test() + "ExampleEither40" { + arrow.core.examples.exampleEither40.test() } "ExampleEither41" { arrow.core.examples.exampleEither41.test() } - "ExampleEither42" { - arrow.core.examples.exampleEither42.test() - } - - "ExampleEither48" { - arrow.core.examples.exampleEither48.test() + "ExampleEither47" { + arrow.core.examples.exampleEither47.test() } - "ExampleEither53" { - arrow.core.examples.exampleEither53.test() + "ExampleEither52" { + arrow.core.examples.exampleEither52.test() } }) { diff --git a/arrow-libs/fx/arrow-fx-coroutines-test/api/arrow-fx-coroutines-test.api b/arrow-libs/fx/arrow-fx-coroutines-test/api/arrow-fx-coroutines-test.api index 196b492279e..e620e10fd85 100644 --- a/arrow-libs/fx/arrow-fx-coroutines-test/api/arrow-fx-coroutines-test.api +++ b/arrow-libs/fx/arrow-fx-coroutines-test/api/arrow-fx-coroutines-test.api @@ -33,8 +33,6 @@ public final class arrow/fx/coroutines/Predef_testKt { public static final fun throwable (Lio/kotest/property/Arb$Companion;)Lio/kotest/property/Arb; public static final fun toEither (Ljava/lang/Object;)Larrow/core/Either; public static final fun unit (Lio/kotest/property/Arb$Companion;)Lio/kotest/property/Arb; - public static final fun validated (Lio/kotest/property/Arb$Companion;Lio/kotest/property/Arb;Lio/kotest/property/Arb;)Lio/kotest/property/Arb; - public static final fun validatedNel (Lio/kotest/property/Arb$Companion;Lio/kotest/property/Arb;Lio/kotest/property/Arb;)Lio/kotest/property/Arb; } public final class arrow/fx/coroutines/Predef_test_jvmKt { diff --git a/arrow-libs/fx/arrow-fx-coroutines-test/src/commonMain/kotlin/arrow/fx/coroutines/predef-test.kt b/arrow-libs/fx/arrow-fx-coroutines-test/src/commonMain/kotlin/arrow/fx/coroutines/predef-test.kt index 3e38d073d2b..bf342f53fc9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines-test/src/commonMain/kotlin/arrow/fx/coroutines/predef-test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines-test/src/commonMain/kotlin/arrow/fx/coroutines/predef-test.kt @@ -1,16 +1,10 @@ package arrow.fx.coroutines import arrow.core.Either -import arrow.core.Validated -import arrow.core.ValidatedNel import arrow.core.identity -import arrow.core.invalid -import arrow.core.invalidNel import arrow.core.left import arrow.core.right import arrow.core.test.concurrency.deprecateArrowTestModules -import arrow.core.valid -import arrow.core.validNel import io.kotest.assertions.fail import io.kotest.matchers.Matcher import io.kotest.matchers.MatcherResult @@ -70,20 +64,6 @@ public fun Arb.Companion.either(left: Arb, right: Arb): Arb Arb.Companion.validated(left: Arb, right: Arb): Arb> { - val failure: Arb> = left.map { l -> l.invalid() } - val success: Arb> = right.map { r -> r.valid() } - return Arb.choice(failure, success) -} - -@Deprecated(deprecateArrowTestModules) -public fun Arb.Companion.validatedNel(left: Arb, right: Arb): Arb> { - val failure: Arb> = left.map { l -> l.invalidNel() } - val success: Arb> = right.map { r -> r.validNel() } - return Arb.choice(failure, success) -} - @Deprecated(deprecateArrowTestModules) public fun Arb.Companion.intRange(min: Int = Int.MIN_VALUE, max: Int = Int.MAX_VALUE): Arb = Arb.bind(Arb.int(min, max), Arb.int(min, max)) { a, b -> diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index 093b5fb9ee0..108050997f4 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -168,18 +168,6 @@ public final class arrow/fx/coroutines/ParTraverse { public static final fun parSequenceScoped (Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun parSequenceScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun parSequenceScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceValidated (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceValidated$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceValidatedN (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceValidatedN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceValidatedN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceValidatedNScoped (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceValidatedNScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceValidatedNScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceValidatedScoped (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceValidatedScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceValidatedScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun parTraverse (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun parTraverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun parTraverse$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; @@ -198,12 +186,6 @@ public final class arrow/fx/coroutines/ParTraverse { public static final fun parTraverseResultN (Ljava/lang/Iterable;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun parTraverseResultN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun parTraverseResultN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverseValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverseValidated (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverseValidated$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverseValidatedN (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverseValidatedN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverseValidatedN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Larrow/typeclasses/Semigroup;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } public final class arrow/fx/coroutines/ParZipKt { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt index 6c0b129865a..75d47a64080 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt @@ -3,7 +3,7 @@ package arrow.fx.coroutines -import arrow.core.sequence +import arrow.core.continuations.result import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async @@ -131,6 +131,8 @@ public suspend fun Iterable.parTraverseResult( ctx: CoroutineContext = EmptyCoroutineContext, f: suspend CoroutineScope.(A) -> Result ): Result> = - coroutineScope { - map { async(ctx) { f.invoke(this, it) } }.awaitAll().sequence() + result { + coroutineScope { + map { async(ctx) { f.invoke(this, it).bind() } }.awaitAll() + } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt deleted file mode 100644 index da530594ed9..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt +++ /dev/null @@ -1,210 +0,0 @@ -@file:JvmMultifileClass -@file:JvmName("ParTraverse") - -package arrow.fx.coroutines - -import arrow.core.Validated -import arrow.core.sequence -import arrow.typeclasses.Semigroup -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.sync.Semaphore -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]. - * If one or more of the tasks returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Cancelling this operation cancels all running tasks. - */ -@JvmName("parSequenceValidatedNScoped") -public suspend fun Iterable Validated>.parSequenceValidatedN(semigroup: Semigroup, n: Int): Validated> = - parTraverseValidatedN(Dispatchers.Default, semigroup, n) { it() } - -public suspend fun Iterable Validated>.parSequenceValidatedN(semigroup: Semigroup, n: Int): Validated> = - parTraverseValidatedN(Dispatchers.Default, semigroup, n) { it() } - -/** - * Traverses this [Iterable] and runs [f] in [n] parallel operations on [CoroutineContext]. - * If one or more of the tasks returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Coroutine context is inherited from a [CoroutineScope], additional context elements can be specified with [ctx] argument. - * If the combined context does not have any dispatcher nor any other [ContinuationInterceptor], then [Dispatchers.Default] is used. - * **WARNING** If the combined context has a single threaded [ContinuationInterceptor], this function will not run in parallel. - * - * Cancelling this operation cancels all running tasks. - */ -@JvmName("parSequenceValidatedNScoped") -public suspend fun Iterable Validated>.parSequenceValidatedN( - ctx: CoroutineContext = EmptyCoroutineContext, - semigroup: Semigroup, - n: Int -): Validated> = - parTraverseValidatedN(ctx, semigroup, n) { it() } - -public suspend fun Iterable Validated>.parSequenceValidatedN( - ctx: CoroutineContext = EmptyCoroutineContext, - semigroup: Semigroup, - n: Int -): Validated> = - parTraverseValidatedN(ctx, semigroup, n) { it() } - -/** - * Traverses this [Iterable] and runs [f] in [n] parallel operations on [Dispatchers.Default]. - * If one or more of the [f] returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Cancelling this operation cancels all running tasks. - */ -public suspend fun Iterable.parTraverseValidatedN( - semigroup: Semigroup, - n: Int, - f: suspend CoroutineScope.(A) -> Validated -): Validated> = - parTraverseValidatedN(Dispatchers.Default, semigroup, n, f) - -/** - * Traverses this [Iterable] and runs [f] in [n] parallel operations on [CoroutineContext]. - * If one or more of the [f] returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Coroutine context is inherited from a [CoroutineScope], additional context elements can be specified with [ctx] argument. - * If the combined context does not have any dispatcher nor any other [ContinuationInterceptor], then [Dispatchers.Default] is used. - * **WARNING** If the combined context has a single threaded [ContinuationInterceptor], this function will not run in parallel. - * - * Cancelling this operation cancels all running tasks. - */ -public suspend fun Iterable.parTraverseValidatedN( - ctx: CoroutineContext = EmptyCoroutineContext, - semigroup: Semigroup, - n: Int, - f: suspend CoroutineScope.(A) -> Validated -): Validated> { - val semaphore = Semaphore(n) - return parTraverseValidated(ctx, semigroup) { a -> - semaphore.withPermit { f(a) } - } -} - -/** - * Sequences all tasks in parallel on [Dispatchers.Default] and returns the result. - * If one or more of the tasks returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Cancelling this operation cancels all running tasks. - */ -@JvmName("parSequenceValidatedScoped") -public suspend fun Iterable Validated>.parSequenceValidated(semigroup: Semigroup): Validated> = - parTraverseValidated(Dispatchers.Default, semigroup) { it() } - -public suspend fun Iterable Validated>.parSequenceValidated(semigroup: Semigroup): Validated> = - parTraverseValidated(Dispatchers.Default, semigroup) { it() } - -/** - * Sequences all tasks in parallel on [ctx] and returns the result. - * If one or more of the tasks returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Coroutine context is inherited from a [CoroutineScope], additional context elements can be specified with [ctx] argument. - * If the combined context does not have any dispatcher nor any other [ContinuationInterceptor], then [Dispatchers.Default] is used. - * **WARNING** If the combined context has a single threaded [ContinuationInterceptor], this function will not run in parallel. - * - * Cancelling this operation cancels all running tasks. - * - * ```kotlin - * import arrow.core.* - * import arrow.typeclasses.Semigroup - * import arrow.fx.coroutines.* - * import kotlinx.coroutines.Dispatchers - * - * typealias Task = suspend () -> ValidatedNel - * - * suspend fun main(): Unit { - * //sampleStart - * fun getTask(id: Int): Task = - * suspend { Validated.catchNel { println("Working on task $id on ${Thread.currentThread().name}") } } - * - * val res = listOf(1, 2, 3) - * .map(::getTask) - * .parSequenceValidated(Dispatchers.IO, Semigroup.nonEmptyList()) - * //sampleEnd - * println(res) - * } - * ``` - * - */ -@JvmName("parSequenceValidatedScoped") -public suspend fun Iterable Validated>.parSequenceValidated( - ctx: CoroutineContext = EmptyCoroutineContext, - semigroup: Semigroup -): Validated> = - parTraverseValidated(ctx, semigroup) { it() } - -public suspend fun Iterable Validated>.parSequenceValidated( - ctx: CoroutineContext = EmptyCoroutineContext, - semigroup: Semigroup -): Validated> = - parTraverseValidated(ctx, semigroup) { it() } - -/** - * Traverses this [Iterable] and runs all mappers [f] on [Dispatchers.Default]. - * If one or more of the [f] returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Cancelling this operation cancels all running tasks. - */ -public suspend fun Iterable.parTraverseValidated( - semigroup: Semigroup, - f: suspend CoroutineScope.(A) -> Validated -): Validated> = - parTraverseValidated(Dispatchers.Default, semigroup, f) - -/** - * Traverses this [Iterable] and runs all mappers [f] on [CoroutineContext]. - * If one or more of the [f] returns [Validated.Invalid] then all the [Validated.Invalid] results will be combined using [semigroup]. - * - * Coroutine context is inherited from a [CoroutineScope], additional context elements can be specified with [ctx] argument. - * If the combined context does not have any dispatcher nor any other [ContinuationInterceptor], then [Dispatchers.Default] is used. - * **WARNING** If the combined context has a single threaded [ContinuationInterceptor], this function will not run in parallel. - * - * Cancelling this operation cancels all running tasks. - * - * ```kotlin - * import arrow.core.* - * import arrow.typeclasses.Semigroup - * import arrow.fx.coroutines.* - * import kotlinx.coroutines.Dispatchers - * - * object Error - * data class User(val id: Int, val createdOn: String) - * - * suspend fun main(): Unit { - * //sampleStart - * suspend fun getUserById(id: Int): ValidatedNel = - * if(id % 2 == 0) Error.invalidNel() - * else User(id, Thread.currentThread().name).validNel() - * - * val res = listOf(1, 3, 5) - * .parTraverseValidated(Dispatchers.IO, Semigroup.nonEmptyList()) { getUserById(it) } - * - * val res2 = listOf(1, 2, 3, 4, 5) - * .parTraverseValidated(Dispatchers.IO, Semigroup.nonEmptyList()) { getUserById(it) } - * //sampleEnd - * println(res) - * println(res2) - * } - * ``` - * - */ -public suspend fun Iterable.parTraverseValidated( - ctx: CoroutineContext = EmptyCoroutineContext, - semigroup: Semigroup, - f: suspend CoroutineScope.(A) -> Validated -): Validated> = - coroutineScope { - map { async(ctx) { f.invoke(this, it) } }.awaitAll() - .sequence(semigroup) - } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt index f6c67ed496f..925a21a5246 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseEitherTest.kt @@ -3,9 +3,10 @@ package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.core.Either +import arrow.core.continuations.either import arrow.core.left import arrow.core.right -import arrow.core.sequence +import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.property.Arb @@ -61,8 +62,8 @@ class ParTraverseEitherTest : ArrowFxSpec( val containsError = l.any(Either::isLeft) val res = l.parTraverseEither { it } - if (containsError) l.contains>(res) shouldBe true - else res shouldBe l.sequence() + if (containsError) l.shouldContain(res) + else res shouldBe either { l.map { it.bind() } } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt index 6bab1da436c..bf178ba8ddc 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt @@ -3,8 +3,9 @@ package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.core.Either -import arrow.core.sequence +import arrow.core.continuations.result import arrow.core.test.generators.result +import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.result.shouldBeFailureOfType import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -59,7 +60,8 @@ class ParTraverseResultTest : ArrowFxSpec( "parTraverseResult identity is identity" { checkAll(Arb.list(Arb.result(Arb.int()))) { l -> val res = l.parTraverseResult { it } - res shouldBe l.sequence() + if (l.any { it.isFailure }) l.shouldContain(res) + else res shouldBe result { l.map { it.bind() } } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt deleted file mode 100644 index 133e1ffa30d..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -package arrow.fx.coroutines - -import arrow.atomic.Atomic -import arrow.atomic.update -import arrow.core.Either -import arrow.core.NonEmptyList -import arrow.core.Validated -import arrow.core.invalidNel -import arrow.core.sequence -import arrow.core.validNel -import arrow.typeclasses.Semigroup -import io.kotest.matchers.should -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.string -import kotlinx.coroutines.CompletableDeferred - -class ParTraverseValidatedTest : ArrowFxSpec( - spec = { - "parTraverseValidated can traverse effect full computations" { - val ref = Atomic(0) - (0 until 100).parTraverseValidated(Semigroup.nonEmptyList()) { - ref.update { it + 1 }.validNel() - } - ref.value shouldBe 100 - } - - "parTraverseValidated runs in parallel" { - val promiseA = CompletableDeferred() - val promiseB = CompletableDeferred() - val promiseC = CompletableDeferred() - - listOf( - suspend { - promiseA.await() - promiseC.complete(Unit).validNel() - }, - suspend { - promiseB.await() - promiseA.complete(Unit).validNel() - }, - suspend { - promiseB.complete(Unit) - promiseC.await().validNel() - } - ).parTraverseValidated(Semigroup.nonEmptyList()) { it() } - } - - "parTraverseValidated results in the correct left" { - checkAll( - Arb.int(min = 10, max = 20), - Arb.int(min = 1, max = 9), - Arb.string() - ) { n, killOn, e -> - (0 until n).parTraverseValidated(Semigroup.nonEmptyList()) { i -> - if (i == killOn) e.invalidNel() else Unit.validNel() - } shouldBe e.invalidNel() - } - } - - "parTraverseValidated identity is identity" { - checkAll(Arb.list(Arb.validatedNel(Arb.int(), Arb.int()))) { l -> - val res: Validated, List> = l.parTraverseValidated(Semigroup.nonEmptyList()) { it } - res shouldBe l.sequence(Semigroup.nonEmptyList()) - } - } - - "parTraverseValidated results in the correct error" { - checkAll( - Arb.int(min = 10, max = 20), - Arb.int(min = 1, max = 9), - Arb.throwable() - ) { n, killOn, e -> - Either.catch { - (0 until n).parTraverseValidated(Semigroup.nonEmptyList()) { i -> - if (i == killOn) throw e else Unit.validNel() - } - } should leftException(e) - } - } - - "parTraverseValidated stack-safe" { - val count = 20_000 - val l = (0 until count).parTraverseValidated(Semigroup.nonEmptyList()) { it.validNel() } - l shouldBe (0 until count).toList().validNel() - } - } -) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt deleted file mode 100644 index eabcac3060b..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedJvmTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package arrow.fx.coroutines - -import arrow.core.orNull -import arrow.core.validNel -import arrow.typeclasses.Semigroup -import io.kotest.assertions.assertSoftly -import io.kotest.assertions.fail -import io.kotest.matchers.string.shouldStartWith -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int - -class ParTraverseValidatedJvmTest : ArrowFxSpec(spec = { - "parTraverseValidated finishes on single thread " { // 100 is same default length as Arb.list - checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> - val res = resourceScope { - val ctx = singleThreadContext("single") - (0 until i).parTraverseValidated(ctx, Semigroup.nonEmptyList()) { Thread.currentThread().name.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/examples/example-partraversevalidated-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-partraversevalidated-01.kt deleted file mode 100644 index dba6a9a37b4..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-partraversevalidated-01.kt +++ /dev/null @@ -1,21 +0,0 @@ -// This file was automatically generated from ParTraverseValidated.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.examplePartraversevalidated01 - -import arrow.core.* -import arrow.typeclasses.Semigroup -import arrow.fx.coroutines.* -import kotlinx.coroutines.Dispatchers - -typealias Task = suspend () -> ValidatedNel - -suspend fun main(): Unit { - //sampleStart - fun getTask(id: Int): Task = - suspend { Validated.catchNel { println("Working on task $id on ${Thread.currentThread().name}") } } - - val res = listOf(1, 2, 3) - .map(::getTask) - .parSequenceValidated(Dispatchers.IO, Semigroup.nonEmptyList()) - //sampleEnd - println(res) -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-partraversevalidated-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-partraversevalidated-02.kt deleted file mode 100644 index 50ec6bb74c4..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-partraversevalidated-02.kt +++ /dev/null @@ -1,26 +0,0 @@ -// This file was automatically generated from ParTraverseValidated.kt by Knit tool. Do not edit. -package arrow.fx.coroutines.examples.examplePartraversevalidated02 - -import arrow.core.* -import arrow.typeclasses.Semigroup -import arrow.fx.coroutines.* -import kotlinx.coroutines.Dispatchers - -object Error -data class User(val id: Int, val createdOn: String) - -suspend fun main(): Unit { - //sampleStart - suspend fun getUserById(id: Int): ValidatedNel = - if(id % 2 == 0) Error.invalidNel() - else User(id, Thread.currentThread().name).validNel() - - val res = listOf(1, 3, 5) - .parTraverseValidated(Dispatchers.IO, Semigroup.nonEmptyList()) { getUserById(it) } - - val res2 = listOf(1, 2, 3, 4, 5) - .parTraverseValidated(Dispatchers.IO, Semigroup.nonEmptyList()) { getUserById(it) } - //sampleEnd - println(res) - println(res2) -} diff --git a/arrow-libs/optics/arrow-optics/api/arrow-optics.api b/arrow-libs/optics/arrow-optics/api/arrow-optics.api index 970a6993266..e69f61deb4d 100644 --- a/arrow-libs/optics/arrow-optics/api/arrow-optics.api +++ b/arrow-libs/optics/arrow-optics/api/arrow-optics.api @@ -252,8 +252,6 @@ public final class arrow/optics/PEvery$DefaultImpls { public abstract interface class arrow/optics/PIso : arrow/optics/Fold, arrow/optics/Getter, arrow/optics/PEvery, arrow/optics/PLens, arrow/optics/POptional, arrow/optics/PPrism, arrow/optics/PSetter, arrow/optics/PTraversal { public static final field Companion Larrow/optics/PIso$Companion; public abstract fun compose (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun eitherToPValidated ()Larrow/optics/PIso; - public static fun eitherToValidated ()Larrow/optics/PIso; public abstract fun first ()Larrow/optics/PIso; public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; @@ -278,13 +276,9 @@ public abstract interface class arrow/optics/PIso : arrow/optics/Fold, arrow/opt public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun split (Larrow/optics/PIso;)Larrow/optics/PIso; public static fun stringToList ()Larrow/optics/PIso; - public static fun validatedToEither ()Larrow/optics/PIso; - public static fun validatedToPEither ()Larrow/optics/PIso; } public final class arrow/optics/PIso$Companion { - public final fun eitherToPValidated ()Larrow/optics/PIso; - public final fun eitherToValidated ()Larrow/optics/PIso; public final fun id ()Larrow/optics/PIso; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/optics/PIso; public final fun listToOptionNel ()Larrow/optics/PIso; @@ -297,8 +291,6 @@ public final class arrow/optics/PIso$Companion { public final fun optionToPEither ()Larrow/optics/PIso; public final fun optionToPNullable ()Larrow/optics/PIso; public final fun stringToList ()Larrow/optics/PIso; - public final fun validatedToEither ()Larrow/optics/PIso; - public final fun validatedToPEither ()Larrow/optics/PIso; } public final class arrow/optics/PIso$DefaultImpls { diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt index 446d625743b..86fbd888422 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt @@ -68,8 +68,8 @@ public interface Fold { val fold = ::fold as (Monoid, S) -> Any? val res = fold(object : Monoid { override fun empty(): Any = EMPTY_VALUE - override fun Any?.combine(b: Any?): Any? = - if (this === EMPTY_VALUE) b else this + override fun append(a: Any?, b: Any?): Any? = + if (a === EMPTY_VALUE) b else a }, source) return EMPTY_VALUE.unbox(res) } @@ -82,8 +82,8 @@ public interface Fold { val fold = ::fold as (Monoid, S) -> Any? val res = fold(object : Monoid { override fun empty(): Any = EMPTY_VALUE - override fun Any?.combine(b: Any?): Any? = - if (b !== EMPTY_VALUE) b else this + override fun append(a: Any?, b: Any?): Any? = + if (b !== EMPTY_VALUE) b else a }, source) return EMPTY_VALUE.unbox(res) } @@ -113,8 +113,8 @@ public interface Fold { public fun findOrNull(source: S, predicate: (focus: A) -> Boolean): A? { val res = foldMap(object : Monoid { override fun empty(): Any = EMPTY_VALUE - override fun Any?.combine(b: Any?): Any? = - if (this === EMPTY_VALUE) b else this + override fun append(a: Any?, b: Any?): Any? = + if (a === EMPTY_VALUE) b else a }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } return EMPTY_VALUE.unbox(res) } @@ -127,8 +127,8 @@ public interface Fold { public fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean { val res = foldMap(object : Monoid { override fun empty(): Any = EMPTY_VALUE - override fun Any?.combine(b: Any?): Any? = - if (this === EMPTY_VALUE) b else this + override fun append(a: Any?, b: Any?): Any? = + if (a === EMPTY_VALUE) b else a }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } return res !== EMPTY_VALUE } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt index 007831bcd90..e7d64b2eb63 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt @@ -6,9 +6,6 @@ import arrow.core.None import arrow.core.Option import arrow.core.Either.Right import arrow.core.Some -import arrow.core.Validated -import arrow.core.Validated.Invalid -import arrow.core.Validated.Valid import arrow.core.compose import arrow.core.identity import arrow.typeclasses.Monoid @@ -168,23 +165,6 @@ public interface PIso : PPrism, PLens, Gette public fun listToOptionNel(): Iso, Option>> = listToPOptionNel() - /** - * [PIso] that defines the equality between [Either] and [Validated] - */ - @JvmStatic - public fun eitherToPValidated(): PIso, Either, Validated, Validated> = - PIso( - get = { it.fold(::Invalid, ::Valid) }, - reverseGet = Validated::toEither - ) - - /** - * [Iso] that defines the equality between [Either] and [Validated] - */ - @JvmStatic - public fun eitherToValidated(): Iso, Validated> = - eitherToPValidated() - /** * [Iso] that defines the equality between a Unit value [Map] and a [Set] with its keys */ @@ -248,22 +228,5 @@ public interface PIso : PPrism, PLens, Gette @JvmStatic public fun stringToList(): Iso> = stringToList - - /** - * [PIso] that defines equality between [Validated] and [Either] - */ - @JvmStatic - public fun validatedToPEither(): PIso, Validated, Either, Either> = - PIso( - get = Validated::toEither, - reverseGet = Validated.Companion::fromEither - ) - - /** - * [Iso] that defines equality between [Validated] and [Either] - */ - @JvmStatic - public fun validatedToEither(): Iso, Either> = - validatedToPEither() } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt index 419f0ad2401..bde68db7922 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt @@ -11,7 +11,7 @@ internal object EMPTY_VALUE { private object BooleanOr : Monoid { override fun empty(): Boolean = false - override fun Boolean.combine(b: Boolean): Boolean = this || b + override fun append(a: Boolean, b: Boolean): Boolean = a || b } internal fun Monoid.Companion.booleanOr(): Monoid = diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/EitherTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/EitherTest.kt deleted file mode 100644 index e434dd4f2f9..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/EitherTest.kt +++ /dev/null @@ -1,25 +0,0 @@ -package arrow.optics.std - -import arrow.core.test.UnitSpec -import arrow.core.test.generators.either -import arrow.core.test.generators.functionAToB -import arrow.core.test.generators.validated -import arrow.optics.Iso -import arrow.optics.test.laws.IsoLaws -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.string - -class EitherTest : UnitSpec() { - - init { - testLaws( - IsoLaws.laws( - iso = Iso.eitherToValidated(), - aGen = Arb.either(Arb.string(), Arb.int()), - bGen = Arb.validated(Arb.string(), Arb.int()), - funcGen = Arb.functionAToB(Arb.validated(Arb.string(), Arb.int())), - ) - ) - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ValidatedTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ValidatedTest.kt deleted file mode 100644 index fe5b0d1d89f..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ValidatedTest.kt +++ /dev/null @@ -1,27 +0,0 @@ -package arrow.optics.std - -import arrow.core.test.UnitSpec -import arrow.core.test.generators.either -import arrow.core.test.generators.functionAToB -import arrow.core.test.generators.validated -import arrow.optics.Iso -import arrow.optics.test.laws.IsoLaws -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.string - -class ValidatedTest : UnitSpec() { - - init { - - testLaws( - "Iso validated to either - ", - IsoLaws.laws( - iso = Iso.validatedToEither(), - aGen = Arb.validated(Arb.string(), Arb.int()), - bGen = Arb.either(Arb.string(), Arb.int()), - funcGen = Arb.functionAToB(Arb.either(Arb.string(), Arb.int())), - ) - ) - } -} diff --git a/arrow-site/docs/_code/fx-home-code.md b/arrow-site/docs/_code/fx-home-code.md index f4cbb2f9f02..75ad8627875 100644 --- a/arrow-site/docs/_code/fx-home-code.md +++ b/arrow-site/docs/_code/fx-home-code.md @@ -2,7 +2,7 @@ library: fx --- * * [Atomic] also offers some other interesting operators such as [loop], [update], [tryUpdate], etc. + * + * **WARNING**: this class may not work as intended on [Int] and [Long] on Kotlin Native! */ public interface Atomic { public var value: A diff --git a/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt b/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt index 1bba5a2e5c7..c6435dcc568 100644 --- a/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt +++ b/arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicTest.kt @@ -1,10 +1,9 @@ package arrow.atomic -import arrow.fx.coroutines.parTraverse import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb -import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import kotlin.coroutines.Continuation import kotlin.coroutines.EmptyCoroutineContext @@ -12,8 +11,10 @@ import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn class AtomicTest : StringSpec({ + // NOTE: we test with strings because testing with ints doesn't work! + "set get - successful" { - checkAll(Arb.int(), Arb.int()) { x, y -> + checkAll(Arb.string(), Arb.string()) { x, y -> val r = Atomic(x) r.update { y } r.value shouldBe y @@ -21,7 +22,7 @@ class AtomicTest : StringSpec({ } "getAndSet - successful" { - checkAll(Arb.int(), Arb.int()) { x, y -> + checkAll(Arb.string(), Arb.string()) { x, y -> val ref = Atomic(x) ref.getAndSet(y) shouldBe x ref.value shouldBe y @@ -29,7 +30,7 @@ class AtomicTest : StringSpec({ } "tryUpdate - modification occurs successfully" { - checkAll(Arb.int()) { x -> + checkAll(Arb.string()) { x -> val ref = Atomic(x) ref.tryUpdate { it + 1 } ref.value shouldBe x + 1 @@ -37,18 +38,18 @@ class AtomicTest : StringSpec({ } "tryUpdate - should fail to update if modification has occurred" { - checkAll(Arb.int()) { x -> + checkAll(Arb.string()) { x -> val ref = Atomic(x) ref.tryUpdate { - suspend { ref.update(Int::inc) } + suspend { ref.update { it + "a" } } .startCoroutineUninterceptedOrReturn(Continuation(EmptyCoroutineContext) { }) - it + 1 + it + "b" } shouldBe false } } - "consistent set update" { - checkAll(Arb.int(), Arb.int()) { x, y -> + "consistent set update on strings" { + checkAll(Arb.string(), Arb.string()) { x, y -> val set = suspend { val r = Atomic(x) r.update { y } @@ -67,9 +68,9 @@ class AtomicTest : StringSpec({ "concurrent modifications" { val finalValue = 50_000 - val r = Atomic(0) - (0 until finalValue).parTraverse { r.update { it + 1 } } - r.value shouldBe finalValue + val r = Atomic("") + (0 until finalValue).forEach { r.update { it + "a" } } + r.value shouldBe "a".repeat(finalValue) } } ) diff --git a/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt b/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt index 5bf7a24ce01..700f3b4acd0 100644 --- a/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt +++ b/arrow-libs/core/arrow-atomic/src/jvmTest/kotlin/examples/example-atomic-01.kt @@ -3,11 +3,10 @@ package arrow.atomic.examples.exampleAtomic01 import arrow.atomic.Atomic import arrow.atomic.update -import arrow.fx.coroutines.parTraverse suspend fun main() { val count = Atomic(0) - (0 until 20_000).parTraverse { + (0 until 20_000).forEach { count.update(Int::inc) } println(count.value) diff --git a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt index 1714904e917..4a6b041bc62 100644 --- a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt +++ b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt @@ -1,3 +1,4 @@ +@file:OptIn(FreezingIsDeprecated::class) package arrow.atomic import kotlin.native.concurrent.AtomicReference @@ -8,7 +9,7 @@ public actual fun Atomic(initialValue: A): Atomic = AtomicRef(AtomicReference(initialValue.freeze())) private class AtomicRef(private val atom: AtomicReference): Atomic { - + override fun getAndSet(value: V): V { if (atom.isFrozen) value.freeze() while (true) { @@ -32,4 +33,3 @@ private class AtomicRef(private val atom: AtomicReference): Atomic { return value } } - From 154658fa0f0fd612f6550b9bfb77bfd8dc30b519 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 29 Dec 2022 15:07:34 +0100 Subject: [PATCH 021/114] Smaller timeouts --- .github/workflows/pull_request.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c127ac818ff..8ff4dbeec33 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -8,7 +8,7 @@ env: jobs: ios_watchos: runs-on: macos-latest - timeout-minutes: 90 + timeout-minutes: 60 steps: - uses: actions/checkout@v3 @@ -38,7 +38,7 @@ jobs: macos_tvos: runs-on: macos-latest - timeout-minutes: 90 + timeout-minutes: 60 steps: - uses: actions/checkout@v3 @@ -65,7 +65,7 @@ jobs: windows: runs-on: windows-latest - timeout-minutes: 90 + timeout-minutes: 60 steps: - uses: actions/checkout@v3 @@ -92,7 +92,7 @@ jobs: jvm: runs-on: ubuntu-latest - timeout-minutes: 90 + timeout-minutes: 60 steps: - uses: actions/checkout@v3 @@ -199,7 +199,7 @@ jobs: update_api: runs-on: ubuntu-latest - timeout-minutes: 90 + timeout-minutes: 30 steps: - uses: actions/checkout@v3 From 39e326f47ec1a534f6fdd6cabecf50bd72d16195 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 12 Jan 2023 14:15:51 +0100 Subject: [PATCH 022/114] Remove Tuple10 to Tuple22, Const, Eval, computation blocks, and arrow-continuations (#2784) --- arrow-libs/core/arrow-atomic/build.gradle.kts | 17 + .../api/arrow-continuations.api | 52 -- .../core/arrow-continuations/build.gradle.kts | 55 -- .../arrow-continuations/gradle.properties | 4 - .../kotlin/arrow/continuations/Effect.kt | 27 - .../kotlin/arrow/continuations/Reset.kt | 42 - .../arrow/continuations/generic/AtomicRef.kt | 57 -- .../continuations/generic/ControlThrowable.kt | 13 - .../continuations/generic/DelimContScope.kt | 133 --- .../continuations/generic/DelimitedCont.kt | 34 - .../generic/MultiShotDelimCont.kt | 140 --- .../continuations/generic/ShortCircuit.kt | 4 - .../generic/SuspendingComputation.kt | 97 -- .../arrow/continuations/generic/Token.kt | 7 - .../src/commonTest/kotlin/generic/Maybe.kt | 15 - .../commonTest/kotlin/generic/MaybeEffect.kt | 11 - .../generic/SuspendingComputationTest.kt | 221 ----- .../commonTest/kotlin/generic/TestSuite.kt | 24 - .../arrow/continuations/generic/AtomicRef.kt | 31 - .../continuations/generic/ControlThrowable.kt | 10 - .../arrow/continuations/generic/AtomicRef.kt | 8 - .../continuations/generic/ControlThrowable.kt | 13 - .../arrow.continuations/generic/AtomicRef.kt | 30 - .../generic/ControlThrowable.kt | 10 - arrow-libs/core/arrow-core/api/arrow-core.api | 860 ------------------ arrow-libs/core/arrow-core/build.gradle.kts | 6 +- .../src/commonMain/kotlin/arrow/core/Const.kt | 176 ---- .../src/commonMain/kotlin/arrow/core/Eval.kt | 566 ------------ .../commonMain/kotlin/arrow/core/Option.kt | 62 +- .../commonMain/kotlin/arrow/core/Tuple10.kt | 57 -- .../commonMain/kotlin/arrow/core/TupleN.kt | 283 +----- .../kotlin/arrow/core/computations/either.kt | 111 --- .../kotlin/arrow/core/computations/eval.kt | 27 - .../arrow/core/computations/nullable.kt | 95 -- .../kotlin/arrow/core/computations/option.kt | 93 -- .../kotlin/arrow/core/computations/result.kt | 55 -- .../kotlin/arrow/typeclasses/Monoid.kt | 10 - .../kotlin/arrow/typeclasses/Semigroup.kt | 6 - .../kotlin/arrow/core/EitherTest.kt | 16 - .../kotlin/arrow/core/EitherZipTest.kt | 27 +- .../commonTest/kotlin/arrow/core/EvalTest.kt | 134 --- .../kotlin/arrow/core/IterableTest.kt | 28 - .../commonTest/kotlin/arrow/core/MapKTest.kt | 28 - .../kotlin/arrow/core/NonEmptyListTest.kt | 20 - .../kotlin/arrow/core/OptionTest.kt | 17 - .../kotlin/arrow/core/SequenceKTest.kt | 30 +- .../arrow/core/computations/NullableTest.kt | 97 -- .../arrow/core/computations/ResultTest.kt | 223 ----- .../kotlin/arrow/core/test/Generators.kt | 4 - .../src/jsMain/kotlin/arrow/core/NonFatal.kt | 3 +- .../src/jvmMain/kotlin/arrow/core/NonFatal.kt | 3 +- .../jvmTest/java/arrow/core/DeadlockTest.kt | 14 - .../jvmTest/java/arrow/core/EitherJvmTest.kt | 5 - .../jvmTest/java/arrow/core/EvalJvmTest.kt | 69 -- .../jvmTest/java/arrow/core/EvalUsage.java | 12 - .../arrow/typeclasses/MonoidUsageTest.java | 2 - .../arrow/typeclasses/SemigroupUsageTest.java | 1 - .../example-either-computations-01.kt | 16 - .../example-either-computations-02.kt | 17 - .../kotlin/examples/example-eval-01.kt | 21 - .../kotlin/examples/example-eval-02.kt | 9 - .../kotlin/examples/example-eval-03.kt | 9 - .../kotlin/examples/example-eval-04.kt | 9 - .../example-nullable-computations-01.kt | 16 - .../example-nullable-computations-02.kt | 17 - .../kotlin/examples/example-option-17.kt | 15 +- .../kotlin/examples/example-option-18.kt | 14 +- .../kotlin/examples/example-option-19.kt | 10 +- .../kotlin/examples/example-option-20.kt | 10 +- .../kotlin/examples/example-option-21.kt | 11 - .../kotlin/examples/example-option-22.kt | 14 - .../kotlin/examples/example-option-23.kt | 3 - .../example-option-computations-01.kt | 16 - .../example-option-computations-02.kt | 17 - .../example-result-computations-01.kt | 23 - .../nativeMain/kotlin/arrow/core/NonFatal.kt | 3 +- .../api/arrow-fx-coroutines.api | 18 +- .../fx/arrow-fx-coroutines/build.gradle.kts | 3 +- .../kotlin/arrow/fx/coroutines/Schedule.kt | 59 +- .../arrow/fx/coroutines/ScheduleTest.kt | 15 +- .../arrow/fx/coroutines/ParMap6JvmTest.kt | 4 +- .../arrow/fx/coroutines/ParMap7JvmTest.kt | 4 +- .../arrow/fx/coroutines/ParMap8JvmTest.kt | 4 +- arrow-libs/fx/arrow-fx-stm/build.gradle.kts | 2 +- .../commonTest/kotlin/arrow/fx/stm/STMTest.kt | 4 +- .../optics/arrow-optics/api/arrow-optics.api | 5 - .../optics/arrow-optics/build.gradle.kts | 5 +- .../commonMain/kotlin/arrow/optics/Every.kt | 44 +- .../kotlin/arrow/optics/Traversal.kt | 26 - .../kotlin/arrow/optics/TraversalTest.kt | 3 +- .../instances/FilterIndexInstanceTest.kt | 3 +- .../optics/instances/IndexInstanceTest.kt | 2 +- .../kotlin/arrow/optics/std/TupleTest.kt | 93 ++ .../kotlin/arrow/optics/test/Generators.kt | 69 ++ gradle/libs.versions.toml | 1 + settings.gradle.kts | 3 - 96 files changed, 292 insertions(+), 4520 deletions(-) delete mode 100644 arrow-libs/core/arrow-continuations/api/arrow-continuations.api delete mode 100644 arrow-libs/core/arrow-continuations/build.gradle.kts delete mode 100644 arrow-libs/core/arrow-continuations/gradle.properties delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Effect.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/AtomicRef.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ControlThrowable.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimContScope.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimitedCont.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ShortCircuit.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/Maybe.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/MaybeEffect.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/SuspendingComputationTest.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/TestSuite.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/AtomicRef.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/AtomicRef.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ControlThrowable.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/AtomicRef.kt delete mode 100644 arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Const.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Eval.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple10.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/eval.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/nullable.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/option.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/NullableTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalJvmTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalUsage.java delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-03.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-04.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-23.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-01.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-02.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt diff --git a/arrow-libs/core/arrow-atomic/build.gradle.kts b/arrow-libs/core/arrow-atomic/build.gradle.kts index a38d7f61e23..fcb518fac59 100644 --- a/arrow-libs/core/arrow-atomic/build.gradle.kts +++ b/arrow-libs/core/arrow-atomic/build.gradle.kts @@ -53,5 +53,22 @@ kotlin { implementation(libs.kotlin.stdlibJS) } } + + if (!enableCompatibilityMetadataVariant) { + commonTest { + dependencies { + implementation(projects.arrowFxCoroutines) + implementation(libs.kotest.frameworkApi) + implementation(libs.kotest.assertionsCore) + implementation(libs.kotest.property) + } + } + jvmTest { + dependencies { + runtimeOnly(libs.kotest.frameworkEngine) + runtimeOnly(libs.kotest.runnerJUnit5) + } + } + } } } diff --git a/arrow-libs/core/arrow-continuations/api/arrow-continuations.api b/arrow-libs/core/arrow-continuations/api/arrow-continuations.api deleted file mode 100644 index 5e268c691e4..00000000000 --- a/arrow-libs/core/arrow-continuations/api/arrow-continuations.api +++ /dev/null @@ -1,52 +0,0 @@ -public abstract interface class arrow/continuations/Effect { - public static final field Companion Larrow/continuations/Effect$Companion; - public abstract fun control ()Larrow/continuations/generic/DelimitedScope; -} - -public final class arrow/continuations/Effect$Companion { - public final fun restricted (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun suspended (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/continuations/Reset { - public static final field INSTANCE Larrow/continuations/Reset; - public final fun restricted (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun suspended (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/continuations/generic/AtomicRefKt { - public static final fun getAndUpdate (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun loop (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; - public static final fun update (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)V - public static final fun updateAndGet (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public class arrow/continuations/generic/ControlThrowable : java/lang/Throwable { - public fun ()V - public fun fillInStackTrace ()Ljava/lang/Throwable; -} - -public abstract interface class arrow/continuations/generic/DelimitedContinuation { - public abstract fun invoke (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/continuations/generic/DelimitedScope { - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/continuations/generic/RestrictedScope : arrow/continuations/generic/DelimitedScope { - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/continuations/generic/RestrictedScope$DefaultImpls { - public static fun shift (Larrow/continuations/generic/RestrictedScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/continuations/generic/ShortCircuit : arrow/continuations/generic/ControlThrowable { - public final fun getRaiseValue ()Ljava/lang/Object; -} - -public abstract interface class arrow/continuations/generic/SuspendedScope : arrow/continuations/generic/DelimitedScope { -} - diff --git a/arrow-libs/core/arrow-continuations/build.gradle.kts b/arrow-libs/core/arrow-continuations/build.gradle.kts deleted file mode 100644 index dece0ef79fd..00000000000 --- a/arrow-libs/core/arrow-continuations/build.gradle.kts +++ /dev/null @@ -1,55 +0,0 @@ -plugins { - id(libs.plugins.kotlin.multiplatform.get().pluginId) - alias(libs.plugins.arrowGradleConfig.kotlin) - alias(libs.plugins.arrowGradleConfig.publish) -} - -apply(from = property("TEST_COVERAGE")) -apply(from = property("ANIMALSNIFFER_MPP")) -apply(plugin = "io.kotest.multiplatform") - -val enableCompatibilityMetadataVariant = - providers.gradleProperty("kotlin.mpp.enableCompatibilityMetadataVariant") - .forUseAtConfigurationTime().orNull?.toBoolean() == true - - -if (enableCompatibilityMetadataVariant) { - tasks.withType().configureEach { - exclude("**/*") - } -} - -kotlin { - sourceSets { - commonMain { - dependencies { - implementation(libs.kotlin.stdlibCommon) - } - } - if(!enableCompatibilityMetadataVariant) { - commonTest { - dependencies { - implementation(projects.arrowCore) - implementation(libs.kotest.frameworkEngine) - implementation(libs.kotest.assertionsCore) - implementation(libs.kotest.property) - } - } - jvmTest { - dependencies { - runtimeOnly(libs.kotest.runnerJUnit5) - } - } - } - jvmMain { - dependencies { - implementation(libs.kotlin.stdlibJDK8) - } - } - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) - } - } - } -} diff --git a/arrow-libs/core/arrow-continuations/gradle.properties b/arrow-libs/core/arrow-continuations/gradle.properties deleted file mode 100644 index b657b4ed748..00000000000 --- a/arrow-libs/core/arrow-continuations/gradle.properties +++ /dev/null @@ -1,4 +0,0 @@ -# Maven publishing configuration -pom.name=Arrow Continuations -# Build configuration -kapt.incremental.apt=false diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Effect.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Effect.kt deleted file mode 100644 index 798141bbe30..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Effect.kt +++ /dev/null @@ -1,27 +0,0 @@ -package arrow.continuations - -import arrow.continuations.generic.DelimitedScope -import arrow.continuations.generic.deprecateArrowContinuation - -@Deprecated(deprecateArrowContinuation) -public fun interface Effect { - public fun control(): DelimitedScope - - public companion object { - @Deprecated("$deprecateArrowContinuation Here one can use effect { } directly") - public suspend inline fun , F, A> suspended( - crossinline eff: (DelimitedScope) -> Eff, - crossinline just: (A) -> F, - crossinline f: suspend Eff.() -> A, - ): F = - Reset.suspended { just(f(eff(this))) } - - @Deprecated("$deprecateArrowContinuation Here one can use eagerEffect { } directly") - public inline fun , F, A> restricted( - crossinline eff: (DelimitedScope) -> Eff, - crossinline just: (A) -> F, - crossinline f: suspend Eff.() -> A, - ): F = - Reset.restricted { just(f(eff(this))) } - } -} diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt deleted file mode 100644 index c6a4dab39d7..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Reset.kt +++ /dev/null @@ -1,42 +0,0 @@ -package arrow.continuations - -import arrow.continuations.generic.ShortCircuit -import arrow.continuations.generic.ControlThrowable -import arrow.continuations.generic.DelimContScope -import arrow.continuations.generic.RestrictedScope -import arrow.continuations.generic.SuspendMonadContinuation -import arrow.continuations.generic.SuspendedScope -import arrow.continuations.generic.deprecateArrowContinuation -import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn - -@PublishedApi -@Deprecated(deprecateArrowContinuation) -internal object Reset { - /** - * Allows for building suspending single-shot computation blocks. - * For short-circuiting, or shifting, a [ShortCircuit] [ControlThrowable] is used. - * This ensures that any concurrent nested scopes are correctly closed. - * - * The usage of `try { ... } catch(e: Throwable) { ... }` will catch the [ShortCircuit] error, - * and will lead to recover of short-circuiting. - * You should always prefer to catch the most specific exception class, or - * use `Either.catch` etc or `e.nonFatalOrThrow()` - * to ensure you're not catching `ShortCircuit`. - */ - @Deprecated(deprecateArrowContinuation) - public suspend fun suspended(block: suspend SuspendedScope.() -> A): A = - suspendCoroutineUninterceptedOrReturn { cont -> - SuspendMonadContinuation(cont, block) - .startCoroutineUninterceptedOrReturn() - } - - /** - * Allows for building eager single-shot computation blocks. - * For short-circuiting, or shifting, `@RestrictSuspension` state machine is used. - * This doesn't allow nesting of computation blocks, or foreign suspension. - */ - @Deprecated(deprecateArrowContinuation) - // TODO This should be @RestrictSuspension but that breaks because a superclass is not considered to be correct scope - fun restricted(block: suspend RestrictedScope.() -> A): A = - DelimContScope(block).invoke() -} diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/AtomicRef.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/AtomicRef.kt deleted file mode 100644 index 8b4c0433661..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/AtomicRef.kt +++ /dev/null @@ -1,57 +0,0 @@ -package arrow.continuations.generic - -@Deprecated("$deprecateArrowContinuation The AtomicRef APIs have been moved to arrow.core.generic", ReplaceWith("AtomicRef", "arrow.core.generic.AtomicRef")) -public expect class AtomicRef(initialValue: V) { - public fun get(): V - public fun set(value: V) - public fun getAndSet(value: V): V - - /** - * Compare current value with expected and set to new if they're the same. Note, 'compare' is checking - * the actual object id, not 'equals'. - */ - public fun compareAndSet(expected: V, new: V): Boolean -} - -/** - * Infinite loop that reads this atomic variable and performs the specified [action] on its value. - */ -@Deprecated("$deprecateArrowContinuation The AtomicRef APIs have been moved to arrow.core.generic", ReplaceWith("loop(action)", "arrow.core.generic.loop")) -public inline fun AtomicRef.loop(action: (V) -> Unit): Nothing { - while (true) { - action(get()) - } -} - -@Deprecated("$deprecateArrowContinuation The AtomicRef APIs have been moved to arrow.core.generic", ReplaceWith("update(function)", "arrow.core.generic.update")) -public inline fun AtomicRef.update(function: (V) -> V) { - while (true) { - val cur = get() - val upd = function(cur) - if (compareAndSet(cur, upd)) return - } -} - -/** - * Updates variable atomically using the specified [function] of its value and returns its old value. - */ -@Deprecated("$deprecateArrowContinuation The AtomicRef APIs have been moved to arrow.core.generic", ReplaceWith("getAndUpdate(function)", "arrow.core.generic.getAndUpdate")) -public inline fun AtomicRef.getAndUpdate(function: (V) -> V): V { - while (true) { - val cur = get() - val upd = function(cur) - if (compareAndSet(cur, upd)) return cur - } -} - -/** - * Updates variable atomically using the specified [function] of its value and returns its new value. - */ -@Deprecated("$deprecateArrowContinuation The AtomicRef APIs have been moved to arrow.core.generic", ReplaceWith("updateAndGet", "arrow.core.generic.updateAndGet")) -public inline fun AtomicRef.updateAndGet(function: (V) -> V): V { - while (true) { - val cur = get() - val upd = function(cur) - if (compareAndSet(cur, upd)) return upd - } -} 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 deleted file mode 100644 index 234953e85a9..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ControlThrowable.kt +++ /dev/null @@ -1,13 +0,0 @@ -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` also don't catch [ControlThrowable]. - */ -@Deprecated(deprecateArrowContinuation) -public expect open class ControlThrowable() : Throwable - -internal const val deprecateArrowContinuation: String = - "arrow.continuation is being discontinued and will be removed in the next version in favor of the Effect/ EagerEffect Runtime. If you depend on low-level APIs as in arrow.continuation, feel free to write us in the Kotlin Slack channel for guidance." diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimContScope.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimContScope.kt deleted file mode 100644 index 4ce2b6bea2a..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimContScope.kt +++ /dev/null @@ -1,133 +0,0 @@ -package arrow.continuations.generic - -import kotlin.coroutines.Continuation -import kotlin.coroutines.EmptyCoroutineContext -import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED -import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn -import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn -import kotlin.coroutines.resume - -/** - * Implements delimited continuations with with no multi shot support (apart from shiftCPS which trivially supports it). - * - * For a version that simulates multishot (albeit with drawbacks) see [MultiShotDelimContScope]. - * For a version that allows nesting [reset] and calling parent scopes inside inner scopes see [NestedDelimContScope]. - * - * The basic concept here is appending callbacks and polling for a result. - * Every shift is evaluated until it either finishes (short-circuit) or suspends (called continuation). When it suspends its - * continuation is appended to a list waiting to be invoked with the final result of the block. - * When running a function we jump back and forth between the main function and every function inside shift via their continuations. - */ -internal open class DelimContScope(private val f: suspend RestrictedScope.() -> R) : RestrictedScope { - - /** - * Variable used for polling the result after suspension happened. - */ - private var resultVar: Any? = EMPTY_VALUE - - /** - * Variable for the next shift block to (partially) run, if it is empty that usually means we are done. - */ - private var nextShift: (suspend () -> R)? = null - - /** - * "Callbacks"/partially evaluated shift blocks which now wait for the final result - */ - // TODO This can be append only, but needs fast reversed access - private val shiftFnContinuations = mutableListOf>() - - /** - * Small wrapper that handles invoking the correct continuations and appending continuations from shift blocks - */ - public data class SingleShotCont( - private val continuation: Continuation, - private val shiftFnContinuations: MutableList> - ) : DelimitedContinuation { - public override suspend fun invoke(a: A): R = suspendCoroutineUninterceptedOrReturn { resumeShift -> - shiftFnContinuations.add(resumeShift) - continuation.resume(a) - COROUTINE_SUSPENDED - } - } - - /** - * Wrapper that handles invoking manually cps transformed continuations - */ - public data class CPSCont( - private val runFunc: suspend DelimitedScope.(A) -> R - ) : DelimitedContinuation { - public override suspend fun invoke(a: A): R = DelimContScope { runFunc(a) }.invoke() - } - - /** - * Captures the continuation and set [f] with the continuation to be executed next by the runloop. - */ - public override suspend fun shift(f: suspend RestrictedScope.(DelimitedContinuation) -> R): A = - suspendCoroutineUninterceptedOrReturn { continueMain -> - val delCont = SingleShotCont(continueMain, shiftFnContinuations) - require(nextShift == null) - nextShift = suspend { this.f(delCont) } - COROUTINE_SUSPENDED - } - - /** - * Same as [shift] except we never resume execution because we only continue in [c]. - */ - public suspend fun shiftCPS(f: suspend (DelimitedContinuation) -> R, c: suspend DelimitedScope.(A) -> B): Nothing = - suspendCoroutineUninterceptedOrReturn { - require(nextShift == null) - nextShift = suspend { f(CPSCont(c)) } - COROUTINE_SUSPENDED - } - - /** - * Unsafe if [f] calls [shift] on this scope! Use [NestedDelimContScope] instead if this is a problem. - */ - fun reset(f: suspend DelimitedScope.() -> A): A = - DelimContScope(f).invoke() - - @Suppress("UNCHECKED_CAST") - fun invoke(): R { - f.startCoroutineUninterceptedOrReturn( - this, - Continuation(EmptyCoroutineContext) { result -> - resultVar = result.getOrThrow() - } - ).let { - if (it == COROUTINE_SUSPENDED) { - // we have a call to shift so we must start execution the blocks there - while (true) { - if (resultVar === EMPTY_VALUE) { - val nextShiftFn = requireNotNull(nextShift) { "No further work to do but also no result!" } - nextShift = null - nextShiftFn.startCoroutineUninterceptedOrReturn( - Continuation(EmptyCoroutineContext) { result -> - resultVar = result.getOrThrow() - } - ).let { nextRes -> - // If we suspended here we can just continue to loop because we should now have a new function to run - // If we did not suspend we short-circuited and are thus done with looping - if (nextRes != COROUTINE_SUSPENDED) resultVar = nextRes as R - } - // Break out of the infinite loop if we have a result - } else return@let - } - } - // we can return directly if we never suspended/called shift - else return@invoke it as R - } - 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) - // Return the final result - return resultVar as R - } -} - -@Suppress("ClassName") -internal object EMPTY_VALUE { - @Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE") - public inline fun unbox(value: Any?): T = - if (value === this) null as T else value as T -} diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimitedCont.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimitedCont.kt deleted file mode 100644 index a84f969fcd9..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/DelimitedCont.kt +++ /dev/null @@ -1,34 +0,0 @@ -package arrow.continuations.generic - -/** - * Base interface for a continuation - */ -@Deprecated(deprecateArrowContinuation) -public interface DelimitedContinuation { - public suspend operator fun invoke(a: A): R -} - -/** - * Base interface for our scope. - */ -@Deprecated(deprecateArrowContinuation) -public interface DelimitedScope { - - /** - * Exit the [DelimitedScope] with [R] - */ - public suspend fun shift(r: R): A -} - -@Deprecated(deprecateArrowContinuation) -public interface RestrictedScope : DelimitedScope { - /** - * Capture the continuation and pass it to [f]. - */ - public suspend fun shift(f: suspend RestrictedScope.(DelimitedContinuation) -> R): A - - public override suspend fun shift(r: R): A = shift { r } -} - -@Deprecated(deprecateArrowContinuation) -public interface SuspendedScope : DelimitedScope diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt deleted file mode 100644 index 32a8824b8f8..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/MultiShotDelimCont.kt +++ /dev/null @@ -1,140 +0,0 @@ -package arrow.continuations.generic - -import kotlin.coroutines.Continuation -import kotlin.coroutines.EmptyCoroutineContext -import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED -import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn -import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn -import kotlin.coroutines.resume -import kotlin.coroutines.suspendCoroutine - -/** - * (Simulated) Multishot capable delimited control scope - * - * This has several drawbacks: - * - f will rerun completely on multishot and only the results of [shift] are cached so any sideeffects outside of - * [shift] will rerun! - * - This accumulates all results of [shift] (every argument passed when invoking the continuation) so on long running computations - * this may keep quite a bit of memory - * - If the pure part before a multishot is expensive the multishot itself will have to rerun that, which makes it somewhat slow - * - This is terribly hard to implement properly with nested scopes (which this one does not support) - * - * As per usual understanding of [DelimContScope] is required as I will only be commenting differences for now. - */ -internal open class MultiShotDelimContScope(val f: suspend RestrictedScope.() -> R) : RestrictedScope { - - // TODO Since runs blocking these don't need to be atomic - private val resultVar = AtomicRef(null) - private val nextShift = AtomicRef<(suspend RestrictedScope.() -> R)?>(null) - - // TODO This can be append only and needs fast reversed access - private val shiftFnContinuations = mutableListOf>() - - /** - * Keep the arguments passed to [DelimitedContinuation.invoke] to be able to replay the scope if necessary - */ - // TODO This can be append only and needs fast random access and slicing - internal open val stack = mutableListOf() - - /** - * Our continuation now includes the function [f] to rerun on multishot, the current live (single-shot) continuation, - * the current stack and the offset from that stack when this is created which is used to know when to resume normal - * execution again on a replay. - */ - public class MultiShotCont( - liveContinuation: Continuation, - private val f: suspend RestrictedScope.() -> R, - private val stack: MutableList, - private val shiftFnContinuations: MutableList> - ) : DelimitedContinuation { - // To make sure the continuation is only invoked once we put it in a nullable atomic and only access it through getAndSet - private val liveContinuation = AtomicRef?>(liveContinuation) - private val stackOffset = stack.size - - public override suspend fun invoke(a: A): R = - when (val cont = liveContinuation.getAndSet(null)) { - // On multishot we replay with a prefilled stack from start to the point at which this object was created - // (when the shift block this runs in was first called) - null -> PrefilledDelimContScope((stack.subList(0, stackOffset).toList() + a).toMutableList(), f).invoke() - // on the first pass we operate like a normal delimited scope but we also save the argument to the stack before resuming - else -> suspendCoroutine { resumeShift -> - shiftFnContinuations.add(resumeShift) - stack.add(a) - cont.resume(a) - } - } - } - - public data class CPSCont( - private val runFunc: suspend DelimitedScope.(A) -> R - ) : DelimitedContinuation { - public override suspend fun invoke(a: A): R = DelimContScope { runFunc(a) }.invoke() - } - - public override suspend fun shift(func: suspend RestrictedScope.(DelimitedContinuation) -> R): A = - suspendCoroutineUninterceptedOrReturn { continueMain -> - val c = MultiShotCont(continueMain, f, stack, shiftFnContinuations) - val s: suspend RestrictedScope.() -> R = { this.func(c) } - require(nextShift.compareAndSet(null, s)) - COROUTINE_SUSPENDED - } - - public suspend fun shiftCPS(func: suspend DelimitedScope.(DelimitedContinuation) -> R, c: suspend DelimitedScope.(A) -> B): Nothing = - suspendCoroutine { - val s: suspend DelimitedScope.() -> R = { func(CPSCont(c)) } - require(nextShift.compareAndSet(null, s)) - } - - // This assumes RestrictSuspension or at least assumes the user to never reference the parent scope in f. - public suspend fun reset(f: suspend DelimitedScope.() -> A): A = - MultiShotDelimContScope(f).invoke() - - fun invoke(): R { - f.startCoroutineUninterceptedOrReturn( - this, - Continuation(EmptyCoroutineContext) { result -> - resultVar.set(result.getOrThrow()) - } - ).let { - if (it == COROUTINE_SUSPENDED) { - resultVar.loop { mRes -> - if (mRes == null) { - val nextShiftFn = nextShift.getAndSet(null) - ?: throw IllegalStateException("No further work to do but also no result!") - nextShiftFn.startCoroutineUninterceptedOrReturn( - this, - Continuation(EmptyCoroutineContext) { result -> - resultVar.set(result.getOrThrow()) - } - ).let { - if (it != COROUTINE_SUSPENDED) resultVar.set(it as R) - } - } else return@let - } - } else return@invoke it as R - } - require(resultVar.get() != null) - for (c in shiftFnContinuations.asReversed()) c.resume(resultVar.get()!!) - return resultVar.get()!! - } - - public companion object { - internal fun reset(f: suspend RestrictedScope.() -> R): R = MultiShotDelimContScope(f).invoke() - } -} - -private class PrefilledDelimContScope( - override val stack: MutableList, - f: suspend RestrictedScope.() -> R -) : MultiShotDelimContScope(f) { - var depth = 0 - - // Here we first check if we still have values in our local stack and if so we use those first - // if not we delegate to the normal delimited control implementation - public override suspend fun shift(func: suspend RestrictedScope.(DelimitedContinuation) -> R): A = - if (stack.size > depth) stack[depth++] as A - else { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - super.shift(func).also { depth++ } - } -} diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ShortCircuit.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ShortCircuit.kt deleted file mode 100644 index 66b2c445979..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ShortCircuit.kt +++ /dev/null @@ -1,4 +0,0 @@ -package arrow.continuations.generic - -@Deprecated(deprecateArrowContinuation) -public class ShortCircuit internal constructor(internal val token: Token, public val raiseValue: Any?) : ControlThrowable() diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt deleted file mode 100644 index 88e8b5c13c5..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/SuspendingComputation.kt +++ /dev/null @@ -1,97 +0,0 @@ -package arrow.continuations.generic - -import kotlin.coroutines.Continuation -import kotlin.coroutines.CoroutineContext -import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED -import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn -import kotlin.coroutines.resumeWithException - -internal const val UNDECIDED = 0 -internal const val SUSPENDED = 1 - -@Suppress("UNCHECKED_CAST") -internal open class SuspendMonadContinuation( - private val parent: Continuation, - val f: suspend SuspendedScope.() -> R -) : Continuation, SuspendedScope { - - /** - * State is either - * 0 - UNDECIDED - * 1 - SUSPENDED - * Any? (3) `resumeWith` always stores it upon UNDECIDED, and `getResult` can atomically get it. - */ - private val _decision = AtomicRef(UNDECIDED) - private val token: Token = Token() - - override val context: CoroutineContext = parent.context - - override fun resumeWith(result: Result) { - _decision.loop { decision -> - when (decision) { - UNDECIDED -> { - val r: R? = result.fold({ it }) { EMPTY_VALUE.unbox(it.shiftedOrNull()) } - when { - r == null -> { - parent.resumeWithException(result.exceptionOrNull()!!) - return - } - _decision.compareAndSet(UNDECIDED, r) -> { - return - } - else -> Unit // loop again - } - } - else -> { // If not `UNDECIDED` then we need to pass result to `parent` - val res: Result = result.fold( - { Result.success(it) }, - { t -> - val x = t.shiftedOrNull() - if (x === EMPTY_VALUE) Result.failure(t) - else Result.success(EMPTY_VALUE.unbox(x)) - } - ) - parent.resumeWith(res) - return - } - } - } - } - - @PublishedApi // return the result - internal fun getResult(): Any? = - _decision.loop { decision -> - when (decision) { - UNDECIDED -> if (this._decision.compareAndSet(UNDECIDED, SUSPENDED)) return COROUTINE_SUSPENDED - else -> return decision - } - } - - // If ShortCircuit causes CancellationException, we also want to shift back to R - private tailrec fun Throwable.shortCircuitCause(): ShortCircuit? = - when (val cause = this.cause) { - null -> null - is ShortCircuit -> cause - else -> cause.shortCircuitCause() - } - - private fun Throwable.shiftedOrNull(): Any? { - val shortCircuit = if (this is ShortCircuit) this else shortCircuitCause() - return if (shortCircuit != null && shortCircuit.token === token) shortCircuit.raiseValue as R - else EMPTY_VALUE - } - - public override suspend fun shift(r: R): A = - throw ShortCircuit(token, r) - - fun startCoroutineUninterceptedOrReturn(): Any? = - try { - f.startCoroutineUninterceptedOrReturn(this, this)?.let { - if (it == COROUTINE_SUSPENDED) getResult() - else it - } - } catch (e: Throwable) { - val x = e.shiftedOrNull() - if (x === EMPTY_VALUE) throw e else x - } -} diff --git a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt b/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt deleted file mode 100644 index 511f90b1fef..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt +++ /dev/null @@ -1,7 +0,0 @@ -package arrow.continuations.generic - -/** Represents a unique identifier using object equality. */ -@Deprecated(deprecateArrowContinuation) -internal class Token { - override fun toString(): String = "Token(${hashCode().toString(16)})" -} diff --git a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/Maybe.kt b/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/Maybe.kt deleted file mode 100644 index fa0b12cbede..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/Maybe.kt +++ /dev/null @@ -1,15 +0,0 @@ -package generic - -import arrow.continuations.Reset - -sealed class Maybe -data class Just(val a: A) : Maybe() -object None : Maybe() - -object maybeEff { // if you change the name to maybe it breaks the tests in 1.4.10 - inline fun restricted(crossinline c: suspend MaybeEffect<*>.() -> A): Maybe = - Reset.restricted { Just(c(MaybeEffect { this })) } - - suspend inline operator fun invoke(crossinline c: suspend MaybeEffect<*>.() -> A): Maybe = - Reset.suspended { Just(c(MaybeEffect { this })) } -} diff --git a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/MaybeEffect.kt b/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/MaybeEffect.kt deleted file mode 100644 index c082f7f5bff..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/MaybeEffect.kt +++ /dev/null @@ -1,11 +0,0 @@ -package generic - -import arrow.continuations.Effect - -fun interface MaybeEffect : Effect> { - suspend fun Maybe.bind(): B = - when (this) { - is Just -> a - is None -> control().shift(None) - } -} diff --git a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/SuspendingComputationTest.kt b/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/SuspendingComputationTest.kt deleted file mode 100644 index 128a4f351e5..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/SuspendingComputationTest.kt +++ /dev/null @@ -1,221 +0,0 @@ -package arrow.continuations - -import arrow.core.Either -import arrow.core.computations.either -import arrow.core.Either.Right -import arrow.core.Either.Left -import arrow.core.Eval -import arrow.core.computations.ensureNotNull -import arrow.core.computations.eval -import arrow.core.left -import arrow.core.right -import io.kotest.assertions.fail -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.orNull -import io.kotest.property.arbitrary.string -import io.kotest.property.checkAll -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import kotlinx.coroutines.suspendCancellableCoroutine -import kotlin.coroutines.Continuation -import kotlin.coroutines.CoroutineContext -import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED -import kotlin.coroutines.intrinsics.intercepted -import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn -import kotlin.coroutines.startCoroutine - -class SuspendingComputationTest : StringSpec({ - - "immediate values" { - either { - Right(1).bind() - } shouldBe Right(1) - } - - "suspended value" { - either { - Right(1).suspend().bind() - } shouldBe Right(1) - } - - "immediate short-circuit" { - either { - Left("hello").bind() - } shouldBe Left("hello") - } - - "suspended short-circuit" { - either { - Left("hello").suspend().bind() - } shouldBe Left("hello") - } - - "Rethrows immediate exceptions" { - val e = RuntimeException("test") - Either.catch { - either { - Right(1).bind() - Right(1).suspend().bind() - throw e - } - } shouldBe Left(e) - } - - "Rethrows suspended exceptions" { - val e = RuntimeException("test") - Either.catch { - either { - Right(1).bind() - Right(1).suspend().bind() - e.suspend() - } - } shouldBe Either.Left(e) - } - - "Can short-circuit immediately from nested blocks" { - either { - val x = eval { - Left("test").bind() - 5L - } - - println(x) - 1 - } shouldBe Left("test") - } - - "Can short-circuit suspended from nested blocks" { - either { - val x = eval { - Left("test").suspend().bind() - 5L - } - - println(x) - 1 - } shouldBe Left("test") - } - - "Can short-circuit immediately after suspending from nested blocks" { - either { - val x = eval { - Eval.Now(1L).suspend().bind() - Left("test").suspend().bind() - 5L - } - - println(x) - 1 - } shouldBe Left("test") - } - - "Can short-circuit suspended after suspending from nested blocks" { - either { - val x = eval { - Eval.Now(1L).suspend().bind() - Left("test").suspend().bind() - 5L - } - - println(x) - 1 - } shouldBe Left("test") - } - - "ensure null in either computation" { - checkAll(Arb.boolean(), Arb.int(), Arb.string()) { predicate, rValue, lValue -> - either { - ensure(predicate) { lValue } - rValue - } shouldBe if (predicate) rValue.right() else lValue.left() - } - } - - "ensureNotNull in either computation" { - fun square(i: Int): Int = i * i - - checkAll(Arb.int().orNull(), Arb.string()) { i: Int?, lValue: String -> - val res = either { - val ii = i - ensureNotNull(ii) { lValue } - square(ii) // Smart-cast by contract - } - val expected = i?.let(::square)?.right() ?: lValue.left() - res shouldBe expected - } - } - - "Short-circuiting cancels KotlinX Coroutines" { - val scope = CoroutineScope(Dispatchers.Default) - val latch = CompletableDeferred() - val cancelled = CompletableDeferred() - - either { - val deferreds: List> = listOf( - scope.async { - completeOnCancellation(latch, cancelled) - 1 - }, - scope.async { - latch.await() - Left("hello").bind() - } - ) - - deferreds.awaitAll().sum() - } shouldBe Left("hello") - - cancelled.await() - } - - "Computation blocks run on parent context" { - val parentCtx = currentContext() - either { - currentContext() shouldBe parentCtx - } - } -}) - -suspend fun currentContext(): CoroutineContext = - kotlin.coroutines.coroutineContext - -suspend fun completeOnCancellation(latch: CompletableDeferred, cancelled: CompletableDeferred): Unit = - suspendCancellableCoroutine { cont -> - cont.invokeOnCancellation { - if (!cancelled.complete(Unit)) fail("cancelled latch was completed twice") - else Unit - } - - if (!latch.complete(Unit)) fail("latch was completed twice") - else Unit - } - -internal suspend fun Throwable.suspend(): Nothing = - suspendCoroutineUninterceptedOrReturn { cont -> - suspend { throw this }.startCoroutine( - Continuation(Dispatchers.Default) { - cont.intercepted().resumeWith(it) - } - ) - - COROUTINE_SUSPENDED - } - -internal suspend fun A.suspend(): A = - suspendCoroutineUninterceptedOrReturn { cont -> - suspend { this }.startCoroutine( - Continuation(Dispatchers.Default) { - cont.intercepted().resumeWith(it) - } - ) - - COROUTINE_SUSPENDED - } diff --git a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/TestSuite.kt b/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/TestSuite.kt deleted file mode 100644 index 12314a24a27..00000000000 --- a/arrow-libs/core/arrow-continuations/src/commonTest/kotlin/generic/TestSuite.kt +++ /dev/null @@ -1,24 +0,0 @@ -package generic - -import arrow.continuations.Reset -import arrow.continuations.generic.RestrictedScope -import arrow.core.Either -import arrow.core.Either.Left -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe - -class SingleShotContTestSuite : StringSpec({ - "yield a list (also verifies stacksafety)" { - Reset.restricted { - suspend fun RestrictedScope>.yield(a: A): Unit = shift { k -> listOf(a) + k(Unit) } - for (i in 0..10_000) yield(i) - emptyList() - } shouldBe (0..10_000).toList() - } - "short circuit" { - Reset.restricted> { - val no: Int = shift { Left("No thank you") } - throw IllegalStateException("This should not be executed") - } shouldBe Left("No thank you") - } -}) diff --git a/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/AtomicRef.kt b/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/AtomicRef.kt deleted file mode 100644 index 9b845acb0a9..00000000000 --- a/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/AtomicRef.kt +++ /dev/null @@ -1,31 +0,0 @@ -package arrow.continuations.generic - -@Deprecated(deprecateArrowContinuation) -public actual class AtomicRef actual constructor(initialValue: V) { - private var internalValue: V = initialValue - - /** - * Compare current value with expected and set to new if they're the same. Note, 'compare' is checking - * the actual object id, not 'equals'. - */ - public actual fun compareAndSet(expected: V, new: V): Boolean { - return if (expected === internalValue) { - internalValue = new - true - } else { - false - } - } - - public actual fun getAndSet(value: V): V { - val oldValue = internalValue - internalValue = value - return oldValue - } - - public actual fun get(): V = internalValue - - public actual fun set(value: V) { - internalValue = value - } -} diff --git a/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt b/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt deleted file mode 100644 index aab29577711..00000000000 --- a/arrow-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/ControlThrowable.kt +++ /dev/null @@ -1,10 +0,0 @@ -package arrow.continuations.generic - -/** - * A [Throwable] class intended for control flow. - * Instance of [ControlThrowable.kt] should **not** be caught, - * and `arrow.core.NonFatal` does not catch this [Throwable]. - * Thus by extension `Either.catch` also don't catch [ControlThrowable.kt]. - */ -@Deprecated(deprecateArrowContinuation) -public actual open class ControlThrowable : Throwable() diff --git a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/AtomicRef.kt b/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/AtomicRef.kt deleted file mode 100644 index 2a6268230d7..00000000000 --- a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/AtomicRef.kt +++ /dev/null @@ -1,8 +0,0 @@ -@file:JvmName("AtomicReferenceActual") - -package arrow.continuations.generic - -import java.util.concurrent.atomic.AtomicReference - -@Deprecated(deprecateArrowContinuation) -public actual typealias AtomicRef = AtomicReference 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 deleted file mode 100644 index 46bf67112e5..00000000000 --- a/arrow-libs/core/arrow-continuations/src/jvmMain/kotlin/arrow/continuations/generic/ControlThrowable.kt +++ /dev/null @@ -1,13 +0,0 @@ - -package arrow.continuations.generic - -/** - * A [Throwable] class intended for control flow. - * Instance of [ControlThrowable.kt] should **not** be caught, - * and `arrow.core.NonFatal` does not catch this [Throwable]. - * Thus by extension `Either.catch` also don't catch [ControlThrowable.kt]. - */ -@Deprecated(deprecateArrowContinuation) -public actual open class ControlThrowable : Throwable() { - override fun fillInStackTrace(): Throwable = this -} diff --git a/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/AtomicRef.kt b/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/AtomicRef.kt deleted file mode 100644 index 36d201b6cbc..00000000000 --- a/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/AtomicRef.kt +++ /dev/null @@ -1,30 +0,0 @@ -package arrow.continuations.generic - -import kotlin.native.concurrent.AtomicReference -import kotlin.native.concurrent.freeze -import kotlin.native.concurrent.isFrozen - -@Deprecated(deprecateArrowContinuation) -public actual class AtomicRef actual constructor(initialValue: V) { - private val atom = AtomicReference(initialValue.freeze()) - public actual fun get(): V = atom.value - - public actual fun set(value: V) { - atom.value = value.freeze() - } - - public actual fun getAndSet(value: V): V { - if (atom.isFrozen) value.freeze() - while (true) { - val cur = atom.value - if (cur === value) return cur - if (atom.compareAndSwap(cur, value) === cur) return cur - } - } - - /** - * Compare current value with expected and set to new if they're the same. Note, 'compare' is checking - * the actual object id, not 'equals'. - */ - public actual fun compareAndSet(expected: V, new: V): Boolean = atom.compareAndSet(expected, new.freeze()) -} diff --git a/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt b/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt deleted file mode 100644 index 839dc4043ba..00000000000 --- a/arrow-libs/core/arrow-continuations/src/nativeMain/kotlin/arrow.continuations/generic/ControlThrowable.kt +++ /dev/null @@ -1,10 +0,0 @@ -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` also don't catch [ControlThrowable]. - */ -@Deprecated(deprecateArrowContinuation) -public actual open class ControlThrowable : Throwable() diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index fbb6dd02f7c..8f0f4850d69 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -31,38 +31,6 @@ public final class arrow/core/Composition { public static final fun compose (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public final class arrow/core/Const { - public static final field Companion Larrow/core/Const$Companion; - public fun (Ljava/lang/Object;)V - public final fun copy (Ljava/lang/Object;)Larrow/core/Const; - public static synthetic fun copy$default (Larrow/core/Const;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Const; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Const; - public final fun retag ()Larrow/core/Const; - public fun toString ()Ljava/lang/String; - public final fun value ()Ljava/lang/Object; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function10;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function9;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function8;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function7;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function6;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function5;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function4;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function3;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Lkotlin/jvm/functions/Function2;)Larrow/core/Const; -} - -public final class arrow/core/Const$Companion { -} - -public final class arrow/core/ConstKt { - public static final fun combine (Larrow/core/Const;Larrow/typeclasses/Semigroup;Larrow/core/Const;)Larrow/core/Const; - public static final fun compareTo (Larrow/core/Const;Larrow/core/Const;)I - public static final fun const (Ljava/lang/Object;)Larrow/core/Const; - public static final fun contramap (Larrow/core/Const;Lkotlin/jvm/functions/Function1;)Larrow/core/Const; -} - public final class arrow/core/Currying { public static final fun curried (Lkotlin/jvm/functions/Function10;)Lkotlin/jvm/functions/Function1; public static final fun curried (Lkotlin/jvm/functions/Function11;)Lkotlin/jvm/functions/Function1; @@ -320,108 +288,6 @@ public final class arrow/core/Endo { public final class arrow/core/Endo$Companion { } -public abstract class arrow/core/Eval { - public static final field Companion Larrow/core/Eval$Companion; - public static final fun always (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public final fun coflatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public static final fun defer (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval; - public final fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public static final fun later (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public abstract fun memoize ()Larrow/core/Eval; - public static final fun now (Ljava/lang/Object;)Larrow/core/Eval; - public static final fun raise (Ljava/lang/Throwable;)Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public abstract fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Always : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public static synthetic fun copy$default (Larrow/core/Eval$Always;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Always; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Companion { - public final fun always (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public final fun defer (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval; - public final fun later (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public final fun now (Ljava/lang/Object;)Larrow/core/Eval; - public final fun raise (Ljava/lang/Throwable;)Larrow/core/Eval; -} - -public final class arrow/core/Eval$Defer : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun component1 ()Lkotlin/jvm/functions/Function0; - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Defer; - public static synthetic fun copy$default (Larrow/core/Eval$Defer;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Defer; - public fun equals (Ljava/lang/Object;)Z - public final fun getThunk ()Lkotlin/jvm/functions/Function0; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public abstract class arrow/core/Eval$FlatMap : arrow/core/Eval { - public fun ()V - public fun memoize ()Larrow/core/Eval; - public abstract fun run (Ljava/lang/Object;)Larrow/core/Eval; - public abstract fun start ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Later : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public static synthetic fun copy$default (Larrow/core/Eval$Later;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Later; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Now : arrow/core/Eval { - public static final field Companion Larrow/core/Eval$Now$Companion; - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Eval$Now; - public static synthetic fun copy$default (Larrow/core/Eval$Now;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Eval$Now; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Now$Companion { - public final fun getUnit ()Larrow/core/Eval; -} - -public final class arrow/core/EvalKt { - public static final fun iterateRight (Ljava/util/Iterator;Larrow/core/Eval;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; - public static final fun replicate (Larrow/core/Eval;I)Larrow/core/Eval; - public static final fun replicate (Larrow/core/Eval;ILarrow/typeclasses/Monoid;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function10;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function9;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function8;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function7;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function6;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function5;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function4;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function3;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; -} - public abstract class arrow/core/Ior { public static final field Companion Larrow/core/Ior$Companion; public final fun all (Lkotlin/jvm/functions/Function1;)Z @@ -767,7 +633,6 @@ public abstract class arrow/core/Option { public final fun pairLeft (Ljava/lang/Object;)Larrow/core/Option; public final fun pairRight (Ljava/lang/Object;)Larrow/core/Option; public final fun reduceOrNull (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun reduceRightEvalOrNull (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; public final fun replicate (I)Larrow/core/Option; public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public final fun tapNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; @@ -1431,591 +1296,6 @@ public final class arrow/core/StringKt { public static final fun escaped (Ljava/lang/String;)Ljava/lang/String; } -public final class arrow/core/Tuple10 { - public static final field Companion Larrow/core/Tuple10$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple10; - public static synthetic fun copy$default (Larrow/core/Tuple10;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple10; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple10$Companion { -} - -public final class arrow/core/Tuple11 { - public static final field Companion Larrow/core/Tuple11$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple11; - public static synthetic fun copy$default (Larrow/core/Tuple11;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple11; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple11$Companion { -} - -public final class arrow/core/Tuple12 { - public static final field Companion Larrow/core/Tuple12$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple12; - public static synthetic fun copy$default (Larrow/core/Tuple12;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple12; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple12$Companion { -} - -public final class arrow/core/Tuple13 { - public static final field Companion Larrow/core/Tuple13$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple13; - public static synthetic fun copy$default (Larrow/core/Tuple13;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple13; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple13$Companion { -} - -public final class arrow/core/Tuple14 { - public static final field Companion Larrow/core/Tuple14$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple14; - public static synthetic fun copy$default (Larrow/core/Tuple14;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple14; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple14$Companion { -} - -public final class arrow/core/Tuple15 { - public static final field Companion Larrow/core/Tuple15$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple15; - public static synthetic fun copy$default (Larrow/core/Tuple15;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple15; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple15$Companion { -} - -public final class arrow/core/Tuple16 { - public static final field Companion Larrow/core/Tuple16$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple16; - public static synthetic fun copy$default (Larrow/core/Tuple16;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple16; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple16$Companion { -} - -public final class arrow/core/Tuple17 { - public static final field Companion Larrow/core/Tuple17$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple17; - public static synthetic fun copy$default (Larrow/core/Tuple17;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple17; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple17$Companion { -} - -public final class arrow/core/Tuple18 { - public static final field Companion Larrow/core/Tuple18$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple18; - public static synthetic fun copy$default (Larrow/core/Tuple18;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple18; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple18$Companion { -} - -public final class arrow/core/Tuple19 { - public static final field Companion Larrow/core/Tuple19$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple19; - public static synthetic fun copy$default (Larrow/core/Tuple19;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple19; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple19$Companion { -} - -public final class arrow/core/Tuple20 { - public static final field Companion Larrow/core/Tuple20$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple20; - public static synthetic fun copy$default (Larrow/core/Tuple20;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple20; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple20$Companion { -} - -public final class arrow/core/Tuple21 { - public static final field Companion Larrow/core/Tuple21$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component21 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple21; - public static synthetic fun copy$default (Larrow/core/Tuple21;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple21; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public final fun getTwentyFirst ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple21$Companion { -} - -public final class arrow/core/Tuple22 { - public static final field Companion Larrow/core/Tuple22$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component21 ()Ljava/lang/Object; - public final fun component22 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple22; - public static synthetic fun copy$default (Larrow/core/Tuple22;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple22; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public final fun getTwentyFirst ()Ljava/lang/Object; - public final fun getTwentySecond ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple22$Companion { -} - public final class arrow/core/Tuple4 { public static final field Companion Larrow/core/Tuple4$Companion; public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V @@ -2174,7 +1454,6 @@ public final class arrow/core/Tuple9$Companion { public final class arrow/core/TupleNKt { public static final fun combine (Lkotlin/Pair;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Lkotlin/Pair;)Lkotlin/Pair; - public static final fun compareTo (Larrow/core/Tuple10;Larrow/core/Tuple10;)I public static final fun compareTo (Larrow/core/Tuple4;Larrow/core/Tuple4;)I public static final fun compareTo (Larrow/core/Tuple5;Larrow/core/Tuple5;)I public static final fun compareTo (Larrow/core/Tuple6;Larrow/core/Tuple6;)I @@ -2183,24 +1462,11 @@ public final class arrow/core/TupleNKt { public static final fun compareTo (Larrow/core/Tuple9;Larrow/core/Tuple9;)I public static final fun compareTo (Lkotlin/Pair;Lkotlin/Pair;)I public static final fun compareTo (Lkotlin/Triple;Lkotlin/Triple;)I - public static final fun plus (Larrow/core/Tuple10;Ljava/lang/Object;)Larrow/core/Tuple11; - public static final fun plus (Larrow/core/Tuple11;Ljava/lang/Object;)Larrow/core/Tuple12; - public static final fun plus (Larrow/core/Tuple12;Ljava/lang/Object;)Larrow/core/Tuple13; - public static final fun plus (Larrow/core/Tuple13;Ljava/lang/Object;)Larrow/core/Tuple14; - public static final fun plus (Larrow/core/Tuple14;Ljava/lang/Object;)Larrow/core/Tuple15; - public static final fun plus (Larrow/core/Tuple15;Ljava/lang/Object;)Larrow/core/Tuple16; - public static final fun plus (Larrow/core/Tuple16;Ljava/lang/Object;)Larrow/core/Tuple17; - public static final fun plus (Larrow/core/Tuple17;Ljava/lang/Object;)Larrow/core/Tuple18; - public static final fun plus (Larrow/core/Tuple18;Ljava/lang/Object;)Larrow/core/Tuple19; - public static final fun plus (Larrow/core/Tuple19;Ljava/lang/Object;)Larrow/core/Tuple20; - public static final fun plus (Larrow/core/Tuple20;Ljava/lang/Object;)Larrow/core/Tuple21; - public static final fun plus (Larrow/core/Tuple21;Ljava/lang/Object;)Larrow/core/Tuple22; public static final fun plus (Larrow/core/Tuple4;Ljava/lang/Object;)Larrow/core/Tuple5; public static final fun plus (Larrow/core/Tuple5;Ljava/lang/Object;)Larrow/core/Tuple6; public static final fun plus (Larrow/core/Tuple6;Ljava/lang/Object;)Larrow/core/Tuple7; public static final fun plus (Larrow/core/Tuple7;Ljava/lang/Object;)Larrow/core/Tuple8; public static final fun plus (Larrow/core/Tuple8;Ljava/lang/Object;)Larrow/core/Tuple9; - public static final fun plus (Larrow/core/Tuple9;Ljava/lang/Object;)Larrow/core/Tuple10; public static final fun plus (Lkotlin/Pair;Ljava/lang/Object;)Lkotlin/Triple; public static final fun plus (Lkotlin/Triple;Ljava/lang/Object;)Larrow/core/Tuple4; } @@ -2212,128 +1478,6 @@ public final class arrow/core/UtilsKt { public static final fun mapNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public abstract interface class arrow/core/computations/EitherEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EitherEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/EitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/EitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/EitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EitherKt { - public static final fun ensureNotNull (Larrow/core/computations/EitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/EvalEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EvalEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/EvalEffect;Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/NullableEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/NullableEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/NullableEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/NullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/NullableEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/NullableKt { - public static final fun ensureNotNull (Larrow/core/computations/NullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/OptionEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/OptionEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/OptionEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/OptionEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/OptionKt { - public static final fun ensureNotNull (Larrow/core/computations/OptionEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedEitherEffect : arrow/core/computations/EitherEffect { -} - -public final class arrow/core/computations/RestrictedEitherEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedEitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedEvalEffect : arrow/core/computations/EvalEffect { -} - -public final class arrow/core/computations/RestrictedEvalEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedEvalEffect;Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedNullableEffect : arrow/core/computations/NullableEffect { -} - -public final class arrow/core/computations/RestrictedNullableEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedNullableEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedNullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedNullableEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedOptionEffect : arrow/core/computations/OptionEffect { -} - -public final class arrow/core/computations/RestrictedOptionEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedOptionEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedOptionEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/ResultEffect { - public static final field INSTANCE Larrow/core/computations/ResultEffect; - public final fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/core/computations/ResultEffect$result { - public static final field INSTANCE Larrow/core/computations/ResultEffect$result; - public final fun invoke-IoAF18A (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public final class arrow/core/computations/either { - public static final field INSTANCE Larrow/core/computations/either; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/eval { - public static final field INSTANCE Larrow/core/computations/eval; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/nullable { - public static final field INSTANCE Larrow/core/computations/nullable; - public final fun eager (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/option { - public static final field INSTANCE Larrow/core/computations/option; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - public final class arrow/core/continuations/DefaultRaise : arrow/core/continuations/Raise { public fun ()V public fun bind (Larrow/core/Either;)Ljava/lang/Object; @@ -2649,7 +1793,6 @@ public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Sem public static fun Short ()Larrow/typeclasses/Monoid; public abstract fun combineAll (Ljava/util/Collection;)Ljava/lang/Object; public abstract fun combineAll (Ljava/util/List;)Ljava/lang/Object; - public static fun constant (Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public static fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public abstract fun empty ()Ljava/lang/Object; public static fun endo ()Larrow/typeclasses/Monoid; @@ -2669,7 +1812,6 @@ public final class arrow/typeclasses/Monoid$Companion { public final fun Integer ()Larrow/typeclasses/Monoid; public final fun Long ()Larrow/typeclasses/Monoid; public final fun Short ()Larrow/typeclasses/Monoid; - public final fun constant (Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final synthetic fun either (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final fun endo ()Larrow/typeclasses/Monoid; @@ -2700,7 +1842,6 @@ public abstract interface class arrow/typeclasses/Semigroup { public static fun Short ()Larrow/typeclasses/Semigroup; public abstract fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun constant (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public static fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public static fun endo ()Larrow/typeclasses/Semigroup; public static fun ior (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; @@ -2721,7 +1862,6 @@ public final class arrow/typeclasses/Semigroup$Companion { public final fun Integer ()Larrow/typeclasses/Semigroup; public final fun Long ()Larrow/typeclasses/Semigroup; public final fun Short ()Larrow/typeclasses/Semigroup; - public final fun constant (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public final fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public final fun endo ()Larrow/typeclasses/Semigroup; public final fun ior (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index 60ae0ca847a..87549a71ae3 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -4,9 +4,9 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) + alias(libs.plugins.kotest.multiplatform) } -apply(plugin = "io.kotest.multiplatform") apply(from = property("TEST_COVERAGE")) apply(from = property("ANIMALSNIFFER_MPP")) @@ -24,7 +24,6 @@ kotlin { sourceSets { commonMain { dependencies { - api(projects.arrowContinuations) api(projects.arrowAtomic) api(projects.arrowAnnotations) api(libs.kotlin.stdlibCommon) @@ -39,9 +38,10 @@ kotlin { implementation(libs.kotest.property) } } - jvmTest { dependencies { + implementation(projects.arrowFxCoroutines) + runtimeOnly(libs.kotest.frameworkEngine) runtimeOnly(libs.kotest.runnerJUnit5) } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Const.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Const.kt deleted file mode 100644 index 4d09516f9b5..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Const.kt +++ /dev/null @@ -1,176 +0,0 @@ -package arrow.core - -import arrow.typeclasses.Semigroup - -public data class Const(private val value: A) { - - @Suppress("UNCHECKED_CAST") - public fun retag(): Const = - this as Const - - public companion object {} - - public fun value(): A = - value - - public fun map(f: (T) -> U): Const = - retag() - - public inline fun zip( - SG: Semigroup, - b: Const, - map: (T, B) -> C - ): Const = - retag().combine(SG, b.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - map: (T, B, C) -> D - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - d: Const, - map: (T, B, C, D) -> E - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - .combine(SG, d.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - d: Const, - e: Const, - map: (T, B, C, D, E) -> F - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - .combine(SG, d.retag()) - .combine(SG, e.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - d: Const, - e: Const, - f: Const, - map: (A, B, C, D, E, F) -> G - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - .combine(SG, d.retag()) - .combine(SG, e.retag()) - .combine(SG, f.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - d: Const, - e: Const, - f: Const, - g: Const, - map: (A, B, C, D, E, F, G) -> H - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - .combine(SG, d.retag()) - .combine(SG, e.retag()) - .combine(SG, f.retag()) - .combine(SG, g.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - d: Const, - e: Const, - f: Const, - g: Const, - h: Const, - map: (A, B, C, D, E, F, G, H) -> I - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - .combine(SG, d.retag()) - .combine(SG, e.retag()) - .combine(SG, f.retag()) - .combine(SG, g.retag()) - .combine(SG, h.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - d: Const, - e: Const, - f: Const, - g: Const, - h: Const, - i: Const, - map: (A, B, C, D, E, F, G, H, I) -> J - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - .combine(SG, d.retag()) - .combine(SG, e.retag()) - .combine(SG, f.retag()) - .combine(SG, g.retag()) - .combine(SG, h.retag()) - .combine(SG, i.retag()) - - public inline fun zip( - SG: Semigroup, - b: Const, - c: Const, - d: Const, - e: Const, - f: Const, - g: Const, - h: Const, - i: Const, - j: Const, - map: (A, B, C, D, E, F, G, H, I, J) -> K - ): Const = - retag() - .combine(SG, b.retag()) - .combine(SG, c.retag()) - .combine(SG, d.retag()) - .combine(SG, e.retag()) - .combine(SG, f.retag()) - .combine(SG, g.retag()) - .combine(SG, h.retag()) - .combine(SG, i.retag()) - .combine(SG, j.retag()) - - override fun toString(): String = - "$Const($value)" -} - -public fun Const.combine(SG: Semigroup, that: Const): Const = - Const(SG.run { this@combine.value().combine(that.value()) }) - -public inline fun A.const(): Const = - Const(this) - -public fun Const.contramap(f: (U) -> T): Const = - retag() - -public operator fun , T> Const.compareTo(other: Const): Int = - value().compareTo(other.value()) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Eval.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Eval.kt deleted file mode 100644 index d3c73905223..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Eval.kt +++ /dev/null @@ -1,566 +0,0 @@ -package arrow.core - -import arrow.typeclasses.Monoid -import kotlin.js.JsName -import kotlin.jvm.JvmStatic - -/** - * Eval is a monad which controls evaluation of a value or a computation that produces a value. - * - * Three basic evaluation strategies: - * - * - Now: evaluated immediately - * - Later: evaluated once when value is needed - * - Always: evaluated every time value is needed - * - * The Later and Always are both lazy strategies while Now is eager. - * Later and Always are distinguished from each other only by - * memoization: once evaluated Later will save the value to be returned - * immediately if it is needed again. Always will run its computation - * every time. - * - * methods, which use an internal trampoline to avoid stack overflows. - * Computation done within .map and .flatMap is always done lazily, - * even when applied to a Now instance. - * - * It is not generally good style to pattern-match on Eval instances. - * Rather, use .map and .flatMap to chain computation, and use .value - * to get the result when needed. It is also not good style to create - * Eval instances whose computation involves calling .value on another - * Eval instance -- this can defeat the trampolining and lead to stack - * overflows. - * - * Example of stack safety: - * - * ```kotlin - * import arrow.core.Eval - * - * //sampleStart - * fun even(n: Int): Eval = - * Eval.always { n == 0 }.flatMap { - * if(it == true) Eval.now(true) - * else odd(n - 1) - * } - * - * fun odd(n: Int): Eval = - * Eval.always { n == 0 }.flatMap { - * if(it == true) Eval.now(false) - * else even(n - 1) - * } - * - * // if not wrapped in eval this type of computation would blow the stack and result in a StackOverflowError - * fun main() { - * println(odd(100000).value()) - * } - * //sampleEnd - * ``` - * - * - */ -public sealed class Eval { - - public companion object { - - /** - * Creates an Eval instance from an already constructed value but still defers evaluation when chaining expressions with `map` and `flatMap` - * - * @param a is an already computed value of type [A] - * - * ```kotlin - * import arrow.core.* - * - * fun main() { - * //sampleStart - * val eager = Eval.now(1).map { it + 1 } - * println(eager.value()) - * //sampleEnd - * } - * ``` - * - * - * It will return 2. - */ - @JvmStatic - public fun now(a: A): Eval = - Now(a) - - /** - * Creates an Eval instance from a function deferring it's evaluation until `.value()` is invoked memoizing the computed value. - * - * @param f is a function or computation that will be called only once when `.value()` is invoked for the first time. - * - * ```kotlin - * import arrow.core.* - * - * fun main() { - * //sampleStart - * val lazyEvaled = Eval.later { "expensive computation" } - * println(lazyEvaled.value()) - * //sampleEnd - * } - * ``` - * - * - * "expensive computation" is only computed once since the results are memoized and multiple calls to `value()` will just return the cached value. - */ - @JvmStatic - public inline fun later(crossinline f: () -> A): Later = - Later { f() } - - /** - * Creates an Eval instance from a function deferring it's evaluation until `.value()` is invoked recomputing each time `.value()` is invoked. - * - * @param f is a function or computation that will be called every time `.value()` is invoked. - * - * ```kotlin - * import arrow.core.* - * - * fun main() { - * //sampleStart - * val alwaysEvaled = Eval.always { "expensive computation" } - * println(alwaysEvaled.value()) - * //sampleEnd - * } - * ``` - * - * - * "expensive computation" is computed every time `value()` is invoked. - */ - @JvmStatic - public inline fun always(crossinline f: () -> A): Always = - Always { f() } - - @JvmStatic - public inline fun defer(crossinline f: () -> Eval): Eval = - Defer { f() } - - @JvmStatic - public fun raise(t: Throwable): Eval = - defer { throw t } - - /** - * Collapse the call stack for eager evaluations. - */ - private tailrec fun collapse(fa: Eval): Eval = - when (fa) { - is Defer -> collapse(fa.thunk()) - is FlatMap -> - object : FlatMap() { - override fun start(): Eval = fa.start() - override fun run(s: S): Eval = collapse1(fa.run(s)) - } - else -> fa - } - - // Enforce tailrec call to collapse inside compute loop - private fun collapse1(fa: Eval): Eval = collapse(fa) - - @Suppress("UNCHECKED_CAST") - private fun evaluate(e: Eval): A = run { - var curr: Eval = e - val fs: MutableList<(Any?) -> Eval> = mutableListOf() - - fun addToMemo(m: Memoize): (Any?) -> Eval = { - m.result = Some(it) - now(it) - } - - loop@ while (true) { - when (curr) { - is FlatMap -> { - val currComp = curr as FlatMap - currComp.start().let { cc -> - when (cc) { - is FlatMap -> { - curr = cc.start() - fs.add(0, currComp::run) - fs.add(0, cc::run) - } - is Memoize -> { - cc.result.fold( - { - curr = cc.eval - fs.add(0, currComp::run) - fs.add(0, addToMemo(cc as Memoize)) - }, - { - curr = Now(it) - fs.add(0, currComp::run) - } - ) - } - else -> { - curr = currComp.run(cc.value()) - } - } - } - } - is Memoize -> { - val currComp = curr as Memoize - val eval = currComp.eval - currComp.result.fold( - { - curr = eval - fs.add(0, addToMemo(currComp)) - }, - { - if (fs.isNotEmpty()) { - curr = fs[0](it) - fs.removeAt(0) - } - } - ) - } - else -> - if (fs.isNotEmpty()) { - curr = fs[0](curr.value()) - fs.removeAt(0) - } else { - break@loop - } - } - } - - return curr.value() as A - } - } - - public abstract fun value(): A - - public abstract fun memoize(): Eval - - public inline fun map(crossinline f: (A) -> B): Eval = - flatMap { a -> Now(f(a)) } - - @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE", "UNCHECKED_CAST") - public fun flatMap(f: (A) -> Eval): Eval = - when (this) { - is FlatMap -> object : FlatMap() { - override fun start(): Eval = (this@Eval).start() - - // @IgnoreJRERequirement - override fun run(s: S): Eval = - object : FlatMap() { - override fun start(): Eval = (this@Eval).run(s) as Eval - override fun run(s1: S1): Eval = f(s1 as A) - } - } - is Defer -> object : FlatMap() { - override fun start(): Eval = this@Eval.thunk() as Eval - override fun run(s: S): Eval = f(s as A) - } - else -> object : FlatMap() { - override fun start(): Eval = this@Eval as Eval - override fun run(s: S): Eval = f(s as A) - } - } - - public inline fun coflatMap(crossinline f: (Eval) -> B): Eval = - Later { f(this) } - - /** - * Construct an eager Eval instance. In some sense it is equivalent to using a val. - * - * This type should be used when an A value is already in hand, or when the computation to produce an A value is - * pure and very fast. - */ - public data class Now(@JsName("_value") val value: A) : Eval() { - override fun value(): A = value - override fun memoize(): Eval = this - - override fun toString(): String = - "Eval.Now($value)" - - public companion object { - @PublishedApi - internal val unit: Eval = Now(Unit) - } - } - - /** - * Construct a lazy Eval instance. - * - * This type should be used for most "lazy" values. In some sense it is equivalent to using a lazy val. - * - * When caching is not required or desired (e.g. if the value produced may be large) prefer Always. When there - * is no computation necessary, prefer Now. - * - * Once Later has been evaluated, the closure (and any values captured by the closure) will not be retained, and - * will be available for garbage collection. - */ - public data class Later(private val f: () -> A) : Eval() { - @JsName("_name") - val value: A by lazy(f) - - override fun value(): A = value - override fun memoize(): Eval = this - - override fun toString(): String = - "Eval.Later(f)" - } - - /** - * Construct a lazy Eval instance. - * - * This type can be used for "lazy" values. In some sense it is equivalent to using a Function0 value. - * - * This type will evaluate the computation every time the value is required. It should be avoided except when - * laziness is required and caching must be avoided. Generally, prefer Later. - */ - public data class Always(private val f: () -> A) : Eval() { - override fun value(): A = f() - override fun memoize(): Eval = Later(f) - - override fun toString(): String = - "Eval.Always(f)" - } - - /** - * Defer is a type of Eval that is used to defer computations which produce Eval. - * - * Users should not instantiate Defer instances themselves. Instead, they will be automatically created when needed. - */ - public data class Defer(val thunk: () -> Eval) : Eval() { - override fun memoize(): Eval = Memoize(this) - override fun value(): A = collapse(this).value() - - override fun toString(): String = - "Eval.Defer(thunk)" - } - - /** - * FlatMap is a type of Eval that is used to chain computations involving .map and .flatMap. Along with - * Eval#flatMap. It implements the trampoline that guarantees stack-safety. - * - * Users should not instantiate FlatMap instances themselves. Instead, they will be automatically created when - * needed. - * - * Unlike a traditional trampoline, the internal workings of the trampoline are not exposed. This allows a slightly - * more efficient implementation of the .value method. - */ - public abstract class FlatMap : Eval() { - public abstract fun start(): Eval - public abstract fun run(s: S): Eval - override fun memoize(): Eval = Memoize(this) - override fun value(): A = evaluate(this) - - override fun toString(): String = - "Eval.FlatMap(..)" - } - - /** - * Memoize is a type of Eval that is used to memoize an eval value. Unlike Later, Memoize exposes its cache, - * allowing Eval's internal trampoline to compute it when needed. - * - * Users should not instantiate Memoize instances themselves. Instead, they will be automatically created when - * needed. - */ - internal data class Memoize(val eval: Eval) : Eval() { - var result: Option = None - override fun memoize() = this - override fun value(): A = result.getOrElse { - evaluate(eval).also { result = Some(it) } - } - - override fun toString(): String = - "Eval.Memoize($eval)" - } - - override fun toString(): String = - "Eval(...)" -} - -public fun Iterator.iterateRight(lb: Eval, f: (A, Eval) -> Eval): Eval { - fun loop(): Eval = - Eval.defer { if (this.hasNext()) f(this.next(), loop()) else lb } - return loop() -} - -public fun Eval.zip(b: Eval, map: (A, B) -> Z): Eval = - flatMap { a: A -> b.map { bb: B -> map(a, bb) } } - -public fun Eval.zip(b: Eval): Eval> = - flatMap { a: A -> b.map { bb: B -> Pair(a, bb) } } - -public fun Eval.zip( - b: Eval, - 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) } - -public fun Eval.zip( - b: Eval, - c: Eval, - 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) } - -public fun Eval.zip( - b: Eval, - c: Eval, - d: Eval, - 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 - ) - } - -public fun Eval.zip( - b: Eval, - c: Eval, - d: Eval, - e: Eval, - 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 - ) - } - -public fun Eval.zip( - b: Eval, - c: Eval, - d: Eval, - e: Eval, - f: Eval, - 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 - ) - } - -public fun Eval.zip( - b: Eval, - c: Eval, - d: Eval, - e: Eval, - f: Eval, - g: Eval, - 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 - ) - } - -public fun Eval.zip( - b: Eval, - c: Eval, - d: Eval, - e: Eval, - f: Eval, - g: Eval, - h: Eval, - 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 - ) - } - -public fun Eval.zip( - b: Eval, - c: Eval, - d: Eval, - e: Eval, - f: Eval, - g: Eval, - h: Eval, - i: Eval, - j: Eval, - map: (A, B, C, D, E, F, G, H, I, J) -> K -): Eval = - flatMap { aa -> - b.flatMap { bb -> - c.flatMap { cc -> - d.flatMap { dd -> - e.flatMap { ee -> - f.flatMap { ff -> - g.flatMap { gg -> - h.flatMap { hh -> - i.flatMap { ii -> - j.map { jj -> - map(aa, bb, cc, dd, ee, ff, gg, hh, ii, jj) - } - } - } - } - } - } - } - } - } - } - -public fun Eval.replicate(n: Int): Eval> = - if (n <= 0) Eval.now(emptyList()) - else this.zip(replicate(n - 1)) { a: A, xs: List -> listOf(a) + xs } - -public fun Eval.replicate(n: Int, MA: Monoid): Eval = MA.run { - if (n <= 0) Eval.now(MA.empty()) - else this@replicate.zip(replicate(n - 1, MA)) { a: A, xs: A -> MA.run { a + xs } } -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 6fe6dbaaf87..6a552bef578 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -298,49 +298,6 @@ import kotlin.jvm.JvmStatic * ``` * * - * ### Computing over dependent values ignoring absence - * - * ```kotlin - * import arrow.core.computations.option - * import arrow.core.Some - * import arrow.core.Option - * - * suspend fun value(): Option = - * //sampleStart - * option { - * val a = Some(1).bind() - * val b = Some(1 + a).bind() - * val c = Some(1 + b).bind() - * a + b + c - * } - * //sampleEnd - * suspend fun main() { - * println(value()) - * } - * ``` - * - * - * ```kotlin - * import arrow.core.computations.option - * import arrow.core.Some - * import arrow.core.none - * import arrow.core.Option - * - * suspend fun value(): Option = - * //sampleStart - * option { - * val x = none().bind() - * val y = Some(1 + x).bind() - * val z = Some(1 + y).bind() - * x + y + z - * } - * //sampleEnd - * suspend fun main() { - * println(value()) - * } - * ``` - * - * * ## Credits * * Contents partially adapted from [Scala Exercises Option Tutorial](https://www.scala-exercises.org/std_lib/options) @@ -432,7 +389,7 @@ public sealed class Option { * none().tapNone { println("flower") } // Result: prints "flower" and returns: None * } * ``` - * + * */ public inline fun tapNone(f: () -> Unit): Option = when (this) { @@ -459,7 +416,7 @@ public sealed class Option { * none().tap { println("flower") } // Result: None * } * ``` - * + * */ public inline fun tap(f: (A) -> Unit): Option = when (this) { @@ -732,7 +689,7 @@ public sealed class Option { * none.exists { it > 10 } // Result: false * } * ``` - * + * * * @param predicate the predicate to test */ @@ -757,7 +714,7 @@ public sealed class Option { * none.exists { it > 10 } // Result: null * } * ``` - * + * */ public inline fun findOrNull(predicate: (A) -> Boolean): A? = when (this) { @@ -799,15 +756,6 @@ public sealed class Option { is Some -> operation(initial(value), value) } - public inline fun reduceRightEvalOrNull( - initial: (A) -> B, - operation: (A, acc: Eval) -> Eval - ): Eval = - when (this) { - is None -> Eval.now(null) - is Some -> operation(value, Eval.now(initial(value))) - } - public fun replicate(n: Int): Option> = if (n <= 0) Some(emptyList()) else map { a -> List(n) { a } } @@ -1010,7 +958,7 @@ public inline fun Option.unzip(f: (C) -> Pair): Pair + * */ public fun Option.widen(): Option = this diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple10.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple10.kt deleted file mode 100644 index 5c81d2ab261..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Tuple10.kt +++ /dev/null @@ -1,57 +0,0 @@ -@file:JvmMultifileClass -@file:JvmName("TupleNKt") - -package arrow.core - -import kotlin.jvm.JvmMultifileClass -import kotlin.jvm.JvmName - -public data class Tuple10( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J -) { - - override fun toString(): String = - "($first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eighth, $ninth, $tenth)" - - public companion object -} - -public operator fun , B : Comparable, C : Comparable, D : Comparable, E : Comparable, F : Comparable, G : Comparable, H : Comparable, I : Comparable, J : Comparable> -Tuple10.compareTo(other: Tuple10): Int { - val first = first.compareTo(other.first) - return if (first == 0) { - val second = second.compareTo(other.second) - if (second == 0) { - val third = third.compareTo(other.third) - if (third == 0) { - val fourth = fourth.compareTo(other.fourth) - if (fourth == 0) { - val fifth = fifth.compareTo(other.fifth) - if (fifth == 0) { - val sixth = sixth.compareTo(other.sixth) - if (sixth == 0) { - val seventh = seventh.compareTo(other.seventh) - if (seventh == 0) { - val eighth = eighth.compareTo(other.eighth) - if (eighth == 0) { - val ninth = ninth.compareTo(other.ninth) - if (ninth == 0) tenth.compareTo(other.tenth) - else ninth - } else eighth - } else seventh - } else sixth - } else fifth - } else fourth - } else third - } else second - } else first -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt index a75f0c357af..1fbff275366 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/TupleN.kt @@ -6,274 +6,6 @@ package arrow.core import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName -public data class Tuple11( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, -) { - public companion object -} - -public data class Tuple12( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L -) { - public companion object -} - -public data class Tuple13( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M -) { - - public companion object -} - -public data class Tuple14( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N -) { - - public companion object -} - -public data class Tuple15( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O -) { - - public companion object -} - -public data class Tuple16( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O, - val sixteenth: P -) { - - public companion object -} - -public data class Tuple17( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O, - val sixteenth: P, - val seventeenth: Q -) { - - public companion object -} - -public data class Tuple18( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O, - val sixteenth: P, - val seventeenth: Q, - val eighteenth: R -) { - - public companion object -} - -public data class Tuple19( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O, - val sixteenth: P, - val seventeenth: Q, - val eighteenth: R, - val nineteenth: S -) { - - public companion object -} - -public data class Tuple20( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O, - val sixteenth: P, - val seventeenth: Q, - val eighteenth: R, - val nineteenth: S, - val twentieth: T -) { - - public companion object -} - -public data class Tuple21( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O, - val sixteenth: P, - val seventeenth: Q, - val eighteenth: R, - val nineteenth: S, - val twentieth: T, - val twentyFirst: U -) { - public companion object -} - -public data class Tuple22( - val first: A, - val second: B, - val third: C, - val fourth: D, - val fifth: E, - val sixth: F, - val seventh: G, - val eighth: H, - val ninth: I, - val tenth: J, - val eleventh: K, - val twelfth: L, - val thirteenth: M, - val fourteenth: N, - val fifteenth: O, - val sixteenth: P, - val seventeenth: Q, - val eighteenth: R, - val nineteenth: S, - val twentieth: T, - val twentyFirst: U, - val twentySecond: V -) { - public companion object -} - -private const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 - public operator fun Pair.plus(c: C): Triple = Triple(this.first, this.second, c) public operator fun Triple.plus(d: D): Tuple4 = Tuple4(this.first, this.second, this.third, d) public operator fun Tuple4.plus(e: E): Tuple5 = Tuple5(this.first, this.second, this.third, this.fourth, e) @@ -281,19 +13,8 @@ public operator fun Tuple5.plus(f: F): Tuple6< public operator fun Tuple6.plus(g: G): Tuple7 = Tuple7(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, g) public operator fun Tuple7.plus(h: H): Tuple8 = Tuple8(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, h) public operator fun Tuple8.plus(i: I): Tuple9 = Tuple9(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, i) -public operator fun Tuple9.plus(j: J): Tuple10 = Tuple10(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, j) -public operator fun Tuple10.plus(k: K): Tuple11 = Tuple11(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, k) -public operator fun Tuple11.plus(l: L): Tuple12 = Tuple12(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, l) -public operator fun Tuple12.plus(m: M): Tuple13 = Tuple13(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, m) -public operator fun Tuple13.plus(n: N): Tuple14 = Tuple14(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, n) -public operator fun Tuple14.plus(o: O): Tuple15 = Tuple15(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, o) -public operator fun Tuple15.plus(p: P): Tuple16 = Tuple16(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, this.fifteenth, p) -public operator fun Tuple16.plus(q: Q): Tuple17 = Tuple17(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, this.fifteenth, this.sixteenth, q) -public operator fun Tuple17.plus(r: R): Tuple18 = Tuple18(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, this.fifteenth, this.sixteenth, this.seventeenth, r) -public operator fun Tuple18.plus(s: S): Tuple19 = Tuple19(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, this.fifteenth, this.sixteenth, this.seventeenth, this.eighteenth, s) -public operator fun Tuple19.plus(t: T): Tuple20 = Tuple20(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, this.fifteenth, this.sixteenth, this.seventeenth, this.eighteenth, this.nineteenth, t) -public operator fun Tuple20.plus(u: U): Tuple21 = Tuple21(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, this.fifteenth, this.sixteenth, this.seventeenth, this.eighteenth, this.nineteenth, this.twentieth, u) -public operator fun Tuple21.plus(v: V): Tuple22 = Tuple22(this.first, this.second, this.third, this.fourth, this.fifth, this.sixth, this.seventh, this.eighth, this.ninth, this.tenth, this.eleventh, this.twelfth, this.thirteenth, this.fourteenth, this.fifteenth, this.sixteenth, this.seventeenth, this.eighteenth, this.nineteenth, this.twentieth, this.twentyFirst, v) + +private const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 internal fun mapCapacity(expectedSize: Int): Int = when { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt deleted file mode 100644 index 4939b08d7ad..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/either.kt +++ /dev/null @@ -1,111 +0,0 @@ -package arrow.core.computations - -import arrow.continuations.Effect -import arrow.core.Either -import arrow.core.Either.Left -import arrow.core.identity -import arrow.core.left -import arrow.core.right -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.coroutines.RestrictsSuspension - -@Deprecated(deprecateInFavorOfEffectScope, ReplaceWith("EffectScope", "arrow.core.continuations.EffectScope")) -public fun interface EitherEffect : Effect> { - - public suspend fun Either.bind(): B = - when (this) { - is Either.Right -> value - is Left -> control().shift(this@bind) - } - - public suspend fun Result.bind(transform: (Throwable) -> E): B = - fold(::identity) { throwable -> - control().shift(transform(throwable).left()) - } - - /** - * Ensure check if the [value] is `true`, - * and if it is it allows the `either { }` binding to continue. - * In case it is `false`, then it short-circuits the binding and returns - * the provided value by [orLeft] inside an [Either.Left]. - * - * ```kotlin - * import arrow.core.computations.either - * - * //sampleStart - * suspend fun main() { - * either { - * ensure(true) { "" } - * println("ensure(true) passes") - * ensure(false) { "failed" } - * 1 - * } - * //sampleEnd - * .let(::println) - * } - * // println: "ensure(true) passes" - * // res: Either.Left("failed") - * ``` - * - */ - public suspend fun ensure(value: Boolean, orLeft: () -> E): Unit = - if (value) Unit else orLeft().left().bind() -} - -/** - * Ensures that [value] is not null. - * When the value is not null, then it will be returned as non null and the check value is now smart-checked to non-null. - * Otherwise, if the [value] is null then the [either] binding will short-circuit with [orLeft] inside of [Either.Left]. - * - * ```kotlin - * import arrow.core.computations.either - * import arrow.core.computations.ensureNotNull - * - * //sampleStart - * suspend fun main() { - * either { - * val x: Int? = 1 - * ensureNotNull(x) { "passes" } - * println(x) - * ensureNotNull(null) { "failed" } - * } - * //sampleEnd - * .let(::println) - * } - * // println: "1" - * // res: Either.Left("failed") - * ``` - * - */ -@Deprecated(deprecateInFavorOfEffectScope) -@OptIn(ExperimentalContracts::class) // Contracts not available on open functions, so made it top-level. -public suspend fun EitherEffect.ensureNotNull(value: B?, orLeft: () -> E): B { - contract { - returns() implies (value != null) - } - - return value ?: orLeft().left().bind() -} - -@Deprecated(deprecatedInFavorOfEagerEffectScope, ReplaceWith("EagerEffectScope", "arrow.core.continuations.EagerEffectScope")) -@RestrictsSuspension -public fun interface RestrictedEitherEffect : EitherEffect - -@Deprecated(deprecateInFavorOfEffectOrEagerEffect, ReplaceWith("either", "arrow.core.continuations.either")) -@Suppress("ClassName") -public object either { - @Deprecated(deprecateInFavorOfEagerEffect, ReplaceWith("either.eager(c)", "arrow.core.continuations.either")) - public inline fun eager(crossinline c: suspend RestrictedEitherEffect.() -> A): Either = - Effect.restricted(eff = { RestrictedEitherEffect { it } }, f = c, just = { it.right() }) - - @Deprecated(deprecateInFavorOfEffect, ReplaceWith("either(c)", "arrow.core.continuations.either")) - public suspend inline operator fun invoke(crossinline c: suspend EitherEffect.() -> A): Either = - Effect.suspended(eff = { EitherEffect { it } }, f = c, just = { it.right() }) -} - -internal const val deprecatedInFavorOfEagerEffectScope: String = "Deprecated in favor of Eager Effect DSL: EagerEffectScope" -internal const val deprecateInFavorOfEffectScope: String = "Deprecated in favor of Effect DSL: EffectScope" -internal const val deprecateInFavorOfEffect: String = "Deprecated in favor of the Effect Runtime" -internal const val deprecateInFavorOfEagerEffect: String = "Deprecated in favor of the EagerEffect Runtime" -internal const val deprecateInFavorOfEffectOrEagerEffect: String = "Deprecated in favor of the Effect or EagerEffect Runtime" diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/eval.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/eval.kt deleted file mode 100644 index 20579e4ebf2..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/eval.kt +++ /dev/null @@ -1,27 +0,0 @@ -package arrow.core.computations - -import arrow.continuations.Effect -import arrow.core.Eval -import kotlin.coroutines.RestrictsSuspension - -@Deprecated(deprecateInFavorOfEffectScope, ReplaceWith("EffectScope", "arrow.core.continuations.EffectScope")) -public fun interface EvalEffect : Effect> { - public suspend fun Eval.bind(): B = - value() -} - -@Deprecated(deprecatedInFavorOfEagerEffectScope, ReplaceWith("EagerEffectScope", "arrow.core.continuations.EagerEffectScope")) -@RestrictsSuspension -public fun interface RestrictedEvalEffect : EvalEffect - -@Deprecated(deprecateInFavorOfEffectOrEagerEffect) -@Suppress("ClassName") -public object eval { - @Deprecated(deprecateInFavorOfEagerEffect, ReplaceWith("eagerEffect(func)", "arrow.core.continuations.eagerEffect")) - public inline fun eager(crossinline func: suspend RestrictedEvalEffect.() -> A): Eval = - Effect.restricted(eff = { RestrictedEvalEffect { it } }, f = func, just = Eval.Companion::now) - - @Deprecated(deprecateInFavorOfEffect, ReplaceWith("effect(func)", "arrow.core.continuations.effect")) - public suspend inline operator fun invoke(crossinline func: suspend EvalEffect<*>.() -> A): Eval = - Effect.suspended(eff = { EvalEffect { it } }, f = func, just = Eval.Companion::now) -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/nullable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/nullable.kt deleted file mode 100644 index 883da45cf17..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/nullable.kt +++ /dev/null @@ -1,95 +0,0 @@ -package arrow.core.computations - -import arrow.continuations.Effect -import arrow.core.None -import arrow.core.Option -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.coroutines.RestrictsSuspension - -@Deprecated(deprecateInFavorOfEffectScope) -public fun interface NullableEffect : Effect { - public suspend fun B?.bind(): B = - this ?: control().shift(null) - - public suspend fun Option.bind(): B = - orNull().bind() - - /** - * Ensure check if the [value] is `true`, - * and if it is it allows the `nullable { }` binding to continue. - * In case it is `false`, then it short-circuits the binding and returns `null`. - * - * ```kotlin - * import arrow.core.computations.nullable - * - * //sampleStart - * suspend fun main() { - * nullable { - * ensure(true) - * println("ensure(true) passes") - * ensure(false) - * 1 - * } - * //sampleEnd - * .let(::println) - * } - * // println: "ensure(true) passes" - * // res: null - * ``` - * - */ - public suspend fun ensure(value: Boolean): Unit = - if (value) Unit else control().shift(null) -} - -/** - * Ensures that [value] is not null. - * When the value is not null, then it will be returned as non null and the check value is now smart-checked to non-null. - * Otherwise, if the [value] is null then the [option] binding will short-circuit with [None]. - * - * ```kotlin - * import arrow.core.computations.nullable - * import arrow.core.computations.ensureNotNull - * - * //sampleStart - * suspend fun main() { - * nullable { - * val x: Int? = 1 - * ensureNotNull(x) - * println(x) - * ensureNotNull(null) - * } - * //sampleEnd - * .let(::println) - * } - * // println: "1" - * // res: null - * ``` - * - */ -@Deprecated(deprecateInFavorOfEffectScope, ReplaceWith("ensureNotNull", "arrow.core.continuations.ensureNotNull")) -@OptIn(ExperimentalContracts::class) // Contracts not available on open functions, so made it top-level. -public suspend fun NullableEffect<*>.ensureNotNull(value: B?): B { - contract { - returns() implies (value != null) - } - - return value ?: control().shift(null) -} - -@Deprecated(deprecatedInFavorOfEagerEffectScope) -@RestrictsSuspension -public fun interface RestrictedNullableEffect : NullableEffect - -@Deprecated(deprecateInFavorOfEffectOrEagerEffect, ReplaceWith("nullable", "arrow.core.continuations.nullable")) -@Suppress("ClassName") -public object nullable { - @Deprecated(deprecateInFavorOfEagerEffect, ReplaceWith("nullable.eager(func)", "arrow.core.continuations.nullable")) - public inline fun eager(crossinline func: suspend RestrictedNullableEffect.() -> A?): A? = - Effect.restricted(eff = { RestrictedNullableEffect { it } }, f = func, just = { it }) - - @Deprecated(deprecateInFavorOfEffect, ReplaceWith("nullable(func)", "arrow.core.continuations.nullable")) - public suspend inline operator fun invoke(crossinline func: suspend NullableEffect<*>.() -> A?): A? = - Effect.suspended(eff = { NullableEffect { it } }, f = func, just = { it }) -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/option.kt deleted file mode 100644 index 754bf1eb7c5..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/option.kt +++ /dev/null @@ -1,93 +0,0 @@ -package arrow.core.computations - -import arrow.continuations.Effect -import arrow.core.None -import arrow.core.Option -import arrow.core.identity -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.coroutines.RestrictsSuspension - -@Deprecated(deprecateInFavorOfEffectScope, ReplaceWith("EffectScope", "arrow.core.continuations.EffectScope")) -public fun interface OptionEffect : Effect> { - public suspend fun Option.bind(): B = - fold({ control().shift(None) }, ::identity) - - /** - * Ensure check if the [value] is `true`, - * and if it is it allows the `option { }` binding to continue. - * In case it is `false`, then it short-circuits the binding and returns [None]. - * - * ```kotlin - * import arrow.core.computations.option - * - * //sampleStart - * suspend fun main() { - * option { - * ensure(true) - * println("ensure(true) passes") - * ensure(false) - * 1 - * } - * //sampleEnd - * .let(::println) - * } - * // println: "ensure(true) passes" - * // res: None - * ``` - * - */ - public suspend fun ensure(value: Boolean): Unit = - if (value) Unit else control().shift(None) -} - -/** - * Ensures that [value] is not null. - * When the value is not null, then it will be returned as non null and the check value is now smart-checked to non-null. - * Otherwise, if the [value] is null then the [option] binding will short-circuit with [None]. - * - * ```kotlin - * import arrow.core.computations.option - * import arrow.core.computations.ensureNotNull - * - * //sampleStart - * suspend fun main() { - * option { - * val x: Int? = 1 - * ensureNotNull(x) - * println(x) - * ensureNotNull(null) - * } - * //sampleEnd - * .let(::println) - * } - * // println: "1" - * // res: None - * ``` - * - */ -@Deprecated(deprecateInFavorOfEffectScope) -@OptIn(ExperimentalContracts::class) // Contracts not available on open functions, so made it top-level. -public suspend fun OptionEffect<*>.ensureNotNull(value: B?): B { - contract { - returns() implies (value != null) - } - - return value ?: (this as OptionEffect).control().shift(None) -} - -@Deprecated(deprecatedInFavorOfEagerEffectScope, ReplaceWith("EagerEffectScope", "arrow.core.continuations.EagerEffectScope")) -@RestrictsSuspension -public fun interface RestrictedOptionEffect : OptionEffect - -@Deprecated(deprecateInFavorOfEffectOrEagerEffect, ReplaceWith("option", "arrow.core.continuations.option")) -@Suppress("ClassName") -public object option { - @Deprecated(deprecateInFavorOfEagerEffect, ReplaceWith("option.eager(func)", "arrow.core.continuations.option")) - public inline fun eager(crossinline func: suspend RestrictedOptionEffect.() -> A): Option = - Effect.restricted(eff = { RestrictedOptionEffect { it } }, f = func, just = { Option.fromNullable(it) }) - - @Deprecated(deprecateInFavorOfEffect, ReplaceWith("option(func)", "arrow.core.continuations.option")) - public suspend inline operator fun invoke(crossinline func: suspend OptionEffect<*>.() -> A?): Option = - Effect.suspended(eff = { OptionEffect { it } }, f = func, just = { Option.fromNullable(it) }) -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt deleted file mode 100644 index f2893377b91..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/computations/result.kt +++ /dev/null @@ -1,55 +0,0 @@ -package arrow.core.computations - -import arrow.core.Either -import arrow.core.identity - -/** - * DSL Receiver Syntax for [result]. - */ -@Deprecated("$deprecatedInFavorOfEagerEffectScope\nThis object introduces dangerous behavior and will be removed in the next version: https://github.com/arrow-kt/arrow/issues/2547") -public object ResultEffect { - - @Deprecated("$deprecatedInFavorOfEagerEffectScope\nThis object introduces dangerous behavior and will be removed in the next version: https://github.com/arrow-kt/arrow/issues/2547") - public fun Result.bind(): A = - getOrThrow() - - @Deprecated("$deprecatedInFavorOfEagerEffectScope\nThis object introduces dangerous behavior and will be removed in the next version: https://github.com/arrow-kt/arrow/issues/2547") - public fun Either.bind(): A = - fold({ throw it }, ::identity) - - @Deprecated(deprecateInFavorOfEffectOrEagerEffect, ReplaceWith("result", "arrow.core.continuations.result")) - @Suppress("ClassName") - public object result { - - /** - * Provides a computation block for [Result] which is build on top of Kotlin's Result Std operations. - * - * ```kotlin - * import arrow.core.* - * import arrow.core.computations.ResultEffect.result - * - * fun main() { - * result { // We can safely use assertion based operation inside blocks - * kotlin.require(false) { "Boom" } - * } // Result.Failure(IllegalArgumentException("Boom")) - * - * result { - * Result.failure(RuntimeException("Boom")) - * .recover { 1 } - * .bind() - * } // Result.Success(1) - * - * result { - * val x = Result.success(1).bind() - * val y = Result.success(x + 1).bind() - * x + y - * } // Result.Success(3) - * } - * ``` - * - */ - @Deprecated(deprecateInFavorOfEffect, ReplaceWith("result.eager(block)", "arrow.core.continuations.result")) - public inline operator fun invoke(block: ResultEffect.() -> A): Result = - kotlin.runCatching { block(ResultEffect) } - } -} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt index 889aae95f06..0490d94fdd6 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Monoid.kt @@ -1,6 +1,5 @@ package arrow.typeclasses -import arrow.core.Const import arrow.core.Either import arrow.core.Endo import arrow.core.None @@ -89,15 +88,6 @@ public interface Monoid : Semigroup { override fun append(a: Endo, b: Endo): Endo = Endo(a.f.compose(b.f)) } - @JvmStatic - @JvmName("constant") - public fun const(MA: Monoid): Monoid> = - object : Monoid> { - override fun empty(): Const = Const(MA.empty()) - override fun append(a: Const, b: Const): Const = - a.combine(MA, b) - } - @JvmStatic public fun map(SG: Semigroup): Monoid> = MapMonoid(SG) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt index dbaa26d1c72..fd28e4ee3d3 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/typeclasses/Semigroup.kt @@ -1,6 +1,5 @@ package arrow.typeclasses -import arrow.core.Const import arrow.core.Either import arrow.core.Endo import arrow.core.Ior @@ -70,11 +69,6 @@ public fun interface Semigroup { public fun endo(): Semigroup> = Semigroup { f, g -> Endo(f.f.compose(g.f)) } - @JvmStatic - @JvmName("constant") - public fun const(SA: Semigroup): Semigroup> = - Semigroup { a, b -> a.combine(SA, b) } - @JvmStatic public fun map(SG: Semigroup): Semigroup> = MapSemigroup(SG) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt index ee40790501b..b2f083b6b1d 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt @@ -30,22 +30,6 @@ class EitherTest : StringSpec({ testLaws( MonoidLaws.laws(Monoid.either(Monoid.string(), Monoid.int()), ARB), - /*FxLaws.suspended, Either, Int>( - Arb.int().map(::Right), - ARB.map { it }, - Either::equals, - either::invoke - ) { - it.bind() - }, - FxLaws.eager, Either, Int>( - Arb.int().map(::Right), - ARB.map { it }, - Either::equals, - either::eager - ) { - it.bind() - }*/ ) "isLeft should return true if Left and false if Right" { diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt index 7a0d7244a80..8d2b7d31d40 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherZipTest.kt @@ -29,17 +29,16 @@ class EitherZipTest : StringSpec({ Arb.either(Arb.string(), Arb.double()), Arb.either(Arb.string(), Arb.char()), Arb.either(Arb.string(), Arb.string()), - Arb.either(Arb.string(), Arb.boolean()), Arb.either(Arb.string(), Arb.boolean()) - ) { a, b, c, d, e, f, g, h, i, j -> - val res = a.zip({ e1, e2 -> "$e1$e2" }, b, c, d, e, f, g, h, i, j, ::Tuple10) - val all = listOf(a, b, c, d, e, f, g, h, i, j) + ) { a, b, c, d, e, f, g, h, i -> + val res = a.zip({ e1, e2 -> "$e1$e2" }, b, c, d, e, f, g, h, i, ::Tuple9) + val all = listOf(a, b, c, d, e, f, g, h, i) val expected = if (all.any { it.isLeft() }) { all.filterIsInstance>().fold("") { acc, t -> "$acc${t.value}" }.left() } else { all.filterIsInstance>().map { it.value }.let { - Tuple10(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8], it[9]).right() + Tuple9(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8]).right() } } @@ -57,17 +56,16 @@ class EitherZipTest : StringSpec({ Arb.either(Arb.string(), Arb.double()), Arb.either(Arb.string(), Arb.char()), Arb.either(Arb.string(), Arb.string()), - Arb.either(Arb.string(), Arb.boolean()), Arb.either(Arb.string(), Arb.boolean()) - ) { a, b, c, d, e, f, g, h, i, j -> - val res = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) - val all = listOf(a, b, c, d, e, f, g, h, i, j) + ) { a, b, c, d, e, f, g, h, i -> + val res = a.zip(b, c, d, e, f, g, h, i, ::Tuple9) + val all = listOf(a, b, c, d, e, f, g, h, i) val expected = if (all.any { it.isLeft() }) { all.filterIsInstance>().map { it.value }.toNonEmptyListOrNull()!!.left() } else { all.filterIsInstance>().map { it.value }.let { - Tuple10(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8], it[9]).right() + Tuple9(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8]).right() } } @@ -88,11 +86,10 @@ class EitherZipTest : StringSpec({ Arb.either(Arb.nonEmptyList(Arb.string()), Arb.double()), Arb.either(Arb.nonEmptyList(Arb.string()), Arb.char()), Arb.either(Arb.nonEmptyList(Arb.string()), Arb.string()), - Arb.either(Arb.nonEmptyList(Arb.string()), Arb.boolean()), Arb.either(Arb.nonEmptyList(Arb.string()), Arb.boolean()) - ) { a, b, c, d, e, f, g, h, i, j -> - val res = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) - val all = listOf(a, b, c, d, e, f, g, h, i, j) + ) { a, b, c, d, e, f, g, h, i -> + val res = a.zip(b, c, d, e, f, g, h, i, ::Tuple9) + val all = listOf(a, b, c, d, e, f, g, h, i) val expected = if (all.any { it.isLeft() }) { all.filterIsInstance>>() @@ -100,7 +97,7 @@ class EitherZipTest : StringSpec({ .toNonEmptyListOrNull()!!.left() } else { all.filterIsInstance>().map { it.value }.let { - Tuple10(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8], it[9]).right() + Tuple9(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7], it[8]).right() } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt deleted file mode 100644 index c77faef7345..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt +++ /dev/null @@ -1,134 +0,0 @@ -package arrow.core - -import arrow.core.test.stackSafeIteration -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe - -internal data class SideEffect(var counter: Int = 0) { - fun increment() { - counter++ - } -} - -private fun recur(limit: Int, sideEffect: SideEffect): (Int) -> Eval { - return { num -> - if (num <= limit) { - sideEffect.increment() - Eval.defer { - recur(limit, sideEffect).invoke(num + 1) - } - } else { - Eval.now(-1) - } - } -} - -class EvalTest : StringSpec({ - - "should map wrapped value" { - val sideEffect = SideEffect() - val mapped = Eval.now(0) - .map { sideEffect.increment(); it + 1 } - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 2 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 3 - } - - "later should lazily evaluate values once" { - val sideEffect = SideEffect() - val mapped = Eval.later { sideEffect.increment(); sideEffect.counter } - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - } - - "later should memoize values" { - val sideEffect = SideEffect() - val mapped = Eval.later { sideEffect.increment(); sideEffect.counter }.memoize() - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - } - - "always should lazily evaluate values repeatedly" { - val sideEffect = SideEffect() - val mapped = Eval.always { sideEffect.increment(); sideEffect.counter } - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 2 - sideEffect.counter shouldBe 2 - mapped.value() shouldBe 3 - sideEffect.counter shouldBe 3 - } - - "always should memoize values" { - val sideEffect = SideEffect() - val mapped = Eval.always { sideEffect.increment(); sideEffect.counter }.memoize() - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - } - - "defer should lazily evaluate other Evals" { - val sideEffect = SideEffect() - val mapped = Eval.defer { sideEffect.increment(); Eval.later { sideEffect.increment(); sideEffect.counter } } - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 2 - sideEffect.counter shouldBe 2 - mapped.value() shouldBe 4 - sideEffect.counter shouldBe 4 - mapped.value() shouldBe 6 - sideEffect.counter shouldBe 6 - } - - "defer should memoize Eval#later" { - val sideEffect = SideEffect() - val mapped = Eval.defer { sideEffect.increment(); Eval.later { sideEffect.increment(); sideEffect.counter } }.memoize() - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 2 - sideEffect.counter shouldBe 2 - mapped.value() shouldBe 2 - sideEffect.counter shouldBe 2 - mapped.value() shouldBe 2 - sideEffect.counter shouldBe 2 - } - - "defer should memoize Eval#now" { - val sideEffect = SideEffect() - val mapped = Eval.defer { sideEffect.increment(); Eval.now(sideEffect.counter) }.memoize() - sideEffect.counter shouldBe 0 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - mapped.value() shouldBe 1 - sideEffect.counter shouldBe 1 - } - - "flatMap should complete without blowing up the stack" { - val limit = stackSafeIteration() - val sideEffect = SideEffect() - val flatMapped = Eval.now(0).flatMap(recur(limit, sideEffect)) - sideEffect.counter shouldBe 0 - flatMapped.value() shouldBe -1 - sideEffect.counter shouldBe limit + 1 - } - -}) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index 063c666abb1..8b87abc8abe 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -170,34 +170,6 @@ class IterableTest : StringSpec({ } } - "zip10" { - checkAll( - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()), - Arb.list(Arb.int()) - ) { a, b, c, d, e, f, g, h, i, j -> - val result = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) - val expected = a.zip(b, ::Pair) - .zip(c) { (a, b), c -> Triple(a, b, c) } - .zip(d) { (a, b, c), d -> Tuple4(a, b, c, d) } - .zip(e) { (a, b, c, d), e -> Tuple5(a, b, c, d, e) } - .zip(f) { (a, b, c, d, e), f -> Tuple6(a, b, c, d, e, f) } - .zip(g) { (a, b, c, d, e, f), g -> Tuple7(a, b, c, d, e, f, g) } - .zip(h) { (a, b, c, d, e, f, g), h -> Tuple8(a, b, c, d, e, f, g, h) } - .zip(i) { (a, b, c, d, e, f, g, h), i -> Tuple9(a, b, c, d, e, f, g, h, i) } - .zip(j) { (a, b, c, d, e, f, g, h, i), j -> Tuple10(a, b, c, d, e, f, g, h, i, j) } - - result shouldBe expected - } - } - "can align lists with different lengths" { checkAll(Arb.list(Arb.boolean()), Arb.list(Arb.boolean())) { a, b -> a.align(b).size shouldBe max(a.size, b.size) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt index ab3b0e06b79..8d176b8895e 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt @@ -187,34 +187,6 @@ class MapKTest : StringSpec({ } } - "zip10" { - checkAll( - Arb.map(Arb.intSmall(), Arb.intSmall()), - Arb.map(Arb.intSmall(), Arb.intSmall()) - ) { a, b -> - val result = a.zip(b, b, b, b, b, b, b, b, b) { _, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj -> - Tuple10( - aa, - bb, - cc, - dd, - ee, - ff, - gg, - hh, - ii, - jj - ) - } - - val expected = a.filter { (k, _) -> b.containsKey(k) } - .map { (k, v) -> Pair(k, Tuple10(v, b[k]!!, b[k]!!, b[k]!!, b[k]!!, b[k]!!, b[k]!!, b[k]!!, b[k]!!, b[k]!!)) } - .toMap() - - result shouldBe expected - } - } - "flatMap" { checkAll( Arb.map(Arb.string(), Arb.intSmall()), diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index bf582259ff7..7469f44da12 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -161,26 +161,6 @@ class NonEmptyListTest : StringSpec({ } } - "zip10" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c, d, e, f, g, h, i, j -> - val result = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) - val expected = a.all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, i.all, j.all, ::Tuple10) - .toNonEmptyListOrNull() - result shouldBe expected - } - } - "max element" { checkAll( Arb.nonEmptyList(Arb.int()) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt index 60a7e320bab..94e3b61a068 100755 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt @@ -1,6 +1,5 @@ package arrow.core -import arrow.core.continuations.ensureNotNull import arrow.core.continuations.option import arrow.core.test.laws.MonoidLaws import arrow.core.test.option @@ -23,22 +22,6 @@ class OptionTest : StringSpec({ testLaws( MonoidLaws.laws(Monoid.option(Monoid.int()), Arb.option(Arb.int())), - /*FxLaws.suspended, Option, String>( - Arb.string().map(Option.Companion::invoke), - Arb.option(Arb.string()), - Option::equals, - option::invoke - ) { - it.bind() - }, - FxLaws.eager, Option, String>( - Arb.string().map(Option.Companion::invoke), - Arb.option(Arb.string()), - Option::equals, - option::eager - ) { - it.bind() - }*/ ) "ensure null in option computation" { diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt index 8d0244b8b18..f473287a449 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt @@ -1,10 +1,10 @@ package arrow.core -import arrow.typeclasses.Monoid import arrow.core.test.laws.MonoidLaws import arrow.core.test.option import arrow.core.test.sequence import arrow.core.test.testLaws +import arrow.typeclasses.Monoid import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.sequences.shouldBeEmpty import io.kotest.property.Arb @@ -155,34 +155,6 @@ class SequenceKTest : StringSpec({ } } - "zip10" { - checkAll( - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()), - Arb.sequence(Arb.int()) - ) { a, b, c, d, e, f, g, h, i, j -> - val result = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) - val expected = a.zip(b, ::Pair) - .zip(c) { (a, b), c -> Triple(a, b, c) } - .zip(d) { (a, b, c), d -> Tuple4(a, b, c, d) } - .zip(e) { (a, b, c, d), e -> Tuple5(a, b, c, d, e) } - .zip(f) { (a, b, c, d, e), f -> Tuple6(a, b, c, d, e, f) } - .zip(g) { (a, b, c, d, e, f), g -> Tuple7(a, b, c, d, e, f, g) } - .zip(h) { (a, b, c, d, e, f, g), h -> Tuple8(a, b, c, d, e, f, g, h) } - .zip(i) { (a, b, c, d, e, f, g, h), i -> Tuple9(a, b, c, d, e, f, g, h, i) } - .zip(j) { (a, b, c, d, e, f, g, h, i), j -> Tuple10(a, b, c, d, e, f, g, h, i, j) } - - result.toList() shouldBe expected.toList() - } - } - "can align sequences - 1" { checkAll(Arb.sequence(Arb.int()), Arb.sequence(Arb.string())) { a, b -> a.align(b).toList().size shouldBe max(a.toList().size, b.toList().size) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/NullableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/NullableTest.kt deleted file mode 100644 index d47281f9c0f..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/NullableTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -package arrow.core.computations - -import arrow.core.Some -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.orNull -import io.kotest.property.checkAll - -class NullableTest : StringSpec({ - "simple case" { - nullable { - "s".length.bind() - } shouldBe 1 - } - "multiple types" { - nullable { - val number = "s".length - val string = number.toString().bind() - string - } shouldBe "1" - } - "binding option in nullable" { - nullable { - val number = Some("s".length) - val string = number.map(Int::toString).bind() - string - } shouldBe "1" - } - "short circuit" { - nullable { - val number: Int = "s".length - (number.takeIf { it > 1 }?.toString()).bind() - throw IllegalStateException("This should not be executed") - } shouldBe null - } - "short circuit option" { - nullable { - val number = Some("s".length) - number.filter { it > 1 }.map(Int::toString).bind() - throw IllegalStateException("This should not be executed") - } shouldBe null - } - "when expression" { - nullable { - val number = "s".length.bind() - val string = when (number) { - 1 -> number.toString() - else -> null - }.bind() - string - } shouldBe "1" - } - "if expression" { - nullable { - val number = "s".length.bind() - val string = if (number == 1) { - number.toString() - } else { - null - }.bind() - string - } shouldBe "1" - } - "if expression short circuit" { - nullable { - val number = "s".length.bind() - val string = if (number != 1) { - number.toString() - } else { - null - }.bind() - string - } shouldBe null - } - "ensure null in nullable computation" { - checkAll(Arb.boolean(), Arb.int()) { predicate, i -> - nullable { - ensure(predicate) - i - } shouldBe if (predicate) i else null - } - } - - "ensureNotNull in nullable computation" { - fun square(i: Int): Int = i * i - checkAll(Arb.int().orNull()) { i: Int? -> - nullable { - val ii = i - ensureNotNull(ii) - square(ii) // Smart-cast by contract - } shouldBe i?.let(::square) - } - } -}) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt deleted file mode 100644 index e74ff849cd8..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/computations/ResultTest.kt +++ /dev/null @@ -1,223 +0,0 @@ -package arrow.core.computations - -import arrow.core.Eval -import arrow.core.Tuple10 -import arrow.core.composeErrors -import arrow.core.computations.ResultEffect.result -import arrow.core.flatMap -import arrow.core.handleErrorWith -import arrow.core.redeemWith -import arrow.core.test.result -import arrow.core.test.suspend -import arrow.core.test.throwable -import arrow.core.zip -import io.kotest.assertions.fail -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.nulls.shouldNotBeNull -import io.kotest.matchers.result.shouldBeFailureOfType -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.map -import io.kotest.property.arbitrary.string -import io.kotest.property.checkAll -import kotlin.Result.Companion.failure -import kotlin.Result.Companion.success -import kotlin.coroutines.CoroutineContext -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import kotlinx.coroutines.suspendCancellableCoroutine - -class ResultTest : StringSpec({ - "flatMap" { - checkAll(Arb.result(Arb.int()), Arb.result(Arb.string())) { ints, strs -> - val res = ints.flatMap { strs } - if (ints.isFailure) res shouldBe ints - else res shouldBe strs - } - } - - "handleErrorWith" { - checkAll(Arb.result(Arb.int()), Arb.result(Arb.string())) { ints, strs -> - val res = ints.handleErrorWith { strs } - if (ints.isFailure) res shouldBe strs - else res shouldBe ints - } - } - - "redeemWith" { - checkAll(Arb.result(Arb.int()), Arb.result(Arb.string()), Arb.result(Arb.string())) { ints, failed, success -> - val res = ints.redeemWith({ failed }, { success }) - if (ints.isFailure) res shouldBe failed - else res shouldBe success - } - } - - "zip" { - checkAll( - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - Arb.result(Arb.int()), - ) { a, b, c, d, e, f, g, h, i, j -> - val res = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10) - val all = listOf(a, b, c, d, e, f, g, h, i, j) - if (all.all { it.isSuccess }) res shouldBe success( - Tuple10( - a.getOrThrow(), - b.getOrThrow(), - c.getOrThrow(), - d.getOrThrow(), - e.getOrThrow(), - f.getOrThrow(), - g.getOrThrow(), - h.getOrThrow(), - i.getOrThrow(), - j.getOrThrow() - ) - ) else res shouldBe failure( - composeErrors( - a.exceptionOrNull(), - b.exceptionOrNull(), - c.exceptionOrNull(), - d.exceptionOrNull(), - e.exceptionOrNull(), - f.exceptionOrNull(), - g.exceptionOrNull(), - h.exceptionOrNull(), - i.exceptionOrNull(), - j.exceptionOrNull() - ).shouldNotBeNull() - ) - } - } - - "immediate values" { - checkAll(Arb.result(Arb.int())) { res -> - result { - res.bind() - } shouldBe res - } - } - - "suspended value" { - checkAll(Arb.result(Arb.int())) { res -> - result { - res.suspend().bind() - } shouldBe res - } - } - - "Rethrows immediate exceptions" { - checkAll(Arb.throwable(), Arb.int(), Arb.int()) { e, a, b -> - result { - success(a).bind() - success(b).suspend().bind() - throw e - } shouldBe failure(e) - } - } - - "result captures exception" { - checkAll(Arb.throwable(), Arb.int(), Arb.int()) { e, a, b -> - result { - success(a).bind() - success(b).suspend().bind() - e.suspend() - } shouldBe failure(e) - } - } - - "Can short-circuit from nested blocks" { - checkAll(Arb.throwable()) { e -> - result { - val x = eval { - failure(e).suspend().bind() - 5L - } - - x.value() - } shouldBe failure(e) - } - } - - "Can short-circuit suspended from nested blocks" { - checkAll(Arb.throwable().map { failure(it) }) { res -> - result { - val x = eval { - res.suspend().bind() - 5L - } - - x.value() - } shouldBe res - } - } - - "Can short-circuit after bind from nested blocks" { - checkAll(Arb.throwable().map { failure(it) }) { res -> - result { - val x = eval { - Eval.Now(1L).suspend().bind() - res.suspend().bind() - 5L - } - - 1 - } shouldBe res - } - } - - "Short-circuiting cancels KotlinX Coroutines" { - suspend fun completeOnCancellation(latch: CompletableDeferred, cancelled: CompletableDeferred): Unit = - suspendCancellableCoroutine { cont -> - cont.invokeOnCancellation { - if (!cancelled.complete(Unit)) fail("cancelled latch was completed twice") - else Unit - } - - if (!latch.complete(Unit)) fail("latch was completed twice") - else Unit - } - - val scope = CoroutineScope(Dispatchers.Default) - val latch = CompletableDeferred() - val cancelled = CompletableDeferred() - result { - val deferreds: List> = listOf( - scope.async { - completeOnCancellation(latch, cancelled) - success(1).bind() - }, - scope.async { - latch.await() - failure(RuntimeException()).bind() - } - ) - - deferreds.awaitAll().sum() - }.shouldBeFailureOfType() - - cancelled.await() - } - - "Computation blocks run on parent context" { - suspend fun currentContext(): CoroutineContext = - kotlin.coroutines.coroutineContext - - val parentCtx = currentContext() - result { - currentContext() shouldBe parentCtx - } - } -}) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index d176e45fa33..c424bd291cc 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -2,7 +2,6 @@ package arrow.core.test import arrow.core.Either import arrow.core.Endo -import arrow.core.Eval import arrow.core.Ior import arrow.core.NonEmptyList import arrow.core.Option @@ -70,9 +69,6 @@ fun Arb.Companion.unit(): Arb = fun Arb.Companion.ior(arbA: Arb, arbB: Arb): Arb> = arbA.alignWith(arbB) { it } -fun Arb.eval(): Arb> = - map { Eval.now(it) } - private fun Arb.alignWith(arbB: Arb, transform: (Ior) -> R): Arb = Arb.bind(this, arbB) { a, b -> transform(Ior.Both(a, b)) } diff --git a/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/NonFatal.kt b/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/NonFatal.kt index 6f6aead04a3..befa68dc021 100644 --- a/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/NonFatal.kt +++ b/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/NonFatal.kt @@ -1,10 +1,9 @@ package arrow.core -import arrow.continuations.generic.ControlThrowable import kotlin.coroutines.cancellation.CancellationException public actual fun NonFatal(t: Throwable): Boolean = when (t) { - is ControlThrowable, is CancellationException -> false + is CancellationException -> false else -> true } 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 5074cadc9b4..b27c7f3bdcb 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 @@ -2,11 +2,10 @@ @file:JvmName("NonFatalKt") package arrow.core -import arrow.continuations.generic.ControlThrowable import kotlin.coroutines.cancellation.CancellationException public actual fun NonFatal(t: Throwable): Boolean = when (t) { - is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError, is ControlThrowable, is CancellationException -> false + is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError, is CancellationException -> false else -> true } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt index 9750daf6bb4..47450994cd8 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt @@ -50,18 +50,4 @@ class DeadlockTest : StringSpec({ } } - "classloader should not deadlock Eval initialization" { - runBlocking { - (0..10).map { i -> - GlobalScope.launch { - if (i % 2 == 0) { - Eval.Now(Unit) - } else { - Eval.Later { null } - } - } - }.joinAll() - } - } - }) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EitherJvmTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EitherJvmTest.kt index a0c5c659be9..0935aa5540b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EitherJvmTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EitherJvmTest.kt @@ -13,11 +13,6 @@ class EitherJvmTest : StringSpec({ Arb.suspendFunThatThrowsFatalThrowable(), Arb.any() ) { f: suspend () -> Either, returnObject: Any -> - - val comparator: Comparator = - Comparator.comparingInt(Person::age) - .thenComparing(Person::name) - shouldThrow { Either.resolve( f = { f() }, diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalJvmTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalJvmTest.kt deleted file mode 100644 index cf466decb01..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalJvmTest.kt +++ /dev/null @@ -1,69 +0,0 @@ -package arrow.core - -import io.kotest.assertions.fail -import io.kotest.core.spec.style.StringSpec -import io.kotest.property.Arb -import io.kotest.property.Sample -import io.kotest.property.arbitrary.arbitrary -import io.kotest.property.arbitrary.choice -import io.kotest.property.checkAll - -class EvalJvmTest : StringSpec({ - "stack safety stress test" { - checkAll(DeepEval.gen) { d: DeepEval -> - try { - d.eval.value() - } catch (e: StackOverflowError) { - fail("stack overflowed with eval-depth ${DeepEval.maxDepth}") - } - } - } -}) - -private data class DeepEval(val eval: Eval) { - sealed class O { - data class Map(val f: (Int) -> Int) : O() - data class FlatMap(val f: (Int) -> Eval) : O() - class Memoize : O() - class Defer : O() - - companion object { - val gen = Arb.choice( - arbitrary { O.Map { it + 1 } }, - arbitrary { O.FlatMap { Eval.Now(it) } }, - arbitrary { O.Memoize() }, - arbitrary { O.Defer() } - ) - } - } - - companion object { - const val maxDepth = 10000 - - fun build(leaf: () -> Eval, os: List) = run { - tailrec fun step(i: Int, leaf: () -> Eval, cbs: MutableList<(Eval) -> Eval>): Eval = - if (i >= os.size) { - cbs.fold(leaf()) { e, f -> f(e) } - } else { - val o = os[i] - when (o) { - is O.Defer -> Eval.defer { - @Suppress("NON_TAIL_RECURSIVE_CALL") - step(i + 1, leaf, cbs) - } - is O.Memoize -> step(i + 1, leaf, cbs.also { it.add(0) { e: Eval -> e.memoize() } }) - is O.Map -> step(i + 1, leaf, cbs.also { it.add(0) { e: Eval -> e.map(o.f) } }) - is O.FlatMap -> step(i + 1, leaf, cbs.also { it.add(0) { e: Eval -> e.flatMap(o.f) } }) - } - } - - step(0, leaf, mutableListOf()) - } - - val gen = arbitrary { rs -> - val leaf = { Eval.Now(0) } - val eval = build(leaf, O.gen.samples().map(Sample::value).take(maxDepth).toList()) - DeepEval(eval) - } - } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalUsage.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalUsage.java deleted file mode 100644 index 82d2d43f8be..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/EvalUsage.java +++ /dev/null @@ -1,12 +0,0 @@ -package arrow.core; - -public class EvalUsage { - - public void testUsage() { - Eval now = Eval.now(1); - Eval.Later later = Eval.later(() -> 1); - Eval raise = Eval.raise(new RuntimeException()); - Eval.Always always = Eval.always(() -> 1); - Eval.defer(() -> Eval.now(1)); - } -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java index 41821542af6..a0e98b53aae 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/MonoidUsageTest.java @@ -24,7 +24,5 @@ public void testUsage() { Monoid> map = Monoid.map(Semigroup.Integer()); Monoid> option = Monoid.option(Semigroup.Integer()); Monoid> pair = Monoid.pair(Monoid.Boolean(), Monoid.Integer()); - - Monoid.constant(Monoid.Integer()); } } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java index 3485ee812ec..3138ef231de 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/typeclasses/SemigroupUsageTest.java @@ -22,7 +22,6 @@ public void testUsage() { Semigroup> option = Semigroup.option(Semigroup.Integer()); Semigroup> nonEmptyList = Semigroup.nonEmptyList(); Semigroup> pair = Semigroup.pair(Semigroup.Boolean(), Semigroup.Integer()); - Semigroup> constant = Semigroup.constant(Semigroup.Integer()); Semigroup aByte = Semigroup.Byte(); Semigroup aShort = Semigroup.Short(); } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-01.kt deleted file mode 100644 index e02ffc279db..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-01.kt +++ /dev/null @@ -1,16 +0,0 @@ -// This file was automatically generated from either.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEitherComputations01 - -import arrow.core.computations.either - -suspend fun main() { - either { - ensure(true) { "" } - println("ensure(true) passes") - ensure(false) { "failed" } - 1 - } - .let(::println) -} -// println: "ensure(true) passes" -// res: Either.Left("failed") diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-02.kt deleted file mode 100644 index ba2f60c2023..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-computations-02.kt +++ /dev/null @@ -1,17 +0,0 @@ -// This file was automatically generated from either.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEitherComputations02 - -import arrow.core.computations.either -import arrow.core.computations.ensureNotNull - -suspend fun main() { - either { - val x: Int? = 1 - ensureNotNull(x) { "passes" } - println(x) - ensureNotNull(null) { "failed" } - } - .let(::println) -} -// println: "1" -// res: Either.Left("failed") diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-01.kt deleted file mode 100644 index a66dcc08cd2..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-01.kt +++ /dev/null @@ -1,21 +0,0 @@ -// This file was automatically generated from Eval.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEval01 - -import arrow.core.Eval - -fun even(n: Int): Eval = - Eval.always { n == 0 }.flatMap { - if(it == true) Eval.now(true) - else odd(n - 1) - } - -fun odd(n: Int): Eval = - Eval.always { n == 0 }.flatMap { - if(it == true) Eval.now(false) - else even(n - 1) - } - -// if not wrapped in eval this type of computation would blow the stack and result in a StackOverflowError -fun main() { - println(odd(100000).value()) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-02.kt deleted file mode 100644 index 0923e57eb8d..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-02.kt +++ /dev/null @@ -1,9 +0,0 @@ -// This file was automatically generated from Eval.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEval02 - -import arrow.core.* - -fun main() { - val eager = Eval.now(1).map { it + 1 } - println(eager.value()) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-03.kt deleted file mode 100644 index 7fd34596244..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-03.kt +++ /dev/null @@ -1,9 +0,0 @@ -// This file was automatically generated from Eval.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEval03 - -import arrow.core.* - -fun main() { - val lazyEvaled = Eval.later { "expensive computation" } - println(lazyEvaled.value()) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-04.kt deleted file mode 100644 index 4b38eb8331a..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-eval-04.kt +++ /dev/null @@ -1,9 +0,0 @@ -// This file was automatically generated from Eval.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEval04 - -import arrow.core.* - -fun main() { - val alwaysEvaled = Eval.always { "expensive computation" } - println(alwaysEvaled.value()) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-01.kt deleted file mode 100644 index 56bda9ce6f8..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-01.kt +++ /dev/null @@ -1,16 +0,0 @@ -// This file was automatically generated from nullable.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleNullableComputations01 - -import arrow.core.computations.nullable - -suspend fun main() { - nullable { - ensure(true) - println("ensure(true) passes") - ensure(false) - 1 - } - .let(::println) -} -// println: "ensure(true) passes" -// res: null diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-02.kt deleted file mode 100644 index a14151a5e3f..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nullable-computations-02.kt +++ /dev/null @@ -1,17 +0,0 @@ -// This file was automatically generated from nullable.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleNullableComputations02 - -import arrow.core.computations.nullable -import arrow.core.computations.ensureNotNull - -suspend fun main() { - nullable { - val x: Int? = 1 - ensureNotNull(x) - println(x) - ensureNotNull(null) - } - .let(::println) -} -// println: "1" -// res: null diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt index 4fc22facd84..24a65d7ac6f 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt @@ -1,17 +1,10 @@ // This file was automatically generated from Option.kt by Knit tool. Do not edit. package arrow.core.examples.exampleOption17 -import arrow.core.computations.option import arrow.core.Some -import arrow.core.Option +import arrow.core.none -suspend fun value(): Option = - option { - val a = Some(1).bind() - val b = Some(1 + a).bind() - val c = Some(1 + b).bind() - a + b + c -} -suspend fun main() { - println(value()) +fun main() { + Some(12).tapNone { println("flower") } // Result: Some(12) + none().tapNone { println("flower") } // Result: prints "flower" and returns: None } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt index e47211b5ef6..d03af3c4b3a 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt @@ -1,18 +1,10 @@ // This file was automatically generated from Option.kt by Knit tool. Do not edit. package arrow.core.examples.exampleOption18 -import arrow.core.computations.option import arrow.core.Some import arrow.core.none -import arrow.core.Option -suspend fun value(): Option = - option { - val x = none().bind() - val y = Some(1 + x).bind() - val z = Some(1 + y).bind() - x + y + z - } -suspend fun main() { - println(value()) +fun main() { + Some(12).tap { println("flower") } // Result: prints "flower" and returns: Some(12) + none().tap { println("flower") } // Result: None } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt index 364813486b9..de3db082548 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt @@ -2,9 +2,13 @@ package arrow.core.examples.exampleOption19 import arrow.core.Some -import arrow.core.none +import arrow.core.None +import arrow.core.Option fun main() { - Some(12).tapNone { println("flower") } // Result: Some(12) - none().tapNone { println("flower") } // Result: prints "flower" and returns: None + Some(12).exists { it > 10 } // Result: true + Some(7).exists { it > 10 } // Result: false + + val none: Option = None + none.exists { it > 10 } // Result: false } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt index 2e5652f4aac..8c562e7f4a5 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt @@ -2,9 +2,13 @@ package arrow.core.examples.exampleOption20 import arrow.core.Some -import arrow.core.none +import arrow.core.None +import arrow.core.Option fun main() { - Some(12).tap { println("flower") } // Result: prints "flower" and returns: Some(12) - none().tap { println("flower") } // Result: None + Some(12).exists { it > 10 } // Result: 12 + Some(7).exists { it > 10 } // Result: null + + val none: Option = None + none.exists { it > 10 } // Result: null } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt index 07a9d4ec693..6b92d2b9051 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt @@ -1,14 +1,3 @@ // This file was automatically generated from Option.kt by Knit tool. Do not edit. package arrow.core.examples.exampleOption21 -import arrow.core.Some -import arrow.core.None -import arrow.core.Option - -fun main() { - Some(12).exists { it > 10 } // Result: true - Some(7).exists { it > 10 } // Result: false - - val none: Option = None - none.exists { it > 10 } // Result: false -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt deleted file mode 100644 index 9263fd76499..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt +++ /dev/null @@ -1,14 +0,0 @@ -// This file was automatically generated from Option.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleOption22 - -import arrow.core.Some -import arrow.core.None -import arrow.core.Option - -fun main() { - Some(12).exists { it > 10 } // Result: 12 - Some(7).exists { it > 10 } // Result: null - - val none: Option = None - none.exists { it > 10 } // Result: null -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-23.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-23.kt deleted file mode 100644 index dfcf262a5ae..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-23.kt +++ /dev/null @@ -1,3 +0,0 @@ -// This file was automatically generated from Option.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleOption23 - diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-01.kt deleted file mode 100644 index bd53693beba..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-01.kt +++ /dev/null @@ -1,16 +0,0 @@ -// This file was automatically generated from option.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleOptionComputations01 - -import arrow.core.computations.option - -suspend fun main() { - option { - ensure(true) - println("ensure(true) passes") - ensure(false) - 1 - } - .let(::println) -} -// println: "ensure(true) passes" -// res: None diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-02.kt deleted file mode 100644 index cc9f62c7d1b..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-computations-02.kt +++ /dev/null @@ -1,17 +0,0 @@ -// This file was automatically generated from option.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleOptionComputations02 - -import arrow.core.computations.option -import arrow.core.computations.ensureNotNull - -suspend fun main() { - option { - val x: Int? = 1 - ensureNotNull(x) - println(x) - ensureNotNull(null) - } - .let(::println) -} -// println: "1" -// res: None diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt deleted file mode 100644 index 20281fe4a0e..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-result-computations-01.kt +++ /dev/null @@ -1,23 +0,0 @@ -// This file was automatically generated from result.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleResultComputations01 - -import arrow.core.* -import arrow.core.computations.ResultEffect.result - -fun main() { - result { // We can safely use assertion based operation inside blocks - kotlin.require(false) { "Boom" } - } // Result.Failure(IllegalArgumentException("Boom")) - - result { - Result.failure(RuntimeException("Boom")) - .recover { 1 } - .bind() - } // Result.Success(1) - - result { - val x = Result.success(1).bind() - val y = Result.success(x + 1).bind() - x + y - } // Result.Success(3) -} diff --git a/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/NonFatal.kt b/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/NonFatal.kt index 6f6aead04a3..befa68dc021 100644 --- a/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/NonFatal.kt +++ b/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/NonFatal.kt @@ -1,10 +1,9 @@ package arrow.core -import arrow.continuations.generic.ControlThrowable import kotlin.coroutines.cancellation.CancellationException public actual fun NonFatal(t: Throwable): Boolean = when (t) { - is ControlThrowable, is CancellationException -> false + is CancellationException -> false else -> true } diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index 07ebb70cceb..23bc767feb4 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -409,21 +409,21 @@ public final class arrow/fx/coroutines/Schedule$Companion { public final class arrow/fx/coroutines/Schedule$Decision { public static final field Companion Larrow/fx/coroutines/Schedule$Decision$Companion; - public fun (ZDLjava/lang/Object;Larrow/core/Eval;)V + public fun (ZDLjava/lang/Object;Lkotlin/jvm/functions/Function0;)V public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule$Decision; public final fun combine (Larrow/fx/coroutines/Schedule$Decision;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule$Decision; public final fun combineNanos (Larrow/fx/coroutines/Schedule$Decision;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule$Decision; public final fun component1 ()Z public final fun component2 ()D public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Larrow/core/Eval; - public final fun copy (ZDLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/coroutines/Schedule$Decision; - public static synthetic fun copy$default (Larrow/fx/coroutines/Schedule$Decision;ZDLjava/lang/Object;Larrow/core/Eval;ILjava/lang/Object;)Larrow/fx/coroutines/Schedule$Decision; + public final fun component4 ()Lkotlin/jvm/functions/Function0; + public final fun copy (ZDLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; + public static synthetic fun copy$default (Larrow/fx/coroutines/Schedule$Decision;ZDLjava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/fx/coroutines/Schedule$Decision; public fun equals (Ljava/lang/Object;)Z public final fun getCont ()Z public final fun getDelayInNanos ()D public final fun getDuration-UwyO8pc ()J - public final fun getFinish ()Larrow/core/Eval; + public final fun getFinish ()Lkotlin/jvm/functions/Function0; public final fun getState ()Ljava/lang/Object; public fun hashCode ()I public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule$Decision; @@ -433,10 +433,10 @@ public final class arrow/fx/coroutines/Schedule$Decision { } public final class arrow/fx/coroutines/Schedule$Decision$Companion { - public final fun cont (DLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/coroutines/Schedule$Decision; - public final fun cont-KLykuaI (JLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/coroutines/Schedule$Decision; - public final fun done (DLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/coroutines/Schedule$Decision; - public final fun done-KLykuaI (JLjava/lang/Object;Larrow/core/Eval;)Larrow/fx/coroutines/Schedule$Decision; + public final fun cont (DLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; + public final fun cont-KLykuaI (JLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; + public final fun done (DLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; + public final fun done-KLykuaI (JLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; } public final class arrow/fx/coroutines/ScheduleKt { diff --git a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts index 3ce6a7f2844..6da957283cd 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts @@ -2,9 +2,9 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) + // alias(libs.plugins.kotest.multiplatform) } -apply(plugin = "io.kotest.multiplatform") apply(from = property("TEST_COVERAGE")) val enableCompatibilityMetadataVariant = @@ -31,6 +31,7 @@ kotlin { if (!enableCompatibilityMetadataVariant) { commonTest { dependencies { + implementation(projects.arrowCore) implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt index 246d38a2f44..a0b4a4e26f5 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt @@ -1,7 +1,6 @@ package arrow.fx.coroutines import arrow.core.Either -import arrow.core.Eval import arrow.core.identity import arrow.core.left import arrow.core.nonFatalOrThrow @@ -474,12 +473,12 @@ public sealed class Schedule { try { val a = fa.invoke() val step = update(a, state) - if (!step.cont) return Either.Right(step.finish.value()) + if (!step.cont) return Either.Right(step.finish()) else { delay((step.delayInNanos / 1_000_000).toLong()) // Set state before looping again - last = { step.finish.value() } + last = { step.finish() } state = step.state } } catch (e: Throwable) { @@ -503,11 +502,11 @@ public sealed class Schedule { val a = fa.invoke() val step = update(a, state) if (!step.cont) { - emit(Either.Right(step.finish.value())) + emit(Either.Right(step.finish())) loop = false } else { delay((step.delayInNanos / 1_000_000).toLong()) - val output = step.finish.value() + val output = step.finish() // Set state before looping again and emit Output emit(Either.Right(output)) last = { output } @@ -530,7 +529,7 @@ public sealed class Schedule { updated { f -> { a: A, s: State -> val dec = f(a, s) - if (dec.cont) pred(a, dec.finish.value()).let { dec.copy(cont = it) } + if (dec.cont) pred(a, dec.finish()).let { dec.copy(cont = it) } else dec } } @@ -587,7 +586,7 @@ public sealed class Schedule { updated { update -> { a: Input, s: State -> val step = update(a, s) - val d = f(step.finish.value(), step.delayInNanos) + val d = f(step.finish(), step.delayInNanos) step.copy(delayInNanos = d) } } @@ -602,14 +601,14 @@ public sealed class Schedule { override fun logOutput(f: suspend (output: Output) -> Unit): Schedule = updated { update -> { a: Input, s: State -> - update(a, s).also { f(it.finish.value()) } + update(a, s).also { f(it.finish()) } } } override fun foldLazy(initial: suspend () -> C, f: suspend (acc: C, output: Output) -> C): Schedule = ScheduleImpl(suspend { Pair(initialState.invoke(), initial.invoke()) }) { i, s -> val dec = update(i, s.first) - val c = if (dec.cont) f(s.second, dec.finish.value()) else s.second + val c = if (dec.cont) f(s.second, dec.finish()) else s.second dec.bimap({ state -> Pair(state, c) }, { c }) } @@ -618,7 +617,7 @@ public sealed class Schedule { (other as ScheduleImpl).let { other -> ScheduleImpl(suspend { Pair(initialState.invoke(), other.initialState.invoke()) }) { i, s -> val dec1 = update(i, s.first) - val dec2 = other.update(dec1.finish.value(), s.second) + val dec2 = other.update(dec1.finish(), s.second) dec1.combineNanos(dec2, { a, b -> a && b }, { a, b -> a + b }, { _, b -> b }) } } @@ -687,7 +686,7 @@ public sealed class Schedule { val cont: Boolean, val delayInNanos: Double, val state: A, - val finish: Eval + val finish: () -> B ) { @ExperimentalTime @@ -698,7 +697,7 @@ public sealed class Schedule { copy(cont = !cont) public fun bimap(f: (A) -> C, g: (B) -> D): Decision = - Decision(cont, delayInNanos, f(state), finish.map(g)) + Decision(cont, delayInNanos, f(state), { g(finish()) }) public fun mapLeft(f: (A) -> C): Decision = bimap(f, ::identity) @@ -715,7 +714,7 @@ public sealed class Schedule { f(cont, other.cont), g(delayInNanos, other.delayInNanos), Pair(state, other.state), - finish.flatMap { first -> other.finish.map { second -> zip(first, second) } } + { zip(finish(), other.finish()) } ) @ExperimentalTime @@ -728,7 +727,7 @@ public sealed class Schedule { f(cont, other.cont), g(delayInNanos.nanoseconds, other.delayInNanos.nanoseconds).toDouble(NANOSECONDS), Pair(state, other.state), - finish.flatMap { first -> other.finish.map { second -> zip(first, second) } } + { zip(finish(), other.finish()) } ) override fun equals(other: Any?): Boolean = @@ -736,21 +735,21 @@ public sealed class Schedule { else cont == other.cont && state == other.state && delayInNanos == other.delayInNanos && - finish.value() == other.finish.value() + finish() == other.finish() public companion object { - public fun cont(d: Double, a: A, b: Eval): Decision = + public fun cont(d: Double, a: A, b: () -> B): Decision = Decision(true, d, a, b) - public fun done(d: Double, a: A, b: Eval): Decision = + public fun done(d: Double, a: A, b: () -> B): Decision = Decision(false, d, a, b) @ExperimentalTime - public fun cont(d: Duration, a: A, b: Eval): Decision = + public fun cont(d: Duration, a: A, b: () -> B): Decision = cont(d.toDouble(NANOSECONDS), a, b) @ExperimentalTime - public fun done(d: Duration, a: A, b: Eval): Decision = + public fun done(d: Duration, a: A, b: () -> B): Decision = done(d.toDouble(NANOSECONDS), a, b) } } @@ -771,7 +770,7 @@ public sealed class Schedule { */ public fun identity(): Schedule = Schedule({ Unit }) { a, s -> - Decision.cont(0.0, s, Eval.now(a)) + Decision.cont(0.0, s, { a }) } /** @@ -788,7 +787,7 @@ public sealed class Schedule { public fun unfoldLazy(c: suspend () -> A, f: suspend (A) -> A): Schedule = Schedule(c) { _: I, acc -> val a = f(acc) - Decision.cont(0.0, a, Eval.now(a)) + Decision.cont(0.0, a, { a }) } /** @@ -808,8 +807,8 @@ public sealed class Schedule { */ public fun recurs(n: Int): Schedule = Schedule(suspend { 0 }) { _: A, acc -> - if (acc < n) Decision.cont(0.0, acc + 1, Eval.now(acc + 1)) - else Decision.done(0.0, acc, Eval.now(acc)) + if (acc < n) Decision.cont(0.0, acc + 1, { acc + 1 }) + else Decision.done(0.0, acc, { acc }) } /** @@ -825,7 +824,7 @@ public sealed class Schedule { */ public fun never(): Schedule = Schedule(suspend { arrow.fx.coroutines.never() }) { _, _ -> - Decision(false, 0.0, Unit, Eval.later { throw IllegalArgumentException("Impossible") }) + Decision(false, 0.0, Unit, { throw IllegalArgumentException("Impossible") }) } /** @@ -842,7 +841,7 @@ public sealed class Schedule { @JvmName("delayedNanos") public fun delayed(delaySchedule: Schedule): Schedule = (delaySchedule.modifyNanos { a, b -> a + b } as ScheduleImpl) - .reconsider { _, dec -> dec.copy(finish = Eval.now(dec.delayInNanos)) } + .reconsider { _, dec -> dec.copy(finish = { dec.delayInNanos }) } /** * Creates a Schedule that uses another Schedule to generate the delay of this schedule. @@ -856,7 +855,7 @@ public sealed class Schedule { @JvmName("delayedDuration") public fun delayed(delaySchedule: Schedule): Schedule = (delaySchedule.modify { a, b -> a + b } as ScheduleImpl) - .reconsider { _, dec -> dec.copy(finish = Eval.now(dec.delayInNanos.nanoseconds)) } + .reconsider { _, dec -> dec.copy(finish = { dec.delayInNanos.nanoseconds }) } /** * Creates a Schedule which collects all its inputs in a list. @@ -894,7 +893,7 @@ public sealed class Schedule { cont = decision.cont, delayInNanos = decision.delayInNanos, state = decision.state, - finish = Eval.now(decision.delayInNanos) + finish = { decision.delayInNanos } ) } @@ -905,7 +904,7 @@ public sealed class Schedule { cont = decision.cont, delayInNanos = decision.delayInNanos, state = decision.state, - finish = Eval.now(decision.delayInNanos.nanoseconds) + finish = { decision.delayInNanos.nanoseconds } ) } @@ -919,7 +918,7 @@ public sealed class Schedule { cont = decision.cont, delayInNanos = decision.delayInNanos, state = decision.state, - finish = Eval.now(decision.cont) + finish = { decision.cont } ) } @@ -1037,7 +1036,7 @@ public suspend fun Schedule.retryOrElseEither( state = dec.state if (dec.cont) delay((dec.delayInNanos / 1_000_000).toLong()) - else return Either.Left(orElse(e.nonFatalOrThrow(), dec.finish.value())) + else return Either.Left(orElse(e.nonFatalOrThrow(), dec.finish())) } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt index b121fa3d4aa..f5c1f355496 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ScheduleTest.kt @@ -1,7 +1,6 @@ package arrow.fx.coroutines import arrow.core.Either -import arrow.core.Eval import io.kotest.assertions.fail import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should @@ -32,14 +31,14 @@ class ScheduleTest : StringSpec({ "Schedule.identity()" { val dec = Schedule.identity().calculateSchedule1(1) - val expected = Schedule.Decision(true, 0.0, Unit, Eval.now(1)) + val expected = Schedule.Decision(true, 0.0, Unit, { 1 }) dec eqv expected } "Schedule.unfold()" { val dec = Schedule.unfold(0) { it + 1 }.calculateSchedule1(0) - val expected = Schedule.Decision(true, 0.0, 1, Eval.now(1)) + val expected = Schedule.Decision(true, 0.0, 1, { 1 }) dec eqv expected } @@ -70,7 +69,7 @@ class ScheduleTest : StringSpec({ res.dropLast(1).map { it.delayInNanos.nanoseconds } shouldBe res.dropLast(1).map { 0.nanoseconds } res.dropLast(1).map { it.cont } shouldBe res.dropLast(1).map { true } - res.last() eqv Schedule.Decision(false, 0.0, n + 1, Eval.now(n + 1)) + res.last() eqv Schedule.Decision(false, 0.0, n + 1, { n + 1 }) } "Schedule.once() repeats 1 additional time" { @@ -190,7 +189,7 @@ class ScheduleTest : StringSpec({ "repeat" { val stop = RuntimeException("WOOO") - val dec = Schedule.Decision(true, 10.0, 0, Eval.now("state")) + val dec = Schedule.Decision(true, 10.0, 0, { "state" }) val n = 100 val schedule = Schedule({ 0 }) { _: Unit, _ -> dec } @@ -209,7 +208,7 @@ class ScheduleTest : StringSpec({ "repeatAsFlow" { val stop = RuntimeException("WOOO") - val dec = Schedule.Decision(true, 10.0, 0, Eval.now("state")) + val dec = Schedule.Decision(true, 10.0, 0, { "state" }) val n = 100 val schedule = Schedule({ 0 }) { _: Unit, _ -> dec } @@ -352,8 +351,8 @@ private infix fun Schedule.Decision.eqv(other: Schedule.Decision withContext(_single) { threadName() shouldStartWith "single" - + val (s1, s2, s3, s4, s5, s6) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName, threadName ) { a, b, c, d, e, f -> Tuple6(a, b, c, d, e, f) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt index b5eb62b0f6d..428deb6ea9e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap7JvmTest.kt @@ -23,13 +23,13 @@ class ParMap7JvmTest : StringSpec({ parallelCtx(7, mapCtxName) { _single, _mapCtx -> withContext(_single) { threadName() shouldStartWith "single" - + val (s1, s2, s3, s4, s5, s6, s7) = parZip( _mapCtx, threadName, threadName, threadName, threadName, threadName, threadName, threadName ) { a, b, c, d, e, f, g -> Tuple7(a, b, c, d, e, f, g) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt index 0259914e322..69eadc83e11 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMap8JvmTest.kt @@ -23,13 +23,13 @@ class ParMap8JvmTest : StringSpec({ parallelCtx(7, mapCtxName) { _single, _mapCtx -> withContext(_single) { threadName() shouldStartWith "single" - + val (s1, s2, s3, s4, s5, s6, s7, s8) = parZip( _mapCtx, 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) } - + s1 shouldStartWith mapCtxName s2 shouldStartWith mapCtxName s3 shouldStartWith mapCtxName diff --git a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts index ccec09d7679..c367ea639a2 100644 --- a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts @@ -2,9 +2,9 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) + // alias(libs.plugins.kotest.multiplatform) } -apply(plugin = "io.kotest.multiplatform") apply(from = property("TEST_COVERAGE")) apply(from = property("ANIMALSNIFFER_MPP")) diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt index 540772bb7ea..ad3dc1b103f 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt @@ -267,5 +267,5 @@ class STMTest : StringSpec({ // the above only finishes if the consumer reads at least 100 values, this here is just to make sure there are no leftovers atomically { tq.flush() } shouldBe emptyList() } - } -) + +}) diff --git a/arrow-libs/optics/arrow-optics/api/arrow-optics.api b/arrow-libs/optics/arrow-optics/api/arrow-optics.api index 785225f47fa..796525e2c59 100644 --- a/arrow-libs/optics/arrow-optics/api/arrow-optics.api +++ b/arrow-libs/optics/arrow-optics/api/arrow-optics.api @@ -23,7 +23,6 @@ public final class arrow/optics/Every { public static final fun sequence ()Larrow/optics/PTraversal; public static final fun string ()Larrow/optics/PTraversal; public static final fun triple ()Larrow/optics/PTraversal; - public static final fun tuple10 ()Larrow/optics/PTraversal; public static final fun tuple4 ()Larrow/optics/PTraversal; public static final fun tuple5 ()Larrow/optics/PTraversal; public static final fun tuple6 ()Larrow/optics/PTraversal; @@ -300,7 +299,6 @@ public abstract interface class arrow/optics/PTraversal { public static fun option ()Larrow/optics/PTraversal; public static fun pPair ()Larrow/optics/PTraversal; public static fun pTriple ()Larrow/optics/PTraversal; - public static fun pTuple10 ()Larrow/optics/PTraversal; public static fun pTuple4 ()Larrow/optics/PTraversal; public static fun pTuple5 ()Larrow/optics/PTraversal; public static fun pTuple6 ()Larrow/optics/PTraversal; @@ -314,7 +312,6 @@ public abstract interface class arrow/optics/PTraversal { public abstract fun size (Ljava/lang/Object;)I public static fun string ()Larrow/optics/PTraversal; public static fun triple ()Larrow/optics/PTraversal; - public static fun tuple10 ()Larrow/optics/PTraversal; public static fun tuple4 ()Larrow/optics/PTraversal; public static fun tuple5 ()Larrow/optics/PTraversal; public static fun tuple6 ()Larrow/optics/PTraversal; @@ -342,7 +339,6 @@ public final class arrow/optics/PTraversal$Companion { public final fun option ()Larrow/optics/PTraversal; public final fun pPair ()Larrow/optics/PTraversal; public final fun pTriple ()Larrow/optics/PTraversal; - public final fun pTuple10 ()Larrow/optics/PTraversal; public final fun pTuple4 ()Larrow/optics/PTraversal; public final fun pTuple5 ()Larrow/optics/PTraversal; public final fun pTuple6 ()Larrow/optics/PTraversal; @@ -353,7 +349,6 @@ public final class arrow/optics/PTraversal$Companion { public final fun sequence ()Larrow/optics/PTraversal; public final fun string ()Larrow/optics/PTraversal; public final fun triple ()Larrow/optics/PTraversal; - public final fun tuple10 ()Larrow/optics/PTraversal; public final fun tuple4 ()Larrow/optics/PTraversal; public final fun tuple5 ()Larrow/optics/PTraversal; public final fun tuple6 ()Larrow/optics/PTraversal; diff --git a/arrow-libs/optics/arrow-optics/build.gradle.kts b/arrow-libs/optics/arrow-optics/build.gradle.kts index 168b0342d2c..6b62b5800ac 100644 --- a/arrow-libs/optics/arrow-optics/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics/build.gradle.kts @@ -2,11 +2,9 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) -// alias(libs.plugins.ksp) + alias(libs.plugins.kotest.multiplatform) } -apply(plugin = "io.kotest.multiplatform") - apply(from = property("TEST_COVERAGE")) apply(from = property("ANIMALSNIFFER_MPP")) @@ -39,6 +37,7 @@ kotlin { jvmTest { dependencies { implementation(libs.kotlin.stdlibJDK8) + implementation(libs.kotest.frameworkEngine) implementation(libs.junitJupiterEngine) implementation(libs.kotlin.reflect) } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt index d8d368a6e36..9fb1faabffb 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt @@ -3,7 +3,6 @@ package arrow.optics import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.Option -import arrow.core.Tuple10 import arrow.core.Tuple4 import arrow.core.Tuple5 import arrow.core.Tuple6 @@ -42,7 +41,10 @@ public object Every { source.map(map) override fun foldMap(M: Monoid, source: Either, map: (focus: R) -> A): A = - source.foldMap(M, map) + when (source) { + is Either.Left -> M.empty() + is Either.Right -> map(source.value) + } } @JvmStatic @@ -318,42 +320,4 @@ public object Every { } } - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10] - */ - @JvmStatic - public fun tuple10(): Traversal, A> = - object : Traversal, A> { - override fun modify( - source: Tuple10, - map: (focus: A) -> A - ): Tuple10 = - Tuple10( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh), - map(source.eighth), - map(source.ninth), - map(source.tenth) - ) - - override fun foldMap(M: Monoid, source: Tuple10, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - .combine(map(source.fifth)) - .combine(map(source.sixth)) - .combine(map(source.seventh)) - .combine(map(source.eighth)) - .combine(map(source.ninth)) - .combine(map(source.tenth)) - } - } - } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt index 5060254b364..5d06c9c42a4 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt @@ -3,7 +3,6 @@ package arrow.optics import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.Option -import arrow.core.Tuple10 import arrow.core.Tuple4 import arrow.core.Tuple5 import arrow.core.Tuple6 @@ -588,31 +587,6 @@ public interface PTraversal { public fun tuple9(): Traversal, A> = pTuple9() - /** - * [PTraversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10] - */ - @JvmStatic - public fun pTuple10(): PTraversal, Tuple10, A, B> = - PTraversal( - get1 = { it.first }, - get2 = { it.second }, - get3 = { it.third }, - get4 = { it.fourth }, - get5 = { it.fifth }, - get6 = { it.sixth }, - get7 = { it.seventh }, - get8 = { it.eighth }, - get9 = { it.ninth }, - get10 = { it.tenth }, - set = { a, b, c, d, e, f, g, h, i, j, _ -> Tuple10(a, b, c, d, e, f, g, h, i, j) } - ) - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10] - */ - @JvmStatic - public fun tuple10(): Traversal, A> = - pTuple10() } /** diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt index 2acec09fa9c..305ecd5b84f 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt @@ -5,7 +5,6 @@ import arrow.optics.test.option import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.nonEmptyList -import arrow.optics.test.sequence import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.char @@ -40,7 +39,7 @@ class TraversalTest : StringSpec({ "Traversal sequence - ", TraversalLaws.laws( traversal = Traversal.sequence(), - aGen = Arb.sequence(Arb.string()), + aGen = Arb.list(Arb.string()).map { it.asSequence() }, bGen = Arb.string(), funcGen = Arb.functionAToB(Arb.string()), eq = { a, b -> a.toList() == b.toList() } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt index 0fa58d2ed94..01366a14f0d 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt @@ -4,7 +4,6 @@ import arrow.optics.test.functionAToB import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.nonEmptyList -import arrow.optics.test.sequence import arrow.optics.typeclasses.FilterIndex import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb @@ -30,7 +29,7 @@ class FilterIndexInstanceTest : StringSpec({ "FilterIndex sequence - ", TraversalLaws.laws( traversal = FilterIndex.sequence().filter { true }, - aGen = Arb.sequence(Arb.string()), + aGen = Arb.list(Arb.string()).map { it.asSequence() }, bGen = Arb.string(), funcGen = Arb.functionAToB(Arb.string()), ) { a, b -> a.toList() == b.toList() } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt index 6c139de4b8d..9aabe3d874d 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt @@ -30,7 +30,7 @@ class IndexInstanceTest : StringSpec({ "Index sequence - ", OptionalLaws.laws( optionalGen = Arb.int().map { Index.sequence().index(it) }, - aGen = Arb.sequence(Arb.string()), + aGen = Arb.list(Arb.string()).map { it.asSequence() }, bGen = Arb.string(), funcGen = Arb.functionAToB(Arb.string()), eqa = { a, b -> a.toList() == b.toList() } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt index 8df130ff3bd..4759fe80246 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt @@ -6,6 +6,12 @@ import arrow.optics.test.functionAToB import arrow.optics.test.laws.LensLaws import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws +import arrow.optics.test.tuple4 +import arrow.optics.test.tuple5 +import arrow.optics.test.tuple6 +import arrow.optics.test.tuple7 +import arrow.optics.test.tuple8 +import arrow.optics.test.tuple9 import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean @@ -86,4 +92,91 @@ class TupleTest : StringSpec({ ) ) + testLaws( + "Traversal tuple4 - ", + TraversalLaws.laws( + traversal = Traversal.tuple4(), + aGen = Arb.tuple4(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), + bGen = Arb.boolean(), + funcGen = Arb.functionAToB(Arb.boolean()), + ) + ) + + testLaws( + "Traversal tuple5 - ", + TraversalLaws.laws( + traversal = Traversal.tuple5(), + aGen = Arb.tuple5(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), + bGen = Arb.boolean(), + funcGen = Arb.functionAToB(Arb.boolean()), + ) + ) + + testLaws( + "Traversal tuple6 - ", + TraversalLaws.laws( + traversal = Traversal.tuple6(), + aGen = Arb.tuple6(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), + bGen = Arb.boolean(), + funcGen = Arb.functionAToB(Arb.boolean()), + ) + ) + + testLaws( + "Traversal tuple7 - ", + TraversalLaws.laws( + traversal = Traversal.tuple7(), + aGen = Arb.tuple7( + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean() + ), + bGen = Arb.boolean(), + funcGen = Arb.functionAToB(Arb.boolean()), + ) + ) + + testLaws( + "Traversal tuple8 - ", + TraversalLaws.laws( + traversal = Traversal.tuple8(), + aGen = Arb.tuple8( + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean() + ), + bGen = Arb.boolean(), + funcGen = Arb.functionAToB(Arb.boolean()), + ) + ) + + testLaws( + "Traversal tuple9 - ", + TraversalLaws.laws( + traversal = Traversal.tuple9(), + aGen = Arb.tuple9( + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean(), + Arb.boolean() + ), + bGen = Arb.boolean(), + funcGen = Arb.functionAToB(Arb.int()), + ) + ) + }) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt index bb0674539a2..1f66bd4a5cb 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt @@ -3,6 +3,12 @@ package arrow.optics.test import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.Option +import arrow.core.Tuple4 +import arrow.core.Tuple5 +import arrow.core.Tuple6 +import arrow.core.Tuple7 +import arrow.core.Tuple8 +import arrow.core.Tuple9 import arrow.core.toOption import io.kotest.property.Arb import io.kotest.property.arbitrary.bind @@ -28,3 +34,66 @@ fun Arb.Companion.either(arbE: Arb, arbA: Arb): Arb> { val arbRight = arbA.map { Either.Right(it) } return Arb.choice(arbLeft, arbRight) } + +fun Arb.Companion.tuple4( + arbA: Arb, + arbB: Arb, + arbC: Arb, + arbD: Arb +): Arb> = + Arb.bind(arbA, arbB, arbC, arbD, ::Tuple4) + +fun Arb.Companion.tuple5( + arbA: Arb, + arbB: Arb, + arbC: Arb, + arbD: Arb, + arbE: Arb +): Arb> = + Arb.bind(arbA, arbB, arbC, arbD, arbE, ::Tuple5) + +fun Arb.Companion.tuple6( + arbA: Arb, + arbB: Arb, + arbC: Arb, + arbD: Arb, + arbE: Arb, + arbF: Arb +): Arb> = + Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, ::Tuple6) + +fun Arb.Companion.tuple7( + arbA: Arb, + arbB: Arb, + arbC: Arb, + arbD: Arb, + arbE: Arb, + arbF: Arb, + arbG: Arb +): Arb> = + Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, ::Tuple7) + +fun Arb.Companion.tuple8( + arbA: Arb, + arbB: Arb, + arbC: Arb, + arbD: Arb, + arbE: Arb, + arbF: Arb, + arbG: Arb, + arbH: Arb +): Arb> = + Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, ::Tuple8) + +fun Arb.Companion.tuple9( + arbA: Arb, + arbB: Arb, + arbC: Arb, + arbD: Arb, + arbE: Arb, + arbF: Arb, + arbG: Arb, + arbH: Arb, + arbI: Arb +): Arb> = + Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, arbI, ::Tuple9) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 19d8125c22a..6ea793880ce 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -30,6 +30,7 @@ jUnitVintageEngine = { module = "org.junit.vintage:junit-vintage-engine", versio junitJupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "jUnitJupiter" } junitJupiterEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "jUnitJupiter" } kotest-assertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } +kotest-frameworkApi = { module = "io.kotest:kotest-framework-api", version.ref = "kotest" } kotest-frameworkEngine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } kotest-property = { module = "io.kotest:kotest-property", version.ref = "kotest" } kotest-runnerJUnit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } diff --git a/settings.gradle.kts b/settings.gradle.kts index e263f36ed8d..a143d74025f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -38,9 +38,6 @@ val enableCompatibilityMetadataVariant = providers.gradleProperty("kotlin.mpp.enableCompatibilityMetadataVariant") .forUseAtConfigurationTime().orNull?.toBoolean() == true -include("arrow-continuations") -project(":arrow-continuations").projectDir = file("arrow-libs/core/arrow-continuations") - include("arrow-core-retrofit") project(":arrow-core-retrofit").projectDir = file("arrow-libs/core/arrow-core-retrofit") From d6b867b5b60eadc881d818b9a76df9a3fc31b33c Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Fri, 20 Jan 2023 13:54:33 +0100 Subject: [PATCH 023/114] Revert typo --- .../src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt index 890108283ea..b67d07c0a3c 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt @@ -165,7 +165,7 @@ public suspend inline fun parZip( val fbb = async(ctx) { fb() } val fcc = async(ctx) { fc() } val (a, b, c) = awaitAll(faa, fbb, fcc) - f(a as A, b as B, c gitas C) + f(a as A, b as B, c as C) } /** From 1aa6abeda309b012aa1e9f3aa6341c1a664a3a88 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Fri, 20 Jan 2023 15:06:09 +0100 Subject: [PATCH 024/114] Fix build --- arrow-libs/core/arrow-atomic/build.gradle.kts | 5 ++--- arrow-libs/core/arrow-core/build.gradle.kts | 2 -- .../commonMain/kotlin/arrow/core/continuations/Effect.kt | 3 ++- .../src/commonMain/kotlin/arrow/core/continuations/Fold.kt | 6 +++--- .../src/jvmTest/kotlin/examples/example-effect-guide-02.kt | 3 ++- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/arrow-libs/core/arrow-atomic/build.gradle.kts b/arrow-libs/core/arrow-atomic/build.gradle.kts index fcb518fac59..a2a637957c0 100644 --- a/arrow-libs/core/arrow-atomic/build.gradle.kts +++ b/arrow-libs/core/arrow-atomic/build.gradle.kts @@ -2,9 +2,9 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) + alias(libs.plugins.kotest.multiplatform) } -apply(plugin = "io.kotest.multiplatform") apply(from = property("TEST_COVERAGE")) apply(from = property("ANIMALSNIFFER_MPP")) @@ -58,14 +58,13 @@ kotlin { commonTest { dependencies { implementation(projects.arrowFxCoroutines) - implementation(libs.kotest.frameworkApi) + implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } } jvmTest { dependencies { - runtimeOnly(libs.kotest.frameworkEngine) runtimeOnly(libs.kotest.runnerJUnit5) } } diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index 87549a71ae3..51f1555e88b 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -40,8 +40,6 @@ kotlin { } jvmTest { dependencies { - implementation(projects.arrowFxCoroutines) - runtimeOnly(libs.kotest.frameworkEngine) runtimeOnly(libs.kotest.runnerJUnit5) } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt index 291c60cb993..a7dfb0566d7 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Effect.kt @@ -691,6 +691,7 @@ import kotlin.jvm.JvmMultifileClass * import kotlinx.coroutines.coroutineScope * import kotlinx.coroutines.runBlocking * import arrow.core.continuations.effect + * import arrow.core.continuations.fold * import kotlin.time.Duration.Companion.seconds * * fun main(): Unit = runBlocking { @@ -702,7 +703,7 @@ import kotlin.jvm.JvmMultifileClass * effect { * launch { * delay(3.seconds) - * shift("error") + * raise("error") * } * 1 * }.fold(::println, ::println) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt index af5b036f32b..747fac5c3c5 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/Fold.kt @@ -56,7 +56,8 @@ public inline fun fold( ): B { val raise = DefaultRaise() return try { - transform(program(raise)).also { raise.complete() } + val a = program(raise).also { raise.complete() } + transform(a) } catch (e: CancellationException) { raise.complete() recover(e.raisedOrRethrow(raise)) @@ -81,8 +82,7 @@ internal class DefaultRaise : Raise { internal fun complete(): Boolean = isActive.getAndSet(false) override fun raise(r: Any?): Nothing = - if (isActive.value) throw RaiseCancellationException(r, this) - else throw ShiftLeakedException() + if (isActive.value) throw RaiseCancellationException(r, this) else throw ShiftLeakedException() } /** CancellationException is required to cancel coroutines when raising from within them. */ diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt index ca65a556da9..0e1574b5d31 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-guide-02.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.runBlocking import arrow.core.continuations.effect +import arrow.core.continuations.fold import kotlin.time.Duration.Companion.seconds fun main(): Unit = runBlocking { @@ -13,7 +14,7 @@ fun main(): Unit = runBlocking { effect { launch { delay(3.seconds) - shift("error") + raise("error") } 1 }.fold(::println, ::println) From ef44052593dd4c967f6baa4f3cafbe5bd8b3e508 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Thu, 26 Jan 2023 10:03:12 +0100 Subject: [PATCH 025/114] Fix ParMapJvmTest --- .../src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt index 732b246fb2f..e064c749296 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt @@ -87,3 +87,5 @@ class ParMapJvmTest : StringSpec({ private val emptyError: (Nothing, Nothing) -> Nothing = { _, _ -> throw AssertionError("Should not be called") } + +private val single = singleThreadContext("single") From 1514b53cfb6673846270df136c2df745a00e356c Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 3 Feb 2023 15:32:46 +0100 Subject: [PATCH 026/114] Implement NonEmptyList using value class (#2911) --- arrow-libs/core/arrow-core/api/arrow-core.api | 130 +++++++++----- .../kotlin/arrow/core/NonEmptyList.kt | 162 ++++++------------ .../arrow/core/continuations/EffectSpec.kt | 3 +- .../kotlin/arrow/core/test/Generators.kt | 3 +- .../java/arrow/core/NonEmptyListUsage.java | 23 --- .../api/arrow-fx-coroutines.api | 2 +- .../kotlin/arrow/optics/test/Generators.kt | 4 +- 7 files changed, 143 insertions(+), 184 deletions(-) delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonEmptyListUsage.java diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index d4d232c57c8..39b3944e9fa 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -515,64 +515,100 @@ public final class arrow/core/Memoization { public static final fun memoize (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function5; } -public final class arrow/core/NonEmptyList : kotlin/collections/AbstractList { +public final class arrow/core/NonEmptyList : java/util/List, kotlin/jvm/internal/markers/KMappedMarker { public static final field Companion Larrow/core/NonEmptyList$Companion; - public fun (Ljava/lang/Object;Ljava/util/List;)V - public synthetic fun (Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun align (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun coflatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; + public fun add (ILjava/lang/Object;)V + public fun add (Ljava/lang/Object;)Z + public fun addAll (ILjava/util/Collection;)Z + public fun addAll (Ljava/util/Collection;)Z + public static final fun align-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final synthetic fun box-impl (Ljava/util/List;)Larrow/core/NonEmptyList; + public fun clear ()V + public static final fun coflatMap-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static fun constructor-impl (Ljava/lang/Object;Ljava/util/List;)Ljava/util/List; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public fun contains (Ljava/lang/Object;)Z + public static fun contains-impl (Ljava/util/List;Ljava/lang/Object;)Z + public fun containsAll (Ljava/util/Collection;)Z + public static fun containsAll-impl (Ljava/util/List;Ljava/util/Collection;)Z public fun equals (Ljava/lang/Object;)Z - public final fun extract ()Ljava/lang/Object; - public final fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun fromList (Ljava/util/List;)Larrow/core/Option; - public static final fun fromListUnsafe (Ljava/util/List;)Larrow/core/NonEmptyList; + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public static final fun extract-impl (Ljava/util/List;)Ljava/lang/Object; + public static final fun flatMap-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static final fun foldLeft-impl (Ljava/util/List;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun get (I)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;I)Ljava/lang/Object; public final fun getAll ()Ljava/util/List; - public final fun getHead ()Ljava/lang/Object; + public static final fun getHead-impl (Ljava/util/List;)Ljava/lang/Object; public fun getSize ()I - public final fun getTail ()Ljava/util/List; + public static fun getSize-impl (Ljava/util/List;)I + public static final fun getTail-impl (Ljava/util/List;)Ljava/util/List; public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/List;)I + public fun indexOf (Ljava/lang/Object;)I + public static fun indexOf-impl (Ljava/util/List;Ljava/lang/Object;)I public fun isEmpty ()Z - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; - public final fun padZip (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun plus (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun plus (Ljava/lang/Object;)Larrow/core/NonEmptyList; - public final fun plus (Ljava/util/List;)Larrow/core/NonEmptyList; - public final fun salign (Larrow/typeclasses/Semigroup;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun toList ()Ljava/util/List; + public static fun isEmpty-impl (Ljava/util/List;)Z + public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl (Ljava/util/List;)Ljava/util/Iterator; + public fun lastIndexOf (Ljava/lang/Object;)I + public static fun lastIndexOf-impl (Ljava/util/List;Ljava/lang/Object;)I + public fun listIterator ()Ljava/util/ListIterator; + public fun listIterator (I)Ljava/util/ListIterator; + public static fun listIterator-impl (Ljava/util/List;)Ljava/util/ListIterator; + public static fun listIterator-impl (Ljava/util/List;I)Ljava/util/ListIterator; + public static final fun map-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static final fun padZip-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun plus-0-xjo5U (Ljava/util/List;Ljava/lang/Object;)Ljava/util/List; + public static final fun plus-0-xjo5U (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun plus-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public fun remove (I)Ljava/lang/Object; + public fun remove (Ljava/lang/Object;)Z + public fun removeAll (Ljava/util/Collection;)Z + public fun replaceAll (Ljava/util/function/UnaryOperator;)V + public fun retainAll (Ljava/util/Collection;)Z + public static final fun salign-BnObD6c (Ljava/util/List;Larrow/typeclasses/Semigroup;Ljava/util/List;)Ljava/util/List; + public fun set (ILjava/lang/Object;)Ljava/lang/Object; + public synthetic fun size ()I + public fun sort (Ljava/util/Comparator;)V + public fun subList (II)Ljava/util/List; + public static fun subList-impl (Ljava/util/List;II)Ljava/util/List; + public fun toArray ()[Ljava/lang/Object; + public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object; + public static final fun toList-impl (Ljava/util/List;)Ljava/util/List; public fun toString ()Ljava/lang/String; - public final fun zip (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function10;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function9;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function8;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function7;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function6;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function5;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function4;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function3;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function2;)Larrow/core/NonEmptyList; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; + public static final fun zip-BdUWqYY (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function5;)Ljava/util/List; + public static final fun zip-EkAgaZI (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function10;)Ljava/util/List; + public static final fun zip-FrVv2gs (Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun zip-QNErI5A (Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function3;)Ljava/util/List; + public static final fun zip-Sy0iXXA (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function4;)Ljava/util/List; + public static final fun zip-Vwi0aTY (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function7;)Ljava/util/List; + public static final fun zip-e5uF9gA (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function6;)Ljava/util/List; + public static final fun zip-oYG1GSg (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function8;)Ljava/util/List; + public static final fun zip-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun zip-vi6g5TI (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function9;)Ljava/util/List; } public final class arrow/core/NonEmptyList$Companion { - public final fun fromList (Ljava/util/List;)Larrow/core/Option; - public final fun fromListUnsafe (Ljava/util/List;)Larrow/core/NonEmptyList; - public final fun getUnit ()Larrow/core/NonEmptyList; + public final fun getUnit-1X0FA-Y ()Ljava/util/List; } public final class arrow/core/NonEmptyListKt { - public static final fun compareTo (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)I - public static final fun flatten (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public static final fun max (Larrow/core/NonEmptyList;)Ljava/lang/Comparable; - public static final fun maxBy (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun min (Larrow/core/NonEmptyList;)Ljava/lang/Comparable; - public static final fun minBy (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun nel (Ljava/lang/Object;)Larrow/core/NonEmptyList; - public static final fun nonEmptyListOf (Ljava/lang/Object;[Ljava/lang/Object;)Larrow/core/NonEmptyList; + public static final fun compareTo-8QhqC-A (Ljava/util/List;Ljava/util/List;)I + public static final fun flatten-GZgkXh4 (Ljava/util/List;)Ljava/util/List; + public static final fun max-GZgkXh4 (Ljava/util/List;)Ljava/lang/Comparable; + public static final fun maxBy-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun min-GZgkXh4 (Ljava/util/List;)Ljava/lang/Comparable; + public static final fun minBy-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun nel (Ljava/lang/Object;)Ljava/util/List; + public static final fun nonEmptyListOf (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/util/List; public static final fun toNonEmptyListOrNone (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun toNonEmptyListOrNull (Ljava/lang/Iterable;)Larrow/core/NonEmptyList; - public static final fun unzip (Larrow/core/NonEmptyList;)Lkotlin/Pair; - public static final fun unzip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; + public static final fun toNonEmptyListOrNull (Ljava/lang/Iterable;)Ljava/util/List; + public static final fun unzip-GZgkXh4 (Ljava/util/List;)Lkotlin/Pair; + public static final fun unzip-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; } public final class arrow/core/NonFatalKt { @@ -1880,14 +1916,14 @@ public final class arrow/typeclasses/Semigroup$Companion { public final class arrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup : arrow/typeclasses/Semigroup { public static final field INSTANCE Larrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup; - public fun append (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public synthetic fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun combine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public fun append-dcR1Ndc (Ljava/util/List;Ljava/util/List;)Ljava/util/List; public synthetic fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun maybeCombine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public fun combine-dcR1Ndc (Ljava/util/List;Ljava/util/List;)Ljava/util/List; public synthetic fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public fun maybeCombine-7cP5QJY (Ljava/util/List;Ljava/util/List;)Ljava/util/List; public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus-dcR1Ndc (Ljava/util/List;Ljava/util/List;)Ljava/util/List; } public final class arrow/typeclasses/Semigroup$DefaultImpls { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index 4f10a35ba14..41d53dad7d3 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -1,6 +1,8 @@ package arrow.core import arrow.typeclasses.Semigroup +import kotlin.jvm.JvmInline +import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic public typealias Nel = NonEmptyList @@ -144,33 +146,37 @@ public typealias Nel = NonEmptyList * - `a.zip(b, c) { ... }` can be used to compute over multiple `NonEmptyList` values preserving type information and __abstracting over arity__ with `zip` * */ -public class NonEmptyList( - public val head: A, - public val tail: List -) : AbstractList() { - - private constructor(list: List) : this(list[0], list.drop(1)) - - override val size: Int = - 1 + tail.size - +@JvmInline +public value class NonEmptyList @PublishedApi internal constructor( public val all: List - get() = toList() +) : List by all { - public override operator fun get(index: Int): A { - if (index < 0 || index >= size) throw IndexOutOfBoundsException("$index is not in 1..${size - 1}") - return if (index == 0) head else tail[index - 1] + public constructor(head: A, tail: List): this(listOf(head) + tail) + + @Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS") + override fun equals(other: Any?): Boolean = when (other) { + is NonEmptyList<*> -> this.all == other.all + else -> this.all == other } + @Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS") + override fun hashCode(): Int = all.hashCode() + override fun isEmpty(): Boolean = false - public fun toList(): List = listOf(head) + tail + public fun toList(): List = all + + public val head: A + get() = all.first() + + public val tail: List + get() = all.drop(1) public inline fun map(f: (A) -> B): NonEmptyList = - NonEmptyList(f(head), tail.map(f)) + NonEmptyList(all.map(f)) public inline fun flatMap(f: (A) -> NonEmptyList): NonEmptyList = - f(head) + tail.flatMap { f(it).all } + NonEmptyList(all.flatMap { f(it).all }) public operator fun plus(l: NonEmptyList<@UnsafeVariance A>): NonEmptyList = NonEmptyList(all + l.all) @@ -182,69 +188,33 @@ public class NonEmptyList( NonEmptyList(all + a) public inline fun foldLeft(b: B, f: (B, A) -> B): B = - this.tail.fold(f(b, this.head), f) - - public fun coflatMap(f: (NonEmptyList) -> B): NonEmptyList { - val buf = mutableListOf() - tailrec fun consume(list: List): List = - if (list.isEmpty()) { - buf - } else { - val tail = list.subList(1, list.size) - buf += f(NonEmptyList(list[0], tail)) - consume(tail) + all.fold(b, f) + + public fun coflatMap(f: (NonEmptyList) -> B): NonEmptyList = + buildList { + var current = all + while (current.isNotEmpty()) { + add(f(NonEmptyList(current))) + current = current.drop(1) } - return NonEmptyList(f(this), consume(this.tail)) - } + }.let(::NonEmptyList) public fun extract(): A = this.head - override fun equals(other: Any?): Boolean = - super.equals(other) - - override fun hashCode(): Int = - super.hashCode() - override fun toString(): String = "NonEmptyList(${all.joinToString()})" public fun align(b: NonEmptyList): NonEmptyList> = - NonEmptyList(Ior.Both(head, b.head), tail.align(b.tail)) + NonEmptyList(all.align(b)) public fun salign(SA: Semigroup<@UnsafeVariance A>, b: NonEmptyList<@UnsafeVariance A>): NonEmptyList = - SA.run { - NonEmptyList(head.combine(b.head), tail.salign(SA, b.tail).toList()) - } + NonEmptyList(all.salign(SA, b).toList()) public fun padZip(other: NonEmptyList): NonEmptyList> = - NonEmptyList(head to other.head, tail.padZip(other.tail)) + NonEmptyList(all.padZip(other)) public companion object { - - @Deprecated( - "Use toNonEmptyListOrNull instead", - ReplaceWith( - "l.toNonEmptyListOrNull().toOption()", - "import arrow.core.toNonEmptyListOrNull", - "import arrow.core.toOption" - ) - ) - @JvmStatic - public fun fromList(l: List): Option> = - if (l.isEmpty()) None else Some(NonEmptyList(l)) - - @Deprecated( - "Use toNonEmptyListOrNull instead", - ReplaceWith( - "l.toNonEmptyListOrNull() ?: throw IndexOutOfBoundsException(\"Empty list doesn't contain element at index 0.\")", - "import arrow.core.toNonEmptyListOrNull" - ) - ) - @JvmStatic - public fun fromListUnsafe(l: List): NonEmptyList = - NonEmptyList(l) - @PublishedApi internal val unit: NonEmptyList = nonEmptyListOf(Unit) @@ -257,20 +227,14 @@ public class NonEmptyList( b: NonEmptyList, map: (A, B) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head), - tail.zip(b.tail, map) - ) + NonEmptyList(all.zip(b.all, map)) public inline fun zip( b: NonEmptyList, c: NonEmptyList, map: (A, B, C) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head), - tail.zip(b.tail, c.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, map)) public inline fun zip( b: NonEmptyList, @@ -278,10 +242,7 @@ public class NonEmptyList( d: NonEmptyList, map: (A, B, C, D) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head, d.head), - tail.zip(b.tail, c.tail, d.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, d.all, map)) public inline fun zip( b: NonEmptyList, @@ -290,10 +251,7 @@ public class NonEmptyList( e: NonEmptyList, map: (A, B, C, D, E) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head, d.head, e.head), - tail.zip(b.tail, c.tail, d.tail, e.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, d.all, e.all, map)) public inline fun zip( b: NonEmptyList, @@ -303,10 +261,7 @@ public class NonEmptyList( f: NonEmptyList, map: (A, B, C, D, E, F) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head, d.head, e.head, f.head), - tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, d.all, e.all, f.all, map)) public inline fun zip( b: NonEmptyList, @@ -317,10 +272,7 @@ public class NonEmptyList( g: NonEmptyList, map: (A, B, C, D, E, F, G) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head, d.head, e.head, f.head, g.head), - tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, d.all, e.all, f.all, g.all, map)) public inline fun zip( b: NonEmptyList, @@ -332,10 +284,7 @@ public class NonEmptyList( h: NonEmptyList, map: (A, B, C, D, E, F, G, H) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head, d.head, e.head, f.head, g.head, h.head), - tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, h.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, map)) public inline fun zip( b: NonEmptyList, @@ -348,10 +297,7 @@ public class NonEmptyList( i: NonEmptyList, map: (A, B, C, D, E, F, G, H, I) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head, d.head, e.head, f.head, g.head, h.head, i.head), - tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, h.tail, i.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, i.all, map)) public inline fun zip( b: NonEmptyList, @@ -365,17 +311,16 @@ public class NonEmptyList( j: NonEmptyList, map: (A, B, C, D, E, F, G, H, I, J) -> Z ): NonEmptyList = - NonEmptyList( - map(head, b.head, c.head, d.head, e.head, f.head, g.head, h.head, i.head, j.head), - tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, h.tail, i.tail, j.tail, map) - ) + NonEmptyList(all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, i.all, j.all, map)) } +@JvmName("nonEmptyListOf") public fun nonEmptyListOf(head: A, vararg t: A): NonEmptyList = - NonEmptyList(head, t.asList()) + NonEmptyList(listOf(head) + t) +@JvmName("nel") public inline fun A.nel(): NonEmptyList = - nonEmptyListOf(this) + NonEmptyList(listOf(this)) public operator fun > NonEmptyList.compareTo(other: NonEmptyList): Int = all.compareTo(other.all) @@ -399,15 +344,12 @@ public fun NonEmptyList>.unzip(): Pair, NonEmp this.unzip(::identity) public fun NonEmptyList.unzip(f: (C) -> Pair): Pair, NonEmptyList> = - this.map(f).let { nel -> - nel.tail.unzip().let { - NonEmptyList(nel.head.first, it.first) to - NonEmptyList(nel.head.second, it.second) - } - } + all.unzip(f).let { (a, b) -> NonEmptyList(a) to NonEmptyList(b) } +@JvmName("toNonEmptyListOrNull") public fun Iterable.toNonEmptyListOrNull(): NonEmptyList? = - firstOrNull()?.let { NonEmptyList(it, drop(1)) } + toList().let { if (it.isEmpty()) null else NonEmptyList(it) } +@JvmName("toNonEmptyListOrNone") public fun Iterable.toNonEmptyListOrNone(): Option> = toNonEmptyListOrNull().toOption() diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt index 1473e0617d7..becaaaa0f48 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/EffectSpec.kt @@ -5,6 +5,7 @@ import arrow.core.NonEmptyList import arrow.core.identity import arrow.core.left import arrow.core.right +import arrow.core.toNonEmptyListOrNull import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -378,7 +379,7 @@ class EffectSpec : checkAll(Arb.list(Arb.int(), range = 2 .. 100)) { errors -> either, List> { mapOrAccumulate(errors) { raise(it) } - } shouldBe NonEmptyList.fromListUnsafe(errors).left() + } shouldBe errors.toNonEmptyListOrNull()!!.left() } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index c424bd291cc..51a3eabacc2 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -21,6 +21,7 @@ import io.kotest.property.arbitrary.of import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.string import kotlinx.coroutines.Dispatchers +import kotlin.math.max import kotlin.Result.Companion.failure import kotlin.Result.Companion.success import kotlin.coroutines.Continuation @@ -32,7 +33,7 @@ import kotlin.coroutines.startCoroutine // copied from kotest-extensions-arrow fun Arb.Companion.nonEmptyList(arb: Arb, range: IntRange = 0 .. 100): Arb> = - Arb.bind(arb, Arb.list(arb, range), ::NonEmptyList) + Arb.list(arb, max(range.first, 1) .. range.last).map { NonEmptyList(it) } fun Arb.Companion.sequence(arb: Arb, range: IntRange = 0 .. 100): Arb> = Arb.list(arb, range).map { it.asSequence() } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonEmptyListUsage.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonEmptyListUsage.java deleted file mode 100644 index af0382a41c9..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonEmptyListUsage.java +++ /dev/null @@ -1,23 +0,0 @@ -package arrow.core; - -import java.util.Arrays; - -import static arrow.core.NonEmptyListKt.*; - -public class NonEmptyListUsage { - - public void testUsage() { - NonEmptyList integers = nonEmptyListOf(1, 2, 3, 4, 5); - int i = compareTo( - nonEmptyListOf(1, 2, 3, 4, 5), - nonEmptyListOf(1, 2, 3, 4, 5) - ); - NonEmptyList flatten = flatten(nonEmptyListOf( - nonEmptyListOf(1, 2), - nonEmptyListOf(3, 4) - )); - Option> nonEmptyListOption = NonEmptyList.fromList(Arrays.asList(1, 2, 3)); - NonEmptyList integers1 = NonEmptyList.fromListUnsafe(Arrays.asList(1, 2, 3)); - NonEmptyList integers2 = NonEmptyListKt.toNonEmptyListOrNull(Arrays.asList(1, 2, 3)); - } -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index 42f2a8fbdb0..0532df7e698 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -235,12 +235,12 @@ public final class arrow/fx/coroutines/ParZipKt { public final class arrow/fx/coroutines/Platform { public static final field INSTANCE Larrow/fx/coroutines/Platform; - public final fun composeErrors (Larrow/core/NonEmptyList;)Ljava/lang/Throwable; public final fun composeErrors (Ljava/lang/Throwable;Ljava/lang/Object;)Ljava/lang/Throwable; public final fun composeErrors (Ljava/lang/Throwable;Ljava/lang/Throwable;)Ljava/lang/Throwable; public final fun composeErrors (Ljava/lang/Throwable;Ljava/util/List;)Ljava/lang/Throwable; public final fun composeErrors (Ljava/lang/Throwable;[Ljava/lang/Throwable;)Ljava/lang/Throwable; public final fun composeErrors (Ljava/util/List;)Ljava/lang/Throwable; + public final fun composeErrors-GZgkXh4 (Ljava/util/List;)Ljava/lang/Throwable; public final fun composeErrorsNullable (Ljava/lang/Throwable;Ljava/lang/Throwable;)Ljava/lang/Throwable; } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt index 1f66bd4a5cb..0d3ddd5ed4e 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/Generators.kt @@ -9,6 +9,7 @@ import arrow.core.Tuple6 import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 +import arrow.core.toNonEmptyListOrNull import arrow.core.toOption import io.kotest.property.Arb import io.kotest.property.arbitrary.bind @@ -16,9 +17,10 @@ import io.kotest.property.arbitrary.choice import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.orNull +import kotlin.math.max fun Arb.Companion.nonEmptyList(arb: Arb, range: IntRange = 0 .. 100): Arb> = - Arb.bind(arb, Arb.list(arb, range), ::NonEmptyList) + Arb.list(arb, max(range.first, 1) .. range.last).map { it.toNonEmptyListOrNull()!! } fun Arb.Companion.sequence(arb: Arb, range: IntRange = 0 .. 100): Arb> = Arb.list(arb, range).map { it.asSequence() } From 96108ca0dc03a20905efe1ee9ab21f39fd4e8636 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 3 Feb 2023 23:30:39 +0100 Subject: [PATCH 027/114] Fix merge w.r.t. Saga --- arrow-libs/fx/arrow-fx-resilience/build.gradle.kts | 1 + .../src/commonMain/kotlin/arrow/fx/resilience/Saga.kt | 6 +++--- .../src/commonTest/kotlin/arrow/fx/resilience/SagaSpec.kt | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-resilience/build.gradle.kts b/arrow-libs/fx/arrow-fx-resilience/build.gradle.kts index 4753d79a542..fb7e44480e5 100644 --- a/arrow-libs/fx/arrow-fx-resilience/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-resilience/build.gradle.kts @@ -22,6 +22,7 @@ kotlin { commonMain { dependencies { api(projects.arrowCore) + implementation(projects.arrowAtomic) implementation(projects.arrowFxCoroutines) compileOnly(libs.kotlin.stdlibCommon) implementation(libs.coroutines.core) diff --git a/arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Saga.kt b/arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Saga.kt index ef46b396562..8c43afca951 100644 --- a/arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Saga.kt +++ b/arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Saga.kt @@ -1,7 +1,7 @@ package arrow.fx.resilience -import arrow.core.continuations.AtomicRef -import arrow.core.continuations.updateAndGet +import arrow.atomic.Atomic +import arrow.atomic.updateAndGet import arrow.core.nonFatalOrThrow import kotlin.coroutines.cancellation.CancellationException import kotlinx.coroutines.NonCancellable @@ -118,7 +118,7 @@ public suspend fun Saga.transact(): A { // Internal implementation of the `saga { }` builder. @PublishedApi internal class SagaBuilder( - private val stack: AtomicRef Unit>> = AtomicRef(emptyList()) + private val stack: Atomic Unit>> = Atomic(emptyList()) ) : SagaScope { @SagaDSLMarker diff --git a/arrow-libs/fx/arrow-fx-resilience/src/commonTest/kotlin/arrow/fx/resilience/SagaSpec.kt b/arrow-libs/fx/arrow-fx-resilience/src/commonTest/kotlin/arrow/fx/resilience/SagaSpec.kt index c389b2f3ca6..5248e439c25 100644 --- a/arrow-libs/fx/arrow-fx-resilience/src/commonTest/kotlin/arrow/fx/resilience/SagaSpec.kt +++ b/arrow-libs/fx/arrow-fx-resilience/src/commonTest/kotlin/arrow/fx/resilience/SagaSpec.kt @@ -1,6 +1,6 @@ package arrow.fx.resilience -import arrow.fx.coroutines.parTraverse +import arrow.fx.coroutines.parMap import arrow.fx.coroutines.parZip import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow @@ -106,7 +106,7 @@ class SagaSpec : StringSpec({ "Saga can parTraverse" { checkAll(Arb.list(Arb.int())) { iis -> - saga { iis.parTraverse { saga({ it }) { fail("Doesn't run") } } }.transact() shouldBe iis + saga { iis.parMap { saga({ it }) { fail("Doesn't run") } } }.transact() shouldBe iis } } From e718996e888cd6588319ef885190b6024003d7f2 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 8 Feb 2023 15:04:03 +0100 Subject: [PATCH 028/114] apiDump --- arrow-libs/core/arrow-core/api/arrow-core.api | 2137 ++--------------- 1 file changed, 223 insertions(+), 1914 deletions(-) diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 78eda22d41a..bc01a73ee15 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -31,38 +31,6 @@ public final class arrow/core/Composition { public static final fun compose (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public final class arrow/core/Const { - public static final field Companion Larrow/core/Const$Companion; - public fun (Ljava/lang/Object;)V - public final fun copy (Ljava/lang/Object;)Larrow/core/Const; - public static synthetic fun copy$default (Larrow/core/Const;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Const; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Const; - public final fun retag ()Larrow/core/Const; - public fun toString ()Ljava/lang/String; - public final fun value ()Ljava/lang/Object; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function10;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function9;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function8;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function7;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function6;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function5;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function4;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function3;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Lkotlin/jvm/functions/Function2;)Larrow/core/Const; -} - -public final class arrow/core/Const$Companion { -} - -public final class arrow/core/ConstKt { - public static final fun combine (Larrow/core/Const;Larrow/typeclasses/Semigroup;Larrow/core/Const;)Larrow/core/Const; - public static final fun compareTo (Larrow/core/Const;Larrow/core/Const;)I - public static final fun const (Ljava/lang/Object;)Larrow/core/Const; - public static final fun contramap (Larrow/core/Const;Lkotlin/jvm/functions/Function1;)Larrow/core/Const; -} - public final class arrow/core/Currying { public static final fun curried (Lkotlin/jvm/functions/Function10;)Lkotlin/jvm/functions/Function1; public static final fun curried (Lkotlin/jvm/functions/Function11;)Lkotlin/jvm/functions/Function1; @@ -155,10 +123,6 @@ public abstract class arrow/core/Either { public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun bitraverseValidated (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun conditionally (ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public final fun exists (Lkotlin/jvm/functions/Function1;)Z public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -186,14 +150,6 @@ public abstract class arrow/core/Either { public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public final fun tapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public fun toString ()Ljava/lang/String; - public final fun toValidated ()Larrow/core/Validated; - public final fun toValidatedNel ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public static final fun tryCatchAndFlatten (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; @@ -273,10 +229,6 @@ public final class arrow/core/Either$Right$Companion { public final class arrow/core/EitherKt { public static final field NicheAPI Ljava/lang/String; public static final field RedundantAPI Ljava/lang/String; - public static final fun bisequence (Larrow/core/Either;)Ljava/util/List; - public static final fun bisequenceNullable (Larrow/core/Either;)Larrow/core/Either; - public static final fun bisequenceOption (Larrow/core/Either;)Larrow/core/Option; - public static final fun bisequenceValidated (Larrow/core/Either;)Larrow/core/Validated; public static final fun catch (Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; public static final fun combine (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Either;)Larrow/core/Either; public static final fun combineAll (Ljava/lang/Iterable;Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/core/Either; @@ -307,24 +259,12 @@ public final class arrow/core/EitherKt { public static final fun rightIfNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public static final fun sequence (Larrow/core/Either;)Larrow/core/Either; public static final fun sequence (Larrow/core/Either;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Either;)Larrow/core/Validated; public static final fun sequence (Larrow/core/Either;)Ljava/util/List; public static final fun sequenceNullable (Larrow/core/Either;)Larrow/core/Either; public static final fun sequenceOption (Larrow/core/Either;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/Either;)Larrow/core/Validated; public static final fun toEitherNel (Larrow/core/Either;)Larrow/core/Either; public static final fun toEitherNel (Ljava/lang/Object;)Larrow/core/Either; public static final fun widen (Larrow/core/Either;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function10;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function9;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function8;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function7;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function6;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function5;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function4;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function3;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; } public final class arrow/core/EmptyValue { @@ -349,108 +289,6 @@ public final class arrow/core/Endo { public final class arrow/core/Endo$Companion { } -public abstract class arrow/core/Eval { - public static final field Companion Larrow/core/Eval$Companion; - public static final fun always (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public final fun coflatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public static final fun defer (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval; - public final fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public static final fun later (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public abstract fun memoize ()Larrow/core/Eval; - public static final fun now (Ljava/lang/Object;)Larrow/core/Eval; - public static final fun raise (Ljava/lang/Throwable;)Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public abstract fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Always : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public static synthetic fun copy$default (Larrow/core/Eval$Always;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Always; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Companion { - public final fun always (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public final fun defer (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval; - public final fun later (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public final fun now (Ljava/lang/Object;)Larrow/core/Eval; - public final fun raise (Ljava/lang/Throwable;)Larrow/core/Eval; -} - -public final class arrow/core/Eval$Defer : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun component1 ()Lkotlin/jvm/functions/Function0; - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Defer; - public static synthetic fun copy$default (Larrow/core/Eval$Defer;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Defer; - public fun equals (Ljava/lang/Object;)Z - public final fun getThunk ()Lkotlin/jvm/functions/Function0; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public abstract class arrow/core/Eval$FlatMap : arrow/core/Eval { - public fun ()V - public fun memoize ()Larrow/core/Eval; - public abstract fun run (Ljava/lang/Object;)Larrow/core/Eval; - public abstract fun start ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Later : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public static synthetic fun copy$default (Larrow/core/Eval$Later;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Later; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Now : arrow/core/Eval { - public static final field Companion Larrow/core/Eval$Now$Companion; - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Eval$Now; - public static synthetic fun copy$default (Larrow/core/Eval$Now;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Eval$Now; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Now$Companion { - public final fun getUnit ()Larrow/core/Eval; -} - -public final class arrow/core/EvalKt { - public static final fun iterateRight (Ljava/util/Iterator;Larrow/core/Eval;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; - public static final fun replicate (Larrow/core/Eval;I)Larrow/core/Eval; - public static final fun replicate (Larrow/core/Eval;ILarrow/typeclasses/Monoid;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function10;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function9;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function8;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function7;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function6;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function5;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function4;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function3;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; -} - public abstract class arrow/core/Ior { public static final field Companion Larrow/core/Ior$Companion; public final fun all (Lkotlin/jvm/functions/Function1;)Z @@ -460,11 +298,6 @@ public abstract class arrow/core/Ior { public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun bitraverseValidated (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun bothNel (Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Ior; public final fun crosswalk (Lkotlin/jvm/functions/Function1;)Ljava/util/List; public final fun crosswalkMap (Lkotlin/jvm/functions/Function1;)Ljava/util/Map; @@ -491,15 +324,6 @@ public abstract class arrow/core/Ior { public final fun swap ()Larrow/core/Ior; public final fun toEither ()Larrow/core/Either; public fun toString ()Ljava/lang/String; - public final fun toValidated ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public final fun unwrap ()Larrow/core/Either; public final fun void ()Larrow/core/Ior; } @@ -566,11 +390,6 @@ public final class arrow/core/Ior$Right$Companion { } public final class arrow/core/IorKt { - public static final fun bisequence (Larrow/core/Ior;)Ljava/util/List; - public static final fun bisequenceEither (Larrow/core/Ior;)Larrow/core/Either; - public static final fun bisequenceNullable (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun bisequenceOption (Larrow/core/Ior;)Larrow/core/Option; - public static final fun bisequenceValidated (Larrow/core/Ior;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun bothIor (Lkotlin/Pair;)Larrow/core/Ior; public static final fun combine (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Ior;)Larrow/core/Ior; public static final fun compareTo (Larrow/core/Ior;Larrow/core/Ior;)I @@ -582,15 +401,6 @@ public final class arrow/core/IorKt { public static final fun replicate (Larrow/core/Ior;Larrow/typeclasses/Semigroup;I)Larrow/core/Ior; public static final fun replicate (Larrow/core/Ior;Larrow/typeclasses/Semigroup;ILarrow/typeclasses/Monoid;)Larrow/core/Ior; public static final fun rightIor (Ljava/lang/Object;)Larrow/core/Ior; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Ior;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Ior;)Larrow/core/Either; - public static final fun sequenceNullable (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun sequenceOption (Larrow/core/Ior;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/Ior;)Larrow/core/Validated; public static final fun widen (Larrow/core/Ior;)Larrow/core/Ior; public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;)Larrow/core/Ior; public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function10;)Larrow/core/Ior; @@ -643,39 +453,13 @@ public final class arrow/core/IterableKt { public static final fun rightPadZip (Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun salign (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Ljava/lang/Iterable;)Ljava/lang/Iterable; public static final fun separateEither (Ljava/lang/Iterable;)Lkotlin/Pair; - public static final fun separateValidated (Ljava/lang/Iterable;)Lkotlin/Pair; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Either; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Validated; - public static final fun sequence (Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun sequence (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun sequence (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Ljava/lang/Iterable;)Larrow/core/Either; - public static final fun sequenceNullable (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun sequenceOption (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun sequenceResult (Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun sequenceValidated (Ljava/lang/Iterable;)Larrow/core/Validated; - public static final fun sequenceValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun singleOrNone (Ljava/lang/Iterable;)Larrow/core/Option; public static final fun singleOrNone (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun split (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun tail (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun traverse (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public static final fun traverseEither (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseNullable (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public static final fun traverseOption (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseResult (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun traverseValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverseValidated (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun unalign (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun uniteEither (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun uniteValidated (Ljava/lang/Iterable;)Ljava/util/List; public static final fun unweave (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun unzip (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun unzip (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; @@ -705,18 +489,6 @@ public final class arrow/core/MapKt { public static final fun padZip (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public static final fun padZip (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function3;)Ljava/util/Map; public static final fun salign (Ljava/util/Map;Larrow/typeclasses/Semigroup;Ljava/util/Map;)Ljava/util/Map; - public static final fun sequence (Ljava/util/Map;)Larrow/core/Either; - public static final fun sequence (Ljava/util/Map;)Larrow/core/Option; - public static final fun sequence (Ljava/util/Map;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Ljava/util/Map;)Larrow/core/Either; - public static final fun sequenceOption (Ljava/util/Map;)Larrow/core/Option; - public static final fun sequenceValidated (Ljava/util/Map;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun traverse (Ljava/util/Map;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Ljava/util/Map;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Ljava/util/Map;)Lkotlin/Pair; public static final fun unalign (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun unzip (Ljava/util/Map;)Lkotlin/Pair; @@ -744,76 +516,100 @@ public final class arrow/core/Memoization { public static final fun memoize (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function5; } -public final class arrow/core/NonEmptyList : kotlin/collections/AbstractList { +public final class arrow/core/NonEmptyList : java/util/List, kotlin/jvm/internal/markers/KMappedMarker { public static final field Companion Larrow/core/NonEmptyList$Companion; - public fun (Ljava/lang/Object;Ljava/util/List;)V - public synthetic fun (Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun align (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun coflatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; + public fun add (ILjava/lang/Object;)V + public fun add (Ljava/lang/Object;)Z + public fun addAll (ILjava/util/Collection;)Z + public fun addAll (Ljava/util/Collection;)Z + public static final fun align-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final synthetic fun box-impl (Ljava/util/List;)Larrow/core/NonEmptyList; + public fun clear ()V + public static final fun coflatMap-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static fun constructor-impl (Ljava/lang/Object;Ljava/util/List;)Ljava/util/List; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public fun contains (Ljava/lang/Object;)Z + public static fun contains-impl (Ljava/util/List;Ljava/lang/Object;)Z + public fun containsAll (Ljava/util/Collection;)Z + public static fun containsAll-impl (Ljava/util/List;Ljava/util/Collection;)Z public fun equals (Ljava/lang/Object;)Z - public final fun extract ()Ljava/lang/Object; - public final fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun fromList (Ljava/util/List;)Larrow/core/Option; - public static final fun fromListUnsafe (Ljava/util/List;)Larrow/core/NonEmptyList; + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public static final fun extract-impl (Ljava/util/List;)Ljava/lang/Object; + public static final fun flatMap-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static final fun foldLeft-impl (Ljava/util/List;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun get (I)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;I)Ljava/lang/Object; public final fun getAll ()Ljava/util/List; - public final fun getHead ()Ljava/lang/Object; + public static final fun getHead-impl (Ljava/util/List;)Ljava/lang/Object; public fun getSize ()I - public final fun getTail ()Ljava/util/List; + public static fun getSize-impl (Ljava/util/List;)I + public static final fun getTail-impl (Ljava/util/List;)Ljava/util/List; public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/List;)I + public fun indexOf (Ljava/lang/Object;)I + public static fun indexOf-impl (Ljava/util/List;Ljava/lang/Object;)I public fun isEmpty ()Z - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; - public final fun padZip (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun plus (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun plus (Ljava/lang/Object;)Larrow/core/NonEmptyList; - public final fun plus (Ljava/util/List;)Larrow/core/NonEmptyList; - public final fun salign (Larrow/typeclasses/Semigroup;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun toList ()Ljava/util/List; + public static fun isEmpty-impl (Ljava/util/List;)Z + public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl (Ljava/util/List;)Ljava/util/Iterator; + public fun lastIndexOf (Ljava/lang/Object;)I + public static fun lastIndexOf-impl (Ljava/util/List;Ljava/lang/Object;)I + public fun listIterator ()Ljava/util/ListIterator; + public fun listIterator (I)Ljava/util/ListIterator; + public static fun listIterator-impl (Ljava/util/List;)Ljava/util/ListIterator; + public static fun listIterator-impl (Ljava/util/List;I)Ljava/util/ListIterator; + public static final fun map-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static final fun padZip-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun plus-0-xjo5U (Ljava/util/List;Ljava/lang/Object;)Ljava/util/List; + public static final fun plus-0-xjo5U (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun plus-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public fun remove (I)Ljava/lang/Object; + public fun remove (Ljava/lang/Object;)Z + public fun removeAll (Ljava/util/Collection;)Z + public fun replaceAll (Ljava/util/function/UnaryOperator;)V + public fun retainAll (Ljava/util/Collection;)Z + public static final fun salign-BnObD6c (Ljava/util/List;Larrow/typeclasses/Semigroup;Ljava/util/List;)Ljava/util/List; + public fun set (ILjava/lang/Object;)Ljava/lang/Object; + public synthetic fun size ()I + public fun sort (Ljava/util/Comparator;)V + public fun subList (II)Ljava/util/List; + public static fun subList-impl (Ljava/util/List;II)Ljava/util/List; + public fun toArray ()[Ljava/lang/Object; + public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object; + public static final fun toList-impl (Ljava/util/List;)Ljava/util/List; public fun toString ()Ljava/lang/String; - public final fun zip (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function10;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function9;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function8;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function7;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function6;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function5;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function4;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function3;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function2;)Larrow/core/NonEmptyList; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; + public static final fun zip-BdUWqYY (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function5;)Ljava/util/List; + public static final fun zip-EkAgaZI (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function10;)Ljava/util/List; + public static final fun zip-FrVv2gs (Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun zip-QNErI5A (Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function3;)Ljava/util/List; + public static final fun zip-Sy0iXXA (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function4;)Ljava/util/List; + public static final fun zip-Vwi0aTY (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function7;)Ljava/util/List; + public static final fun zip-e5uF9gA (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function6;)Ljava/util/List; + public static final fun zip-oYG1GSg (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function8;)Ljava/util/List; + public static final fun zip-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun zip-vi6g5TI (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function9;)Ljava/util/List; } public final class arrow/core/NonEmptyList$Companion { - public final fun fromList (Ljava/util/List;)Larrow/core/Option; - public final fun fromListUnsafe (Ljava/util/List;)Larrow/core/NonEmptyList; - public final fun getUnit ()Larrow/core/NonEmptyList; + public final fun getUnit-1X0FA-Y ()Ljava/util/List; } public final class arrow/core/NonEmptyListKt { - public static final fun compareTo (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)I - public static final fun flatten (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public static final fun max (Larrow/core/NonEmptyList;)Ljava/lang/Comparable; - public static final fun maxBy (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun min (Larrow/core/NonEmptyList;)Ljava/lang/Comparable; - public static final fun minBy (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun nel (Ljava/lang/Object;)Larrow/core/NonEmptyList; - public static final fun nonEmptyListOf (Ljava/lang/Object;[Ljava/lang/Object;)Larrow/core/NonEmptyList; - public static final fun sequence (Larrow/core/NonEmptyList;)Larrow/core/Either; - public static final fun sequence (Larrow/core/NonEmptyList;)Larrow/core/Option; - public static final fun sequence (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Larrow/core/NonEmptyList;)Larrow/core/Either; - public static final fun sequenceOption (Larrow/core/NonEmptyList;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; + public static final fun compareTo-8QhqC-A (Ljava/util/List;Ljava/util/List;)I + public static final fun flatten-GZgkXh4 (Ljava/util/List;)Ljava/util/List; + public static final fun max-GZgkXh4 (Ljava/util/List;)Ljava/lang/Comparable; + public static final fun maxBy-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun min-GZgkXh4 (Ljava/util/List;)Ljava/lang/Comparable; + public static final fun minBy-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun nel (Ljava/lang/Object;)Ljava/util/List; + public static final fun nonEmptyListOf (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/util/List; public static final fun toNonEmptyListOrNone (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun toNonEmptyListOrNull (Ljava/lang/Iterable;)Larrow/core/NonEmptyList; - public static final fun traverse (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun unzip (Larrow/core/NonEmptyList;)Lkotlin/Pair; - public static final fun unzip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; + public static final fun toNonEmptyListOrNull (Ljava/lang/Iterable;)Ljava/util/List; + public static final fun unzip-GZgkXh4 (Ljava/util/List;)Lkotlin/Pair; + public static final fun unzip-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; } public final class arrow/core/NonEmptySet : java/util/Set, kotlin/jvm/internal/markers/KMappedMarker { @@ -917,18 +713,12 @@ public abstract class arrow/core/Option { public final fun pairLeft (Ljava/lang/Object;)Larrow/core/Option; public final fun pairRight (Ljava/lang/Object;)Larrow/core/Option; public final fun reduceOrNull (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun reduceRightEvalOrNull (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; public final fun replicate (I)Larrow/core/Option; public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public final fun tapNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public final fun toEither (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public final fun toList ()Ljava/util/List; public fun toString ()Ljava/lang/String; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public static final fun tryCatchOrNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public final fun void ()Larrow/core/Option; @@ -973,12 +763,6 @@ public final class arrow/core/OptionKt { public static final fun rethrow (Larrow/core/Option;)Larrow/core/Option; public static final fun salign (Larrow/core/Option;Larrow/typeclasses/Semigroup;Larrow/core/Option;)Larrow/core/Option; public static final fun separateEither (Larrow/core/Option;)Lkotlin/Pair; - public static final fun separateValidated (Larrow/core/Option;)Lkotlin/Pair; - public static final fun sequence (Larrow/core/Option;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Option;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Option;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Option;)Larrow/core/Either; - public static final fun sequenceValidated (Larrow/core/Option;)Larrow/core/Validated; public static final fun some (Ljava/lang/Object;)Larrow/core/Option; public static final fun toMap (Larrow/core/Option;)Ljava/util/Map; public static final fun toOption (Ljava/lang/Object;)Larrow/core/Option; @@ -986,7 +770,6 @@ public final class arrow/core/OptionKt { public static final fun unalign (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun unite (Larrow/core/Option;Larrow/typeclasses/Monoid;)Larrow/core/Option; public static final fun uniteEither (Larrow/core/Option;)Larrow/core/Option; - public static final fun uniteValidated (Larrow/core/Option;)Larrow/core/Option; public static final fun unzip (Larrow/core/Option;)Lkotlin/Pair; public static final fun unzip (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun widen (Larrow/core/Option;)Larrow/core/Option; @@ -1548,26 +1331,12 @@ public final class arrow/core/SequenceKt { public static final fun rightPadZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; public static final fun salign (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun separateEither (Lkotlin/sequences/Sequence;)Lkotlin/Pair; - public static final fun separateValidated (Lkotlin/sequences/Sequence;)Lkotlin/Pair; - public static final fun sequence (Lkotlin/sequences/Sequence;)Larrow/core/Either; - public static final fun sequence (Lkotlin/sequences/Sequence;)Larrow/core/Option; - public static final fun sequence (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Lkotlin/sequences/Sequence;)Larrow/core/Either; - public static final fun sequenceOption (Lkotlin/sequences/Sequence;)Larrow/core/Option; - public static final fun sequenceValidated (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun some (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun split (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun tail (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; - public static final fun traverse (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun unalign (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun uniteEither (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; - public static final fun uniteValidated (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun unweave (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; public static final fun unzip (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun unzip (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; @@ -1608,159 +1377,106 @@ public final class arrow/core/StringKt { public static final fun escaped (Ljava/lang/String;)Ljava/lang/String; } -public final class arrow/core/Tuple10 { - public static final field Companion Larrow/core/Tuple10$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple4 { + public static final field Companion Larrow/core/Tuple4$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple10; - public static synthetic fun copy$default (Larrow/core/Tuple10;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple10; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple4; + public static synthetic fun copy$default (Larrow/core/Tuple4;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple4; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple10$Companion { +public final class arrow/core/Tuple4$Companion { } -public final class arrow/core/Tuple11 { - public static final field Companion Larrow/core/Tuple11$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple5 { + public static final field Companion Larrow/core/Tuple5$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple11; - public static synthetic fun copy$default (Larrow/core/Tuple11;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple11; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple5; + public static synthetic fun copy$default (Larrow/core/Tuple5;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple5; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple11$Companion { +public final class arrow/core/Tuple5$Companion { } -public final class arrow/core/Tuple12 { - public static final field Companion Larrow/core/Tuple12$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple6 { + public static final field Companion Larrow/core/Tuple6$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; public final fun component5 ()Ljava/lang/Object; public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple12; - public static synthetic fun copy$default (Larrow/core/Tuple12;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple12; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple6; + public static synthetic fun copy$default (Larrow/core/Tuple6;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple6; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple12$Companion { +public final class arrow/core/Tuple6$Companion { } -public final class arrow/core/Tuple13 { - public static final field Companion Larrow/core/Tuple13$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple7 { + public static final field Companion Larrow/core/Tuple7$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; public final fun component5 ()Ljava/lang/Object; public final fun component6 ()Ljava/lang/Object; public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple13; - public static synthetic fun copy$default (Larrow/core/Tuple13;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple13; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple7; + public static synthetic fun copy$default (Larrow/core/Tuple7;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple7; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple13$Companion { +public final class arrow/core/Tuple7$Companion { } -public final class arrow/core/Tuple14 { - public static final field Companion Larrow/core/Tuple14$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple8 { + public static final field Companion Larrow/core/Tuple8$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; @@ -1768,41 +1484,28 @@ public final class arrow/core/Tuple14 { public final fun component6 ()Ljava/lang/Object; public final fun component7 ()Ljava/lang/Object; public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple14; - public static synthetic fun copy$default (Larrow/core/Tuple14;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple14; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple8; + public static synthetic fun copy$default (Larrow/core/Tuple8;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple8; public fun equals (Ljava/lang/Object;)Z public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple14$Companion { +public final class arrow/core/Tuple8$Companion { } -public final class arrow/core/Tuple15 { - public static final field Companion Larrow/core/Tuple15$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple9 { + public static final field Companion Larrow/core/Tuple9$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; @@ -1811,1501 +1514,112 @@ public final class arrow/core/Tuple15 { public final fun component7 ()Ljava/lang/Object; public final fun component8 ()Ljava/lang/Object; public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple15; - public static synthetic fun copy$default (Larrow/core/Tuple15;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple15; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple9; + public static synthetic fun copy$default (Larrow/core/Tuple9;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple9; public fun equals (Ljava/lang/Object;)Z public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple15$Companion { -} - -public final class arrow/core/Tuple16 { - public static final field Companion Larrow/core/Tuple16$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple16; - public static synthetic fun copy$default (Larrow/core/Tuple16;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple16; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public final class arrow/core/Tuple9$Companion { } -public final class arrow/core/Tuple16$Companion { +public final class arrow/core/TupleNKt { + public static final fun combine (Lkotlin/Pair;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Lkotlin/Pair;)Lkotlin/Pair; + public static final fun compareTo (Larrow/core/Tuple4;Larrow/core/Tuple4;)I + public static final fun compareTo (Larrow/core/Tuple5;Larrow/core/Tuple5;)I + public static final fun compareTo (Larrow/core/Tuple6;Larrow/core/Tuple6;)I + public static final fun compareTo (Larrow/core/Tuple7;Larrow/core/Tuple7;)I + public static final fun compareTo (Larrow/core/Tuple8;Larrow/core/Tuple8;)I + public static final fun compareTo (Larrow/core/Tuple9;Larrow/core/Tuple9;)I + public static final fun compareTo (Lkotlin/Pair;Lkotlin/Pair;)I + public static final fun compareTo (Lkotlin/Triple;Lkotlin/Triple;)I + public static final fun plus (Larrow/core/Tuple4;Ljava/lang/Object;)Larrow/core/Tuple5; + public static final fun plus (Larrow/core/Tuple5;Ljava/lang/Object;)Larrow/core/Tuple6; + public static final fun plus (Larrow/core/Tuple6;Ljava/lang/Object;)Larrow/core/Tuple7; + public static final fun plus (Larrow/core/Tuple7;Ljava/lang/Object;)Larrow/core/Tuple8; + public static final fun plus (Larrow/core/Tuple8;Ljava/lang/Object;)Larrow/core/Tuple9; + public static final fun plus (Lkotlin/Pair;Ljava/lang/Object;)Lkotlin/Triple; + public static final fun plus (Lkotlin/Triple;Ljava/lang/Object;)Larrow/core/Tuple4; } -public final class arrow/core/Tuple17 { - public static final field Companion Larrow/core/Tuple17$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple17; - public static synthetic fun copy$default (Larrow/core/Tuple17;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple17; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public final class arrow/core/UtilsKt { + public static final field DeprecatedAmbiguity Ljava/lang/String; + public static final field DeprecatedUnsafeAccess Ljava/lang/String; + public static final fun constant (Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; + public static final fun mapNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public final class arrow/core/Tuple17$Companion { +public class arrow/core/raise/CancellationExceptionNoTrace : java/util/concurrent/CancellationException { + public fun ()V + public fun fillInStackTrace ()Ljava/lang/Throwable; } -public final class arrow/core/Tuple18 { - public static final field Companion Larrow/core/Tuple18$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple18; - public static synthetic fun copy$default (Larrow/core/Tuple18;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple18; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public final class arrow/core/raise/DefaultRaise : arrow/core/raise/Raise { + public fun ()V + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun complete ()Z + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class arrow/core/Tuple18$Companion { -} - -public final class arrow/core/Tuple19 { - public static final field Companion Larrow/core/Tuple19$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple19; - public static synthetic fun copy$default (Larrow/core/Tuple19;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple19; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple19$Companion { -} - -public final class arrow/core/Tuple20 { - public static final field Companion Larrow/core/Tuple20$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple20; - public static synthetic fun copy$default (Larrow/core/Tuple20;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple20; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple20$Companion { -} - -public final class arrow/core/Tuple21 { - public static final field Companion Larrow/core/Tuple21$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component21 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple21; - public static synthetic fun copy$default (Larrow/core/Tuple21;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple21; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public final fun getTwentyFirst ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple21$Companion { -} - -public final class arrow/core/Tuple22 { - public static final field Companion Larrow/core/Tuple22$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component21 ()Ljava/lang/Object; - public final fun component22 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple22; - public static synthetic fun copy$default (Larrow/core/Tuple22;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple22; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public final fun getTwentyFirst ()Ljava/lang/Object; - public final fun getTwentySecond ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple22$Companion { -} - -public final class arrow/core/Tuple4 { - public static final field Companion Larrow/core/Tuple4$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple4; - public static synthetic fun copy$default (Larrow/core/Tuple4;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple4; - public fun equals (Ljava/lang/Object;)Z - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple4$Companion { -} - -public final class arrow/core/Tuple5 { - public static final field Companion Larrow/core/Tuple5$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple5; - public static synthetic fun copy$default (Larrow/core/Tuple5;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple5; - public fun equals (Ljava/lang/Object;)Z - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple5$Companion { -} - -public final class arrow/core/Tuple6 { - public static final field Companion Larrow/core/Tuple6$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple6; - public static synthetic fun copy$default (Larrow/core/Tuple6;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple6; - public fun equals (Ljava/lang/Object;)Z - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple6$Companion { -} - -public final class arrow/core/Tuple7 { - public static final field Companion Larrow/core/Tuple7$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple7; - public static synthetic fun copy$default (Larrow/core/Tuple7;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple7; - public fun equals (Ljava/lang/Object;)Z - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple7$Companion { -} - -public final class arrow/core/Tuple8 { - public static final field Companion Larrow/core/Tuple8$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple8; - public static synthetic fun copy$default (Larrow/core/Tuple8;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple8; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple8$Companion { -} - -public final class arrow/core/Tuple9 { - public static final field Companion Larrow/core/Tuple9$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple9; - public static synthetic fun copy$default (Larrow/core/Tuple9;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple9; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple9$Companion { -} - -public final class arrow/core/TupleNKt { - public static final fun combine (Lkotlin/Pair;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Lkotlin/Pair;)Lkotlin/Pair; - public static final fun compareTo (Larrow/core/Tuple10;Larrow/core/Tuple10;)I - public static final fun compareTo (Larrow/core/Tuple4;Larrow/core/Tuple4;)I - public static final fun compareTo (Larrow/core/Tuple5;Larrow/core/Tuple5;)I - public static final fun compareTo (Larrow/core/Tuple6;Larrow/core/Tuple6;)I - public static final fun compareTo (Larrow/core/Tuple7;Larrow/core/Tuple7;)I - public static final fun compareTo (Larrow/core/Tuple8;Larrow/core/Tuple8;)I - public static final fun compareTo (Larrow/core/Tuple9;Larrow/core/Tuple9;)I - public static final fun compareTo (Lkotlin/Pair;Lkotlin/Pair;)I - public static final fun compareTo (Lkotlin/Triple;Lkotlin/Triple;)I - public static final fun plus (Larrow/core/Tuple10;Ljava/lang/Object;)Larrow/core/Tuple11; - public static final fun plus (Larrow/core/Tuple11;Ljava/lang/Object;)Larrow/core/Tuple12; - public static final fun plus (Larrow/core/Tuple12;Ljava/lang/Object;)Larrow/core/Tuple13; - public static final fun plus (Larrow/core/Tuple13;Ljava/lang/Object;)Larrow/core/Tuple14; - public static final fun plus (Larrow/core/Tuple14;Ljava/lang/Object;)Larrow/core/Tuple15; - public static final fun plus (Larrow/core/Tuple15;Ljava/lang/Object;)Larrow/core/Tuple16; - public static final fun plus (Larrow/core/Tuple16;Ljava/lang/Object;)Larrow/core/Tuple17; - public static final fun plus (Larrow/core/Tuple17;Ljava/lang/Object;)Larrow/core/Tuple18; - public static final fun plus (Larrow/core/Tuple18;Ljava/lang/Object;)Larrow/core/Tuple19; - public static final fun plus (Larrow/core/Tuple19;Ljava/lang/Object;)Larrow/core/Tuple20; - public static final fun plus (Larrow/core/Tuple20;Ljava/lang/Object;)Larrow/core/Tuple21; - public static final fun plus (Larrow/core/Tuple21;Ljava/lang/Object;)Larrow/core/Tuple22; - public static final fun plus (Larrow/core/Tuple4;Ljava/lang/Object;)Larrow/core/Tuple5; - public static final fun plus (Larrow/core/Tuple5;Ljava/lang/Object;)Larrow/core/Tuple6; - public static final fun plus (Larrow/core/Tuple6;Ljava/lang/Object;)Larrow/core/Tuple7; - public static final fun plus (Larrow/core/Tuple7;Ljava/lang/Object;)Larrow/core/Tuple8; - public static final fun plus (Larrow/core/Tuple8;Ljava/lang/Object;)Larrow/core/Tuple9; - public static final fun plus (Larrow/core/Tuple9;Ljava/lang/Object;)Larrow/core/Tuple10; - public static final fun plus (Lkotlin/Pair;Ljava/lang/Object;)Lkotlin/Triple; - public static final fun plus (Lkotlin/Triple;Ljava/lang/Object;)Larrow/core/Tuple4; -} - -public final class arrow/core/UtilsKt { - public static final field DeprecatedAmbiguity Ljava/lang/String; - public static final field DeprecatedUnsafeAccess Ljava/lang/String; - public static final fun constant (Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; - public static final fun mapNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; -} - -public abstract class arrow/core/Validated { - public static final field Companion Larrow/core/Validated$Companion; - public final fun all (Lkotlin/jvm/functions/Function1;)Z - public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun catchNel (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun exist (Lkotlin/jvm/functions/Function1;)Z - public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun foldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun fromEither (Larrow/core/Either;)Larrow/core/Validated; - public static final fun fromNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun fromOption (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun isEmpty ()Z - public final fun isInvalid ()Z - public final fun isNotEmpty ()Z - public final fun isValid ()Z - public static final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun mapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun swap ()Larrow/core/Validated; - public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun tapInvalid (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun toEither ()Larrow/core/Either; - public final fun toList ()Ljava/util/List; - public final fun toOption ()Larrow/core/Option; - public fun toString ()Ljava/lang/String; - public final fun toValidatedNel ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun void ()Larrow/core/Validated; - public final fun withEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; -} - -public final class arrow/core/Validated$Companion { - public final fun catchNel (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun fromEither (Larrow/core/Either;)Larrow/core/Validated; - public final fun fromNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun fromOption (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; -} - -public final class arrow/core/Validated$Invalid : arrow/core/Validated { - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Validated$Invalid; - public static synthetic fun copy$default (Larrow/core/Validated$Invalid;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Validated$Invalid; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Validated$Valid : arrow/core/Validated { - public static final field Companion Larrow/core/Validated$Valid$Companion; - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Validated$Valid; - public static synthetic fun copy$default (Larrow/core/Validated$Valid;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Validated$Valid; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Validated$Valid$Companion { - public final fun getUnit ()Larrow/core/Validated; -} - -public final class arrow/core/ValidatedKt { - public static final fun andThen (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun attempt (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun bisequence (Larrow/core/Validated;)Ljava/util/List; - public static final fun bisequenceEither (Larrow/core/Validated;)Larrow/core/Either; - public static final fun bisequenceNullable (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun bisequenceOption (Larrow/core/Validated;)Larrow/core/Option; - public static final fun combine (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun combineAll (Larrow/core/Validated;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun combineK (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun compareTo (Larrow/core/Validated;Larrow/core/Validated;)I - public static final fun findValid (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun fold (Larrow/core/Validated;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun getOrElse (Larrow/core/Validated;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static final fun handleError (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun handleErrorWith (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun invalid (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun leftWiden (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun merge (Larrow/core/Validated;)Ljava/lang/Object; - public static final fun orElse (Larrow/core/Validated;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun orNone (Larrow/core/Validated;)Larrow/core/Option; - public static final fun orNull (Larrow/core/Validated;)Ljava/lang/Object; - public static final fun redeem (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun replicate (Larrow/core/Validated;Larrow/typeclasses/Semigroup;I)Larrow/core/Validated; - public static final fun replicate (Larrow/core/Validated;Larrow/typeclasses/Semigroup;ILarrow/typeclasses/Monoid;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Validated;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Validated;)Larrow/core/Either; - public static final fun sequenceNullable (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun sequenceOption (Larrow/core/Validated;)Larrow/core/Option; - public static final fun toIor (Larrow/core/Validated;)Larrow/core/Ior; - public static final fun valid (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun valueOr (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun widen (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function10;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function9;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function8;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function7;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function6;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function5;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function4;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function3;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function2;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function10;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function9;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function8;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function7;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function6;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function5;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function4;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function3;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Lkotlin/jvm/functions/Function2;)Larrow/core/Validated; -} - -public abstract interface class arrow/core/computations/EitherEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EitherEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/EitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/EitherEffect;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/EitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/EitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EitherKt { - public static final fun ensureNotNull (Larrow/core/computations/EitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/EvalEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EvalEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/EvalEffect;Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/NullableEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/NullableEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/NullableEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/NullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/NullableEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/NullableKt { - public static final fun ensureNotNull (Larrow/core/computations/NullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/OptionEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/OptionEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/OptionEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/OptionEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/OptionKt { - public static final fun ensureNotNull (Larrow/core/computations/OptionEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedEitherEffect : arrow/core/computations/EitherEffect { -} - -public final class arrow/core/computations/RestrictedEitherEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedEitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedEvalEffect : arrow/core/computations/EvalEffect { -} - -public final class arrow/core/computations/RestrictedEvalEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedEvalEffect;Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedNullableEffect : arrow/core/computations/NullableEffect { -} - -public final class arrow/core/computations/RestrictedNullableEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedNullableEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedNullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedNullableEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedOptionEffect : arrow/core/computations/OptionEffect { -} - -public final class arrow/core/computations/RestrictedOptionEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedOptionEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedOptionEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/ResultEffect { - public static final field INSTANCE Larrow/core/computations/ResultEffect; - public final fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/core/computations/either { - public static final field INSTANCE Larrow/core/computations/either; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/eval { - public static final field INSTANCE Larrow/core/computations/eval; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/nullable { - public static final field INSTANCE Larrow/core/computations/nullable; - public final fun eager (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/option { - public static final field INSTANCE Larrow/core/computations/option; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/result { - public static final field INSTANCE Larrow/core/computations/result; - public final fun invoke-IoAF18A (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/AtomicRefKt { - public static final fun getAndUpdate (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun loop (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; - public static final fun update (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)V - public static final fun updateAndGet (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public class arrow/core/continuations/CancellationExceptionNoTrace : java/util/concurrent/CancellationException { - public fun ()V - public fun fillInStackTrace ()Ljava/lang/Throwable; -} - -public final class arrow/core/continuations/Eager : arrow/core/continuations/ShiftCancellationException { - public fun (Larrow/core/continuations/Token;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)V - public final fun getRecover ()Lkotlin/jvm/functions/Function1; - public final fun getShifted ()Ljava/lang/Object; - public final fun getToken ()Larrow/core/continuations/Token; - public fun toString ()Ljava/lang/String; -} - -public abstract interface class arrow/core/continuations/EagerEffect { - public abstract fun attempt ()Larrow/core/continuations/EagerEffect; - public abstract fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun handleError (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun handleErrorWith (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun orNull ()Ljava/lang/Object; - public abstract fun redeem (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun redeemWith (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun toEither ()Larrow/core/Either; - public abstract fun toIor ()Larrow/core/Ior; - public abstract fun toOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public abstract fun toValidated ()Larrow/core/Validated; -} - -public final class arrow/core/continuations/EagerEffect$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EagerEffect;)Larrow/core/continuations/EagerEffect; - public static fun flatMap (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun fold (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun handleError (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun handleErrorWith (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun map (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun orNull (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; - public static fun redeem (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun redeemWith (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun toEither (Larrow/core/continuations/EagerEffect;)Larrow/core/Either; - public static fun toIor (Larrow/core/continuations/EagerEffect;)Larrow/core/Ior; - public static fun toOption (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static fun toValidated (Larrow/core/continuations/EagerEffect;)Larrow/core/Validated; -} - -public final class arrow/core/continuations/EagerEffectKt { - public static final fun eagerEffect (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/EagerEffect; - public static final fun merge (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/EagerEffectScope { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EagerEffectScope$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun ensure (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EagerEffectScopeKt { - public static final fun ensureNotNull (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/Effect { - public abstract fun attempt ()Larrow/core/continuations/Effect; - public abstract fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun handleError (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun handleErrorWith (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun orNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun redeem (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun redeemWith (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun toEither (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toIor (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toValidated (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/Effect$DefaultImpls { - public static fun attempt (Larrow/core/continuations/Effect;)Larrow/core/continuations/Effect; - public static fun fold (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun handleError (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun handleErrorWith (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun orNull (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun redeem (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun redeemWith (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun toEither (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toIor (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toOption (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toValidated (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectKt { - public static final fun effect (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static final fun merge (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/EffectScope { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectScope$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectScopeKt { - public static final fun ensureNotNull (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/FoldContinuation : arrow/core/continuations/Token, arrow/core/continuations/EffectScope, kotlin/coroutines/Continuation { - public field recover Lkotlin/jvm/functions/Function2; - public fun (Larrow/core/continuations/Token;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)V - public fun (Larrow/core/continuations/Token;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)V - public fun (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun getContext ()Lkotlin/coroutines/CoroutineContext; - public final fun getRecover ()Lkotlin/jvm/functions/Function2; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun resumeWith (Ljava/lang/Object;)V - public final fun setRecover (Lkotlin/jvm/functions/Function2;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/IorEagerEffectScope : arrow/core/continuations/EagerEffectScope, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/EagerEffectScope;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun getLeftState ()Ljava/util/concurrent/atomic/AtomicReference; - public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/IorEffectScope : arrow/core/continuations/EffectScope, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/EffectScope;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun getLeftState ()Ljava/util/concurrent/atomic/AtomicReference; - public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/NullableEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/NullableEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/NullableEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/NullableEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/NullableKt { - public static final fun ensureNotNull-0Rsnnio (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensureNotNull-7s8y1X8 (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/OptionEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/OptionEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public fun shift (Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/OptionEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/OptionEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/OptionKt { - public static final fun ensureNotNull-09sQPHg (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensureNotNull-dxZa7OQ (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toOption (Larrow/core/continuations/EagerEffect;)Larrow/core/Option; - public static final fun toOption (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/ResultEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/ResultEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/ResultEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/ResultEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/ResultKt { - public static final fun toResult (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; - public static final fun toResult (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract class arrow/core/continuations/ShiftCancellationException : arrow/core/continuations/CancellationExceptionNoTrace { -} - -public final class arrow/core/continuations/ShiftLeakedException : java/lang/IllegalStateException { - public fun ()V -} - -public final class arrow/core/continuations/Suspend : arrow/core/continuations/ShiftCancellationException { - public fun (Larrow/core/continuations/Token;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)V - public final fun getRecover ()Lkotlin/jvm/functions/Function2; - public final fun getShifted ()Ljava/lang/Object; - public final fun getToken ()Larrow/core/continuations/Token; - public fun toString ()Ljava/lang/String; -} - -public class arrow/core/continuations/Token { - public fun ()V - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/continuations/either { - public static final field INSTANCE Larrow/core/continuations/either; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/ior { - public static final field INSTANCE Larrow/core/continuations/ior; - public final fun eager (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function2;)Larrow/core/Ior; - public final fun invoke (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/nullable { - public static final field INSTANCE Larrow/core/continuations/nullable; - public final fun eager (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/option { - public static final field INSTANCE Larrow/core/continuations/option; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/result { - public static final field INSTANCE Larrow/core/continuations/result; - public final fun eager-IoAF18A (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke-gIAlu-s (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/raise/DefaultRaise : arrow/core/raise/Raise { - public fun ()V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/core/raise/Effect { - public static final fun _fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun _foldOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; - public static final fun catch (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; - public static final fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; - public static final fun either (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ior (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public static final fun merge (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun merge (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun nullable (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun option (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun orNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun orNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun raisedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/raise/DefaultRaise;)Ljava/lang/Object; - public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; - public static final fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; - public static final fun result (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun toEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun toEither (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toIor (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public static final fun toIor (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun toOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toResult (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun toResult (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun toValidated (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/raise/EffectKt { - public static final fun eagerEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun effect (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; -} - -public final class arrow/core/raise/IorRaise : arrow/core/raise/Raise, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Ljava/util/concurrent/atomic/AtomicReference;Larrow/core/raise/Raise;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Object;)Ljava/lang/Object; +public final class arrow/core/raise/IorRaise : arrow/core/raise/Raise, arrow/typeclasses/Semigroup { + public fun (Larrow/typeclasses/Semigroup;Ljava/util/concurrent/atomic/AtomicReference;Larrow/core/raise/Raise;)V + public fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; + public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; + public fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public final class arrow/core/raise/NullableRaise : arrow/core/raise/Raise { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Either;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Option;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Validated;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/raise/Raise;Ljava/lang/Object;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final synthetic fun box-impl (Larrow/core/raise/Raise;)Larrow/core/raise/NullableRaise; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun catch-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun catch-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun constructor-impl (Larrow/core/raise/Raise;)Larrow/core/raise/Raise; @@ -3329,39 +1643,26 @@ public final class arrow/core/raise/NullableRaise : arrow/core/raise/Raise { public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/raise/Raise;Ljava/lang/Void;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; public static fun toString-impl (Larrow/core/raise/Raise;)Ljava/lang/String; public final synthetic fun unbox-impl ()Larrow/core/raise/Raise; } public final class arrow/core/raise/OptionRaise : arrow/core/raise/Raise { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Either;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Option;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Validated;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final synthetic fun box-impl (Larrow/core/raise/Raise;)Larrow/core/raise/OptionRaise; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun catch-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun catch-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun constructor-impl (Larrow/core/raise/Raise;)Larrow/core/raise/Raise; @@ -3385,25 +1686,17 @@ public final class arrow/core/raise/OptionRaise : arrow/core/raise/Raise { public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Larrow/core/None;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/raise/Raise;Larrow/core/None;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; public static fun toString-impl (Larrow/core/raise/Raise;)Ljava/lang/String; public final synthetic fun unbox-impl ()Larrow/core/raise/Raise; } public abstract interface class arrow/core/raise/Raise { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun bind (Larrow/core/Either;)Ljava/lang/Object; public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -3412,20 +1705,14 @@ public abstract interface class arrow/core/raise/Raise { public abstract fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;)Ljava/lang/Object; } public final class arrow/core/raise/Raise$DefaultImpls { - public static fun attempt (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Larrow/core/Either;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind (Larrow/core/raise/Raise;Larrow/core/Validated;)Ljava/lang/Object; - public static fun bind (Larrow/core/raise/Raise;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun catch (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun catch (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun invoke (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -3433,21 +1720,55 @@ public final class arrow/core/raise/Raise$DefaultImpls { public static fun recover (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun recover (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun recover (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift (Larrow/core/raise/Raise;Ljava/lang/Object;)Ljava/lang/Object; } public abstract interface annotation class arrow/core/raise/RaiseDSL : java/lang/annotation/Annotation { } public final class arrow/core/raise/RaiseKt { + public static final fun _fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun _foldOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun catch (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static final fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; + public static final fun catch (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; + public static final fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; + public static final fun eagerEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; + public static final fun effect (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; + public static final fun either (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun ensure (Larrow/core/raise/Raise;ZLkotlin/jvm/functions/Function0;)V public static final fun ensureNotNull (Larrow/core/raise/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; + public static final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun ior (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; public static final fun mapErrorNel (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Larrow/typeclasses/Semigroup;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun merge (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun merge (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun nullable (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun option (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; + public static final fun orNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun orNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun raisedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/raise/DefaultRaise;)Ljava/lang/Object; public static final fun recover (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static final fun recover (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; + public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; + public static final fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; + public static final fun result (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun toEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; + public static final fun toEither (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toIor (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; + public static final fun toIor (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; + public static final fun toOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; + public static final fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function10;)Ljava/lang/Object; public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function9;)Ljava/lang/Object; public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function8;)Ljava/lang/Object; @@ -3467,30 +1788,20 @@ public final class arrow/core/raise/RaiseKt { } public final class arrow/core/raise/ResultRaise : arrow/core/raise/Raise { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Either;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/Validated;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun bind-impl (Larrow/core/raise/Raise;Ljava/lang/Object;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final synthetic fun box-impl (Larrow/core/raise/Raise;)Larrow/core/raise/ResultRaise; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun catch-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun catch-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun constructor-impl (Larrow/core/raise/Raise;)Larrow/core/raise/Raise; @@ -3512,14 +1823,15 @@ public final class arrow/core/raise/ResultRaise : arrow/core/raise/Raise { public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun recover-impl (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/raise/Raise;Ljava/lang/Throwable;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; public static fun toString-impl (Larrow/core/raise/Raise;)Ljava/lang/String; public final synthetic fun unbox-impl ()Larrow/core/raise/Raise; } +public final class arrow/core/raise/ShiftLeakedException : java/lang/IllegalStateException { + public fun ()V +} + public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Semigroup { public static final field Companion Larrow/typeclasses/Monoid$Companion; public static fun Boolean ()Larrow/typeclasses/Monoid; @@ -3529,7 +1841,6 @@ public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Sem public static fun Short ()Larrow/typeclasses/Monoid; public abstract fun combineAll (Ljava/util/Collection;)Ljava/lang/Object; public abstract fun combineAll (Ljava/util/List;)Ljava/lang/Object; - public static fun constant (Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public static fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public abstract fun empty ()Ljava/lang/Object; public static fun endo ()Larrow/typeclasses/Monoid; @@ -3541,7 +1852,6 @@ public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Sem public static fun pair (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public static fun sequence ()Larrow/typeclasses/Monoid; public static fun string ()Larrow/typeclasses/Monoid; - public static fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; } public final class arrow/typeclasses/Monoid$Companion { @@ -3550,7 +1860,6 @@ public final class arrow/typeclasses/Monoid$Companion { public final fun Integer ()Larrow/typeclasses/Monoid; public final fun Long ()Larrow/typeclasses/Monoid; public final fun Short ()Larrow/typeclasses/Monoid; - public final fun constant (Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final synthetic fun either (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final fun endo ()Larrow/typeclasses/Monoid; @@ -3560,10 +1869,10 @@ public final class arrow/typeclasses/Monoid$Companion { public final fun pair (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; public final fun sequence ()Larrow/typeclasses/Monoid; public final fun string ()Larrow/typeclasses/Monoid; - public final fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; } public final class arrow/typeclasses/Monoid$DefaultImpls { + public static fun combine (Larrow/typeclasses/Monoid;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun combineAll (Larrow/typeclasses/Monoid;Ljava/util/Collection;)Ljava/lang/Object; public static fun combineAll (Larrow/typeclasses/Monoid;Ljava/util/List;)Ljava/lang/Object; public static fun fold (Larrow/typeclasses/Monoid;Ljava/util/Collection;)Ljava/lang/Object; @@ -3579,8 +1888,8 @@ public abstract interface class arrow/typeclasses/Semigroup { public static fun Integer ()Larrow/typeclasses/Semigroup; public static fun Long ()Larrow/typeclasses/Semigroup; public static fun Short ()Larrow/typeclasses/Semigroup; + public abstract fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun constant (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public static fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public static fun endo ()Larrow/typeclasses/Semigroup; public static fun ior (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; @@ -3593,7 +1902,6 @@ public abstract interface class arrow/typeclasses/Semigroup { public abstract fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun sequence ()Larrow/typeclasses/Semigroup; public static fun string ()Larrow/typeclasses/Semigroup; - public static fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; } public final class arrow/typeclasses/Semigroup$Companion { @@ -3602,7 +1910,6 @@ public final class arrow/typeclasses/Semigroup$Companion { public final fun Integer ()Larrow/typeclasses/Semigroup; public final fun Long ()Larrow/typeclasses/Semigroup; public final fun Short ()Larrow/typeclasses/Semigroup; - public final fun constant (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public final fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public final fun endo ()Larrow/typeclasses/Semigroup; public final fun ior (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; @@ -3613,20 +1920,22 @@ public final class arrow/typeclasses/Semigroup$Companion { public final fun pair (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; public final fun sequence ()Larrow/typeclasses/Semigroup; public final fun string ()Larrow/typeclasses/Semigroup; - public final fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; } public final class arrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup : arrow/typeclasses/Semigroup { public static final field INSTANCE Larrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup; - public fun combine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public synthetic fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun append-dcR1Ndc (Ljava/util/List;Ljava/util/List;)Ljava/util/List; public synthetic fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun maybeCombine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public fun combine-dcR1Ndc (Ljava/util/List;Ljava/util/List;)Ljava/util/List; public synthetic fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public fun maybeCombine-7cP5QJY (Ljava/util/List;Ljava/util/List;)Ljava/util/List; public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public fun plus-dcR1Ndc (Ljava/util/List;Ljava/util/List;)Ljava/util/List; } public final class arrow/typeclasses/Semigroup$DefaultImpls { + public static fun combine (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun maybeCombine (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun plus (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; } From 47010648f23b88da128e3b8ece557605ff73005a Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 8 Feb 2023 18:47:43 +0100 Subject: [PATCH 029/114] Test other return expression --- .../commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt index 431960c0d05..de4f7462d5a 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt @@ -552,10 +552,7 @@ public inline fun Raise.mapOrAccumulate( }) } } - return when (val e = EmptyValue.unbox(error)) { - null -> results - else -> raise(e) - } + return if (error === EmptyValue) results else raise(EmptyValue.unbox(error)) } /** From 1cdb5495655fadafda2235f8c0d9951a696ff5dd Mon Sep 17 00:00:00 2001 From: Alphonse Bendt <370821+abendt@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:41:20 +0100 Subject: [PATCH 030/114] change unalign signature (#2972) see discussion in https://github.com/arrow-kt/arrow/pull/2960#issuecomment-1457644028 https://github.com/arrow-kt/arrow/pull/2960#issuecomment-1457898158 --------- Co-authored-by: Alejandro Serrano --- .../commonMain/kotlin/arrow/core/Iterable.kt | 19 +++++++------ .../kotlin/arrow/core/IterableTest.kt | 20 +++++++++++--- .../kotlin/arrow/core/test/Generators.kt | 7 ++++- .../kotlin/arrow/core/test/GeneratorsTest.kt | 27 +++++++++++++++++++ 4 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt index 781cbf322c1..6433baebcbe 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt @@ -793,11 +793,14 @@ public inline fun Iterable.unzip(fc: (C) -> Pair): Pair */ -@Deprecated( - "The current unalign function is renamed to separateIor, and a new unalign function is going to be added to Arrow 2.0.0.", - ReplaceWith("separateIor()", "arrow.core.separateIor") -) -public fun Iterable>.unalign(): Pair, List> = separateIor() +public fun Iterable>.unalign(): Pair, List> = + fold(emptyList() to emptyList()) { (l, r), x -> + x.fold( + { Pair(l + it, r + null) }, + { Pair(l + null, r + it) }, + { a, b -> Pair(l + a, r + b) } + ) + } /** * after applying the given function, splits the resulting union shaped structure into its components parts @@ -817,11 +820,7 @@ public fun Iterable>.unalign(): Pair, List> = separa * ``` * */ -@Deprecated( - "The current unalign function is renamed to separateIor, and a new unalign function is going to be added to Arrow 2.0.0.", - ReplaceWith("map(fa).separateIor()", "arrow.core.separateIor") -) -public inline fun Iterable.unalign(fa: (C) -> Ior): Pair, List> = +public inline fun Iterable.unalign(fa: (C) -> Ior): Pair, List> = map(fa).unalign() /** diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index a76f6367882..2ae7b3e730e 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -1,8 +1,8 @@ package arrow.core import arrow.core.test.either -import arrow.core.test.functionAToB import arrow.core.test.ior +import arrow.core.test.functionAToB import arrow.core.test.option import arrow.typeclasses.Semigroup import io.kotest.core.spec.style.StringSpec @@ -325,15 +325,29 @@ class IterableTest : StringSpec({ } "unalign is the inverse of align" { + fun Pair, List>.fix(): Pair, List> = + first.mapNotNull { it } to second.mapNotNull { it } + checkAll(Arb.list(Arb.int()), Arb.list(Arb.string())) { a, b -> - a.align(b).unalign() shouldBe (a to b) + a.align(b).unalign().fix() shouldBe (a to b) } } "align is the inverse of unalign" { + fun Ior.fix(): Ior = + fold({ Ior.Left(it!!) }, { Ior.Right(it!!) }, { a, b -> + when { + a == null -> Ior.Right(b!!) + b == null -> Ior.Left(a) + else -> Ior.Both(a, b) + } + }) + checkAll(Arb.list(Arb.ior(Arb.int(), Arb.string()))) { xs -> val (a, b) = xs.unalign() - a.align(b) shouldBe xs + a.align(b) { + it.fix() + } shouldBe xs } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index 9847a8faf2a..534661b94ac 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -77,7 +77,12 @@ fun Arb.Companion.ior(arbA: Arb, arbB: Arb): Arb> = arbA.alignWith(arbB) { it } private fun Arb.alignWith(arbB: Arb, transform: (Ior) -> R): Arb = - Arb.bind(this, arbB) { a, b -> transform(Ior.Both(a, b)) } + Arb.choice( + this.map { Ior.Left(it) }, + Arb.bind(this, arbB) { a, b -> Ior.Both(a, b) }, + arbB.map { Ior.Right(it) } + ).map(transform) + fun Arb.Companion.suspendFunThatReturnsEitherAnyOrAnyOrThrows(): Arb Either> = choice( diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt new file mode 100644 index 00000000000..8470972c6b3 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt @@ -0,0 +1,27 @@ +package arrow.core.test + +import io.kotest.assertions.assertSoftly +import io.kotest.core.spec.style.StringSpec +import io.kotest.inspectors.forAtLeastOne +import io.kotest.matchers.booleans.shouldBeTrue +import io.kotest.property.Arb +import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.list +import io.kotest.property.arbitrary.next +import io.kotest.property.arbitrary.string + +class GeneratorsTest : StringSpec({ + "Arb.ior should generate Left, Right & Both" { + assertSoftly(Arb.list(Arb.ior(Arb.string(), Arb.int()), range = 20 .. 100).next()) { + forAtLeastOne { + it.isRight().shouldBeTrue() + } + forAtLeastOne { + it.isBoth().shouldBeTrue() + } + forAtLeastOne { + it.isLeft().shouldBeTrue() + } + } + } +}) From 8f13a3eff5c021339e1db30f12a0093cd09de6cb Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Thu, 30 Mar 2023 20:16:04 +0200 Subject: [PATCH 031/114] Update after merge main --- arrow-libs/core/arrow-core/api/arrow-core.api | 2465 ++--------------- .../commonMain/kotlin/arrow/core/Either.kt | 1127 +------- .../src/commonMain/kotlin/arrow/core/Ior.kt | 824 +----- .../commonMain/kotlin/arrow/core/Iterable.kt | 307 +- .../kotlin/arrow/core/NonEmptyList.kt | 64 - .../commonMain/kotlin/arrow/core/Option.kt | 839 +----- .../src/commonMain/kotlin/arrow/core/Pair.kt | 14 - .../commonMain/kotlin/arrow/core/Result.kt | 298 +- .../commonMain/kotlin/arrow/core/Sequence.kt | 245 +- .../src/commonMain/kotlin/arrow/core/map.kt | 187 +- .../commonMain/kotlin/arrow/core/predef.kt | 11 - .../kotlin/arrow/core/raise/Effect.kt | 4 +- .../kotlin/arrow/core/raise/Mappers.kt | 13 - .../kotlin/arrow/core/raise/Raise.kt | 5 - .../arrow/core/raise/RaiseAccumulate.kt | 3 - .../kotlin/arrow/core/EitherTest.kt | 293 +- .../commonTest/kotlin/arrow/core/IorTest.kt | 114 - .../kotlin/arrow/core/IterableTest.kt | 18 +- .../commonTest/kotlin/arrow/core/MapKTest.kt | 22 +- .../kotlin/arrow/core/NonEmptyListTest.kt | 1 - .../kotlin/arrow/core/OptionTest.kt | 126 +- .../kotlin/arrow/core/SequenceKTest.kt | 1 - .../kotlin/arrow/core/raise/IorSpec.kt | 1 - .../kotlin/arrow/core/raise/MappersSpec.kt | 2 - .../kotlin/arrow/core/test/Generators.kt | 3 - .../src/jvmTest/java/arrow/core/IorUsage.java | 4 - .../jvmTest/java/arrow/core/OptionUsage.java | 8 - .../examples/example-effect-error-01.kt | 14 + .../examples/example-effect-error-02.kt | 14 + .../examples/example-effect-error-03.kt | 16 + .../kotlin/examples/example-either-01.kt | 12 + .../kotlin/examples/example-either-02.kt | 10 + .../kotlin/examples/example-either-03.kt | 11 + .../kotlin/examples/example-either-04.kt | 11 + .../kotlin/examples/example-either-05.kt | 15 + .../kotlin/examples/example-either-06.kt | 21 + .../kotlin/examples/example-either-07.kt | 15 + .../kotlin/examples/example-either-08.kt | 27 + .../kotlin/examples/example-either-09.kt | 31 + .../kotlin/examples/example-either-10.kt | 24 + .../kotlin/examples/example-either-11.kt | 35 + .../kotlin/examples/example-either-12.kt | 16 + .../kotlin/examples/example-either-13.kt | 13 + .../kotlin/examples/example-either-14.kt | 11 + .../kotlin/examples/example-either-15.kt | 10 + .../kotlin/examples/example-either-16.kt | 10 + .../kotlin/examples/example-either-17.kt | 11 + .../kotlin/examples/example-either-18.kt | 11 + .../kotlin/examples/example-either-19.kt | 11 + .../kotlin/examples/example-either-20.kt | 16 + .../kotlin/examples/example-either-21.kt | 15 + .../kotlin/examples/example-either-22.kt | 15 + .../kotlin/examples/example-either-23.kt | 14 + .../kotlin/examples/example-either-24.kt | 10 + .../kotlin/examples/example-either-25.kt | 10 + .../kotlin/examples/example-either-26.kt | 10 + .../kotlin/examples/example-either-27.kt | 9 + .../kotlin/examples/example-either-28.kt | 9 + .../kotlin/examples/example-either-29.kt | 10 + .../kotlin/examples/example-either-30.kt | 10 + .../kotlin/examples/example-either-31.kt | 12 + .../kotlin/examples/example-either-32.kt | 10 + .../kotlin/examples/example-either-33.kt | 11 + .../kotlin/examples/example-either-34.kt | 13 + .../kotlin/examples/example-either-35.kt | 12 + .../kotlin/examples/example-either-36.kt | 12 + .../kotlin/examples/example-either-37.kt | 21 + .../jvmTest/kotlin/examples/example-ior-01.kt | 10 + .../jvmTest/kotlin/examples/example-ior-02.kt | 10 + .../jvmTest/kotlin/examples/example-ior-03.kt | 10 + .../jvmTest/kotlin/examples/example-ior-04.kt | 10 + .../jvmTest/kotlin/examples/example-ior-05.kt | 10 + .../jvmTest/kotlin/examples/example-ior-06.kt | 10 + .../jvmTest/kotlin/examples/example-ior-07.kt | 10 + .../jvmTest/kotlin/examples/example-ior-08.kt | 13 + .../jvmTest/kotlin/examples/example-ior-09.kt | 11 + .../jvmTest/kotlin/examples/example-ior-10.kt | 11 + .../jvmTest/kotlin/examples/example-ior-11.kt | 12 + .../jvmTest/kotlin/examples/example-ior-12.kt | 13 + .../kotlin/examples/example-iterable-01.kt | 19 + .../kotlin/examples/example-iterable-02.kt | 19 + .../kotlin/examples/example-iterable-03.kt | 11 + .../kotlin/examples/example-iterable-04.kt | 11 + .../kotlin/examples/example-iterable-05.kt | 11 + .../kotlin/examples/example-iterable-06.kt | 11 + .../kotlin/examples/example-iterable-07.kt | 11 + .../kotlin/examples/example-iterable-08.kt | 11 + .../kotlin/examples/example-iterable-09.kt | 11 + .../kotlin/examples/example-iterable-10.kt | 10 + .../kotlin/examples/example-iterable-11.kt | 10 + .../kotlin/examples/example-iterable-12.kt | 13 + .../kotlin/examples/example-iterable-13.kt | 13 + .../kotlin/examples/example-iterable-14.kt | 12 + .../kotlin/examples/example-iterable-15.kt | 10 + .../kotlin/examples/example-iterable-16.kt | 11 + .../kotlin/examples/example-iterable-17.kt | 12 + .../kotlin/examples/example-iterable-18.kt | 10 + .../jvmTest/kotlin/examples/example-map-01.kt | 10 + .../jvmTest/kotlin/examples/example-map-02.kt | 11 + .../jvmTest/kotlin/examples/example-map-03.kt | 10 + .../jvmTest/kotlin/examples/example-map-04.kt | 12 + .../jvmTest/kotlin/examples/example-map-05.kt | 13 + .../jvmTest/kotlin/examples/example-map-06.kt | 16 + .../jvmTest/kotlin/examples/example-map-07.kt | 12 + .../jvmTest/kotlin/examples/example-map-08.kt | 16 + .../kotlin/examples/example-memoization-01.kt | 19 + .../examples/example-nonemptylist-01.kt | 11 + .../examples/example-nonemptylist-02.kt | 10 + .../examples/example-nonemptylist-03.kt | 12 + .../examples/example-nonemptylist-04.kt | 10 + .../examples/example-nonemptylist-05.kt | 17 + .../examples/example-nonemptylist-06.kt | 20 + .../kotlin/examples/example-nonfatal-01.kt | 28 + .../examples/example-nonfatalorthrow-01.kt | 24 + .../kotlin/examples/example-option-01.kt | 13 + .../kotlin/examples/example-option-02.kt | 9 + .../kotlin/examples/example-option-03.kt | 17 + .../kotlin/examples/example-option-04.kt | 17 + .../kotlin/examples/example-option-05.kt | 17 + .../kotlin/examples/example-option-06.kt | 10 + .../kotlin/examples/example-option-07.kt | 15 + .../kotlin/examples/example-option-08.kt | 15 + .../kotlin/examples/example-option-09.kt | 17 + .../kotlin/examples/example-option-10.kt | 11 + .../kotlin/examples/example-option-11.kt | 11 + .../kotlin/examples/example-option-12.kt | 12 + .../kotlin/examples/example-option-13.kt | 14 + .../kotlin/examples/example-option-14.kt | 16 + .../kotlin/examples/example-option-15.kt | 12 + .../kotlin/examples/example-option-16.kt | 10 + .../kotlin/examples/example-option-17.kt | 10 + .../kotlin/examples/example-option-18.kt | 14 + .../kotlin/examples/example-option-19.kt | 11 + .../kotlin/examples/example-option-20.kt | 3 + .../kotlin/examples/example-option-21.kt | 14 + .../kotlin/examples/example-option-22.kt | 17 + .../kotlin/examples/example-raise-01.kt | 18 + .../kotlin/examples/example-raise-02.kt | 52 + .../kotlin/examples/example-raise-03.kt | 16 + .../kotlin/examples/example-raise-04.kt | 55 + .../kotlin/examples/example-raise-05.kt | 25 + .../kotlin/examples/example-raise-06.kt | 32 + .../kotlin/examples/example-raise-07.kt | 31 + .../kotlin/examples/example-raise-08.kt | 29 + .../kotlin/examples/example-raise-09.kt | 34 + .../kotlin/examples/example-raise-10.kt | 59 + .../kotlin/examples/example-raise-11.kt | 21 + .../kotlin/examples/example-raise-12.kt | 22 + .../kotlin/examples/example-raise-13.kt | 25 + .../kotlin/examples/example-raise-dsl-01.kt | 10 + .../kotlin/examples/example-raise-dsl-02.kt | 25 + .../kotlin/examples/example-raise-dsl-03.kt | 29 + .../kotlin/examples/example-raise-dsl-04.kt | 23 + .../kotlin/examples/example-raise-dsl-05.kt | 19 + .../kotlin/examples/example-raise-dsl-06.kt | 15 + .../kotlin/examples/example-raise-dsl-07.kt | 20 + .../kotlin/examples/example-raise-dsl-08.kt | 20 + .../kotlin/examples/example-raise-dsl-09.kt | 21 + .../kotlin/examples/example-raise-dsl-10.kt | 21 + .../kotlin/examples/example-sequence-01.kt | 22 + .../kotlin/examples/example-sequence-02.kt | 16 + .../kotlin/examples/example-sequence-03.kt | 11 + .../kotlin/examples/example-sequence-04.kt | 14 + .../kotlin/examples/example-sequence-05.kt | 14 + .../kotlin/examples/example-sequence-06.kt | 14 + .../kotlin/examples/example-sequence-07.kt | 14 + .../kotlin/examples/example-sequence-08.kt | 14 + .../kotlin/examples/example-sequence-09.kt | 14 + .../kotlin/examples/example-sequence-10.kt | 13 + .../kotlin/examples/example-sequence-11.kt | 13 + .../kotlin/examples/example-sequence-12.kt | 12 + .../kotlin/examples/example-sequence-13.kt | 11 + .../kotlin/examples/example-sequence-14.kt | 11 + .../kotlin/examples/example-sequence-15.kt | 16 + .../kotlin/examples/example-sequence-16.kt | 9 + .../kotlin/examples/example-sequence-17.kt | 15 + .../kotlin/examples/test/EitherKnitTest.kt | 69 + .../kotlin/examples/test/IterableKnitTest.kt | 77 + .../kotlin/examples/test/OptionKnitTest.kt | 17 + .../kotlin/examples/test/RaiseKnitTest.kt | 45 + .../kotlin/examples/test/SequenceKnitTest.kt | 29 + .../api/arrow-fx-coroutines.api | 252 -- .../kotlin/arrow/fx/coroutines/Race2.kt | 8 +- .../kotlin/arrow/fx/coroutines/Resource.kt | 10 +- .../kotlin/arrow/fx/coroutines/flow.kt | 55 +- .../arrow/fx/coroutines/CyclicBarrierSpec.kt | 2 +- .../kotlin/arrow/fx/coroutines/FlowTest.kt | 62 +- .../arrow/fx/coroutines/ResourceExtensions.kt | 4 +- .../kotlin/examples/example-bracket-01.kt | 25 + .../kotlin/examples/example-bracket-02.kt | 32 + .../kotlin/examples/example-flow-01.kt | 16 + .../kotlin/examples/example-flow-02.kt | 3 + .../kotlin/examples/example-flow-03.kt | 16 + .../kotlin/examples/example-parzip-01.kt | 16 + .../kotlin/examples/example-parzip-02.kt | 18 + .../kotlin/examples/example-parzip-03.kt | 17 + .../kotlin/examples/example-parzip-04.kt | 19 + .../kotlin/examples/example-parzip-05.kt | 18 + .../kotlin/examples/example-parzip-06.kt | 20 + .../kotlin/examples/example-parzip-07.kt | 19 + .../kotlin/examples/example-parzip-08.kt | 21 + .../kotlin/examples/example-parzip-09.kt | 20 + .../kotlin/examples/example-parzip-10.kt | 22 + .../kotlin/examples/example-parzip-11.kt | 21 + .../kotlin/examples/example-parzip-12.kt | 23 + .../kotlin/examples/example-parzip-13.kt | 22 + .../kotlin/examples/example-parzip-14.kt | 24 + .../kotlin/examples/example-parzip-15.kt | 23 + .../kotlin/examples/example-parzip-16.kt | 25 + .../kotlin/examples/example-race2-01.kt | 22 + .../kotlin/examples/example-race2-02.kt | 23 + .../kotlin/examples/example-resource-01.kt | 27 + .../kotlin/examples/example-resource-02.kt | 28 + .../kotlin/examples/example-resource-03.kt | 44 + .../kotlin/examples/example-resource-04.kt | 34 + .../kotlin/examples/example-resource-05.kt | 38 + .../kotlin/examples/example-resource-06.kt | 20 + .../kotlin/examples/example-resource-07.kt | 16 + .../kotlin/examples/example-resource-08.kt | 24 + .../kotlin/examples/example-resource-09.kt | 18 + .../examples/example-resourceextensions-01.kt | 26 + .../examples/example-resourceextensions-02.kt | 13 + .../examples/example-resourceextensions-03.kt | 13 + .../examples/example-resourceextensions-04.kt | 14 + .../examples/example-resourceextensions-05.kt | 14 + .../commonTest/kotlin/arrow/fx/stm/STMTest.kt | 4 +- .../optics/arrow-optics/api/arrow-optics.api | 646 +---- .../commonMain/kotlin/arrow/optics/Every.kt | 180 +- .../commonMain/kotlin/arrow/optics/Lens.kt | 3 +- .../kotlin/arrow/optics/Optional.kt | 5 +- .../commonMain/kotlin/arrow/optics/Prism.kt | 5 +- .../kotlin/arrow/optics/Traversal.kt | 211 +- .../arrow/optics/typeclasses/FilterIndex.kt | 27 +- .../kotlin/arrow/optics/typeclasses/Snoc.kt | 5 +- .../kotlin/arrow/optics/LensTest.kt | 7 - .../kotlin/arrow/optics/TraversalTest.kt | 7 - .../kotlin/arrow/optics/std/ListTest.kt | 16 - .../kotlin/arrow/optics/std/OptionTest.kt | 21 - .../kotlin/arrow/optics/std/TupleTest.kt | 12 +- 239 files changed, 3927 insertions(+), 7950 deletions(-) create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-09.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-11.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-09.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-11.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-12.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-13.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-14.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-15.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-16.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-17.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-18.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-memoization-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-09.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-11.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-12.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-13.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-14.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-15.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-16.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-09.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-11.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-12.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-13.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-01.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-02.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-03.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-04.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-05.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-06.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-07.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-08.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-09.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-10.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt create mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-01.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-02.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-03.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-01.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-02.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-03.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-04.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-05.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-06.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-07.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-08.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-09.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-10.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-11.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-12.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-13.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-14.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-15.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-16.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-01.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-02.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 3f22b9729ec..a8a751abafc 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -31,39 +31,6 @@ public final class arrow/core/Composition { public static final fun compose (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public final class arrow/core/Const { - public static final field Companion Larrow/core/Const$Companion; - public fun (Ljava/lang/Object;)V - public final fun copy (Ljava/lang/Object;)Larrow/core/Const; - public static synthetic fun copy$default (Larrow/core/Const;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Const; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Const; - public final fun retag ()Larrow/core/Const; - public fun toString ()Ljava/lang/String; - public final fun value ()Ljava/lang/Object; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function10;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function9;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function8;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function7;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function6;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function5;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function4;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Larrow/core/Const;Lkotlin/jvm/functions/Function3;)Larrow/core/Const; - public final fun zip (Larrow/typeclasses/Semigroup;Larrow/core/Const;Lkotlin/jvm/functions/Function2;)Larrow/core/Const; -} - -public final class arrow/core/Const$Companion { -} - -public final class arrow/core/ConstKt { - public static final field ConstDeprecation Ljava/lang/String; - public static final fun combine (Larrow/core/Const;Larrow/typeclasses/Semigroup;Larrow/core/Const;)Larrow/core/Const; - public static final fun compareTo (Larrow/core/Const;Larrow/core/Const;)I - public static final fun const (Ljava/lang/Object;)Larrow/core/Const; - public static final fun contramap (Larrow/core/Const;Lkotlin/jvm/functions/Function1;)Larrow/core/Const; -} - public final class arrow/core/Currying { public static final fun curried (Lkotlin/jvm/functions/Function10;)Lkotlin/jvm/functions/Function1; public static final fun curried (Lkotlin/jvm/functions/Function11;)Lkotlin/jvm/functions/Function1; @@ -152,70 +119,26 @@ public final class arrow/core/Currying { public abstract class arrow/core/Either { public static final field Companion Larrow/core/Either$Companion; - public final fun all (Lkotlin/jvm/functions/Function1;)Z - public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun bitraverseValidated (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun conditionally (ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public final fun exist (Lkotlin/jvm/functions/Function1;)Z - public final fun exists (Lkotlin/jvm/functions/Function1;)Z - public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun catch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun foldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun fromNullable (Ljava/lang/Object;)Larrow/core/Either; public final fun getOrNone ()Larrow/core/Option; public final fun getOrNull ()Ljava/lang/Object; - public final fun isEmpty ()Z public final fun isLeft ()Z public final fun isLeft (Lkotlin/jvm/functions/Function1;)Z - public final fun isNotEmpty ()Z public final fun isRight ()Z public final fun isRight (Lkotlin/jvm/functions/Function1;)Z public final fun leftOrNull ()Ljava/lang/Object; - public static final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public final fun mapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public final fun onLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public final fun onRight (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun orNone ()Larrow/core/Option; - public final fun orNull ()Ljava/lang/Object; - public final fun replicate (I)Larrow/core/Either; - public static final fun resolve (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun swap ()Larrow/core/Either; - public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun tapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun toEither ()Larrow/core/Either; public final fun toIor ()Larrow/core/Ior; public fun toString ()Ljava/lang/String; - public final fun toValidated ()Larrow/core/Validated; - public final fun toValidatedNel ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public static final fun tryCatchAndFlatten (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public final fun void ()Larrow/core/Either; } public final class arrow/core/Either$Companion { - public final fun conditionally (ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public final fun fromNullable (Ljava/lang/Object;)Larrow/core/Either; - public final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun resolve (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public final fun tryCatchAndFlatten (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; + public final fun catch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public final fun zipOrAccumulate (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function10;)Larrow/core/Either; public final fun zipOrAccumulate (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function9;)Larrow/core/Either; public final fun zipOrAccumulate (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function8;)Larrow/core/Either; @@ -258,7 +181,6 @@ public final class arrow/core/Either$Left : arrow/core/Either { } public final class arrow/core/Either$Left$Companion { - public final fun getLeftUnit ()Larrow/core/Either; } public final class arrow/core/Either$Right : arrow/core/Either { @@ -280,58 +202,19 @@ public final class arrow/core/Either$Right$Companion { public final class arrow/core/EitherKt { public static final field NicheAPI Ljava/lang/String; public static final field RedundantAPI Ljava/lang/String; - public static final fun bisequence (Larrow/core/Either;)Ljava/util/List; - public static final fun bisequenceNullable (Larrow/core/Either;)Larrow/core/Either; - public static final fun bisequenceOption (Larrow/core/Either;)Larrow/core/Option; - public static final fun bisequenceValidated (Larrow/core/Either;)Larrow/core/Validated; public static final fun combine (Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public static final fun combine (Larrow/core/Either;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Either;)Larrow/core/Either; - public static final fun combineAll (Ljava/lang/Iterable;Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/core/Either; - public static final fun combineK (Larrow/core/Either;Larrow/core/Either;)Larrow/core/Either; public static final fun compareTo (Larrow/core/Either;Larrow/core/Either;)I - public static final fun contains (Larrow/core/Either;Ljava/lang/Object;)Z - public static final fun ensure (Larrow/core/Either;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun filterOrElse (Larrow/core/Either;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public static final fun filterOrOther (Larrow/core/Either;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun flatMap (Larrow/core/Either;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun flatten (Larrow/core/Either;)Larrow/core/Either; - public static final synthetic fun getOrElse (Larrow/core/Either;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; public static final fun getOrElse (Larrow/core/Either;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun getOrHandle (Larrow/core/Either;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun handleError (Larrow/core/Either;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun handleErrorWith (Larrow/core/Either;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun left (Ljava/lang/Object;)Larrow/core/Either; - public static final fun leftIfNull (Larrow/core/Either;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public static final fun leftNel (Ljava/lang/Object;)Larrow/core/Either; public static final fun leftWiden (Larrow/core/Either;)Larrow/core/Either; public static final fun merge (Larrow/core/Either;)Ljava/lang/Object; - public static final fun orNull (Larrow/core/Either;)Ljava/lang/Object; public static final fun recover (Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public static final fun redeem (Larrow/core/Either;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun redeemWith (Larrow/core/Either;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun replicate (Larrow/core/Either;ILarrow/typeclasses/Monoid;)Larrow/core/Either; public static final fun right (Ljava/lang/Object;)Larrow/core/Either; - public static final fun rightIfNotNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public static final fun rightIfNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Either;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Either;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Either;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Either;)Ljava/util/List; - public static final fun sequenceNullable (Larrow/core/Either;)Larrow/core/Either; - public static final fun sequenceOption (Larrow/core/Either;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/Either;)Larrow/core/Validated; public static final fun toEitherNel (Larrow/core/Either;)Larrow/core/Either; public static final fun widen (Larrow/core/Either;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function10;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function9;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function8;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function7;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function6;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function5;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function4;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function3;)Larrow/core/Either; - public static final fun zip (Larrow/core/Either;Larrow/core/Either;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; } public final class arrow/core/EmptyValue { @@ -340,183 +223,27 @@ public final class arrow/core/EmptyValue { public final fun unbox (Ljava/lang/Object;)Ljava/lang/Object; } -public final class arrow/core/Endo { - public static final field Companion Larrow/core/Endo$Companion; - public fun (Lkotlin/jvm/functions/Function1;)V - public final fun combine (Larrow/core/Endo;)Larrow/core/Endo; - public final fun component1 ()Lkotlin/jvm/functions/Function1; - public final fun copy (Lkotlin/jvm/functions/Function1;)Larrow/core/Endo; - public static synthetic fun copy$default (Larrow/core/Endo;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Larrow/core/Endo; - public fun equals (Ljava/lang/Object;)Z - public final fun getF ()Lkotlin/jvm/functions/Function1; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Endo$Companion { -} - -public abstract class arrow/core/Eval { - public static final field Companion Larrow/core/Eval$Companion; - public static final fun always (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public final fun coflatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public static final fun defer (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval; - public final fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public static final fun later (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Eval; - public abstract fun memoize ()Larrow/core/Eval; - public static final fun now (Ljava/lang/Object;)Larrow/core/Eval; - public static final fun raise (Ljava/lang/Throwable;)Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public abstract fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Always : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public static synthetic fun copy$default (Larrow/core/Eval$Always;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Always; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Companion { - public final fun always (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Always; - public final fun defer (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval; - public final fun later (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public final fun now (Ljava/lang/Object;)Larrow/core/Eval; - public final fun raise (Ljava/lang/Throwable;)Larrow/core/Eval; -} - -public final class arrow/core/Eval$Defer : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun component1 ()Lkotlin/jvm/functions/Function0; - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Defer; - public static synthetic fun copy$default (Larrow/core/Eval$Defer;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Defer; - public fun equals (Ljava/lang/Object;)Z - public final fun getThunk ()Lkotlin/jvm/functions/Function0; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public abstract class arrow/core/Eval$FlatMap : arrow/core/Eval { - public fun ()V - public fun memoize ()Larrow/core/Eval; - public abstract fun run (Ljava/lang/Object;)Larrow/core/Eval; - public abstract fun start ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Later : arrow/core/Eval { - public fun (Lkotlin/jvm/functions/Function0;)V - public final fun copy (Lkotlin/jvm/functions/Function0;)Larrow/core/Eval$Later; - public static synthetic fun copy$default (Larrow/core/Eval$Later;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/core/Eval$Later; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Now : arrow/core/Eval { - public static final field Companion Larrow/core/Eval$Now$Companion; - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Eval$Now; - public static synthetic fun copy$default (Larrow/core/Eval$Now;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Eval$Now; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun memoize ()Larrow/core/Eval; - public fun toString ()Ljava/lang/String; - public fun value ()Ljava/lang/Object; -} - -public final class arrow/core/Eval$Now$Companion { - public final fun getUnit ()Larrow/core/Eval; -} - -public final class arrow/core/EvalKt { - public static final fun iterateRight (Ljava/util/Iterator;Larrow/core/Eval;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; - public static final fun replicate (Larrow/core/Eval;I)Larrow/core/Eval; - public static final fun replicate (Larrow/core/Eval;ILarrow/typeclasses/Monoid;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function10;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function9;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function8;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function7;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function6;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function5;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function4;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function3;)Larrow/core/Eval; - public static final fun zip (Larrow/core/Eval;Larrow/core/Eval;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; -} - public abstract class arrow/core/Ior { public static final field Companion Larrow/core/Ior$Companion; - public final fun _isBoth ()Z - public final fun _isLeft ()Z - public final fun _isRight ()Z - public final fun all (Lkotlin/jvm/functions/Function1;)Z - public final fun bicrosswalk (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bicrosswalkMap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/Map; - public final fun bicrosswalkNull (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun bitraverseValidated (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun bothNel (Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Ior; - public final fun crosswalk (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun crosswalkMap (Lkotlin/jvm/functions/Function1;)Ljava/util/Map; - public final fun crosswalkNull (Larrow/core/Ior;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun exists (Lkotlin/jvm/functions/Function1;)Z - public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun foldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun fromNullables (Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Ior; public final fun getOrNull ()Ljava/lang/Object; - public abstract fun isBoth ()Z + public final fun isBoth ()Z public final fun isBoth (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Z - public final fun isEmpty ()Z - public abstract fun isLeft ()Z + public final fun isLeft ()Z public final fun isLeft (Lkotlin/jvm/functions/Function1;)Z - public final fun isNotEmpty ()Z - public abstract fun isRight ()Z + public final fun isRight ()Z public final fun isRight (Lkotlin/jvm/functions/Function1;)Z public static final fun leftNel (Ljava/lang/Object;)Larrow/core/Ior; public final fun leftOrNull ()Ljava/lang/Object; - public static final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; public final fun mapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun orNull ()Ljava/lang/Object; - public final fun padNull ()Lkotlin/Pair; public final fun swap ()Larrow/core/Ior; public final fun toEither ()Larrow/core/Either; public final fun toPair ()Lkotlin/Pair; public fun toString ()Ljava/lang/String; - public final fun toValidated ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public final fun unwrap ()Larrow/core/Either; - public final fun void ()Larrow/core/Ior; } public final class arrow/core/Ior$Both : arrow/core/Ior { @@ -529,9 +256,6 @@ public final class arrow/core/Ior$Both : arrow/core/Ior { public final fun getLeftValue ()Ljava/lang/Object; public final fun getRightValue ()Ljava/lang/Object; public fun hashCode ()I - public fun isBoth ()Z - public fun isLeft ()Z - public fun isRight ()Z public fun toString ()Ljava/lang/String; } @@ -539,8 +263,6 @@ public final class arrow/core/Ior$Companion { public final fun bothNel (Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Ior; public final fun fromNullables (Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Ior; public final fun leftNel (Ljava/lang/Object;)Larrow/core/Ior; - public final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } public final class arrow/core/Ior$Left : arrow/core/Ior { @@ -552,9 +274,6 @@ public final class arrow/core/Ior$Left : arrow/core/Ior { public fun equals (Ljava/lang/Object;)Z public final fun getValue ()Ljava/lang/Object; public fun hashCode ()I - public fun isBoth ()Z - public fun isLeft ()Z - public fun isRight ()Z public fun toString ()Ljava/lang/String; } @@ -570,64 +289,28 @@ public final class arrow/core/Ior$Right : arrow/core/Ior { public fun equals (Ljava/lang/Object;)Z public final fun getValue ()Ljava/lang/Object; public fun hashCode ()I - public fun isBoth ()Z - public fun isLeft ()Z - public fun isRight ()Z public fun toString ()Ljava/lang/String; } public final class arrow/core/Ior$Right$Companion { - public final fun getUnit ()Larrow/core/Ior; } public final class arrow/core/IorKt { - public static final fun bisequence (Larrow/core/Ior;)Ljava/util/List; - public static final fun bisequenceEither (Larrow/core/Ior;)Larrow/core/Either; - public static final fun bisequenceNullable (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun bisequenceOption (Larrow/core/Ior;)Larrow/core/Option; - public static final fun bisequenceValidated (Larrow/core/Ior;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun bothIor (Lkotlin/Pair;)Larrow/core/Ior; public static final fun combine (Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/Ior; - public static final fun combine (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Ior;)Larrow/core/Ior; public static final fun compareTo (Larrow/core/Ior;Larrow/core/Ior;)I - public static final fun flatMap (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; public static final fun flatMap (Larrow/core/Ior;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public static final fun flatten (Larrow/core/Ior;Larrow/typeclasses/Semigroup;)Larrow/core/Ior; public static final fun flatten (Larrow/core/Ior;Lkotlin/jvm/functions/Function2;)Larrow/core/Ior; - public static final synthetic fun getOrElse (Larrow/core/Ior;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; public static final fun getOrElse (Larrow/core/Ior;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun leftIor (Ljava/lang/Object;)Larrow/core/Ior; - public static final fun leftWiden (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun replicate (Larrow/core/Ior;Larrow/typeclasses/Semigroup;I)Larrow/core/Ior; - public static final fun replicate (Larrow/core/Ior;Larrow/typeclasses/Semigroup;ILarrow/typeclasses/Monoid;)Larrow/core/Ior; public static final fun rightIor (Ljava/lang/Object;)Larrow/core/Ior; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Ior;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Ior;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Ior;)Larrow/core/Either; - public static final fun sequenceNullable (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun sequenceOption (Larrow/core/Ior;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/Ior;)Larrow/core/Validated; public static final fun widen (Larrow/core/Ior;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function10;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function9;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function8;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function7;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function6;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function5;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function4;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Larrow/core/Ior;Lkotlin/jvm/functions/Function3;)Larrow/core/Ior; - public static final fun zip (Larrow/core/Ior;Larrow/typeclasses/Semigroup;Larrow/core/Ior;Lkotlin/jvm/functions/Function2;)Larrow/core/Ior; } public final class arrow/core/IterableKt { public static final fun align (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List; public static final fun align (Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun collectionSizeOrDefault (Ljava/lang/Iterable;I)I - public static final fun combineAll (Ljava/lang/Iterable;Larrow/typeclasses/Monoid;)Ljava/lang/Object; public static final fun compareTo (Ljava/lang/Iterable;Ljava/lang/Iterable;)I public static final fun crosswalk (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun crosswalkMap (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/Map; @@ -642,10 +325,6 @@ public final class arrow/core/IterableKt { public static final fun flattenOption (Ljava/lang/Iterable;)Ljava/util/List; public static final fun flattenOrAccumulate (Ljava/lang/Iterable;)Larrow/core/Either; public static final fun flattenOrAccumulate (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public static final fun fold (Ljava/lang/Iterable;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun foldMap (Ljava/lang/Iterable;Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun getListUnit ()Ljava/util/List; - public static final fun ifThen (Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Iterable; public static final fun interleave (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List; public static final fun lastOrNone (Ljava/lang/Iterable;)Larrow/core/Option; public static final fun lastOrNone (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; @@ -659,50 +338,19 @@ public final class arrow/core/IterableKt { public static final fun prependTo (Ljava/lang/Object;Ljava/lang/Iterable;)Ljava/util/List; public static final fun reduceOrNull (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static final fun reduceRightNull (Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun replicate (Ljava/lang/Iterable;I)Ljava/util/List; - public static final fun replicate (Ljava/lang/Iterable;ILarrow/typeclasses/Monoid;)Ljava/util/List; public static final fun rightPadZip (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List; public static final fun rightPadZip (Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; - public static final fun salign (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Ljava/lang/Iterable;)Ljava/lang/Iterable; public static final fun separateEither (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun separateIor (Ljava/lang/Iterable;)Lkotlin/Pair; - public static final fun separateValidated (Ljava/lang/Iterable;)Lkotlin/Pair; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Either; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Validated; - public static final fun sequence (Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun sequence (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun sequence (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Ljava/lang/Iterable;)Larrow/core/Either; - public static final fun sequenceNullable (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun sequenceOption (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun sequenceResult (Ljava/lang/Iterable;)Ljava/lang/Object; - public static final fun sequenceValidated (Ljava/lang/Iterable;)Larrow/core/Validated; - public static final fun sequenceValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun singleOrNone (Ljava/lang/Iterable;)Larrow/core/Option; public static final fun singleOrNone (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun split (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun tail (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun traverse (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public static final fun traverseEither (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseNullable (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public static final fun traverseOption (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseResult (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun traverseValidated (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverseValidated (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun unalign (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; - public static final fun uniteEither (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun uniteValidated (Ljava/lang/Iterable;)Ljava/util/List; public static final fun unweave (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun unzip (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun unzip (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; - public static final fun void (Ljava/lang/Iterable;)Ljava/util/List; public static final fun widen (Ljava/lang/Iterable;)Ljava/lang/Iterable; public static final fun widen (Ljava/util/List;)Ljava/util/List; public static final fun zip (Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function10;)Ljava/util/List; @@ -718,14 +366,10 @@ public final class arrow/core/IterableKt { public final class arrow/core/MapKt { public static final fun align (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public static final fun align (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Ljava/util/Map; - public static final fun combine (Ljava/util/Map;Larrow/typeclasses/Semigroup;Ljava/util/Map;)Ljava/util/Map; public static final fun combine (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Ljava/util/Map; - public static final fun combineAll (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Ljava/util/Map; - public static final fun filterMap (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Ljava/util/Map; public static final fun filterOption (Ljava/util/Map;)Ljava/util/Map; public static final fun flatMap (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Ljava/util/Map; public static final fun fold (Ljava/util/Map;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun foldLeft (Ljava/util/Map;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static final fun getOrNone (Ljava/util/Map;Ljava/lang/Object;)Larrow/core/Option; public static final fun mapNotNull (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Ljava/util/Map; public static final fun mapOrAccumulate (Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; @@ -733,25 +377,11 @@ public final class arrow/core/MapKt { public static final fun padZip (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public static final fun padZip (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Ljava/util/Map; public static final fun padZip (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function3;)Ljava/util/Map; - public static final fun salign (Ljava/util/Map;Larrow/typeclasses/Semigroup;Ljava/util/Map;)Ljava/util/Map; public static final fun salign (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Ljava/util/Map; - public static final fun sequence (Ljava/util/Map;)Larrow/core/Either; - public static final fun sequence (Ljava/util/Map;)Larrow/core/Option; - public static final fun sequence (Ljava/util/Map;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Ljava/util/Map;)Larrow/core/Either; - public static final fun sequenceOption (Ljava/util/Map;)Larrow/core/Option; - public static final fun sequenceValidated (Ljava/util/Map;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun traverse (Ljava/util/Map;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Ljava/util/Map;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun unalign (Ljava/util/Map;)Lkotlin/Pair; public static final fun unalign (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun unzip (Ljava/util/Map;)Lkotlin/Pair; public static final fun unzip (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; - public static final fun void (Ljava/util/Map;)Ljava/util/Map; public static final fun widen (Ljava/util/Map;)Ljava/util/Map; public static final fun zip (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public static final fun zip (Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function11;)Ljava/util/Map; @@ -774,79 +404,102 @@ public final class arrow/core/Memoization { public static final fun memoize (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function5; } -public final class arrow/core/NonEmptyList : kotlin/collections/AbstractList { +public final class arrow/core/NonEmptyList : java/util/List, kotlin/jvm/internal/markers/KMappedMarker { public static final field Companion Larrow/core/NonEmptyList$Companion; - public fun (Ljava/lang/Object;Ljava/util/List;)V - public synthetic fun (Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun align (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun coflatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; + public fun add (ILjava/lang/Object;)V + public fun add (Ljava/lang/Object;)Z + public fun addAll (ILjava/util/Collection;)Z + public fun addAll (Ljava/util/Collection;)Z + public static final fun align-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final synthetic fun box-impl (Ljava/util/List;)Larrow/core/NonEmptyList; + public fun clear ()V + public static final fun coflatMap-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static fun constructor-impl (Ljava/lang/Object;Ljava/util/List;)Ljava/util/List; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public fun contains (Ljava/lang/Object;)Z + public static fun contains-impl (Ljava/util/List;Ljava/lang/Object;)Z + public fun containsAll (Ljava/util/Collection;)Z + public static fun containsAll-impl (Ljava/util/List;Ljava/util/Collection;)Z public fun equals (Ljava/lang/Object;)Z - public final fun extract ()Ljava/lang/Object; - public final fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun fromList (Ljava/util/List;)Larrow/core/Option; - public static final fun fromListUnsafe (Ljava/util/List;)Larrow/core/NonEmptyList; + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public static final fun extract-impl (Ljava/util/List;)Ljava/lang/Object; + public static final fun flatMap-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static final fun foldLeft-impl (Ljava/util/List;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun get (I)Ljava/lang/Object; + public static fun get-impl (Ljava/util/List;I)Ljava/lang/Object; public final fun getAll ()Ljava/util/List; - public final fun getHead ()Ljava/lang/Object; + public static final fun getHead-impl (Ljava/util/List;)Ljava/lang/Object; public fun getSize ()I - public final fun getTail ()Ljava/util/List; + public static fun getSize-impl (Ljava/util/List;)I + public static final fun getTail-impl (Ljava/util/List;)Ljava/util/List; public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/List;)I + public fun indexOf (Ljava/lang/Object;)I + public static fun indexOf-impl (Ljava/util/List;Ljava/lang/Object;)I public fun isEmpty ()Z - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/NonEmptyList; - public final fun padZip (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun padZip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/core/NonEmptyList; - public final fun plus (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun plus (Ljava/lang/Object;)Larrow/core/NonEmptyList; - public final fun plus (Ljava/util/List;)Larrow/core/NonEmptyList; - public final fun salign (Larrow/typeclasses/Semigroup;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun toList ()Ljava/util/List; + public static fun isEmpty-impl (Ljava/util/List;)Z + public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl (Ljava/util/List;)Ljava/util/Iterator; + public fun lastIndexOf (Ljava/lang/Object;)I + public static fun lastIndexOf-impl (Ljava/util/List;Ljava/lang/Object;)I + public fun listIterator ()Ljava/util/ListIterator; + public fun listIterator (I)Ljava/util/ListIterator; + public static fun listIterator-impl (Ljava/util/List;)Ljava/util/ListIterator; + public static fun listIterator-impl (Ljava/util/List;I)Ljava/util/ListIterator; + public static final fun map-0-xjo5U (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/util/List; + public static final fun padZip-YfahJLU (Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun padZip-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun plus-0-xjo5U (Ljava/util/List;Ljava/lang/Object;)Ljava/util/List; + public static final fun plus-0-xjo5U (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun plus-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public fun remove (I)Ljava/lang/Object; + public fun remove (Ljava/lang/Object;)Z + public fun removeAll (Ljava/util/Collection;)Z + public fun replaceAll (Ljava/util/function/UnaryOperator;)V + public fun retainAll (Ljava/util/Collection;)Z + public fun set (ILjava/lang/Object;)Ljava/lang/Object; + public synthetic fun size ()I + public fun sort (Ljava/util/Comparator;)V + public fun subList (II)Ljava/util/List; + public static fun subList-impl (Ljava/util/List;II)Ljava/util/List; + public fun toArray ()[Ljava/lang/Object; + public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object; + public static final fun toList-impl (Ljava/util/List;)Ljava/util/List; public fun toString ()Ljava/lang/String; - public final fun zip (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function10;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function9;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function8;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function7;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function6;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function5;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function4;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function3;)Larrow/core/NonEmptyList; - public final fun zip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function2;)Larrow/core/NonEmptyList; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; + public static final fun zip-BdUWqYY (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function5;)Ljava/util/List; + public static final fun zip-EkAgaZI (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function10;)Ljava/util/List; + public static final fun zip-FrVv2gs (Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun zip-QNErI5A (Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function3;)Ljava/util/List; + public static final fun zip-Sy0iXXA (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function4;)Ljava/util/List; + public static final fun zip-Vwi0aTY (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function7;)Ljava/util/List; + public static final fun zip-e5uF9gA (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function6;)Ljava/util/List; + public static final fun zip-oYG1GSg (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function8;)Ljava/util/List; + public static final fun zip-vcjLgH4 (Ljava/util/List;Ljava/util/List;)Ljava/util/List; + public static final fun zip-vi6g5TI (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function9;)Ljava/util/List; } public final class arrow/core/NonEmptyList$Companion { - public final fun fromList (Ljava/util/List;)Larrow/core/Option; - public final fun fromListUnsafe (Ljava/util/List;)Larrow/core/NonEmptyList; - public final fun getUnit ()Larrow/core/NonEmptyList; + public final fun getUnit-1X0FA-Y ()Ljava/util/List; } public final class arrow/core/NonEmptyListKt { - public static final fun compareTo (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)I - public static final fun flatten (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public static final fun mapOrAccumulate (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public static final fun mapOrAccumulate (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public static final fun max (Larrow/core/NonEmptyList;)Ljava/lang/Comparable; - public static final fun maxBy (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun min (Larrow/core/NonEmptyList;)Ljava/lang/Comparable; - public static final fun minBy (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun nel (Ljava/lang/Object;)Larrow/core/NonEmptyList; - public static final fun nonEmptyListOf (Ljava/lang/Object;[Ljava/lang/Object;)Larrow/core/NonEmptyList; - public static final fun sequence (Larrow/core/NonEmptyList;)Larrow/core/Either; - public static final fun sequence (Larrow/core/NonEmptyList;)Larrow/core/Option; - public static final fun sequence (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Larrow/core/NonEmptyList;)Larrow/core/Either; - public static final fun sequenceOption (Larrow/core/NonEmptyList;)Larrow/core/Option; - public static final fun sequenceValidated (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; + public static final fun compareTo-8QhqC-A (Ljava/util/List;Ljava/util/List;)I + public static final fun flatten-GZgkXh4 (Ljava/util/List;)Ljava/util/List; + public static final fun mapOrAccumulate-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; + public static final fun mapOrAccumulate-lNWZWLA (Ljava/util/List;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/Either; + public static final fun max-GZgkXh4 (Ljava/util/List;)Ljava/lang/Comparable; + public static final fun maxBy-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun min-GZgkXh4 (Ljava/util/List;)Ljava/lang/Comparable; + public static final fun minBy-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun nel (Ljava/lang/Object;)Ljava/util/List; + public static final fun nonEmptyListOf (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/util/List; public static final fun toNonEmptyListOrNone (Ljava/lang/Iterable;)Larrow/core/Option; - public static final fun toNonEmptyListOrNull (Ljava/lang/Iterable;)Larrow/core/NonEmptyList; - public static final fun traverse (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun traverse (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverse (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Larrow/core/NonEmptyList;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun unzip (Larrow/core/NonEmptyList;)Lkotlin/Pair; - public static final fun unzip (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; + public static final fun toNonEmptyListOrNull (Ljava/lang/Iterable;)Ljava/util/List; + public static final fun unzip-GZgkXh4 (Ljava/util/List;)Lkotlin/Pair; + public static final fun unzip-ZALtuoE (Ljava/util/List;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; } public final class arrow/core/NonEmptySet : java/util/Set, kotlin/jvm/internal/markers/KMappedMarker { @@ -902,137 +555,50 @@ public final class arrow/core/NonFatalOrThrowKt { public final class arrow/core/None : arrow/core/Option { public static final field INSTANCE Larrow/core/None; - public fun isEmpty ()Z public fun toString ()Ljava/lang/String; } -public final class arrow/core/Nullable { - public static final field INSTANCE Larrow/core/Nullable; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function10;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function9;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function8;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function7;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function6;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function5;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function4;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - public abstract class arrow/core/Option { public static final field Companion Larrow/core/Option$Companion; - public final fun align (Larrow/core/Option;)Larrow/core/Option; - public final fun align (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun all (Lkotlin/jvm/functions/Function1;)Z - public final fun and (Larrow/core/Option;)Larrow/core/Option; - public final fun crosswalk (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun crosswalkMap (Lkotlin/jvm/functions/Function1;)Ljava/util/Map; - public final fun crosswalkNull (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun exists (Lkotlin/jvm/functions/Function1;)Z public final fun filter (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public final fun filterNot (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public final fun fold (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun foldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun fromNullable (Ljava/lang/Object;)Larrow/core/Option; public final fun getOrNull ()Ljava/lang/Object; public static final fun invoke (Ljava/lang/Object;)Larrow/core/Option; - public final fun isDefined ()Z - public abstract fun isEmpty ()Z public final fun isNone ()Z - public final fun isNotEmpty ()Z public final fun isSome ()Z public final fun isSome (Lkotlin/jvm/functions/Function1;)Z - public static final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun mapNotNull (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun nonEmpty ()Z public final fun onNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public final fun onSome (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun orNull ()Ljava/lang/Object; - public final fun padZip (Larrow/core/Option;)Larrow/core/Option; - public final fun padZip (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public final fun pairLeft (Ljava/lang/Object;)Larrow/core/Option; - public final fun pairRight (Ljava/lang/Object;)Larrow/core/Option; - public final fun reduceOrNull (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun reduceRightEvalOrNull (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; - public final fun replicate (I)Larrow/core/Option; - public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun tapNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public final fun toEither (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; public final fun toList ()Ljava/util/List; public fun toString ()Ljava/lang/String; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public static final fun tryCatchOrNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; - public final fun void ()Larrow/core/Option; - public final fun zip (Larrow/core/Option;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function10;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function9;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function8;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function7;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function6;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function5;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function4;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function3;)Larrow/core/Option; - public final fun zip (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Larrow/core/Option; } public final class arrow/core/Option$Companion { public final fun fromNullable (Ljava/lang/Object;)Larrow/core/Option; public final fun invoke (Ljava/lang/Object;)Larrow/core/Option; - public final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public final fun tryCatchOrNone (Lkotlin/jvm/functions/Function0;)Larrow/core/Option; } public final class arrow/core/OptionKt { public static final fun combine (Larrow/core/Option;Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public static final fun combine (Larrow/core/Option;Larrow/typeclasses/Semigroup;Larrow/core/Option;)Larrow/core/Option; - public static final fun combineAll (Larrow/core/Option;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun combineAll (Ljava/lang/Iterable;Larrow/typeclasses/Monoid;)Larrow/core/Option; public static final fun compareTo (Larrow/core/Option;Larrow/core/Option;)I - public static final fun ensure (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun flatten (Larrow/core/Option;)Larrow/core/Option; public static final fun getOrElse (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static final fun handleError (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun handleErrorWith (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun maybe (ZLkotlin/jvm/functions/Function0;)Larrow/core/Option; public static final fun none ()Larrow/core/Option; - public static final fun or (Larrow/core/Option;Larrow/core/Option;)Larrow/core/Option; - public static final fun orElse (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Larrow/core/Option; public static final fun recover (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public static final fun redeem (Larrow/core/Option;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun redeemWith (Larrow/core/Option;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun replicate (Larrow/core/Option;ILarrow/typeclasses/Monoid;)Larrow/core/Option; - public static final fun rethrow (Larrow/core/Option;)Larrow/core/Option; - public static final fun salign (Larrow/core/Option;Larrow/typeclasses/Semigroup;Larrow/core/Option;)Larrow/core/Option; - public static final fun separateEither (Larrow/core/Option;)Lkotlin/Pair; - public static final fun separateValidated (Larrow/core/Option;)Lkotlin/Pair; - public static final fun sequence (Larrow/core/Option;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Option;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Option;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Option;)Larrow/core/Either; - public static final fun sequenceValidated (Larrow/core/Option;)Larrow/core/Validated; public static final fun some (Ljava/lang/Object;)Larrow/core/Option; public static final fun toMap (Larrow/core/Option;)Ljava/util/Map; public static final fun toOption (Ljava/lang/Object;)Larrow/core/Option; public static final fun toOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun unalign (Larrow/core/Option;)Lkotlin/Pair; - public static final fun unalign (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; - public static final fun unite (Larrow/core/Option;Larrow/typeclasses/Monoid;)Larrow/core/Option; - public static final fun uniteEither (Larrow/core/Option;)Larrow/core/Option; - public static final fun uniteValidated (Larrow/core/Option;)Larrow/core/Option; - public static final fun unzip (Larrow/core/Option;)Lkotlin/Pair; - public static final fun unzip (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun widen (Larrow/core/Option;)Larrow/core/Option; } @@ -1546,41 +1112,22 @@ public final class arrow/core/Partials { } public final class arrow/core/PredefKt { - public static final fun emptyCombine (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static final fun identity (Ljava/lang/Object;)Ljava/lang/Object; } public final class arrow/core/ResultKt { - public static final fun composeErrors ([Ljava/lang/Throwable;)Ljava/lang/Throwable; public static final fun flatMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun getUnitResult ()Ljava/lang/Object; public static final fun handleErrorWith (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun redeemWith (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function10;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function9;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function8;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function7;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function6;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function5;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function4;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;)Ljava/lang/Object; - public static final fun zip (Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; } public final class arrow/core/SequenceKt { public static final fun align (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun align (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; - public static final fun combineAll (Lkotlin/sequences/Sequence;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun crosswalk (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; - public static final fun crosswalkMap (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/util/Map; - public static final fun crosswalkNull (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; + public static final fun crosswalk (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun crosswalkNullList (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public static final fun crosswalkT (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun filterOption (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun flatten (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; - public static final fun fold (Lkotlin/sequences/Sequence;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun foldMap (Lkotlin/sequences/Sequence;Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun ifThen (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; public static final fun interleave (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun leftPadZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun leftPadZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; @@ -1590,42 +1137,21 @@ public final class arrow/core/SequenceKt { public static final fun once (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun padZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun padZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; - public static final fun replicate (Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence; - public static final fun replicate (Lkotlin/sequences/Sequence;ILarrow/typeclasses/Monoid;)Lkotlin/sequences/Sequence; public static final fun rightPadZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun rightPadZip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; - public static final fun salign (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun salign (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence; - public static final fun separateEither (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun separateEitherToPair (Lkotlin/sequences/Sequence;)Lkotlin/Pair; - public static final fun separateValidated (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun sequence (Lkotlin/sequences/Sequence;)Larrow/core/Either; public static final fun sequence (Lkotlin/sequences/Sequence;)Larrow/core/Option; - public static final fun sequence (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun sequenceEither (Lkotlin/sequences/Sequence;)Larrow/core/Either; - public static final fun sequenceOption (Lkotlin/sequences/Sequence;)Larrow/core/Option; - public static final fun sequenceValidated (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; - public static final fun some (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun split (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun tail (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; - public static final fun traverse (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; public static final fun traverse (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun traverse (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseEither (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public static final fun traverseOption (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun traverseValidated (Lkotlin/sequences/Sequence;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun unalign (Lkotlin/sequences/Sequence;)Lkotlin/Pair; - public static final fun unalign (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun unalignToPair (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun unalignToPair (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; - public static final fun uniteEither (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; - public static final fun uniteValidated (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun unweave (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; - public static final fun unzip (Lkotlin/sequences/Sequence;)Lkotlin/Pair; - public static final fun unzip (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; public static final fun unzipToPair (Lkotlin/sequences/Sequence;)Lkotlin/Pair; public static final fun unzipToPair (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair; - public static final fun void (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun widen (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence; public static final fun zip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function3;)Lkotlin/sequences/Sequence; public static final fun zip (Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function4;)Lkotlin/sequences/Sequence; @@ -1646,12 +1172,10 @@ public final class arrow/core/Some : arrow/core/Option { public fun equals (Ljava/lang/Object;)Z public final fun getValue ()Ljava/lang/Object; public fun hashCode ()I - public fun isEmpty ()Z public fun toString ()Ljava/lang/String; } public final class arrow/core/Some$Companion { - public final fun getUnit ()Larrow/core/Option; } public final class arrow/core/SortedMapKKt { @@ -1662,159 +1186,106 @@ public final class arrow/core/StringKt { public static final fun escaped (Ljava/lang/String;)Ljava/lang/String; } -public final class arrow/core/Tuple10 { - public static final field Companion Larrow/core/Tuple10$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple4 { + public static final field Companion Larrow/core/Tuple4$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple10; - public static synthetic fun copy$default (Larrow/core/Tuple10;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple10; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple4; + public static synthetic fun copy$default (Larrow/core/Tuple4;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple4; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple10$Companion { +public final class arrow/core/Tuple4$Companion { } -public final class arrow/core/Tuple11 { - public static final field Companion Larrow/core/Tuple11$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple5 { + public static final field Companion Larrow/core/Tuple5$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple11; - public static synthetic fun copy$default (Larrow/core/Tuple11;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple11; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple5; + public static synthetic fun copy$default (Larrow/core/Tuple5;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple5; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple11$Companion { +public final class arrow/core/Tuple5$Companion { } -public final class arrow/core/Tuple12 { - public static final field Companion Larrow/core/Tuple12$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple6 { + public static final field Companion Larrow/core/Tuple6$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; public final fun component5 ()Ljava/lang/Object; public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple12; - public static synthetic fun copy$default (Larrow/core/Tuple12;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple12; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple6; + public static synthetic fun copy$default (Larrow/core/Tuple6;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple6; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple12$Companion { +public final class arrow/core/Tuple6$Companion { } -public final class arrow/core/Tuple13 { - public static final field Companion Larrow/core/Tuple13$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple7 { + public static final field Companion Larrow/core/Tuple7$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; public final fun component5 ()Ljava/lang/Object; public final fun component6 ()Ljava/lang/Object; public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple13; - public static synthetic fun copy$default (Larrow/core/Tuple13;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple13; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple7; + public static synthetic fun copy$default (Larrow/core/Tuple7;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple7; public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple13$Companion { +public final class arrow/core/Tuple7$Companion { } -public final class arrow/core/Tuple14 { - public static final field Companion Larrow/core/Tuple14$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple8 { + public static final field Companion Larrow/core/Tuple8$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; @@ -1822,41 +1293,28 @@ public final class arrow/core/Tuple14 { public final fun component6 ()Ljava/lang/Object; public final fun component7 ()Ljava/lang/Object; public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple14; - public static synthetic fun copy$default (Larrow/core/Tuple14;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple14; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple8; + public static synthetic fun copy$default (Larrow/core/Tuple8;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple8; public fun equals (Ljava/lang/Object;)Z public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple14$Companion { +public final class arrow/core/Tuple8$Companion { } -public final class arrow/core/Tuple15 { - public static final field Companion Larrow/core/Tuple15$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V +public final class arrow/core/Tuple9 { + public static final field Companion Larrow/core/Tuple9$Companion; + public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; public final fun component2 ()Ljava/lang/Object; public final fun component3 ()Ljava/lang/Object; public final fun component4 ()Ljava/lang/Object; @@ -1865,1552 +1323,173 @@ public final class arrow/core/Tuple15 { public final fun component7 ()Ljava/lang/Object; public final fun component8 ()Ljava/lang/Object; public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple15; - public static synthetic fun copy$default (Larrow/core/Tuple15;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple15; + public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple9; + public static synthetic fun copy$default (Larrow/core/Tuple9;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple9; public fun equals (Ljava/lang/Object;)Z public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; public final fun getFifth ()Ljava/lang/Object; public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; public final fun getFourth ()Ljava/lang/Object; public final fun getNinth ()Ljava/lang/Object; public final fun getSecond ()Ljava/lang/Object; public final fun getSeventh ()Ljava/lang/Object; public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class arrow/core/Tuple15$Companion { -} - -public final class arrow/core/Tuple16 { - public static final field Companion Larrow/core/Tuple16$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple16; - public static synthetic fun copy$default (Larrow/core/Tuple16;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple16; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public final class arrow/core/Tuple9$Companion { } -public final class arrow/core/Tuple16$Companion { +public final class arrow/core/TupleNKt { + public static final fun compareTo (Larrow/core/Tuple4;Larrow/core/Tuple4;)I + public static final fun compareTo (Larrow/core/Tuple5;Larrow/core/Tuple5;)I + public static final fun compareTo (Larrow/core/Tuple6;Larrow/core/Tuple6;)I + public static final fun compareTo (Larrow/core/Tuple7;Larrow/core/Tuple7;)I + public static final fun compareTo (Larrow/core/Tuple8;Larrow/core/Tuple8;)I + public static final fun compareTo (Larrow/core/Tuple9;Larrow/core/Tuple9;)I + public static final fun compareTo (Lkotlin/Pair;Lkotlin/Pair;)I + public static final fun compareTo (Lkotlin/Triple;Lkotlin/Triple;)I + public static final fun plus (Larrow/core/Tuple4;Ljava/lang/Object;)Larrow/core/Tuple5; + public static final fun plus (Larrow/core/Tuple5;Ljava/lang/Object;)Larrow/core/Tuple6; + public static final fun plus (Larrow/core/Tuple6;Ljava/lang/Object;)Larrow/core/Tuple7; + public static final fun plus (Larrow/core/Tuple7;Ljava/lang/Object;)Larrow/core/Tuple8; + public static final fun plus (Larrow/core/Tuple8;Ljava/lang/Object;)Larrow/core/Tuple9; + public static final fun plus (Lkotlin/Pair;Ljava/lang/Object;)Lkotlin/Triple; + public static final fun plus (Lkotlin/Triple;Ljava/lang/Object;)Larrow/core/Tuple4; } -public final class arrow/core/Tuple17 { - public static final field Companion Larrow/core/Tuple17$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple17; - public static synthetic fun copy$default (Larrow/core/Tuple17;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple17; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public final class arrow/core/UtilsKt { + public static final field DeprecatedAmbiguity Ljava/lang/String; + public static final field DeprecatedUnsafeAccess Ljava/lang/String; + public static final fun constant (Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; + public static final fun mapNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public final class arrow/core/Tuple17$Companion { +public final class arrow/core/raise/DefaultRaise : arrow/core/raise/Raise { + public fun (Z)V + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; + public fun bindAll (Ljava/util/Map;)Ljava/util/Map; + public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; + public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; + public final fun complete ()Z + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun isTraced ()Z + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; } -public final class arrow/core/Tuple18 { - public static final field Companion Larrow/core/Tuple18$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple18; - public static synthetic fun copy$default (Larrow/core/Tuple18;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple18; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public abstract interface annotation class arrow/core/raise/ExperimentalTraceApi : java/lang/annotation/Annotation { } -public final class arrow/core/Tuple18$Companion { -} - -public final class arrow/core/Tuple19 { - public static final field Companion Larrow/core/Tuple19$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple19; - public static synthetic fun copy$default (Larrow/core/Tuple19;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple19; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple19$Companion { -} - -public final class arrow/core/Tuple20 { - public static final field Companion Larrow/core/Tuple20$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple20; - public static synthetic fun copy$default (Larrow/core/Tuple20;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple20; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple20$Companion { -} - -public final class arrow/core/Tuple21 { - public static final field Companion Larrow/core/Tuple21$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component21 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple21; - public static synthetic fun copy$default (Larrow/core/Tuple21;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple21; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public final fun getTwentyFirst ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple21$Companion { -} - -public final class arrow/core/Tuple22 { - public static final field Companion Larrow/core/Tuple22$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component10 ()Ljava/lang/Object; - public final fun component11 ()Ljava/lang/Object; - public final fun component12 ()Ljava/lang/Object; - public final fun component13 ()Ljava/lang/Object; - public final fun component14 ()Ljava/lang/Object; - public final fun component15 ()Ljava/lang/Object; - public final fun component16 ()Ljava/lang/Object; - public final fun component17 ()Ljava/lang/Object; - public final fun component18 ()Ljava/lang/Object; - public final fun component19 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component20 ()Ljava/lang/Object; - public final fun component21 ()Ljava/lang/Object; - public final fun component22 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple22; - public static synthetic fun copy$default (Larrow/core/Tuple22;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple22; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighteenth ()Ljava/lang/Object; - public final fun getEighth ()Ljava/lang/Object; - public final fun getEleventh ()Ljava/lang/Object; - public final fun getFifteenth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourteenth ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNineteenth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventeenth ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixteenth ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getTenth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public final fun getThirteenth ()Ljava/lang/Object; - public final fun getTwelfth ()Ljava/lang/Object; - public final fun getTwentieth ()Ljava/lang/Object; - public final fun getTwentyFirst ()Ljava/lang/Object; - public final fun getTwentySecond ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple22$Companion { -} - -public final class arrow/core/Tuple4 { - public static final field Companion Larrow/core/Tuple4$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple4; - public static synthetic fun copy$default (Larrow/core/Tuple4;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple4; - public fun equals (Ljava/lang/Object;)Z - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple4$Companion { -} - -public final class arrow/core/Tuple5 { - public static final field Companion Larrow/core/Tuple5$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple5; - public static synthetic fun copy$default (Larrow/core/Tuple5;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple5; - public fun equals (Ljava/lang/Object;)Z - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple5$Companion { -} - -public final class arrow/core/Tuple6 { - public static final field Companion Larrow/core/Tuple6$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple6; - public static synthetic fun copy$default (Larrow/core/Tuple6;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple6; - public fun equals (Ljava/lang/Object;)Z - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple6$Companion { -} - -public final class arrow/core/Tuple7 { - public static final field Companion Larrow/core/Tuple7$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple7; - public static synthetic fun copy$default (Larrow/core/Tuple7;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple7; - public fun equals (Ljava/lang/Object;)Z - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple7$Companion { -} - -public final class arrow/core/Tuple8 { - public static final field Companion Larrow/core/Tuple8$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple8; - public static synthetic fun copy$default (Larrow/core/Tuple8;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple8; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple8$Companion { -} - -public final class arrow/core/Tuple9 { - public static final field Companion Larrow/core/Tuple9$Companion; - public fun (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Ljava/lang/Object; - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Ljava/lang/Object; - public final fun component5 ()Ljava/lang/Object; - public final fun component6 ()Ljava/lang/Object; - public final fun component7 ()Ljava/lang/Object; - public final fun component8 ()Ljava/lang/Object; - public final fun component9 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Larrow/core/Tuple9; - public static synthetic fun copy$default (Larrow/core/Tuple9;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Tuple9; - public fun equals (Ljava/lang/Object;)Z - public final fun getEighth ()Ljava/lang/Object; - public final fun getFifth ()Ljava/lang/Object; - public final fun getFirst ()Ljava/lang/Object; - public final fun getFourth ()Ljava/lang/Object; - public final fun getNinth ()Ljava/lang/Object; - public final fun getSecond ()Ljava/lang/Object; - public final fun getSeventh ()Ljava/lang/Object; - public final fun getSixth ()Ljava/lang/Object; - public final fun getThird ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Tuple9$Companion { -} - -public final class arrow/core/TupleNKt { - public static final fun combine (Lkotlin/Pair;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Lkotlin/Pair;)Lkotlin/Pair; - public static final fun compareTo (Larrow/core/Tuple10;Larrow/core/Tuple10;)I - public static final fun compareTo (Larrow/core/Tuple4;Larrow/core/Tuple4;)I - public static final fun compareTo (Larrow/core/Tuple5;Larrow/core/Tuple5;)I - public static final fun compareTo (Larrow/core/Tuple6;Larrow/core/Tuple6;)I - public static final fun compareTo (Larrow/core/Tuple7;Larrow/core/Tuple7;)I - public static final fun compareTo (Larrow/core/Tuple8;Larrow/core/Tuple8;)I - public static final fun compareTo (Larrow/core/Tuple9;Larrow/core/Tuple9;)I - public static final fun compareTo (Lkotlin/Pair;Lkotlin/Pair;)I - public static final fun compareTo (Lkotlin/Triple;Lkotlin/Triple;)I - public static final fun plus (Larrow/core/Tuple10;Ljava/lang/Object;)Larrow/core/Tuple11; - public static final fun plus (Larrow/core/Tuple11;Ljava/lang/Object;)Larrow/core/Tuple12; - public static final fun plus (Larrow/core/Tuple12;Ljava/lang/Object;)Larrow/core/Tuple13; - public static final fun plus (Larrow/core/Tuple13;Ljava/lang/Object;)Larrow/core/Tuple14; - public static final fun plus (Larrow/core/Tuple14;Ljava/lang/Object;)Larrow/core/Tuple15; - public static final fun plus (Larrow/core/Tuple15;Ljava/lang/Object;)Larrow/core/Tuple16; - public static final fun plus (Larrow/core/Tuple16;Ljava/lang/Object;)Larrow/core/Tuple17; - public static final fun plus (Larrow/core/Tuple17;Ljava/lang/Object;)Larrow/core/Tuple18; - public static final fun plus (Larrow/core/Tuple18;Ljava/lang/Object;)Larrow/core/Tuple19; - public static final fun plus (Larrow/core/Tuple19;Ljava/lang/Object;)Larrow/core/Tuple20; - public static final fun plus (Larrow/core/Tuple20;Ljava/lang/Object;)Larrow/core/Tuple21; - public static final fun plus (Larrow/core/Tuple21;Ljava/lang/Object;)Larrow/core/Tuple22; - public static final fun plus (Larrow/core/Tuple4;Ljava/lang/Object;)Larrow/core/Tuple5; - public static final fun plus (Larrow/core/Tuple5;Ljava/lang/Object;)Larrow/core/Tuple6; - public static final fun plus (Larrow/core/Tuple6;Ljava/lang/Object;)Larrow/core/Tuple7; - public static final fun plus (Larrow/core/Tuple7;Ljava/lang/Object;)Larrow/core/Tuple8; - public static final fun plus (Larrow/core/Tuple8;Ljava/lang/Object;)Larrow/core/Tuple9; - public static final fun plus (Larrow/core/Tuple9;Ljava/lang/Object;)Larrow/core/Tuple10; - public static final fun plus (Lkotlin/Pair;Ljava/lang/Object;)Lkotlin/Triple; - public static final fun plus (Lkotlin/Triple;Ljava/lang/Object;)Larrow/core/Tuple4; -} - -public final class arrow/core/UtilsKt { - public static final field DeprecatedAmbiguity Ljava/lang/String; - public static final field DeprecatedUnsafeAccess Ljava/lang/String; - public static final fun constant (Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; - public static final fun mapNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; -} - -public abstract class arrow/core/Validated { - public static final field Companion Larrow/core/Validated$Companion; - public final fun all (Lkotlin/jvm/functions/Function1;)Z - public final fun bifoldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun bifoldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun bitraverse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun bitraverseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun bitraverseNullable (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun bitraverseOption (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun catchNel (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun exist (Lkotlin/jvm/functions/Function1;)Z - public final fun findOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun foldLeft (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun foldMap (Larrow/typeclasses/Monoid;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun fromEither (Larrow/core/Either;)Larrow/core/Validated; - public static final fun fromNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun fromOption (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun isEmpty ()Z - public final fun isInvalid ()Z - public final fun isNotEmpty ()Z - public final fun isValid ()Z - public static final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun mapLeft (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun swap ()Larrow/core/Validated; - public final fun tap (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun tapInvalid (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun toEither ()Larrow/core/Either; - public final fun toList ()Ljava/util/List; - public final fun toOption ()Larrow/core/Option; - public fun toString ()Ljava/lang/String; - public final fun toValidatedNel ()Larrow/core/Validated; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public final fun traverse (Lkotlin/jvm/functions/Function1;)Ljava/util/List; - public final fun traverseEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; - public final fun traverseNullable (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public final fun traverseOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun void ()Larrow/core/Validated; - public final fun withEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; -} - -public final class arrow/core/Validated$Companion { - public final fun catchNel (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun fromEither (Larrow/core/Either;)Larrow/core/Validated; - public final fun fromNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun fromOption (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public final fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun lift (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public final fun tryCatch (Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun tryCatch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; -} - -public final class arrow/core/Validated$Invalid : arrow/core/Validated { - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Validated$Invalid; - public static synthetic fun copy$default (Larrow/core/Validated$Invalid;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Validated$Invalid; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Validated$Valid : arrow/core/Validated { - public static final field Companion Larrow/core/Validated$Valid$Companion; - public fun (Ljava/lang/Object;)V - public final fun component1 ()Ljava/lang/Object; - public final fun copy (Ljava/lang/Object;)Larrow/core/Validated$Valid; - public static synthetic fun copy$default (Larrow/core/Validated$Valid;Ljava/lang/Object;ILjava/lang/Object;)Larrow/core/Validated$Valid; - public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/Validated$Valid$Companion { - public final fun getUnit ()Larrow/core/Validated; -} - -public final class arrow/core/ValidatedKt { - public static final fun andThen (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun attempt (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun bisequence (Larrow/core/Validated;)Ljava/util/List; - public static final fun bisequenceEither (Larrow/core/Validated;)Larrow/core/Either; - public static final fun bisequenceNullable (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun bisequenceOption (Larrow/core/Validated;)Larrow/core/Option; - public static final fun combine (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun combineAll (Larrow/core/Validated;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun combineK (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun compareTo (Larrow/core/Validated;Larrow/core/Validated;)I - public static final fun findValid (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun fold (Larrow/core/Validated;Larrow/typeclasses/Monoid;)Ljava/lang/Object; - public static final fun getOrElse (Larrow/core/Validated;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; - public static final fun handleError (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun handleErrorWith (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun invalid (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun invalidNel (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun leftWiden (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun merge (Larrow/core/Validated;)Ljava/lang/Object; - public static final fun orElse (Larrow/core/Validated;Lkotlin/jvm/functions/Function0;)Larrow/core/Validated; - public static final fun orNone (Larrow/core/Validated;)Larrow/core/Option; - public static final fun orNull (Larrow/core/Validated;)Ljava/lang/Object; - public static final fun redeem (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun replicate (Larrow/core/Validated;Larrow/typeclasses/Semigroup;I)Larrow/core/Validated; - public static final fun replicate (Larrow/core/Validated;Larrow/typeclasses/Semigroup;ILarrow/typeclasses/Monoid;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Either; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Option; - public static final fun sequence (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun sequence (Larrow/core/Validated;)Ljava/util/List; - public static final fun sequenceEither (Larrow/core/Validated;)Larrow/core/Either; - public static final fun sequenceNullable (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun sequenceOption (Larrow/core/Validated;)Larrow/core/Option; - public static final fun toIor (Larrow/core/Validated;)Larrow/core/Ior; - public static final fun valid (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun validNel (Ljava/lang/Object;)Larrow/core/Validated; - public static final fun valueOr (Larrow/core/Validated;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun widen (Larrow/core/Validated;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function10;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function9;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function8;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function7;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function6;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function5;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function4;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function3;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function2;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function10;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function9;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function8;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function7;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function6;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function5;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function4;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Larrow/core/Validated;Lkotlin/jvm/functions/Function3;)Larrow/core/Validated; - public static final fun zip (Larrow/core/Validated;Larrow/typeclasses/Semigroup;Larrow/core/Validated;Lkotlin/jvm/functions/Function2;)Larrow/core/Validated; -} - -public abstract interface class arrow/core/computations/EitherEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EitherEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/EitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/EitherEffect;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/EitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/EitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EitherKt { - public static final fun ensureNotNull (Larrow/core/computations/EitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/EvalEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/EvalEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/EvalEffect;Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/NullableEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/NullableEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/NullableEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/NullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/NullableEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/NullableKt { - public static final fun ensureNotNull (Larrow/core/computations/NullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/OptionEffect : arrow/continuations/Effect { - public abstract fun bind (Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/OptionEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/OptionEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/OptionEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/OptionKt { - public static final fun ensureNotNull (Larrow/core/computations/OptionEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedEitherEffect : arrow/core/computations/EitherEffect { -} - -public final class arrow/core/computations/RestrictedEitherEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedEitherEffect;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedEitherEffect;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedEvalEffect : arrow/core/computations/EvalEffect { -} - -public final class arrow/core/computations/RestrictedEvalEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedEvalEffect;Larrow/core/Eval;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedNullableEffect : arrow/core/computations/NullableEffect { -} - -public final class arrow/core/computations/RestrictedNullableEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedNullableEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/computations/RestrictedNullableEffect;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedNullableEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/computations/RestrictedOptionEffect : arrow/core/computations/OptionEffect { -} - -public final class arrow/core/computations/RestrictedOptionEffect$DefaultImpls { - public static fun bind (Larrow/core/computations/RestrictedOptionEffect;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/computations/RestrictedOptionEffect;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/ResultEffect { - public static final field INSTANCE Larrow/core/computations/ResultEffect; - public final fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/core/computations/either { - public static final field INSTANCE Larrow/core/computations/either; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/eval { - public static final field INSTANCE Larrow/core/computations/eval; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Eval; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/nullable { - public static final field INSTANCE Larrow/core/computations/nullable; - public final fun eager (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/option { - public static final field INSTANCE Larrow/core/computations/option; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/computations/result { - public static final field INSTANCE Larrow/core/computations/result; - public final fun invoke-IoAF18A (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/AtomicRefKt { - public static final fun getAndUpdate (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun loop (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; - public static final fun update (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)V - public static final fun updateAndGet (Ljava/util/concurrent/atomic/AtomicReference;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public class arrow/core/continuations/CancellationExceptionNoTrace : java/util/concurrent/CancellationException { - public fun ()V - public fun fillInStackTrace ()Ljava/lang/Throwable; -} - -public final class arrow/core/continuations/Eager : arrow/core/continuations/ShiftCancellationException { - public fun (Larrow/core/continuations/Token;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)V - public final fun getRecover ()Lkotlin/jvm/functions/Function1; - public final fun getShifted ()Ljava/lang/Object; - public final fun getToken ()Larrow/core/continuations/Token; - public fun toString ()Ljava/lang/String; -} - -public abstract interface class arrow/core/continuations/EagerEffect { - public abstract fun attempt ()Larrow/core/continuations/EagerEffect; - public abstract fun flatMap (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun handleError (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun handleErrorWith (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun map (Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun orNull ()Ljava/lang/Object; - public abstract fun redeem (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun redeemWith (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public abstract fun toEither ()Larrow/core/Either; - public abstract fun toIor ()Larrow/core/Ior; - public abstract fun toOption (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public abstract fun toValidated ()Larrow/core/Validated; -} - -public final class arrow/core/continuations/EagerEffect$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EagerEffect;)Larrow/core/continuations/EagerEffect; - public static fun flatMap (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun fold (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun handleError (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun handleErrorWith (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun map (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun orNull (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; - public static fun redeem (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun redeemWith (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/core/continuations/EagerEffect; - public static fun toEither (Larrow/core/continuations/EagerEffect;)Larrow/core/Either; - public static fun toIor (Larrow/core/continuations/EagerEffect;)Larrow/core/Ior; - public static fun toOption (Larrow/core/continuations/EagerEffect;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static fun toValidated (Larrow/core/continuations/EagerEffect;)Larrow/core/Validated; -} - -public final class arrow/core/continuations/EagerEffectKt { - public static final fun eagerEffect (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/EagerEffect; - public static final fun merge (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/EagerEffectScope { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EagerEffectScope$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun ensure (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EagerEffectScopeKt { - public static final fun ensureNotNull (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/Effect { - public abstract fun attempt ()Larrow/core/continuations/Effect; - public abstract fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun handleError (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun handleErrorWith (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun orNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun redeem (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun redeemWith (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public abstract fun toEither (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toIor (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toOption (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun toValidated (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/Effect$DefaultImpls { - public static fun attempt (Larrow/core/continuations/Effect;)Larrow/core/continuations/Effect; - public static fun fold (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun handleError (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun handleErrorWith (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun orNull (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun redeem (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun redeemWith (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static fun toEither (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toIor (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toOption (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun toValidated (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectKt { - public static final fun effect (Lkotlin/jvm/functions/Function2;)Larrow/core/continuations/Effect; - public static final fun merge (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract interface class arrow/core/continuations/EffectScope { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectScope$DefaultImpls { - public static fun attempt (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/EffectScopeKt { - public static final fun ensureNotNull (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/FoldContinuation : arrow/core/continuations/Token, arrow/core/continuations/EffectScope, kotlin/coroutines/Continuation { - public field recover Lkotlin/jvm/functions/Function2; - public fun (Larrow/core/continuations/Token;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)V - public fun (Larrow/core/continuations/Token;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)V - public fun (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun getContext ()Lkotlin/coroutines/CoroutineContext; - public final fun getRecover ()Lkotlin/jvm/functions/Function2; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun resumeWith (Ljava/lang/Object;)V - public final fun setRecover (Lkotlin/jvm/functions/Function2;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/IorEagerEffectScope : arrow/core/continuations/EagerEffectScope, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/EagerEffectScope;)V - public fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun getLeftState ()Ljava/util/concurrent/atomic/AtomicReference; - public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/IorEffectScope : arrow/core/continuations/EffectScope, arrow/typeclasses/Semigroup { - public fun (Larrow/typeclasses/Semigroup;Larrow/core/continuations/EffectScope;)V - public fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun getLeftState ()Ljava/util/concurrent/atomic/AtomicReference; - public fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun setLeftState (Ljava/util/concurrent/atomic/AtomicReference;)V - public fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/NullableEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/NullableEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/NullableEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/NullableEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Void;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/NullableKt { - public static final fun ensureNotNull-0Rsnnio (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensureNotNull-7s8y1X8 (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/OptionEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/OptionEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public fun shift (Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/OptionEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/OptionEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Larrow/core/None;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/OptionKt { - public static final fun ensureNotNull-09sQPHg (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun ensureNotNull-dxZa7OQ (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toOption (Larrow/core/continuations/EagerEffect;)Larrow/core/Option; - public static final fun toOption (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/ResultEagerEffectScope : arrow/core/continuations/EagerEffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/ResultEagerEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EagerEffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EagerEffectScope;)Larrow/core/continuations/EagerEffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EagerEffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EagerEffectScope;Larrow/core/continuations/EagerEffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EagerEffectScope;)I - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EagerEffectScope;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EagerEffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EagerEffectScope; -} - -public final class arrow/core/continuations/ResultEffectScope : arrow/core/continuations/EffectScope { - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun attempt-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Either;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Option;Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/Validated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final synthetic fun box-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/ResultEffectScope; - public fun catch (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun catch-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun constructor-impl (Larrow/core/continuations/EffectScope;)Larrow/core/continuations/EffectScope; - public fun ensure (ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun ensure-impl (Larrow/core/continuations/EffectScope;ZLkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Larrow/core/continuations/EffectScope;Larrow/core/continuations/EffectScope;)Z - public fun hashCode ()I - public static fun hashCode-impl (Larrow/core/continuations/EffectScope;)I - public fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun recover-impl (Larrow/core/continuations/EffectScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift-impl (Larrow/core/continuations/EffectScope;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Larrow/core/continuations/EffectScope;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Larrow/core/continuations/EffectScope; -} - -public final class arrow/core/continuations/ResultKt { - public static final fun toResult (Larrow/core/continuations/EagerEffect;)Ljava/lang/Object; - public static final fun toResult (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public abstract class arrow/core/continuations/ShiftCancellationException : arrow/core/continuations/CancellationExceptionNoTrace { -} - -public final class arrow/core/continuations/ShiftLeakedException : java/lang/IllegalStateException { - public fun ()V -} - -public final class arrow/core/continuations/Suspend : arrow/core/continuations/ShiftCancellationException { - public fun (Larrow/core/continuations/Token;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)V - public final fun getRecover ()Lkotlin/jvm/functions/Function2; - public final fun getShifted ()Ljava/lang/Object; - public final fun getToken ()Larrow/core/continuations/Token; - public fun toString ()Ljava/lang/String; -} - -public class arrow/core/continuations/Token { - public fun ()V - public fun toString ()Ljava/lang/String; -} - -public final class arrow/core/continuations/either { - public static final field INSTANCE Larrow/core/continuations/either; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Either; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/ior { - public static final field INSTANCE Larrow/core/continuations/ior; - public final fun eager (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function2;)Larrow/core/Ior; - public final fun invoke (Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/nullable { - public static final field INSTANCE Larrow/core/continuations/nullable; - public final fun eager (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/option { - public static final field INSTANCE Larrow/core/continuations/option; - public final fun eager (Lkotlin/jvm/functions/Function2;)Larrow/core/Option; - public final fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/continuations/result { - public static final field INSTANCE Larrow/core/continuations/result; - public final fun eager-IoAF18A (Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; - public final fun invoke-gIAlu-s (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/core/raise/DefaultRaise : arrow/core/raise/Raise { - public fun (Z)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; - public fun bindAll (Ljava/util/Map;)Ljava/util/Map; - public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun complete ()Z - public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun isTraced ()Z - public fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public fun shift (Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface annotation class arrow/core/raise/ExperimentalTraceApi : java/lang/annotation/Annotation { -} - -public final class arrow/core/raise/IorRaise : arrow/core/raise/Raise { - public fun (Lkotlin/jvm/functions/Function2;Ljava/util/concurrent/atomic/AtomicReference;Larrow/core/raise/Raise;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; - public fun bindAll (Ljava/util/Map;)Ljava/util/Map; - public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public final fun bindAllIor (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public final fun bindAllIor (Ljava/lang/Iterable;)Ljava/util/List; - public final fun bindAllIor (Ljava/util/Map;)Ljava/util/Map; - public final fun bindAllIor (Ljava/util/Set;)Ljava/util/Set; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public fun shift (Ljava/lang/Object;)Ljava/lang/Object; +public final class arrow/core/raise/IorRaise : arrow/core/raise/Raise { + public fun (Lkotlin/jvm/functions/Function2;Ljava/util/concurrent/atomic/AtomicReference;Larrow/core/raise/Raise;)V + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public final fun bind (Larrow/core/Ior;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; + public fun bindAll (Ljava/util/Map;)Ljava/util/Map; + public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; + public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; + public final fun bindAllIor (Ljava/lang/Iterable;)Ljava/util/List; + public final fun bindAllIor (Ljava/util/List;)Ljava/util/List; + public final fun bindAllIor (Ljava/util/Map;)Ljava/util/Map; + public final fun bindAllIor (Ljava/util/Set;)Ljava/util/Set; + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; } public final class arrow/core/raise/NullableRaise : arrow/core/raise/Raise { public fun (Larrow/core/raise/Raise;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; public final fun bind (Larrow/core/Option;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; public fun bindAll (Ljava/util/Map;)Ljava/util/Map; public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; + public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; public final fun bindAllNullable (Ljava/lang/Iterable;)Ljava/util/List; public final fun bindAllNullable (Ljava/util/Map;)Ljava/util/Map; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun ensure (Z)V public final fun ensureNotNull (Ljava/lang/Object;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; public fun raise (Ljava/lang/Void;)Ljava/lang/Void; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public fun shift (Ljava/lang/Void;)Ljava/lang/Object; } public final class arrow/core/raise/OptionRaise : arrow/core/raise/Raise { public fun (Larrow/core/raise/Raise;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; public final fun bind (Larrow/core/Option;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; public fun bindAll (Ljava/util/Map;)Ljava/util/Map; public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public final fun bindAllOption (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; public final fun bindAllOption (Ljava/lang/Iterable;)Ljava/util/List; + public final fun bindAllOption (Ljava/util/List;)Ljava/util/List; public final fun bindAllOption (Ljava/util/Map;)Ljava/util/Map; public final fun bindAllOption (Ljava/util/Set;)Ljava/util/Set; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun ensure (Z)V public final fun ensureNotNull (Ljava/lang/Object;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun raise (Larrow/core/None;)Ljava/lang/Void; public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public fun shift (Larrow/core/None;)Ljava/lang/Object; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; } public abstract interface class arrow/core/raise/Raise { - public abstract fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun bind (Larrow/core/Either;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun bindAll (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public abstract fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; public abstract fun bindAll (Ljava/util/Map;)Ljava/util/Map; public abstract fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public abstract fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; public abstract fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public abstract fun shift (Ljava/lang/Object;)Ljava/lang/Object; } public final class arrow/core/raise/Raise$DefaultImpls { - public static fun attempt (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Larrow/core/Either;)Ljava/lang/Object; - public static fun bind (Larrow/core/raise/Raise;Larrow/core/Validated;)Ljava/lang/Object; - public static fun bind (Larrow/core/raise/Raise;Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bind (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun bind (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun bindAll (Larrow/core/raise/Raise;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public static fun bindAll (Larrow/core/raise/Raise;Ljava/lang/Iterable;)Ljava/util/List; public static fun bindAll (Larrow/core/raise/Raise;Ljava/util/Map;)Ljava/util/Map; public static fun bindAll-1TN0_VU (Larrow/core/raise/Raise;Ljava/util/Set;)Ljava/util/Set; - public static fun catch (Larrow/core/raise/Raise;Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static fun bindAll-vcjLgH4 (Larrow/core/raise/Raise;Ljava/util/List;)Ljava/util/List; public static fun invoke (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun invoke (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static fun shift (Larrow/core/raise/Raise;Ljava/lang/Object;)Ljava/lang/Object; } public class arrow/core/raise/RaiseAccumulate : arrow/core/raise/Raise { public fun (Larrow/core/raise/Raise;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; public fun bindAll (Ljava/util/Map;)Ljava/util/Map; public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; + public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; public final fun bindNel (Larrow/core/Either;)Ljava/lang/Object; - public final fun bindNel (Larrow/core/Validated;)Ljava/lang/Object; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getRaise ()Larrow/core/raise/Raise; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun mapOrAccumulate (Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function2;)Larrow/core/NonEmptyList; public final fun mapOrAccumulate (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public final fun mapOrAccumulate-FrVv2gs (Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public final fun mapOrAccumulate-nfMsDo0 (Ljava/util/Set;Lkotlin/jvm/functions/Function2;)Ljava/util/Set; public fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public fun shift (Ljava/lang/Object;)Ljava/lang/Object; public final fun withNel (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } @@ -3440,16 +1519,14 @@ public final class arrow/core/raise/RaiseKt { public static final fun getOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun getOrNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun ior (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; - public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Larrow/core/NonEmptyList;Lkotlin/jvm/functions/Function2;)Larrow/core/NonEmptyList; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate--YW8gn4 (Larrow/core/raise/Raise;Ljava/util/Set;Lkotlin/jvm/functions/Function2;)Ljava/util/Set; + public static final fun mapOrAccumulate-l8IBlHg (Larrow/core/raise/Raise;Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun merge (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun merge (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun nullable (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun option (Lkotlin/jvm/functions/Function1;)Larrow/core/Option; - public static final fun orNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun orNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun raisedOrRethrow (Ljava/util/concurrent/CancellationException;Larrow/core/raise/DefaultRaise;)Ljava/lang/Object; public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -3466,8 +1543,6 @@ public final class arrow/core/raise/RaiseKt { public static final fun toResult (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun toResult (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun toValidated (Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; - public static final fun toValidated (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun traced (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function9;)Ljava/lang/Object; public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function8;)Ljava/lang/Object; @@ -3489,29 +1564,22 @@ public final class arrow/core/raise/RaiseKt { public final class arrow/core/raise/ResultRaise : arrow/core/raise/Raise { public fun (Larrow/core/raise/Raise;)V - public fun attempt (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public fun bind (Larrow/core/Validated;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/EagerEffect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bind (Larrow/core/continuations/Effect;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; public fun bindAll (Ljava/util/Map;)Ljava/util/Map; public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public final fun bindAllResult (Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; + public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; public final fun bindAllResult (Ljava/lang/Iterable;)Ljava/util/List; + public final fun bindAllResult (Ljava/util/List;)Ljava/util/List; public final fun bindAllResult (Ljava/util/Map;)Ljava/util/Map; public final fun bindAllResult (Ljava/util/Set;)Ljava/util/Set; - public fun catch (Larrow/core/continuations/Effect;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; public fun raise (Ljava/lang/Throwable;)Ljava/lang/Void; - public synthetic fun shift (Ljava/lang/Object;)Ljava/lang/Object; - public fun shift (Ljava/lang/Throwable;)Ljava/lang/Object; } public final class arrow/core/raise/Trace { @@ -3530,164 +1598,3 @@ public final class arrow/core/raise/Trace { public final synthetic fun unbox-impl ()Ljava/util/concurrent/CancellationException; } -public abstract interface class arrow/typeclasses/Monoid : arrow/typeclasses/Semigroup { - public static final field Companion Larrow/typeclasses/Monoid$Companion; - public static fun Boolean ()Larrow/typeclasses/Monoid; - public static fun Byte ()Larrow/typeclasses/Monoid; - public static fun Integer ()Larrow/typeclasses/Monoid; - public static fun Long ()Larrow/typeclasses/Monoid; - public static fun Short ()Larrow/typeclasses/Monoid; - public abstract fun combineAll (Ljava/util/Collection;)Ljava/lang/Object; - public abstract fun combineAll (Ljava/util/List;)Ljava/lang/Object; - public static fun constant (Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; - public static fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; - public abstract fun empty ()Ljava/lang/Object; - public static fun endo ()Larrow/typeclasses/Monoid; - public abstract fun fold (Ljava/util/Collection;)Ljava/lang/Object; - public abstract fun fold (Ljava/util/List;)Ljava/lang/Object; - public static fun list ()Larrow/typeclasses/Monoid; - public static fun map (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Monoid; - public static fun option (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Monoid; - public static fun pair (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; - public static fun sequence ()Larrow/typeclasses/Monoid; - public static fun string ()Larrow/typeclasses/Monoid; - public static fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; -} - -public final class arrow/typeclasses/Monoid$Companion { - public final fun Boolean ()Larrow/typeclasses/Monoid; - public final fun Byte ()Larrow/typeclasses/Monoid; - public final fun Integer ()Larrow/typeclasses/Monoid; - public final fun Long ()Larrow/typeclasses/Monoid; - public final fun Short ()Larrow/typeclasses/Monoid; - public final fun constant (Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; - public final synthetic fun either (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; - public final fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; - public final fun endo ()Larrow/typeclasses/Monoid; - public final fun list ()Larrow/typeclasses/Monoid; - public final fun map (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Monoid; - public final fun option (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Monoid; - public final fun pair (Larrow/typeclasses/Monoid;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; - public final fun sequence ()Larrow/typeclasses/Monoid; - public final fun string ()Larrow/typeclasses/Monoid; - public final fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Monoid;)Larrow/typeclasses/Monoid; -} - -public final class arrow/typeclasses/Monoid$DefaultImpls { - public static fun append (Larrow/typeclasses/Monoid;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun combineAll (Larrow/typeclasses/Monoid;Ljava/util/Collection;)Ljava/lang/Object; - public static fun combineAll (Larrow/typeclasses/Monoid;Ljava/util/List;)Ljava/lang/Object; - public static fun fold (Larrow/typeclasses/Monoid;Ljava/util/Collection;)Ljava/lang/Object; - public static fun fold (Larrow/typeclasses/Monoid;Ljava/util/List;)Ljava/lang/Object; - public static fun maybeCombine (Larrow/typeclasses/Monoid;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Larrow/typeclasses/Monoid;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/typeclasses/MonoidKt { - public static final field MonoidDeprecation Ljava/lang/String; -} - -public abstract interface class arrow/typeclasses/Semigroup { - public static final field Companion Larrow/typeclasses/Semigroup$Companion; - public static fun Boolean ()Larrow/typeclasses/Semigroup; - public static fun Byte ()Larrow/typeclasses/Semigroup; - public static fun Integer ()Larrow/typeclasses/Semigroup; - public static fun Long ()Larrow/typeclasses/Semigroup; - public static fun Short ()Larrow/typeclasses/Semigroup; - public abstract fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun constant (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public static fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public static fun endo ()Larrow/typeclasses/Semigroup; - public static fun ior (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public static fun list ()Larrow/typeclasses/Semigroup; - public static fun map (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public abstract fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun nonEmptyList ()Larrow/typeclasses/Semigroup; - public static fun option (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public static fun pair (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public abstract fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun sequence ()Larrow/typeclasses/Semigroup; - public static fun string ()Larrow/typeclasses/Semigroup; - public static fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; -} - -public final class arrow/typeclasses/Semigroup$Companion { - public final fun Boolean ()Larrow/typeclasses/Semigroup; - public final fun Byte ()Larrow/typeclasses/Semigroup; - public final fun Integer ()Larrow/typeclasses/Semigroup; - public final fun Long ()Larrow/typeclasses/Semigroup; - public final fun Short ()Larrow/typeclasses/Semigroup; - public final fun constant (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public final fun either (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public final fun endo ()Larrow/typeclasses/Semigroup; - public final fun ior (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public final fun list ()Larrow/typeclasses/Semigroup; - public final fun map (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public final fun nonEmptyList ()Larrow/typeclasses/Semigroup; - public final fun option (Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public final fun pair (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; - public final fun sequence ()Larrow/typeclasses/Semigroup; - public final fun string ()Larrow/typeclasses/Semigroup; - public final fun validated (Larrow/typeclasses/Semigroup;Larrow/typeclasses/Semigroup;)Larrow/typeclasses/Semigroup; -} - -public final class arrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup : arrow/typeclasses/Semigroup { - public static final field INSTANCE Larrow/typeclasses/Semigroup$Companion$NonEmptyListSemigroup; - public fun append (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public synthetic fun append (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun combine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public synthetic fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun maybeCombine (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public synthetic fun maybeCombine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public fun plus (Larrow/core/NonEmptyList;Larrow/core/NonEmptyList;)Larrow/core/NonEmptyList; - public synthetic fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/typeclasses/Semigroup$DefaultImpls { - public static fun append (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun maybeCombine (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/typeclasses/SemigroupKt { - public static final field SemigroupDeprecation Ljava/lang/String; - public static final fun combine (Larrow/typeclasses/Semigroup;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class arrow/typeclasses/Semiring { - public static final field Companion Larrow/typeclasses/Semiring$Companion; - public static fun Byte ()Larrow/typeclasses/Semiring; - public static fun Integer ()Larrow/typeclasses/Semiring; - public static fun Long ()Larrow/typeclasses/Semiring; - public static fun Short ()Larrow/typeclasses/Semiring; - public abstract fun combine (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun combineMultiplicate (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun maybeCombineAddition (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun maybeCombineMultiplicate (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun one ()Ljava/lang/Object; - public abstract fun plus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun times (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun zero ()Ljava/lang/Object; -} - -public final class arrow/typeclasses/Semiring$Companion { - public final fun Byte ()Larrow/typeclasses/Semiring; - public final fun Integer ()Larrow/typeclasses/Semiring; - public final fun Long ()Larrow/typeclasses/Semiring; - public final fun Short ()Larrow/typeclasses/Semiring; -} - -public final class arrow/typeclasses/Semiring$DefaultImpls { - public static fun maybeCombineAddition (Larrow/typeclasses/Semiring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun maybeCombineMultiplicate (Larrow/typeclasses/Semiring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun plus (Larrow/typeclasses/Semiring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun times (Larrow/typeclasses/Semiring;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/typeclasses/SemiringKt { - public static final field DoubleInstanceDeprecation Ljava/lang/String; - public static final field FloatInstanceDeprecation Ljava/lang/String; - public static final field SemiringDeprecation Ljava/lang/String; -} - diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index b827f4e4521..f195fbb99a8 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -4,21 +4,15 @@ package arrow.core -import arrow.core.Either.Companion.resolve import arrow.core.Either.Left import arrow.core.Either.Right import arrow.core.Either.Right.Companion.unit import arrow.core.raise.Raise import arrow.core.raise.either -import arrow.typeclasses.Monoid -import arrow.typeclasses.MonoidDeprecation -import arrow.typeclasses.Semigroup -import arrow.typeclasses.combine import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.experimental.ExperimentalTypeInference -import kotlin.js.JsName import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic @@ -352,98 +346,6 @@ public typealias EitherNel = Either, A> * ``` * * - * ## Resolve Either into one type of value - * In some cases you can not use Either as a value. For instance, when you need to respond to an HTTP request. To resolve Either into one type of value, you can use the resolve function. - * In the case of an HTTP endpoint you most often need to return some (framework specific) response object which holds the result of the request. The result can be expected and positive, this is the success flow. - * Or the result can be expected but negative, this is the error flow. Or the result can be unexpected and negative, in this case an unhandled exception was thrown. - * In all three cases, you want to use the same kind of response object. But probably you want to respond slightly different in each case. This can be achieved by providing specific functions for the success, error and throwable cases. - * - * Example: - * - * ```kotlin - * import arrow.core.Either - * import arrow.core.flatMap - * import arrow.core.left - * import arrow.core.right - * - * //sampleStart - * suspend fun httpEndpoint(request: String = "Hello?") = - * Either.resolve( - * f = { - * if (request == "Hello?") "HELLO WORLD!".right() - * else Error.SpecificError.left() - * }, - * success = { a -> handleSuccess({ a: Any -> log(Level.INFO, "This is a: $a") }, a) }, - * error = { e -> handleError({ e: Any -> log(Level.WARN, "This is e: $e") }, e) }, - * throwable = { throwable -> handleThrowable({ throwable: Throwable -> log(Level.ERROR, "Log the throwable: $throwable.") }, throwable) }, - * unrecoverableState = { _ -> Unit.right() } - * ) - * //sampleEnd - * suspend fun main() { - * println("httpEndpoint().status = ${httpEndpoint().status}") - * } - * - * @Suppress("UNUSED_PARAMETER") - * suspend fun handleSuccess(log: suspend (a: A) -> Either, a: A): Either = - * Either.catch { - * Response.Builder(HttpStatus.OK) - * .header(CONTENT_TYPE, CONTENT_TYPE_APPLICATION_JSON) - * .body(a) - * .build() - * } - * - * @Suppress("UNUSED_PARAMETER") - * suspend fun handleError(log: suspend (e: E) -> Either, e: E): Either = - * createErrorResponse(HttpStatus.NOT_FOUND, ErrorResponse("$ERROR_MESSAGE_PREFIX $e")) - * - * suspend fun handleThrowable(log: suspend (throwable: Throwable) -> Either, throwable: Throwable): Either = - * log(throwable) - * .flatMap { createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ErrorResponse("$THROWABLE_MESSAGE_PREFIX $throwable")) } - * - * suspend fun createErrorResponse(httpStatus: HttpStatus, errorResponse: ErrorResponse): Either = - * Either.catch { - * Response.Builder(httpStatus) - * .header(CONTENT_TYPE, CONTENT_TYPE_APPLICATION_JSON) - * .body(errorResponse) - * .build() - * } - * - * suspend fun log(level: Level, message: String): Either = - * Unit.right() // Should implement logging. - * - * enum class HttpStatus(val value: Int) { OK(200), NOT_FOUND(404), INTERNAL_SERVER_ERROR(500) } - * - * class Response private constructor( - * val status: HttpStatus, - * val headers: Map, - * val body: Any? - * ) { - * - * data class Builder( - * val status: HttpStatus, - * var headers: Map = emptyMap(), - * var body: Any? = null - * ) { - * fun header(key: String, value: String) = apply { this.headers = this.headers + mapOf(key to value) } - * fun body(body: Any?) = apply { this.body = body } - * fun build() = Response(status, headers, body) - * } - * } - * - * val CONTENT_TYPE = "Content-Type" - * val CONTENT_TYPE_APPLICATION_JSON = "application/json" - * val ERROR_MESSAGE_PREFIX = "An error has occurred. The error is:" - * val THROWABLE_MESSAGE_PREFIX = "An exception was thrown. The exception is:" - * sealed class Error { - * object SpecificError : Error() - * } - * data class ErrorResponse(val errorMessage: String) - * enum class Level { INFO, WARN, ERROR } - * ``` - * - * - * There are far more use cases for the resolve function, the HTTP endpoint example is just one of them. - * * ## Syntax * * Either can also map over the [Left] value with `mapLeft`, which is similar to map, but applies on left instances. @@ -462,7 +364,7 @@ public typealias EitherNel = Either, A> * println("leftMapLeft = $leftMapLeft") * } * ``` - * + * * * `Either` can be transformed to `Either` using the `swap()` method. * @@ -478,10 +380,10 @@ public typealias EitherNel = Either, A> * println("swapped = $swapped") * } * ``` - * + * * * For using Either's syntax on arbitrary data types. - * This will make possible to use the `left()`, `right()`, `contains()`, `getOrElse()` methods: + * This will make possible to use the `left()`, `right()`, `getOrElse()` methods: * * ```kotlin * import arrow.core.right @@ -494,7 +396,7 @@ public typealias EitherNel = Either, A> * println(right7) * } * ``` - * + * * * ```kotlin * import arrow.core.left @@ -507,21 +409,7 @@ public typealias EitherNel = Either, A> * println(leftHello) * } * ``` - * - * - * ```kotlin - * import arrow.core.right - * import arrow.core.contains - * - * //sampleStart - * val x = 7.right() - * val contains7 = x.contains(7) - * //sampleEnd - * fun main() { - * println("contains7 = $contains7") - * } - * ``` - * + * * * ```kotlin * import arrow.core.left @@ -529,57 +417,13 @@ public typealias EitherNel = Either, A> * * //sampleStart * val x = "hello".left() - * val getOr7 = x.getOrElse { 7 } - * //sampleEnd - * fun main() { - * println("getOr7 = $getOr7") - * } - * ``` - * - * - * ```kotlin - * import arrow.core.left - * import arrow.core.getOrHandle - * - * //sampleStart - * val x = "hello".left() - * val value = x.getOrHandle { "$it world!" } + * val value = x.getOrElse { "$it world!" } * //sampleEnd * fun main() { * println("value = $value") * } * ``` - * - * - * For creating Either instance based on a predicate, use `Either.conditionally()` method. It will evaluate an expression - * passed as first parameter, in case the expression evaluates to `false` it will give an `Either.Left` build from the second parameter. - * If the expression evaluates to a `true` it will take the third parameter and give an `Either.Right`: - * - * ```kotlin - * import arrow.core.Either - * - * val value = - * //sampleStart - * Either.conditionally(true, { "Error" }, { 42 }) - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * - * ```kotlin - * import arrow.core.Either - * - * val value = - * //sampleStart - * Either.conditionally(false, { "Error" }, { 42 }) - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * + * * * Another operation is `fold`. This operation will extract the value from the Either, or provide a default if the value is [Left] * @@ -595,7 +439,7 @@ public typealias EitherNel = Either, A> * println("fold = $fold") * } * ``` - * + * * * ```kotlin * import arrow.core.Either @@ -609,7 +453,7 @@ public typealias EitherNel = Either, A> * println("fold = $fold") * } * ``` - * + * * * The `getOrHandle()` operation allows the transformation of an `Either.Left` value to a `Either.Right` using * the value of [Left]. This can be useful when mapping to a single result type is required like `fold()`, but without @@ -619,11 +463,11 @@ public typealias EitherNel = Either, A> * * ```kotlin * import arrow.core.Either - * import arrow.core.getOrHandle + * import arrow.core.getOrElse * * //sampleStart * val r: Either = Either.Left(NumberFormatException()) - * val httpStatusCode = r.getOrHandle { + * val httpStatusCode = r.getOrElse { * when(it) { * is NumberFormatException -> 400 * else -> 500 @@ -634,148 +478,13 @@ public typealias EitherNel = Either, A> * println("httpStatusCode = $httpStatusCode") * } * ``` - * - * - * The ```leftIfNull``` operation transforms a null `Either.Right` value to the specified ```Either.Left``` value. - * If the value is non-null, the value wrapped into a non-nullable ```Either.Right``` is returned (very useful to - * skip null-check further down the call chain). - * If the operation is called on an ```Either.Left```, the same ```Either.Left``` is returned. - * - * See the examples below: - * - * ```kotlin - * import arrow.core.Either.Right - * import arrow.core.leftIfNull - * - * fun main() { - * val value = - * //sampleStart - * Right(12).leftIfNull({ -1 }) - * //sampleEnd - * println(value) - * } - * ``` - * - * - * ```kotlin - * import arrow.core.Either.Right - * import arrow.core.leftIfNull - * - * val value = - * //sampleStart - * Right(null).leftIfNull({ -1 }) - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * - * ```kotlin - * import arrow.core.Either.Left - * import arrow.core.leftIfNull - * - * val value = - * //sampleStart - * Left(12).leftIfNull({ -1 }) - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * - * Another useful operation when working with null is `rightIfNotNull`. - * If the value is null, it will be transformed to the specified `Either.Left` and, if it's not null, the type will - * be wrapped to `Either.Right`. - * - * Example: - * - * ```kotlin - * import arrow.core.rightIfNotNull - * - * val value = - * //sampleStart - * "value".rightIfNotNull { "left" } - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * - * ```kotlin - * import arrow.core.rightIfNotNull - * - * val value = - * //sampleStart - * null.rightIfNotNull { "left" } - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * - * The inverse of `rightIfNotNull`, `rightIfNull`. - * If the value is null it will be transformed to the specified `Either.right` and the type will be `Nothing?`. - * If the value is not null than it will be transformed to the specified `Either.Left`. - * - * Example: - * - * ```kotlin - * import arrow.core.rightIfNull - * - * val value = - * //sampleStart - * "value".rightIfNull { "left" } - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * - * ```kotlin - * import arrow.core.rightIfNull - * - * val value = - * //sampleStart - * null.rightIfNull { "left" } - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * - * Arrow contains `Either` instances for many useful typeclasses that allows you to use and transform right values. - * Option does not require a type parameter with the following functions, but it is specifically used for Either.Left + * */ public sealed class Either { - /** - * Returns `true` if this is a [Right], `false` otherwise. - * Used only for performance instead of fold. - */ - @Deprecated( - RedundantAPI + "Use isRight()", - ReplaceWith("isRight()") - ) - @JsName("_isRight") - internal abstract val isRight: Boolean - /** * Returns `true` if this is a [Left], `false` otherwise. - * Used only for performance instead of fold. */ - @Deprecated( - RedundantAPI + "Use isLeft()", - ReplaceWith("isLeft()") - ) - @JsName("_isLeft") - internal abstract val isLeft: Boolean - public fun isLeft(): Boolean { contract { returns(true) implies (this@Either is Left) @@ -784,6 +493,9 @@ public sealed class Either { return this@Either is Left } + /** + * Returns `true` if this is a [Right], `false` otherwise. + */ public fun isRight(): Boolean { contract { returns(true) implies (this@Either is Right) @@ -810,7 +522,7 @@ public sealed class Either { * right.isLeft { it > 10 } shouldBe false * } * ``` - * + * * */ public inline fun isLeft(predicate: (A) -> Boolean): Boolean { @@ -836,7 +548,7 @@ public sealed class Either { * left.isRight { it > 10 } shouldBe false * } * ``` - * + * * */ public inline fun isRight(predicate: (B) -> Boolean): Boolean { @@ -861,7 +573,7 @@ public sealed class Either { * .fold({ -1 }, { fail("Cannot be right") }) shouldBe -1 * } * ``` - * + * * * * @param ifLeft transform the [Either.Left] type [A] to [C]. @@ -879,34 +591,6 @@ public sealed class Either { } } - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("this.fold({ initial }) { rightOperation(initial, it) }") - ) - public inline fun foldLeft(initial: C, rightOperation: (C, B) -> C): C = - fold({ initial }) { rightOperation(initial, it) } - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("fold({ ifLeft }, f)") - ) - public fun foldMap(MN: Monoid, f: (B) -> C): C = - fold({ MN.empty() }, f) - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("fold({ f(c, it) }, { g(c, it) })") - ) - public inline fun bifoldLeft(c: C, f: (C, A) -> C, g: (C, B) -> C): C = - fold({ f(c, it) }, { g(c, it) }) - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("fold(f, g)") - ) - public inline fun bifoldMap(MN: Monoid, f: (A) -> C, g: (B) -> C): C = - fold(f, g) - /** * Swap the generic parameters [A] and [B] of this [Either]. * @@ -919,7 +603,7 @@ public sealed class Either { * Either.Right("right").swap() shouldBe Either.Left("right") * } * ``` - * + * * */ public fun swap(): Either = @@ -937,7 +621,7 @@ public sealed class Either { * Either.Left(12).map { _: Nothing -> "flower" } shouldBe Either.Left(12) * } * ``` - * + * * */ public inline fun map(f: (right: B) -> C): Either { @@ -960,7 +644,7 @@ public sealed class Either { * Either.Left(12).mapLeft { _: Int -> "flower" } shouldBe Either.Left("flower") * } * ``` - * + * * */ public inline fun mapLeft(f: (A) -> C): Either { @@ -970,20 +654,6 @@ public sealed class Either { return fold({ Left(f(it)) }, { Right(it) }) } - @Deprecated( - "tapLeft is being renamed to onLeft to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("onLeft(f)") - ) - public inline fun tapLeft(f: (left: A) -> Unit): Either = - onLeft(f) - - @Deprecated( - "tap is being renamed to onRight to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("onRight(f)") - ) - public inline fun tap(f: (right: B) -> Unit): Either = - onRight(f) - /** * Performs the given [action] on the encapsulated [B] value if this instance represents [Either.Right]. * Returns the original [Either] unchanged. @@ -996,7 +666,7 @@ public sealed class Either { * Either.Right(1).onRight(::println) shouldBe Either.Right(1) * } * ``` - * + * * */ public inline fun onRight(action: (right: B) -> Unit): Either { @@ -1018,7 +688,7 @@ public sealed class Either { * Either.Left(2).onLeft(::println) shouldBe Either.Left(2) * } * ``` - * + * * */ public inline fun onLeft(action: (left: A) -> Unit): Either { @@ -1028,81 +698,6 @@ public sealed class Either { return also { if (it.isLeft()) action(it.value) } } - /** - * Map over Left and Right of this Either - */ - @Deprecated( - NicheAPI + "Prefer using the Either DSL, or map + mapLeft", - ReplaceWith("map(rightOperation).mapLeft(leftOperation)") - ) - public inline fun bimap(leftOperation: (left: A) -> C, rightOperation: (right: B) -> D): Either = - map(rightOperation).mapLeft(leftOperation) - - /** - * Returns `false` if [Left] or returns the result of the application of - * the given predicate to the [Right] value. - * - * Example: - * ```kotlin - * import arrow.core.Either - * import arrow.core.Either.Left - * - * fun main() { - * Either.Right(12).exists { it > 10 } // Result: true - * Either.Right(7).exists { it > 10 } // Result: false - * - * val left: Either = Left(12) - * left.exists { it > 10 } // Result: false - * } - * ``` - * - */ - @Deprecated( - NicheAPI + "Prefer isRight", - ReplaceWith("isRight(predicate)") - ) - public inline fun exists(predicate: (B) -> Boolean): Boolean = - fold({ false }, predicate) - - @Deprecated( - "Facilitates the migration from Validated to Either.", - ReplaceWith("isRight(predicate)") - ) - public inline fun exist(predicate: (B) -> Boolean): Boolean = - exists(predicate) - - /** - * Returns `true` if [Left] or returns the result of the application of - * the given predicate to the [Right] value. - * - * Example: - * ``` - * Right(12).all { it > 10 } // Result: true - * Right(7).all { it > 10 } // Result: false - * - * val left: Either = Left(12) - * left.all { it > 10 } // Result: true - * ``` - */ - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("fold({ true }, predicate)") - ) - public inline fun all(predicate: (B) -> Boolean): Boolean = - fold({ true }, predicate) - - @Deprecated( - "orNull is being renamed to getOrNull to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("getOrNull()") - ) - public fun orNull(): B? { - contract { - returns(null) implies (this@Either is Left) - returnsNotNull() implies (this@Either is Right) - } - return fold({ null }, { it }) - } - /** * Returns the unwrapped value [B] of [Either.Right] or `null` if it is [Either.Left]. * @@ -1115,7 +710,7 @@ public sealed class Either { * Either.Left(12).getOrNull() shouldBe null * } * ``` - * + * * */ public fun getOrNull(): B? { @@ -1138,7 +733,7 @@ public sealed class Either { * Either.Left(12).leftOrNull() shouldBe 12 * } * ``` - * + * * */ public fun leftOrNull(): A? { @@ -1149,12 +744,6 @@ public sealed class Either { return fold(::identity) { null } } - @Deprecated( - "orNone is being renamed to getOrNone to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("getOrNone()") - ) - public fun orNone(): Option = getOrNone() - /** * Transforms [Either] into [Option], * where the encapsulated value [B] is wrapped in [Some] when this instance represents [Either.Right], @@ -1171,167 +760,24 @@ public sealed class Either { * Either.Left(12).getOrNone() shouldBe None * } * ``` - * + * * */ public fun getOrNone(): Option = fold({ None }, { Some(it) }) - @Deprecated( - NicheAPI + "Prefer using the Either DSL, or map", - ReplaceWith("if (n <= 0) Right(emptyList()) else map { b -> List(n) { b } }") - ) - public fun replicate(n: Int): Either> = - if (n <= 0) Right(emptyList()) else map { b -> List(n) { b } } - - @Deprecated( - NicheAPI + "Prefer using the Either DSL, or explicit fold or when", - ReplaceWith( - "fold({ listOf(it.left()) }, { fa(it).map(::Right) })", - "arrow.core.Either.Right", - "arrow.core.Either.left" - ) - ) - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Iterable): List> = - fold({ listOf(it.left()) }, { fa(it).map(::Right) }) - - @Deprecated( - NicheAPI + "Prefer using the Either DSL, or explicit fold or when", - ReplaceWith( - "fold({ Some(it.left()) }, { right -> fa(right).map(::Right) })", - "arrow.core.Either.Right", - "arrow.core.Some", - "arrow.core.left" - ) - ) - @OptIn(ExperimentalTypeInference::class) - @OverloadResolutionByLambdaReturnType - public inline fun traverse(fa: (B) -> Option): Option> = - fold({ Some(it.left()) }, { right -> fa(right).map(::Right) }) - - @Deprecated("traverseOption is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(fa)")) - public inline fun traverseOption(fa: (B) -> Option): Option> = - traverse(fa) - - @Deprecated( - RedundantAPI + "Use orNull() and Kotlin nullable types", - ReplaceWith("fold({ it.left() }) { fa(it)?.right() }", "arrow.core.left", "arrow.core.right") - ) - public inline fun traverseNullable(fa: (B) -> C?): Either? = - fold({ it.left() }) { fa(it)?.right() } - - @Deprecated( - NicheAPI + "Prefer explicit fold instead", - ReplaceWith("fold({ fe(it).map { aa -> Left(aa) } }, { fa(it).map { c -> Right(c) } })") - ) - public inline fun bitraverse(fe: (A) -> Iterable, fa: (B) -> Iterable): List> = - fold({ fe(it).map { aa -> Left(aa) } }, { fa(it).map { c -> Right(c) } }) - - @Deprecated( - NicheAPI + "Prefer explicit fold instead", - ReplaceWith("fold({ fl(it).map(::Left) }, { fr(it).map(::Right) })") - ) - public inline fun bitraverseOption(fl: (A) -> Option, fr: (B) -> Option): Option> = - fold({ fl(it).map(::Left) }, { fr(it).map(::Right) }) - - @Deprecated( - NicheAPI + "Prefer explicit fold instead", - ReplaceWith("fold({ fl(it)?.let(::Left) }, { fr(it)?.let(::Right) })") - ) - public inline fun bitraverseNullable(fl: (A) -> AA?, fr: (B) -> C?): Either? = - fold({ fl(it)?.let(::Left) }, { fr(it)?.let(::Right) }) - - @Deprecated( - NicheAPI + "Prefer Kotlin nullable syntax instead", - ReplaceWith("orNull()?.takeIf(predicate)") - ) - public inline fun findOrNull(predicate: (B) -> Boolean): B? = - getOrNull()?.takeIf(predicate) - /** - * Returns `true` if [Left] - * - * Example: - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * //sampleStart - * Either.Left("foo").isEmpty() // Result: true - * Either.Right("foo").isEmpty() // Result: false - * } - * ``` - * - */ - @Deprecated( - RedundantAPI + "Use isLeft()", - ReplaceWith("isLeft()") - ) - public fun isEmpty(): Boolean = isLeft - - /** - * Returns `true` if [Right] - * - * Example: - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * //sampleStart - * Either.Left("foo").isNotEmpty() // Result: false - * Either.Right("foo").isNotEmpty() // Result: true - * //sampleEnd - * } - * ``` - * - */ - @Deprecated( - RedundantAPI + "Use isRight()", - ReplaceWith("isRight()") - ) - public fun isNotEmpty(): Boolean = isRight - /** * The left side of the disjoint union, as opposed to the [Right] side. */ public data class Left constructor(val value: A) : Either() { - @Deprecated( - RedundantAPI + "Use `is Either.Left<*>`, `when`, or `fold` instead", - ReplaceWith("(this is Either.Left<*>)") - ) - override val isLeft = true - - @Deprecated( - RedundantAPI + "Use `is Either.Right<*>`, `when`, or `fold` instead", - ReplaceWith("(this is Either.Right<*>)") - ) - override val isRight = false - override fun toString(): String = "Either.Left($value)" - public companion object { - @Deprecated("Unused, will be removed from bytecode in Arrow 2.x.x", ReplaceWith("Left(Unit)")) - @PublishedApi - internal val leftUnit: Either = Left(Unit) - } + public companion object } /** * The right side of the disjoint union, as opposed to the [Left] side. */ public data class Right constructor(val value: B) : Either() { - @Deprecated( - RedundantAPI + "Use `is Either.Left<*>`, `when`, or `fold` instead", - ReplaceWith("(this is Either.Left<*>)") - ) - override val isLeft = false - - @Deprecated( - RedundantAPI + "Use `is Either.Right<*>`, `when`, or `fold` instead", - ReplaceWith("(this is Either.Right<*>)") - ) - override val isRight = true - override fun toString(): String = "Either.Right($value)" public companion object { @@ -1349,36 +795,7 @@ public sealed class Either { fold({ Ior.Left(it) }, { Ior.Right(it) }) public companion object { - - @Deprecated( - RedundantAPI + "Prefer Kotlin nullable syntax, or ensureNotNull inside Either DSL", - ReplaceWith("a?.right() ?: Unit.left()") - ) - @JvmStatic - public fun fromNullable(a: A?): Either = a?.right() ?: Unit.left() - - /** - * Will create an [Either] from the result of evaluating the first parameter using the functions - * provided on second and third parameters. Second parameter represents function for creating - * an [Left] in case of a false result of evaluation and third parameter will be used - * to create a [Right] in case of a true result. - * - * @param test expression to evaluate and build an [Either] - * @param ifFalse function to create a [Left] in case of false result of test - * @param ifTrue function to create a [Right] in case of true result of test - * - * @return [Right] if evaluation succeed, [Left] otherwise - */ - @Deprecated( - RedundantAPI + "Prefer explicit if-else statements, or ensure inside Either DSL", - ReplaceWith("if (test) Right(ifTrue()) else Left(ifFalse())") - ) - @JvmStatic - public inline fun conditionally(test: Boolean, ifFalse: () -> L, ifTrue: () -> R): Either = - if (test) Right(ifTrue()) else Left(ifFalse()) - @JvmStatic - @JvmName("tryCatch") public inline fun catch(f: () -> R): Either = arrow.core.raise.catch({ f().right() }) { it.left() } @@ -1386,95 +803,6 @@ public sealed class Either { public inline fun catchOrThrow(f: () -> R): Either = arrow.core.raise.catch>({ f().right() }) { it.left() } - @Deprecated( - RedundantAPI + "Compose catch with flatten instead", - ReplaceWith("catch(f).flatten()") - ) - @JvmStatic - @JvmName("tryCatchAndFlatten") - public inline fun catchAndFlatten(f: () -> Either): Either = - catch(f).flatten() - - @Deprecated( - RedundantAPI + "Compose catch with mapLeft instead", - ReplaceWith("catch(f).mapLeft(fe)") - ) - @JvmStatic - @JvmName("tryCatch") - public inline fun catch(fe: (Throwable) -> L, f: () -> R): Either { - contract { callsInPlace(fe, InvocationKind.AT_MOST_ONCE) } - return catch(f).mapLeft(fe) - } - - /** - * The resolve function can resolve any function that yields an Either into one type of value. - * - * @param f the function that needs to be resolved. - * @param success the function to apply if [f] yields a success of type [A]. - * @param error the function to apply if [f] yields an error of type [E]. - * @param throwable the function to apply if [f] throws a [Throwable]. - * Throwing any [Throwable] in the [throwable] function will render the [resolve] function nondeterministic. - * @param unrecoverableState the function to apply if [resolve] is in an unrecoverable state. - * @return the result of applying the [resolve] function. - */ - @Deprecated(NicheAPI + "Prefer using recover, catch and the either DSL to work with errors") - @JvmStatic - public inline fun resolve( - f: () -> Either, - success: (a: A) -> Either, - error: (e: E) -> Either, - throwable: (throwable: Throwable) -> Either, - unrecoverableState: (throwable: Throwable) -> Either, - ): B { - contract { - callsInPlace(success, InvocationKind.AT_MOST_ONCE) - callsInPlace(error, InvocationKind.AT_MOST_ONCE) - callsInPlace(throwable, InvocationKind.AT_MOST_ONCE) - callsInPlace(unrecoverableState, InvocationKind.AT_MOST_ONCE) - } - return catch(f) - .fold( - { t: Throwable -> throwable(t) }, - { it.fold({ e: E -> catchAndFlatten { error(e) } }, { a: A -> catchAndFlatten { success(a) } }) }) - .fold({ t: Throwable -> throwable(t) }, { b: B -> b.right() }) - .fold({ t: Throwable -> unrecoverableState(t); throw t }, { b: B -> b }) - } - - /** - * Lifts a function `(B) -> C` to the [Either] structure returning a polymorphic function - * that can be applied over all [Either] values in the shape of Either - * - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * //sampleStart - * val f = Either.lift { s: CharSequence -> "$s World" } - * val either: Either = "Hello".right() - * val result = f(either) - * //sampleEnd - * println(result) - * } - * ``` - * - */ - @JvmStatic - @Deprecated( - RedundantAPI + "Prefer explicitly creating lambdas", - ReplaceWith("{ it.map(f) }") - ) - public fun lift(f: (B) -> C): (Either) -> Either = - { it.map(f) } - - @JvmStatic - @Deprecated( - RedundantAPI + "Prefer explicitly creating lambdas", - ReplaceWith("{ it.bimap(fa, fb) }") - ) - public fun lift(fa: (A) -> C, fb: (B) -> D): (Either) -> Either = - { it.bimap(fa, fb) } - - public inline fun zipOrAccumulate( combine: (E, E) -> E, a: Either, @@ -1944,20 +1272,6 @@ public sealed class Either { } } } - - @Deprecated( - RedundantAPI + "Map with Unit", - ReplaceWith("map { }") - ) - public fun void(): Either = - map { } - - @Deprecated( - "Facilitates the migration from Validated to Either, you can simply remove this method call.", - ReplaceWith("this") - ) - public inline fun toEither(): Either = - this } /** @@ -1978,29 +1292,6 @@ public inline fun Either.flatMap(f: (right: B) -> Either): public fun Either>.flatten(): Either = flatMap(::identity) -/** - * Returns the value from this [Right] or the given argument if this is a [Left]. - * - * Example: - * ```kotlin - * import arrow.core.Either.Right - * import arrow.core.Either.Left - * import arrow.core.getOrElse - * - * fun main() { - * Right(12).getOrElse { 17 } // Result: 12 - * Left(12).getOrElse { 17 } // Result: 17 - * } - * ``` - * - */ -@Deprecated( - RedundantAPI + "This API is overloaded with an API with a single argument", - level = DeprecationLevel.HIDDEN -) -public inline fun Either<*, B>.getOrElse(default: () -> B): B = - fold({ default() }, ::identity) - /** * Get the right value [B] of this [Either], * or compute a [default] value with the left value [A]. @@ -2014,7 +1305,7 @@ public inline fun Either<*, B>.getOrElse(default: () -> B): B = * Either.Left(12) getOrElse { it + 5 } shouldBe 17 * } * ``` - * + * * */ public inline infix fun Either.getOrElse(default: (A) -> B): B { @@ -2022,120 +1313,6 @@ public inline infix fun Either.getOrElse(default: (A) -> B): B { return fold(default, ::identity) } -/** - * Returns the value from this [Right] or null if this is a [Left]. - * - * Example: - * ```kotlin - * import arrow.core.Either.Right - * import arrow.core.Either.Left - * - * fun main() { - * Right(12).orNull() // Result: 12 - * Left(12).orNull() // Result: null - * } - * ``` - * - */ -@Deprecated( - "Duplicated API. Please use Either's member function orNull. This will be removed towards Arrow 2.0", - ReplaceWith("orNull()") -) -public fun Either<*, B>.orNull(): B? = - getOrNull() - -/** - * Returns the value from this [Right] or allows clients to transform the value from [Left] with the [default] lambda. - * - * Example: - * ```kotlin - * import arrow.core.Either.Right - * import arrow.core.Either.Left - * import arrow.core.getOrHandle - * - * fun main() { - * Right(12).getOrHandle { 17 } // Result: 12 - * Left(12).getOrHandle { it + 5 } // Result: 17 - * } - * ``` - * - */ -@Deprecated( - RedundantAPI + "Use other getOrElse signature", - ReplaceWith("getOrElse(default)") -) -public inline fun Either.getOrHandle(default: (A) -> B): B = - fold({ default(it) }, ::identity) - -/** - * Returns [Right] with the existing value of [Right] if this is a [Right] and the given predicate - * holds for the right value.
- * - * Returns `Left(default)` if this is a [Right] and the given predicate does not - * hold for the right value.
- * - * Returns [Left] with the existing value of [Left] if this is a [Left].
- * - * Example: - * ```kotlin - * import arrow.core.Either.* - * import arrow.core.Either - * import arrow.core.filterOrElse - * - * fun main() { - * Right(12).filterOrElse({ it > 10 }, { -1 }) // Result: Right(12) - * Right(7).filterOrElse({ it > 10 }, { -1 }) // Result: Left(-1) - * - * val left: Either = Left(12) - * left.filterOrElse({ it > 10 }, { -1 }) // Result: Left(12) - * } - * ``` - * - */ -@Deprecated( - RedundantAPI + "Prefer if-else statement inside either DSL, or replace with explicit flatMap", - ReplaceWith("this.flatMap { if (predicate(it)) Either.Right(it) else Either.Left(default(it)) }") -) -public inline fun Either.filterOrElse(predicate: (B) -> Boolean, default: () -> A): Either = - flatMap { if (predicate(it)) Right(it) else Left(default()) } - -/** - * Returns [Right] with the existing value of [Right] if this is a [Right] and the given - * predicate holds for the right value.
- * - * Returns `Left(default({right}))` if this is a [Right] and the given predicate does not - * hold for the right value. Useful for error handling where 'default' returns a message with context on why the value - * did not pass the filter
- * - * Returns [Left] with the existing value of [Left] if this is a [Left].
- * - * Example: - * - * ```kotlin - * import arrow.core.* - * - * suspend fun main(): Unit { - * //sampleStart - * Either.Right(7).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) - * .let(::println) // Either.Left(Value '7' is not equal to 10") - * - * Either.Right(10).filterOrOther({ it == 10 }, { "Value '$it' is not equal to 10" }) - * .let(::println) // Either.Right(10) - * - * Either.Left(12).filterOrOther({ str: String -> str.contains("impossible") }, { -1 }) - * .let(::println) // Either.Left(12) - * //sampleEnd - * } - * ``` - * - */ -@Deprecated( - RedundantAPI + "Prefer if-else statement inside either DSL, or replace with explicit flatMap", - ReplaceWith("this.flatMap { if (predicate(it)) Either.Right(it) else Either.Left(default()) }") -) -public inline fun Either.filterOrOther(predicate: (B) -> Boolean, default: (B) -> A): Either = - flatMap { if (predicate(it)) Right(it) else Left(default(it)) } - /** * Returns the value from this [Right] or [Left]. * @@ -2150,149 +1327,16 @@ public inline fun Either.filterOrOther(predicate: (B) -> Boolean, d * Left(12).merge() // Result: 12 * } * ``` - * + * * */ public inline fun
Either.merge(): A = fold(::identity, ::identity) -/** - * Returns [Right] with the existing value of [Right] if this is an [Right] with a non-null value. - * The returned Either.Right type is not nullable. - * - * Returns `Left(default())` if this is an [Right] and the existing value is null - * - * Returns [Left] with the existing value of [Left] if this is an [Left]. - * - * Example: - * ```kotlin - * import arrow.core.Either.* - * import arrow.core.leftIfNull - * - * fun main() { - * Right(12).leftIfNull({ -1 }) // Result: Right(12) - * Right(null).leftIfNull({ -1 }) // Result: Left(-1) - * - * Left(12).leftIfNull({ -1 }) // Result: Left(12) - * } - * ``` - * - */ -@Deprecated( - RedundantAPI + "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit flatMap", - ReplaceWith("flatMap { b -> b?.right() ?: default().left() }") -) -public inline fun Either.leftIfNull(default: () -> A): Either = - flatMap { b -> b?.right() ?: default().left() } - -/** - * Returns `true` if this is a [Right] and its value is equal to `elem` (as determined by `==`), - * returns `false` otherwise. - * - * Example: - * ```kotlin - * import arrow.core.Either.Right - * import arrow.core.Either.Left - * import arrow.core.contains - * - * fun main() { - * Right("something").contains("something") // Result: true - * Right("something").contains("anything") // Result: false - * Left("something").contains("something") // Result: false - * } - * ``` - * - * - * @param elem the element to test. - * @return `true` if the option has an element that is equal (as determined by `==`) to `elem`, `false` otherwise. - */ -@Deprecated( - RedundantAPI + "Prefer the Either DSL, or replace with explicit fold", - ReplaceWith("fold({ false }) { it == elem }") -) -public fun Either.contains(elem: B): Boolean = - fold({ false }) { it == elem } - -@Deprecated( - RedundantAPI + "Prefer the Either DSL, or new recover API", - ReplaceWith("recover { y.bind() }") -) -public fun Either.combineK(y: Either): Either = - recover { y.bind() } - public fun A.left(): Either = Left(this) public fun A.right(): Either = Right(this) -/** - * Returns [Right] if the value of type B is not null, otherwise the specified A value wrapped into an - * [Left]. - * - * Example: - * ```kotlin - * import arrow.core.rightIfNotNull - * - * fun main() { - * "value".rightIfNotNull { "left" } // Right(b="value") - * null.rightIfNotNull { "left" } // Left(a="left") - * } - * ``` - * - */ -@Deprecated( - RedundantAPI + "Prefer Kotlin nullable syntax", - ReplaceWith("this?.right() ?: default().left()") -) -public inline fun B?.rightIfNotNull(default: () -> A): Either = - this?.right() ?: default().left() - -/** - * Returns [Right] if the value of type Any? is null, otherwise the specified A value wrapped into an - * [Left]. - */ -@Deprecated( - RedundantAPI + "Prefer Kotlin nullable syntax", - ReplaceWith("this?.let { default().left() } ?: null.right()") -) -public inline fun Any?.rightIfNull(default: () -> A): Either = - this?.let { default().left() } ?: null.right() - -@Deprecated( - RedundantAPI + "Prefer the new recover API", - ReplaceWith( - "recover { a -> f(a).bind() }", - "arrow.core.recover" - ) -) -public inline fun Either.handleErrorWith(f: (A) -> Either): Either { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return recover { a -> f(a).bind() } -} - -@Deprecated( - RedundantAPI + "Prefer resolving the error with getOrElse.", - ReplaceWith("getOrElse(f).right()", "arrow.core.right", "arrow.core.getOrElse") -) -public inline fun Either.handleError(f: (A) -> B): Either { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return getOrElse(f).right() -} - -@Deprecated( - RedundantAPI + "Prefer using the Either DSL or explicit fold with right", - ReplaceWith( - "fold({ a -> fe(a) }, fa).right()", - "arrow.core.right" - ) -) -public inline fun Either.redeem(fe: (A) -> C, fa: (B) -> C): Either { - contract { - callsInPlace(fe, InvocationKind.AT_MOST_ONCE) - callsInPlace(fa, InvocationKind.AT_MOST_ONCE) - } - return fold({ a -> fe(a) }, fa).right() -} - public operator fun , B : Comparable> Either.compareTo(other: Either): Int = fold( { a1 -> other.fold({ a2 -> a1.compareTo(a2) }, { -1 }) }, @@ -2317,23 +1361,6 @@ public fun Either.combine(other: Either, combineLeft: (A, A) } } -@Deprecated( - RedundantAPI + "Prefer zipOrAccumulate", - ReplaceWith("Either.zipOrAccumulate({ a:A, bb:A -> a + bb }, this, b) { a:B, bb:B -> a + bb }") -) -public fun Either.combine(SGA: Semigroup, SGB: Semigroup, b: Either): Either = - combine(b, SGA::combine, SGB::combine) - - -@Deprecated( - MonoidDeprecation, - ReplaceWith( - "this.fold, Either>(initialValue.right()) { x, y -> Either.zipOrAccumulate({a1, a2 -> a1 + a2}, x, y, {b1, b2 -> b1 + b2}) }" - ) -) -public fun Iterable>.combineAll(MA: Monoid, MB: Monoid): Either = - fold, Either>(MB.empty().right()) { x, y -> Either.zipOrAccumulate(MA::combine, x, y, MB::combine) } - /** * Given [B] is a subtype of [C], re-type this value from Either to Either * @@ -2349,7 +1376,7 @@ public fun Iterable>.combineAll(MA: Monoid, MB: Monoid * println(chars) * } * ``` - * + * */ public fun Either.widen(): Either = this @@ -2357,94 +1384,6 @@ public fun Either.widen(): Either = public fun Either.leftWiden(): Either = this -@Deprecated( - NicheAPI + "Prefer using the Either DSL, or map", - ReplaceWith("if (n <= 0) Either.Right(initial) else this.map { b -> List(n) { b }.fold(initial){r, t -> r + t} }") -) -public fun Either.replicate(n: Int, MB: Monoid): Either = - map { b -> List(n) { b }.fold(MB.empty(), MB::combine) } - -@Deprecated( - RedundantAPI + "Prefer if-else statement inside either DSL, or replace with explicit flatMap", - ReplaceWith("flatMap { b -> b.takeIf(predicate)?.right() ?: error().left() }") -) // TODO open-question: should we expose `ensureNotNull` or `ensure` DSL API on Either or Companion? -public inline fun Either.ensure(error: () -> A, predicate: (B) -> Boolean): Either = - flatMap { b -> b.takeIf(predicate)?.right() ?: error().left() } - -@Deprecated( - NicheAPI + "Prefer using a simple fold, or when expression", - ReplaceWith("fold(fa, fb)") -) -public inline fun Either.redeemWith(fa: (A) -> Either, fb: (B) -> Either): Either { - contract { - callsInPlace(fa, InvocationKind.AT_MOST_ONCE) - callsInPlace(fb, InvocationKind.AT_MOST_ONCE) - } - return fold(fa, fb) -} - -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "fold({ listOf>(it.left()) }, { iterable -> iterable.map> { it.right() } })", - "arrow.core.right", "arrow.core.left" - ) -) -public fun Either>.sequence(): List> = - fold({ listOf(it.left()) }, { iterable -> iterable.map { it.right() } }) - -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "this.fold>>({ Some(it.left()) }, { iterable -> iterable.map> { it.right() } })", - "arrow.core.Either", - "arrow.core.Option", - "arrow.core.Some", - "arrow.core.left", - "arrow.core.right" - ) -) -public fun Either>.sequenceOption(): Option> = - sequence() - -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "this.fold>>({ Some(it.left()) }, { iterable -> iterable.map> { it.right() } })", - "arrow.core.Either", - "arrow.core.Option", - "arrow.core.Some", - "arrow.core.left", - "arrow.core.right" - ) -) -public fun Either>.sequence(): Option> = - fold({ Some(it.left()) }) { it.map { it.right() } } - -@Deprecated( - "Prefer Kotlin nullable syntax inside either DSL, or replace with explicit fold", - ReplaceWith( - "this.fold?>({ it.left() }, { it?.right() })", - "arrow.core.Either", - "arrow.core.right", - "arrow.core.left" - ) -) -public fun Either.sequenceNullable(): Either? = - sequence() - -@Deprecated( - "Prefer Kotlin nullable syntax", - ReplaceWith( - "this.fold?>({ it.left() }, { it?.right() })", - "arrow.core.Either", - "arrow.core.right", - "arrow.core.left" - ) -) -public fun Either.sequence(): Either? = - this.fold?>({ it.left() }, { it?.right() }) - public const val NicheAPI: String = "This API is niche and will be removed in the future. If this method is crucial for you, please let us know on the Arrow Github. Thanks!\n https://github.com/arrow-kt/arrow/issues\n" @@ -2478,7 +1417,7 @@ public fun E.leftNel(): EitherNel = * fallback shouldBe Either.Right(5) * } * ``` - * + * * * * When shifting a new error [EE] into the [Either.Left] channel, @@ -2495,7 +1434,7 @@ public fun E.leftNel(): EitherNel = * listOfErrors shouldBe Either.Left(listOf('e', 'r', 'r', 'o', 'r')) * } * ``` - * + * * */ @OptIn(ExperimentalTypeInference::class) @@ -2532,7 +1471,7 @@ public inline fun Either.recover(@BuilderInference recover: Rai * failure shouldBe Either.Left("failure") * } * ``` - * + * * */ @OptIn(ExperimentalTypeInference::class) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt index 1b48b448263..b6a0a6514f5 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt @@ -5,20 +5,9 @@ package arrow.core import arrow.core.Ior.Both import arrow.core.Ior.Left import arrow.core.Ior.Right -import arrow.core.raise.either -import arrow.core.raise.ior -import arrow.core.raise.nullable -import arrow.core.raise.option -import arrow.typeclasses.Monoid -import arrow.typeclasses.Semigroup -import arrow.typeclasses.SemigroupDeprecation -import arrow.typeclasses.combine import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract -import kotlin.experimental.ExperimentalTypeInference -import kotlin.js.JsName -import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic public typealias IorNel = Ior, B> @@ -36,7 +25,7 @@ public typealias IorNel = Ior, B> * [Ior]<`A`,`B`> is similar to [Either]<`A`,`B`>, except that it can represent the simultaneous presence of * an `A` and a `B`. It is right-biased so methods such as `map` and `flatMap` operate on the * `B` value. Some methods, like `flatMap`, handle the presence of two [Ior.Both] values using a - * [Semigroup]<`A`>, while other methods, like [toEither], ignore the `A` value in a [Ior.Both Both]. + * `combine` function `(A, A) -> A`, while other methods, like [toEither], ignore the `A` value in a [Ior.Both Both]. * * [Ior]<`A`,`B`> is isomorphic to [Either]<[Either]<`A`,`B`>, [Pair]<`A`,`B`>>, but provides methods biased toward `B` * values, regardless of whether the `B` values appear in a [Ior.Right] or a [Ior.Both]. @@ -45,7 +34,7 @@ public typealias IorNel = Ior, B> public sealed class Ior { /** - * Returns `true` if this is a [Right], `false` otherwise. + * Returns `true` if this is a [Left], `false` otherwise. * * Example: * @@ -53,21 +42,24 @@ public sealed class Ior { * import arrow.core.Ior * * fun main() { - * Ior.Left("tulip").isRight // Result: false - * Ior.Right("venus fly-trap").isRight // Result: true - * Ior.Both("venus", "fly-trap").isRight // Result: false + * Ior.Left("tulip").isLeft() // Result: true + * Ior.Right("venus fly-trap").isLeft() // Result: false + * Ior.Both("venus", "fly-trap").isLeft() // Result: false * } * ``` * */ - @Deprecated( - RedundantAPI + "Use isRight()", - ReplaceWith("isRight()") - ) - public abstract val isRight: Boolean + public fun isLeft(): Boolean { + contract { + returns(true) implies (this@Ior is Ior.Left) + returns(false) implies (this@Ior is Ior.Right) + returns(false) implies (this@Ior is Ior.Both) + } + return this@Ior is Ior.Left + } /** - * Returns `true` if this is a [Left], `false` otherwise. + * Returns `true` if this is a [Right], `false` otherwise. * * Example: * @@ -75,18 +67,21 @@ public sealed class Ior { * import arrow.core.Ior * * fun main() { - * Ior.Left("tulip").isLeft // Result: true - * Ior.Right("venus fly-trap").isLeft // Result: false - * Ior.Both("venus", "fly-trap").isLeft // Result: false + * Ior.Left("tulip").isRight() // Result: false + * Ior.Right("venus fly-trap").isRight() // Result: true + * Ior.Both("venus", "fly-trap").isRight() // Result: false * } * ``` * */ - @Deprecated( - RedundantAPI + "Use isLeft()", - ReplaceWith("isLeft()") - ) - public abstract val isLeft: Boolean + public fun isRight(): Boolean { + contract { + returns(true) implies (this@Ior is Ior.Right) + returns(false) implies (this@Ior is Ior.Left) + returns(false) implies (this@Ior is Ior.Both) + } + return this@Ior is Ior.Right + } /** * Returns `true` if this is a [Both], `false` otherwise. @@ -96,43 +91,13 @@ public sealed class Ior { * import arrow.core.Ior * * fun main() { - * Ior.Left("tulip").isBoth // Result: false - * Ior.Right("venus fly-trap").isBoth // Result: false - * Ior.Both("venus", "fly-trap").isBoth // Result: true + * Ior.Left("tulip").isBoth() // Result: false + * Ior.Right("venus fly-trap").isBoth() // Result: false + * Ior.Both("venus", "fly-trap").isBoth() // Result: true * } * ``` * */ - - @Deprecated( - RedundantAPI + "Use isBoth()", - ReplaceWith("isBoth()") - ) - public abstract val isBoth: Boolean - @JsName("_isLeft") - @JvmName("_isLeft") - public fun isLeft(): Boolean { - contract { - returns(true) implies (this@Ior is Ior.Left) - returns(false) implies (this@Ior is Ior.Right) - returns(false) implies (this@Ior is Ior.Both) - } - return this@Ior is Ior.Left - } - - @JsName("_isRight") - @JvmName("_isRight") - public fun isRight(): Boolean { - contract { - returns(true) implies (this@Ior is Ior.Right) - returns(false) implies (this@Ior is Ior.Left) - returns(false) implies (this@Ior is Ior.Both) - } - return this@Ior is Ior.Right - } - - @JsName("_isBoth") - @JvmName("_isBoth") public fun isBoth(): Boolean { contract { returns(false) implies (this@Ior is Ior.Right) @@ -149,7 +114,7 @@ public sealed class Ior { * @param a an element (nullable) for the left side of the [Ior] * @param b an element (nullable) for the right side of the [Ior] * - * @return [null] if both [a] and [b] are [null]. Otherwise + * @return `null` if both [a] and [b] are `null`. Otherwise * an [Ior.Left], [Ior.Right], or [Ior.Both] if [a], [b], or both are defined (respectively). */ @JvmStatic @@ -171,39 +136,6 @@ public sealed class Ior { @JvmStatic public fun bothNel(a: A, b: B): IorNel = Both(nonEmptyListOf(a), b) - - /** - * Lifts a function `(B) -> C` to the [Ior] structure returning a polymorphic function - * that can be applied over all [Ior] values in the shape of Ior - * - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * //sampleStart - * val f = Ior.lift { s: CharSequence -> "$s World" } - * val ior: Ior = Ior.Right("Hello") - * val result = f(ior) - * //sampleEnd - * println(result) - * } - * ``` - */ - @JvmStatic - @Deprecated( - RedundantAPI + "Prefer explicitly creating lambdas", - ReplaceWith("{ it.map(f) }") - ) - public fun lift(f: (B) -> C): (Ior) -> Ior = - { it.map(f) } - - @JvmStatic - @Deprecated( - RedundantAPI + "Prefer explicitly creating lambdas", - ReplaceWith("{ it.map(fb).mapLeft(fa) }") - ) - public fun lift(fa: (A) -> C, fb: (B) -> D): (Ior) -> Ior = - { it.map(fb).mapLeft(fa) } } /** @@ -228,49 +160,6 @@ public sealed class Ior { } } - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("fold({ c }, { f(c, it) }, { _, b -> f(c, b) })") - ) - public inline fun foldLeft(c: C, f: (C, B) -> C): C { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return fold({ c }, { f(c, it) }, { _, b -> f(c, b) }) - } - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("this.fold({ leftValue }, { f }, { _, b -> f(b) })") - ) - public inline fun foldMap(MN: Monoid, f: (B) -> C): C { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return MN.run { - fold({ MN.empty() }, { f(it) }, { _, b -> f(b) }) - } - } - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("this.fold({ f(c, it) }, { g(c, it) }, { a, b -> g(f(c, a), b) })") - ) - public inline fun bifoldLeft(c: C, f: (C, A) -> C, g: (C, B) -> C): C { - contract { - callsInPlace(f, InvocationKind.AT_MOST_ONCE) - callsInPlace(g, InvocationKind.AT_MOST_ONCE) - } - return fold({ f(c, it) }, { g(c, it) }, { a, b -> g(f(c, a), b) }) - } - - @Deprecated(NicheAPI + "Prefer when or fold instead. See the Arrow web migration guide for more info.") - public inline fun bifoldMap(MN: Monoid, f: (A) -> C, g: (B) -> C): C { - contract { - callsInPlace(f, InvocationKind.AT_MOST_ONCE) - callsInPlace(g, InvocationKind.AT_MOST_ONCE) - } - return MN.run { - fold({ f(it) }, { g(it) }, { a, b -> f(a).combine(g(b)) }) - } - } - /** * The given function is applied if this is a [Right] or [Both] to `B`. * @@ -295,34 +184,6 @@ public sealed class Ior { } } - /** - * Apply `fa` if this is a [Left] or [Both] to `A` - * and apply `fb` if this is [Right] or [Both] to `B` - * - * Example: - * ```kotlin - * import arrow.core.Ior - * - * fun main() { - * Ior.Right(12).bimap ({ "flower" }, { 12 }) // Result: Right(12) - * Ior.Left(12).bimap({ "flower" }, { 12 }) // Result: Left("flower") - * Ior.Both(12, "power").bimap ({ it * 2 }, { b -> "flower $b" }) // Result: Both("flower power", 24) - * } - * ``` - * - */ - @Deprecated( - NicheAPI + "Prefer using the Either DSL, or map + mapLeft", - ReplaceWith("map(fb).mapLeft(fa)") - ) - public inline fun bimap(fa: (A) -> C, fb: (B) -> D): Ior { - contract { - callsInPlace(fa, InvocationKind.AT_MOST_ONCE) - callsInPlace(fb, InvocationKind.AT_MOST_ONCE) - } - return map(fb).mapLeft(fa) - } - /** * The given function is applied if this is a [Left] or [Both] to `A`. * @@ -336,7 +197,7 @@ public sealed class Ior { * Ior.Both(12, "power").mapLeft { "flower $it" } // Result: Both("flower 12", "power") * } * ``` - * + * */ public inline fun mapLeft(fa: (A) -> C): Ior { contract { callsInPlace(fa, InvocationKind.AT_MOST_ONCE) } @@ -361,7 +222,7 @@ public sealed class Ior { * Ior.Both("left", "right").swap() // Result: Both("right", "left") * } * ``` - * + * */ public fun swap(): Ior = fold( { Right(it) }, @@ -378,34 +239,6 @@ public sealed class Ior { { a, b -> Either.Right(Pair(a, b)) } ) - /** - * Return this [Ior] as [Pair] of nullables] - * - * Example: - * ```kotlin - * import arrow.core.Ior - * - * fun main() { - * val right = Ior.Right(12).padNull() // Result: Pair(null, 12) - * val left = Ior.Left(12).padNull() // Result: Pair(12, null) - * val both = Ior.Both("power", 12).padNull() // Result: Pair("power", 12) - * - * println("right = $right") - * println("left = $left") - * println("both = $both") - * } - * ``` - * - */ - @Deprecated( - "padNull is being renamed to toPair to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("toPair()") - ) - public fun padNull(): Pair = fold( - { Pair(it, null) }, - { Pair(null, it) }, - { a, b -> Pair(a, b) } - ) public fun toPair(): Pair = fold( { Pair(it, null) }, { Pair(null, it) }, @@ -426,43 +259,11 @@ public sealed class Ior { * Ior.Both("power", 12).toEither() // Result: Either.Right(12) * } * ``` - * + * */ public fun toEither(): Either = fold({ Either.Left(it) }, { Either.Right(it) }, { _, b -> Either.Right(b) }) - /** - * Returns the [Right] value or `B` if this is [Right] or [Both] - * and [null] if this is a [Left]. - * - * Example: - * ```kotlin - * import arrow.core.Ior - * - * fun main() { - * val right = Ior.Right(12).orNull() // Result: 12 - * val left = Ior.Left(12).orNull() // Result: null - * val both = Ior.Both(12, "power").orNull() // Result: "power" - * - * println("right = $right") - * println("left = $left") - * println("both = $both") - * } - * ``` - * - */ - @Deprecated( - "orNull is being renamed to getOrNull to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("getOrNull()") - ) - public fun orNull(): B? { - contract { - returns(null) implies (this@Ior is Left) - returnsNotNull() implies ((this@Ior is Right) || (this@Ior is Both)) - } - return fold({ null }, { it }, { _, b -> b }) - } - public fun getOrNull(): B? { contract { returns(null) implies (this@Ior is Left) @@ -473,7 +274,7 @@ public sealed class Ior { /** * Returns the [Left] value or `A` if this is [Left] or [Both] - * and [null] if this is a [Right]. + * and `null` if this is a [Right]. * * Example: * ```kotlin @@ -488,7 +289,7 @@ public sealed class Ior { * println("both = $both") * } * ``` - * + * */ public fun leftOrNull(): A? { contract { @@ -499,34 +300,18 @@ public sealed class Ior { } public data class Left(val value: A) : Ior() { - override val isRight: Boolean get() = false - override val isLeft: Boolean get() = true - override val isBoth: Boolean get() = false - override fun toString(): String = "Ior.Left($value)" public companion object } public data class Right(val value: B) : Ior() { - override val isRight: Boolean get() = true - override val isLeft: Boolean get() = false - override val isBoth: Boolean get() = false - override fun toString(): String = "Ior.Right($value)" - public companion object { - @PublishedApi - internal val unit: Ior = - Right(Unit) - } + public companion object } public data class Both(val leftValue: A, val rightValue: B) : Ior() { - override val isRight: Boolean get() = false - override val isLeft: Boolean get() = false - override val isBoth: Boolean get() = true - override fun toString(): String = "Ior.Both($leftValue, $rightValue)" } @@ -535,105 +320,6 @@ public sealed class Ior { { "Ior.Right($it)" }, { a, b -> "Ior.Both($a, $b)" } ) - @Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") - public inline fun bicrosswalk( - fa: (A) -> Iterable, - fb: (B) -> Iterable, - ): List> = - fold( - { a -> fa(a).map { it.leftIor() } }, - { b -> fb(b).map { it.rightIor() } }, - { a, b -> fa(a).align(fb(b)) } - ) - @Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") - public inline fun bicrosswalkMap( - fa: (A) -> Map, - fb: (B) -> Map, - ): Map> = - fold( - { a -> fa(a).mapValues { it.value.leftIor() } }, - { b -> fb(b).mapValues { it.value.rightIor() } }, - { a, b -> fa(a).align(fb(b)) } - ) - @Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") - public inline fun bicrosswalkNull( - fa: (A) -> C?, - fb: (B) -> D?, - ): Ior? = - fold( - { a -> fa(a)?.let { Left(it) } }, - { b -> fb(b)?.let { Right(it) } }, - { a, b -> fromNullables(fa(a), fb(b)) } - ) - - @Deprecated( - NicheAPI + "Prefer using Ior DSL, or explicit fold, or when", - ReplaceWith("fold({ emptyList() },{ b -> fa(b).map { Ior.Right(it) } },{ a, b -> fa(b).map { Ior.Both(a, it) } })", - "arrow.core.Ior") - ) - public inline fun crosswalk(fa: (B) -> Iterable): List> = - fold( - { emptyList() }, - { b -> fa(b).map { Right(it) } }, - { a, b -> fa(b).map { Both(a, it) } } - ) - @Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") - public inline fun crosswalkMap(fa: (B) -> Map): Map> = - fold( - { emptyMap() }, - { b -> fa(b).mapValues { Right(it.value) } }, - { a, b -> fa(b).mapValues { Both(a, it.value) } } - ) - @Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") - public inline fun crosswalkNull(ior: Ior, fa: (B) -> C?): Ior? = - ior.fold( - { a -> Left(a) }, - { b -> fa(b)?.let { Right(it) } }, - { a, b -> fa(b)?.let { Both(a, it) } } - ) - - @Deprecated(NicheAPI + "Prefer using fold, or map + getOrElse. See the Arrow web migration guide for more info.") - public inline fun all(predicate: (B) -> Boolean): Boolean { - contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } - return fold({ true }, predicate, { _, b -> predicate(b) }) - } - - /** - * Returns `false` if [Left] or returns the result of the application of - * the given predicate to the [Right] value. - * - * Example: - * ```kotlin - * import arrow.core.Ior - * - * fun main() { - * Ior.Both(5, 12).exists { it > 10 } // Result: true - * Ior.Right(12).exists { it > 10 } // Result: true - * Ior.Right(7).exists { it > 10 } // Result: false - * val left: Ior = Ior.Left(12) - * left.exists { it > 10 } // Result: false - * } - * ``` - * - */ - @Deprecated( - NicheAPI + "Prefer using fold, or map + getOrElse", - ReplaceWith("fold({ false }, predicate, { _, b -> predicate(b) })") - ) - public inline fun exists(predicate: (B) -> Boolean): Boolean { - contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } - return fold({ false }, predicate, { _, b -> predicate(b) }) - } - - @Deprecated( - NicheAPI + "Prefer Kotlin nullable syntax instead", - ReplaceWith("getOrNull()?.takeIf(predicate)") - ) - public inline fun findOrNull(predicate: (B) -> Boolean): B? { - contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } - return getOrNull()?.takeIf(predicate) - } - /** * Returns `false` if [Right] or [Both], or returns the result of the application of @@ -650,7 +336,7 @@ public sealed class Ior { * Ior.Left(12).isLeft { it > 10 } // Result: true * } * ``` - * + * */ public inline fun isLeft(predicate: (A) -> Boolean): Boolean { contract { @@ -675,7 +361,7 @@ public sealed class Ior { * left.isRight { it > 10 } // Result: true * } * ``` - * + * */ public inline fun isRight(predicate: (B) -> Boolean): Boolean { contract { @@ -701,7 +387,7 @@ public sealed class Ior { * left.isBoth ( {it > 10}, {it > 6 }) // Result: false * } * ``` - * + * */ public inline fun isBoth(leftPredicate: (A) -> Boolean, rightPredicate: (B) -> Boolean): Boolean { contract { @@ -710,47 +396,8 @@ public sealed class Ior { } return this@Ior is Both && leftPredicate(leftValue) && rightPredicate(rightValue) } - - - @Deprecated( - NicheAPI + "Prefer using isLeft", - ReplaceWith("isLeft()") - ) - public fun isEmpty(): Boolean { - contract { - returns(true) implies (this@Ior is Left) - returns(false) implies (this@Ior is Right || this@Ior is Both) - } - return isLeft - } - - @Deprecated( - NicheAPI + "Prefer using isRight and isBoth", - ReplaceWith("(this.isRight() || this.isBoth())") - ) - public fun isNotEmpty(): Boolean { - contract { - returns(false) implies (this@Ior is Left) - returns(true) implies (this@Ior is Right || this@Ior is Both) - } - return !isLeft - } - - @Deprecated( - NicheAPI + "Prefer using map", - ReplaceWith("map { }") - ) - public fun void(): Ior = - map { Unit } } -@Deprecated( - "$SemigroupDeprecation.", - ReplaceWith("this.flatMap({a, b -> a + b}, f)") -) -public inline fun Ior.flatMap(SG: Semigroup, f: (B) -> Ior): Ior = - flatMap(SG::combine, f) - /** * Binds the given function across [Ior.Right]. * @@ -767,15 +414,6 @@ public inline fun Ior.flatMap(combine: (A, A) -> A, f: (B) -> Io ) } -@Deprecated( - RedundantAPI + "This API is overloaded with an API with a single argument", - level = DeprecationLevel.HIDDEN -) -public inline fun Ior.getOrElse(default: () -> B): B { - contract { callsInPlace(default, InvocationKind.AT_MOST_ONCE) } - return fold({ default() }, ::identity, { _, b -> b }) -} - public inline fun Ior.getOrElse(default: (A) -> B): B { contract { callsInPlace(default, InvocationKind.AT_MOST_ONCE) } return fold(default, ::identity) { _, b -> b } @@ -788,86 +426,6 @@ public fun A.leftIor(): Ior = Ior.Left(this) public fun A.rightIor(): Ior = Ior.Right(this) -@Deprecated( - NicheAPI + "Prefer using Ior DSL, or explicit fold, or when", - ReplaceWith( - "this.fold>>({ a: List -> a.map> { Ior.Left(it) } }, {b: List -> b.map>{ Ior.Right(it) } }, { a, b -> a.zip>(b) { aa, c -> Ior.Both(aa, c) } })", - "arrow.core.Ior" - ) -) -public fun Ior, Iterable>.bisequence(): List> = - fold({ a -> a.map { Left(it) } }, - { b -> b.map { Right(it) } }, - { a, b -> a.zip(b) { aa, c -> Both(aa, c) } }) - -@Deprecated( - NicheAPI + "Prefer using Ior DSL, or explicit fold, or when", - ReplaceWith( - "this.fold>>({ a -> a.map> { Ior.Left(it) } }, {b -> b.map>{ Ior.Right(it) } }, { a: Either, b: Either -> either> { Ior.Both(a.bind(), b.bind()) } })", - "arrow.core.Ior", - "arrow.core.raise.either" - ) -) -public fun Ior, Either>.bisequenceEither(): Either> = - fold({ a -> a.map { Left(it) } }, - { b -> b.map { Right(it) } }, - { a, b -> either { Both(a.bind(), b.bind()) } }) - -@Deprecated( - NicheAPI + "Prefer using Ior DSL, or explicit fold, or when", - ReplaceWith( - "this.fold>>({ a -> a.map> { Ior.Left(it) } }, {b -> b.map>{ Ior.Right(it) } }, { a, b -> option> { Ior.Both(a.bind(), b.bind()) } })", - "arrow.core.Ior", - "arrow.core.raise.option" - ) -) -public fun Ior, Option>.bisequenceOption(): Option> = - fold({ a -> a.map { Left(it) } }, - { b -> b.map { Right(it) } }, - { a, b -> option { Both(a.bind(), b.bind()) } }) - -@Deprecated( - NicheAPI + "Prefer using Ior DSL, or explicit fold, or when", - ReplaceWith( - "fold({ a -> a?.let>{ Ior.Left(it) } }, {b -> b?.let>{ Ior.Right(it) } }, { a, b -> nullable> { Ior.Both(a.bind(), b.bind()) } })", - "arrow.core.Ior", - "arrow.core.raise.nullable" - ) -) -public fun Ior.bisequenceNullable(): Ior? = - fold( - { a -> a?.let { Left(it) } }, - { b -> b?.let { Right(it) } }, - { a, b -> nullable { Both(a.bind(), b.bind()) } }) - -@Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") -public fun Ior, Validated>.bisequenceValidated(SA: Semigroup): Validated> = - bitraverseValidated(SA, ::identity, ::identity) - -@Deprecated( - "$SemigroupDeprecation", - ReplaceWith("combine(other, {a1, a2 -> a1 + a2}, {b1, b2 -> b1 + b2} )") -) -public fun Ior.combine(other: Ior, combineA: (A, A) -> A, combineB: (B, B) -> B): Ior = - when (this) { - is Ior.Left -> when (other) { - is Ior.Left -> Ior.Left(combineA(value, other.value)) - is Ior.Right -> Ior.Both(value, other.value) - is Ior.Both -> Ior.Both(combineA(value, other.leftValue), other.rightValue) - } - - is Ior.Right -> when (other) { - is Ior.Left -> Ior.Both(other.value, value) - is Ior.Right -> Ior.Right(combineB(value, other.value)) - is Ior.Both -> Ior.Both(other.leftValue, combineB(value, other.rightValue)) - } - - is Ior.Both -> when (other) { - is Ior.Left -> Ior.Both(combineA(leftValue, other.value), rightValue) - is Ior.Right -> Ior.Both(leftValue, combineB(rightValue, other.value)) - is Ior.Both -> Ior.Both(combineA(leftValue, other.leftValue), combineB(rightValue, other.rightValue)) - combine(other, SA::combine, SB::combine) - public fun Ior.combine(other: Ior, combineA: (A, A) -> A, combineB: (B, B) -> B): Ior = when (this) { is Ior.Left -> when (other) { @@ -892,36 +450,6 @@ public fun Ior.combine(other: Ior, combineA: (A, A) -> A, com public inline fun Ior>.flatten(combine: (A, A) -> A): Ior = flatMap(combine, ::identity) -@Suppress("NOTHING_TO_INLINE") -@Deprecated( - "$SemigroupDeprecation.", - ReplaceWith("this.flatten{a1, a2 -> a1 + a2}") -) -public inline fun Ior>.flatten(SA: Semigroup): Ior = - flatMap(SA, ::identity) - -@Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") -public fun Ior.replicate(SA: Semigroup, n: Int): Ior> = - if (n <= 0) Ior.Right(emptyList()) - else when (this) { - is Ior.Right -> Ior.Right(List(n) { value }) - is Ior.Left -> this - is Ior.Both -> map { List(n) { rightValue } }.mapLeft { List(n - 1) { leftValue }.fold(leftValue) { acc, a -> SA.run { acc + a } } } - } - -@Deprecated(NicheAPI + "Prefer using Ior DSL, or explicit fold, or when. See the Arrow web migration guide for more info.") -public fun Ior.replicate(SA: Semigroup, n: Int, MB: Monoid): Ior = - if (n <= 0) Ior.Right(MB.empty()) - else when (this) { - is Ior.Right -> Ior.Right(MB.run { List(n) { value }.fold() }) - is Ior.Left -> this - is Ior.Both -> map { MB.run { List(n) { rightValue }.fold() } }.mapLeft { - List(n - 1) { leftValue }.fold( - leftValue - ) { acc, a -> SA.run { acc + a } } - } - } - /** * Given [B] is a sub type of [C], re-type this value from Ior to Ior * @@ -937,285 +465,11 @@ public fun Ior.replicate(SA: Semigroup, n: Int, MB: Monoid): * println(chars) * } * ``` - * + * */ public fun Ior.widen(): Ior = this -@Deprecated( - NicheAPI + "Prefer using widen", - ReplaceWith("widen()", "arrow.core.widen") -) -public fun Ior.leftWiden(): Ior = - this - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith( - "ior({a, b -> a + b}) { Pair(this.bind(), fb.bind()) }", - "arrow.core.raise.ior", - "arrow.typeclasses.combine" - ) -) -public fun Ior.zip(SA: Semigroup, fb: Ior): Ior> = - ior(SA::combine) { Pair(this@zip.bind(), fb.bind()) } - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith("ior({a, b -> a + b}) { map(this.bind(), c.bind()) }", "arrow.core.raise.ior") -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - map: (B, C) -> D -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith("ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()) }", "arrow.core.raise.ior") -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - map: (B, C, D) -> E -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind(), d.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith("ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()), e.bind() }", "arrow.core.raise.ior") -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - e: Ior, - map: (B, C, D, E) -> F -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind(), d.bind(), e.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith( - "ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()), e.bind(), f.bind() }", - "arrow.core.raise.ior" - ) -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - e: Ior, - f: Ior, - map: (B, C, D, E, F) -> G -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind(), d.bind(), e.bind(), f.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith( - "ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()), e.bind(), f.bind(), g.bind() }", - "arrow.core.raise.ior" - ) -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - e: Ior, - f: Ior, - g: Ior, - map: (B, C, D, E, F, G) -> H -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith( - "ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()), e.bind(), f.bind(), g.bind(), h.bind() }", - "arrow.core.raise.ior" - ) -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - e: Ior, - f: Ior, - g: Ior, - h: Ior, - map: (B, C, D, E, F, G, H) -> I -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith( - "ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()), e.bind(), f.bind(), g.bind(), h.bind(), i.bind() }", - "arrow.core.raise.ior" - ) -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - e: Ior, - f: Ior, - g: Ior, - h: Ior, - i: Ior, - map: (B, C, D, E, F, G, H, I) -> J -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith( - "ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind() }", - "arrow.core.raise.ior" - ) -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - e: Ior, - f: Ior, - g: Ior, - h: Ior, - i: Ior, - j: Ior, - map: (B, C, D, E, F, G, H, I, J) -> K -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return ior(SA::combine) { - map(this@zip.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind()) - } -} - -@Deprecated( - NicheAPI + "Prefer using the inline ior DSL", - ReplaceWith( - "ior({a, b -> a + b}) { map(this.bind(), c.bind(), d.bind()), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind(), k.bind() }", - "arrow.core.raise.ior" - ) -) -public inline fun Ior.zip( - SA: Semigroup, - c: Ior, - d: Ior, - e: Ior, - f: Ior, - g: Ior, - h: Ior, - i: Ior, - j: Ior, - k: Ior, - map: (B, C, D, E, F, G, H, I, J, K) -> L, -): Ior { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - // If any of the values is Right or Both then we can calculate L otherwise it results in MY_NULL - val rightValue: Any? = if ( - (this@zip.isRight() || this@zip.isBoth()) && - (c.isRight() || c.isBoth()) && - (d.isRight() || d.isBoth()) && - (e.isRight() || e.isBoth()) && - (f.isRight() || f.isBoth()) && - (g.isRight() || g.isBoth()) && - (h.isRight() || h.isBoth()) && - (i.isRight() || i.isBoth()) && - (j.isRight() || j.isBoth()) && - (k.isRight() || k.isBoth()) - ) { - map( - this@zip.orNull() as B, - c.orNull() as C, - d.orNull() as D, - e.orNull() as E, - f.orNull() as F, - g.orNull() as G, - h.orNull() as H, - i.orNull() as I, - j.orNull() as J, - k.orNull() as K - ) - } else EmptyValue - - val leftValue: Any? = SA.run { - var accumulatedLeft: Any? = EmptyValue - - if (this@zip is Left) return@zip Left(this@zip.value) - accumulatedLeft = - if (this@zip is Both) this@zip.leftValue else accumulatedLeft - - if (c is Left) return@zip Left(emptyCombine(accumulatedLeft, c.value)) - accumulatedLeft = if (c is Both) emptyCombine(accumulatedLeft, c.leftValue) else accumulatedLeft - - if (d is Left) return@zip Left(emptyCombine(accumulatedLeft, d.value)) - accumulatedLeft = if (d is Both) emptyCombine(accumulatedLeft, d.leftValue) else accumulatedLeft - - if (e is Left) return@zip Left(emptyCombine(accumulatedLeft, e.value)) - accumulatedLeft = if (e is Both) emptyCombine(accumulatedLeft, e.leftValue) else accumulatedLeft - - if (f is Left) return@zip Left(emptyCombine(accumulatedLeft, f.value)) - accumulatedLeft = if (f is Both) emptyCombine(accumulatedLeft, f.leftValue) else accumulatedLeft - - if (g is Left) return@zip Left(emptyCombine(accumulatedLeft, g.value)) - accumulatedLeft = if (g is Both) emptyCombine(accumulatedLeft, g.leftValue) else accumulatedLeft - - if (h is Left) return@zip Left(emptyCombine(accumulatedLeft, h.value)) - accumulatedLeft = if (h is Both) emptyCombine(accumulatedLeft, h.leftValue) else accumulatedLeft - - if (i is Left) return@zip Left(emptyCombine(accumulatedLeft, i.value)) - accumulatedLeft = if (i is Both) emptyCombine(accumulatedLeft, i.leftValue) else accumulatedLeft - - if (j is Left) return@zip Left(emptyCombine(accumulatedLeft, j.value)) - accumulatedLeft = if (j is Both) emptyCombine(accumulatedLeft, j.leftValue) else accumulatedLeft - - if (k is Left) return@zip Left(emptyCombine(accumulatedLeft, k.value)) - accumulatedLeft = if (k is Both) emptyCombine(accumulatedLeft, k.leftValue) else accumulatedLeft - - accumulatedLeft - } - - return when { - rightValue != EmptyValue && leftValue == EmptyValue -> Right(rightValue as L) - rightValue != EmptyValue && leftValue != EmptyValue -> Both(leftValue as A, rightValue as L) - rightValue == EmptyValue && leftValue != EmptyValue -> Left(leftValue as A) - else -> throw ArrowCoreInternalException - } -} - public operator fun , B : Comparable> Ior.compareTo(other: Ior): Int = fold( { a1 -> other.fold({ a2 -> a1.compareTo(a2) }, { -1 }, { _, _ -> -1 }) }, { b1 -> other.fold({ 1 }, { b2 -> b1.compareTo(b2) }, { _, _ -> -1 }) }, diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt index 0341717bb9c..3e8166c6461 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt @@ -11,14 +11,6 @@ import arrow.core.raise.Raise import arrow.core.raise.either import arrow.core.raise.RaiseAccumulate import arrow.core.raise.mapOrAccumulate -import arrow.core.raise.nullable -import arrow.core.raise.option -import arrow.core.raise.result -import arrow.typeclasses.Monoid -import arrow.typeclasses.MonoidDeprecation -import arrow.typeclasses.Semigroup -import arrow.typeclasses.SemigroupDeprecation -import arrow.typeclasses.combine import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmName @@ -296,222 +288,6 @@ public inline fun Iterable.zip( internal fun Iterable.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default -@Deprecated( - "Traverse for Either is being deprecated in favor of Either DSL + Iterable.map.\n$NicheAPI", - ReplaceWith("let, Either>> { l -> either> { l.map { f(it).bind() } } }", "arrow.core.raise.either") -) -public inline fun Iterable.traverseEither(f: (A) -> Either): Either> = - let { l -> either { l.map { f(it).bind() } } } - -@Deprecated( - "Traverse for Either is being deprecated in favor of Either DSL + Iterable.map.\n$NicheAPI", - ReplaceWith("let, Either>> { l -> either> { l.map { f(it).bind() } } }", "arrow.core.raise.either") -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> Either): Either> = - let { l -> either { l.map { f(it).bind() } } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the either DSL.", - ReplaceWith("let { l -> either> { l.bindAll() } }", "arrow.core.raise.either") -) -public fun Iterable>.sequenceEither(): Either> = - let { l -> either { l.bindAll() } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the either DSL.", - ReplaceWith("let { l -> either> { l.bindAll() } }", "arrow.core.raise.either") -) -public fun Iterable>.sequence(): Either> = - let { l -> either { l.bindAll() } } - -@Deprecated( - "Traverse for Result is being deprecated in favor of Result DSL + Iterable.map.\n$NicheAPI", - ReplaceWith("let, Result>> { l -> result> { l.map { f(it).bind() } } }", "arrow.core.raise.result") -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> Result): Result> = - let { l -> result { l.map { f(it).bind() } } } - -@Deprecated( - "Traverse for Result is being deprecated in favor of Result DSL + Iterable.map.\n$NicheAPI", - ReplaceWith("let, Result>> { l -> result> { l.map { f(it).bind() } } }", "arrow.core.raise.result") -) -public inline fun Iterable.traverseResult(f: (A) -> Result): Result> = - let { l -> result { l.map { f(it).bind() } } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the result DSL.", - ReplaceWith("let { l -> result> { l.bindAll() } }", "arrow.core.raise.result") -) -public fun Iterable>.sequenceResult(): Result> = - let { l -> result { l.bindAll() } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the result DSL.", - ReplaceWith("let { l -> result> { l.bindAll() } }", "arrow.core.raise.result") -) -public fun Iterable>.sequence(): Result> = - let { l -> result { l.bindAll() } } - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { f(it).bind() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -public inline fun Iterable.traverseValidated( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { f(it).bind() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { f(it).bind() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { f(it).bind() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate { f(it).bindNel() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -public inline fun Iterable.traverseValidated(f: (A) -> ValidatedNel): ValidatedNel> = - mapOrAccumulate { f(it).bindNel() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate { f(it).bindNel() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> ValidatedNel): ValidatedNel> = - mapOrAccumulate { f(it).bindNel() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { it.bind() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -public fun Iterable>.sequenceValidated(semigroup: Semigroup): Validated> = - mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { it.bind() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { it.bind() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -public fun Iterable>.sequence(semigroup: Semigroup): Validated> = - mapOrAccumulate({ a, b -> semigroup.run { a.combine(b) } }) { it.bind() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate, A> { it.bindNel() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -public fun Iterable>.sequenceValidated(): ValidatedNel> = - mapOrAccumulate { it.bindNel() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate, A> { it.bindNel() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -public fun Iterable>.sequence(): ValidatedNel> = - mapOrAccumulate { it.bindNel() }.toValidated() - -@Deprecated( - "Traverse for Option is being deprecated in favor of Option DSL + Iterable.map.\n$NicheAPI", - ReplaceWith("let, Option>> { l -> option> { l.map { f(it).bind() } } }", "arrow.core.raise.option") -) -public inline fun Iterable.traverseOption(f: (A) -> Option): Option> = - let { l -> option { l.map { f(it).bind() } } } - -@Deprecated( - "Traverse for Option is being deprecated in favor of Option DSL + Iterable.map.\n$NicheAPI", - ReplaceWith("let, Option>> { l -> option> { l.map { f(it).bind() } } }", "arrow.core.raise.option") -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> Option): Option> = - let { l -> option { l.map { f(it).bind() } } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the option DSL.", - ReplaceWith("let { l -> option> { l.bindAll() } }", "arrow.core.raise.option") -) -public fun Iterable>.sequenceOption(): Option> = - let { l -> option { l.bindAll() } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the option DSL.", - ReplaceWith("let { l -> option> { l.bindAll() } }", "arrow.core.raise.option") -) -public fun Iterable>.sequence(): Option> = - let { l -> option { l.bindAll() } } - -@Deprecated( - "Traverse for nullable is being deprecated in favor of Nullable DSL + Iterable.map.\n$NicheAPI", - ReplaceWith( - "let, List?> { l -> nullable> { l.map { f(it).bind() } } }", - "arrow.core.raise.nullable" - ) -) -public inline fun Iterable.traverseNullable(f: (A) -> B?): List? = - traverse(f) - -@Deprecated( - "Traverse for nullable is being deprecated in favor of Nullable DSL + Iterable.map.\n$NicheAPI", - ReplaceWith( - "let, List?> { l -> nullable> { l.map { f(it).bind() } } }", - "arrow.core.raise.nullable" - ) -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Iterable.traverse(f: (A) -> B?): List? = - let { l -> nullable { l.map { f(it).bind() } } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the nullable DSL.", - ReplaceWith("let { l -> nullable> { l.bindAll() } }", "arrow.core.raise.nullable") -) -public fun Iterable.sequenceNullable(): List? = - let { l -> nullable { l.bindAll() } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the nullable DSL.", - ReplaceWith("let { l -> nullable> { l.bindAll() } }", "arrow.core.raise.nullable") -) -public fun Iterable.sequence(): List? = - let { l -> nullable { l.bindAll() } } - /** * Returns [Either] a [List] containing the results of applying the given [transform] function to each element in the original collection, * **or** accumulate all the _logical errors_ that were _raised_ while transforming the collection using the [combine] function is used to accumulate all the _logical errors_. @@ -615,13 +391,6 @@ public fun Iterable>.flattenOrAccumulate(): Either Iterable>.flattenOrAccumulate(): Either, List> = mapOrAccumulate { it.bindNel() } -@Deprecated( - "Void is being deprecated in favor of simple Iterable.map.\n$NicheAPI", - ReplaceWith("map { }") -) -public fun Iterable.void(): List = - map { } - public inline fun Iterable.reduceOrNull(initial: (A) -> B, operation: (acc: B, A) -> B): B? { val iterator = this.iterator() if (!iterator.hasNext()) return null @@ -820,15 +589,6 @@ public inline fun Iterable.align(b: Iterable, fa: (Ior) -> public fun Iterable.align(b: Iterable): List> = this.align(b, ::identity) -/** - * aligns two structures and combine them with the given [Semigroup.append] - */ -@Deprecated(SemigroupDeprecation, ReplaceWith("this.padZip(other, { it }, { it }, {a1, a2 -> a1 + a2})")) -public fun Iterable.salign( - SG: Semigroup, - other: Iterable, -): Iterable = padZip(other, { it }, { it }, SG::combine) - /** * unzips the structure holding the resulting elements in an `Pair` * @@ -918,7 +678,7 @@ public fun Iterable>.unalign(): Pair, List> = * listOf(1, 2, 3, 4).unalign { * if(it % 2 == 0) it.rightIor() * else it.leftIor() - * } shouldBe Pair(listOf(1, 3), listOf(2, 4)) + * } shouldBe Pair(listOf(1, null, 3, null), listOf(null, 2, null, 4)) * } * ``` * @@ -927,10 +687,6 @@ public fun Iterable>.unalign(): Pair, List> = public inline fun Iterable.unalign(fa: (C) -> Ior): Pair, List> = map(fa).unalign() -@Deprecated("Use fold from Kotlin Std instead", ReplaceWith("this.fold(initial){a1, a2 -> a1 + a2}")) -public fun Iterable.combineAll(MA: Monoid): A = - fold(MA.empty(), MA::combine) - /** * Returns the first element as [Some], or [None] if the iterable is empty. */ @@ -1108,40 +864,6 @@ public fun Iterable.unweave(ffa: (A) -> Iterable): List = ffa(a).interleave(fa.unweave(ffa)) } ?: emptyList() -/** - * Logical conditional. The equivalent of Prolog's soft-cut. - * If its first argument succeeds at all, then the results will be - * fed into the success branch. Otherwise, the failure branch is taken. - * - * ```kotlin - * import arrow.core.* - * - * fun main(args: Array) { - * //sampleStart - * val result = - * listOf(1,2,3).ifThen(listOf("empty")) { i -> - * listOf("$i, ${i + 1}") - * } - * //sampleEnd - * println(result) - * } - * ``` - * - */ -@Deprecated( - "Use flatMap and ifEmpty instead.\n$NicheAPI", - ReplaceWith("flatMap(ffa).ifEmpty, Iterable> { fb }") -) -public inline fun Iterable.ifThen(fb: Iterable, ffa: (A) -> Iterable): Iterable = - flatMap(ffa).ifEmpty { fb } - -@Deprecated( - "Use mapNotNull and getOrNull instead.\n$NicheAPI", - ReplaceWith("mapNotNull { it.getOrNull() }") -) -public fun Iterable>.uniteEither(): List = - mapNotNull { it.getOrNull() } - /** * Separate the inner [Either] values into the [Either.Left] and [Either.Right]. * @@ -1154,7 +876,7 @@ public fun Iterable>.uniteEither(): List = * .separateEither() shouldBe Pair(listOf("A", "C"), listOf(2, 4)) * } * ``` - * + * * */ public fun Iterable>.separateEither(): Pair, List> { @@ -1204,14 +926,6 @@ public fun Iterable.widen(): Iterable = public fun List.widen(): List = this -@Deprecated(MonoidDeprecation, ReplaceWith("this.fold(initial, {a1, a2 -> a1 + a2})")) -public fun Iterable.fold(MA: Monoid): A = - fold(MA.empty(), MA::combine) - -@Deprecated(MonoidDeprecation, ReplaceWith("this.fold(initial) { acc, a -> combine(acc, f(a)) }")) -public fun Iterable.foldMap(MB: Monoid, f: (A) -> B): B = - fold(MB.empty()) { acc, a -> MB.run { acc.combine(f(a)) } } - public fun Iterable.crosswalk(f: (A) -> Iterable): List> = fold(emptyList()) { bs, a -> f(a).align(bs) { ior -> @@ -1243,23 +957,6 @@ public fun Iterable.crosswalkNull(f: (A) -> B?): List? = ) } -@Deprecated("Not being used anymore. Will be removed from the binary in 2.0.0") -@PublishedApi -internal val listUnit: List = - listOf(Unit) - -@Deprecated( - NicheAPI, - ReplaceWith("toList().let { l -> List(n) { l } }") -) -public fun Iterable.replicate(n: Int): List> = - toList().let { l -> List(n) { l } } - -@Deprecated(NicheAPI) -public fun Iterable.replicate(n: Int, MA: Monoid): List = - if (n <= 0) listOf(MA.empty()) - else this@replicate.zip(replicate(n - 1, MA)) { a, xs -> MA.run { a + xs } } - public operator fun > Iterable.compareTo(other: Iterable): Int = align(other) { ior -> ior.fold({ 1 }, { -1 }, { a1, a2 -> a1.compareTo(a2) }) } .fold(0) { acc, i -> diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index 9a117861620..324c90eff0f 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -3,15 +3,9 @@ package arrow.core import arrow.core.raise.RaiseAccumulate -import arrow.core.raise.either -import arrow.core.raise.option -import arrow.typeclasses.Semigroup -import arrow.typeclasses.SemigroupDeprecation -import arrow.typeclasses.combine import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmInline import kotlin.jvm.JvmName -import kotlin.jvm.JvmStatic public typealias Nel = NonEmptyList @@ -216,10 +210,6 @@ public value class NonEmptyList @PublishedApi internal constructor( public fun align(b: NonEmptyList): NonEmptyList> = NonEmptyList(all.align(b)) - @Deprecated(SemigroupDeprecation, ReplaceWith("padZip(b, ::identity, ::identity, {a1, a2 -> a1 + a2})")) - public fun salign(SA: Semigroup<@UnsafeVariance A>, b: NonEmptyList<@UnsafeVariance A>): NonEmptyList = - padZip(b, ::identity, ::identity, SA::combine) - public fun padZip(other: NonEmptyList): NonEmptyList> = padZip(other, { it to null }, { null to it }, { a, b -> a to b }) @@ -363,40 +353,6 @@ public fun NonEmptyList.unzip(f: (C) -> Pair): Pair, Either>> { nel -> either> { nel.map { f(it).bind() } } }", - "arrow.core.raise.either") -) -public inline fun NonEmptyList.traverseEither(f: (A) -> Either): Either> = - traverse(f) - -@Deprecated( - "Traverse for Either is being deprecated in favor of Either DSL + NonEmptyList.map.\n$NicheAPI", - ReplaceWith( - "let, Either>> { nel -> either> { nel.map { f(it).bind() } } }", - "arrow.core.raise.either") -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun NonEmptyList.traverse(f: (A) -> Either): Either> = - let { nel -> either { nel.map { f(it).bind() } } } - -@Deprecated( - "Sequence for Either is being deprecated in favor of Either DSL + NonEmptyList.map.\n$NicheAPI", - ReplaceWith("either> { this.map { it.bind() } }", "arrow.core.raise.either") -) -public fun NonEmptyList>.sequenceEither(): Either> = - sequence() - -@Deprecated( - "Sequence for Either is being deprecated in favor of Either DSL + NonEmptyList.map.\n$NicheAPI", - ReplaceWith("either> { this.map { it.bind() } }", "arrow.core.raise.either") -) -public fun NonEmptyList>.sequence(): Either> = - traverse(::identity) - public inline fun NonEmptyList.mapOrAccumulate( combine: (E, E) -> E, @BuilderInference transform: RaiseAccumulate.(A) -> B @@ -408,26 +364,6 @@ public inline fun NonEmptyList.mapOrAccumulate( ): Either, NonEmptyList> = all.mapOrAccumulate(transform).map { requireNotNull(it.toNonEmptyListOrNull()) } -@Deprecated( - "Traverse for Option is being deprecated in favor of Option DSL + NonEmptyList.map.\\n$NicheAPI", - ReplaceWith( - "let, Option>> { nel -> option> { nel.map { f(it).bind() } } }", - "arrow.core.raise.option") -) -public inline fun NonEmptyList.traverseOption(f: (A) -> Option): Option> = - traverse(f) - -@Deprecated( - "Traverse for Option is being deprecated in favor of Option DSL + NonEmptyList.map.\\n$NicheAPI", - ReplaceWith( - "let, Option>> { nel -> option> { nel.map { f(it).bind() } } }", - "arrow.core.raise.option") -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun NonEmptyList.traverse(f: (A) -> Option): Option> = - let { nel -> option { nel.map { f(it).bind() } } } - @JvmName("toNonEmptyListOrNull") public fun Iterable.toNonEmptyListOrNull(): NonEmptyList? = toList().let { if (it.isEmpty()) null else NonEmptyList(it) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 39c9d2c1a11..6a5216dc8e0 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -1,16 +1,10 @@ @file:OptIn(ExperimentalContracts::class) package arrow.core -import arrow.core.Either.Right import arrow.core.raise.EagerEffect import arrow.core.raise.Effect import arrow.core.raise.OptionRaise import arrow.core.raise.option -import arrow.typeclasses.Monoid -import arrow.typeclasses.MonoidDeprecation -import arrow.typeclasses.Semigroup -import arrow.typeclasses.SemigroupDeprecation -import arrow.typeclasses.combine import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -295,21 +289,6 @@ import kotlin.jvm.JvmStatic * ``` * * - * ### Computing over independent values - * - * ```kotlin - * import arrow.core.Some - * - * val value = - * //sampleStart - * Some(1).zip(Some("Hello"), Some(20.0), ::Triple) - * //sampleEnd - * fun main() { - * println(value) - * } - * ``` - * - * * ## Credits * * Contents partially adapted from [Scala Exercises Option Tutorial](https://www.scala-exercises.org/std_lib/options) @@ -349,55 +328,6 @@ public sealed class Option { recover(t.nonFatalOrThrow()) } } - - @JvmStatic - @Deprecated( - RedundantAPI + "Prefer explicitly creating lambdas", - ReplaceWith("{ it.map(f) }") - ) - public fun lift(f: (A) -> B): (Option) -> Option = - { it.map(f) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { Pair(bind(), b.bind()) }", - "arrow.core.raise.option" - ) - ) - public fun zip(other: Option): Option> = - zip(other, ::Pair) - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - map: (A, B) -> C - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind()) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - map: (A, B, C) -> D - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind()) } } /** @@ -416,13 +346,13 @@ public sealed class Option { * none().onNone { println("flower") } // Result: prints "flower" and returns: None * } * ``` - * + * */ public inline fun onNone(action: () -> Unit): Option { contract { callsInPlace(action, InvocationKind.AT_MOST_ONCE) } - return also { if (it.isEmpty()) action() } + return also { if (it.isNone()) action() } } /** @@ -441,229 +371,13 @@ public sealed class Option { * none().onSome { println("flower") } // Result: None * } * ``` - * + * */ public inline fun onSome(action: (A) -> Unit): Option { contract { callsInPlace(action, InvocationKind.AT_MOST_ONCE) } - return also { if (it.isNotEmpty()) action(it.value) } - } - - /** - * The given function is applied as a fire and forget effect - * if this is a `None`. - * When applied the result is ignored and the original - * None value is returned - * - * Example: - * ```kotlin - * import arrow.core.Some - * import arrow.core.none - * - * fun main() { - * Some(12).tapNone { println("flower") } // Result: Some(12) - * none().tapNone { println("flower") } // Result: prints "flower" and returns: None - * } - * ``` - * - */ - @Deprecated( - "tapNone is being renamed to onNone to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("onNone(f)") - ) - public inline fun tapNone(f: () -> Unit): Option { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return onNone(f) - } - - /** - * The given function is applied as a fire and forget effect - * if this is a `some`. - * When applied the result is ignored and the original - * Some value is returned - * - * Example: - * ```kotlin - * import arrow.core.Some - * import arrow.core.none - * - * fun main() { - * Some(12).tap { println("flower") } // Result: prints "flower" and returns: Some(12) - * none().tap { println("flower") } // Result: None - * } - * ``` - * - */ - @Deprecated( - "tap is being renamed to onNone to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("onSome(f)") - ) - public inline fun tap(f: (A) -> Unit): Option { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return onSome(f) - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind(), d.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - d: Option, - map: (A, B, C, D) -> E - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind(), d.bind()) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - d: Option, - e: Option, - map: (A, B, C, D, E) -> F - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind()) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - d: Option, - e: Option, - f: Option, - map: (A, B, C, D, E, F) -> G - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind()) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - d: Option, - e: Option, - f: Option, - g: Option, - map: (A, B, C, D, E, F, G) -> H - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - d: Option, - e: Option, - f: Option, - g: Option, - h: Option, - map: (A, B, C, D, E, F, G, H) -> I - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - d: Option, - e: Option, - f: Option, - g: Option, - h: Option, - i: Option, - map: (A, B, C, D, E, F, G, H, I) -> J - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) } - } - - @Deprecated( - "Prefer using the inline option DSL", - ReplaceWith( - "option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind()) }", - "arrow.core.raise.option" - ) - ) - public inline fun zip( - b: Option, - c: Option, - d: Option, - e: Option, - f: Option, - g: Option, - h: Option, - i: Option, - j: Option, - map: (A, B, C, D, E, F, G, H, I, J) -> K - ): Option { - contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return option { map(bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind()) } - } - - /** - * Returns true if the option is [None], false otherwise. - * @note Used only for performance instead of fold. - */ - @Deprecated( - "Duplicated API. Please use Option's member function isNone. This will be removed towards Arrow 2.0", - ReplaceWith("isNone()") - ) - public abstract fun isEmpty(): Boolean - - @Deprecated( - "Duplicated API. Please use Option's member function isSome. This will be removed towards Arrow 2.0", - ReplaceWith("isSome()") - ) - public fun isNotEmpty(): Boolean { - contract { - returns(true) implies (this@Option is Some) - returns(false) implies (this@Option is None) - } - return this@Option is Some + return also { if (it.isSome()) action(it.value) } } /** @@ -709,7 +423,7 @@ public sealed class Option { * none.isSome { it > 10 } // Result: false * } * ``` - * + * * * @param predicate the predicate to test */ @@ -720,36 +434,6 @@ public sealed class Option { } return this@Option is Some && predicate(value) } - /** - * alias for [isDefined] - */ - @Deprecated( - "Duplicated API. Please use Option's member function isSome. This will be removed towards Arrow 2.0", - ReplaceWith("isSome()") - ) - public fun nonEmpty(): Boolean = isDefined() - - /** - * Returns true if the option is an instance of [Some], false otherwise. - * @note Used only for performance instead of fold. - */ - @Deprecated( - "Duplicated API. Please use Option's member function isSome. This will be removed towards Arrow 2.0", - ReplaceWith("isSome()") - ) - public fun isDefined(): Boolean = !isEmpty() - - @Deprecated( - "orNull is being renamed to getOrNull to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("getOrNull()") - ) - public fun orNull(): A? { - contract { - returns(null) implies (this@Option is None) - returnsNotNull() implies (this@Option is Some) - } - return fold({ null }, ::identity) - } /** * Returns the encapsulated value [A] if this instance represents [Some] or `null` if it is [None]. @@ -764,7 +448,7 @@ public sealed class Option { * None.getOrNull() shouldBe null * } * ``` - * + * */ public fun getOrNull(): A? { contract { @@ -800,27 +484,6 @@ public sealed class Option { } } - /** - * Returns $none if the result of applying $f to this $option's value is null. - * Otherwise returns the result. - * - * @note This is similar to `.flatMap { Option.fromNullable(null)) }` - * and primarily for convenience. - * - * @param f the function to apply. - * */ - @Deprecated( - NicheAPI + "Prefer using the Option DSL, or fold or map", - ReplaceWith( - "flatMap { fromNullable(f(it)) }", - "arrow.core.Option.Companion.fromNullable" - ) - ) - public inline fun mapNotNull(f: (A) -> B?): Option { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return flatMap { a -> fromNullable(f(a)) } - } - /** * Returns the result of applying $f to this $option's value if * this $option is nonempty. @@ -839,91 +502,6 @@ public sealed class Option { } } - /** - * Align two options (`this` on the left and [b] on the right) as one Option of [Ior]. - */ - @Deprecated(NicheAPI + "Prefer using a simple fold, or when expression") - public infix fun align(b: Option): Option> = - when (this) { - None -> when (b) { - None -> None - is Some -> Some(b.value.rightIor()) - } - - is Some -> when (b) { - None -> Some(this.value.leftIor()) - is Some -> Some(Pair(this.value, b.value).bothIor()) - } - } - - /** - * Align two options (`this` on the left and [b] on the right) as one Option of [Ior], and then, if it's not [None], map it using [f]. - * - * @note This function works like a regular `align` function, but is then mapped by the `map` function. - */ - @Deprecated(NicheAPI + "Prefer using a simple fold, or when expression") - public inline fun align(b: Option, f: (Ior) -> C): Option { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return align(b).map(f) - } - - /** - * Returns true if this option is empty '''or''' the predicate - * $predicate returns true when applied to this $option's value. - * - * @param predicate the predicate to test - */ - @Deprecated( - NicheAPI + "Prefer using the Option DSL, or fold or map", - ReplaceWith("fold({ true }, predicate)") - ) - public inline fun all(predicate: (A) -> Boolean): Boolean { - contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } - return fold({ true }, predicate) - } - - @Deprecated( - NicheAPI + "Prefer using the Option DSL or fold", - ReplaceWith( - "fold>>({ None }) { value -> f(value).map(::Some) }", - "arrow.core.None", - "arrow.core.Option", - "arrow.core.Some" - ) - ) - public inline fun crosswalk(f: (A) -> Option): Option> = - when (this) { - is None -> this - is Some -> f(value).map { Some(it) } - } - - @Deprecated( - NicheAPI + "Prefer using the Option DSL or fold", - ReplaceWith( - "fold>>({ emptyMap() }) { value -> f(value).mapValues { Some(it.value) } }", - "arrow.core.Option", - "arrow.core.Some" - ) - ) - public inline fun crosswalkMap(f: (A) -> Map): Map> = - when (this) { - is None -> emptyMap() - is Some -> f(value).mapValues { Some(it.value) } - } - - @Deprecated( - NicheAPI + "Prefer using the Option DSL or fold", - ReplaceWith( - "getOrNull()?.let { value -> f(value)?.let(::Some) }", - "arrow.core.Some" - ) - ) - public inline fun crosswalkNull(f: (A) -> B?): Option? = - when (this) { - is None -> null - is Some -> f(value)?.let { Some(it) } - } - /** * Returns this $option if it is nonempty '''and''' applying the predicate $p to * this $option's value returns true. Otherwise, return $none. @@ -946,125 +524,6 @@ public sealed class Option { return flatMap { a -> if (!predicate(a)) Some(a) else None } } - /** - * Returns true if this option is nonempty '''and''' the predicate - * $p returns true when applied to this $option's value. - * Otherwise, returns false. - * - * Example: - * ```kotlin - * import arrow.core.Some - * import arrow.core.None - * import arrow.core.Option - * - * fun main() { - * Some(12).exists { it > 10 } // Result: true - * Some(7).exists { it > 10 } // Result: false - * - * val none: Option = None - * none.exists { it > 10 } // Result: false - * } - * ``` - * - * - * @param predicate the predicate to test - */ - @Deprecated( - RedundantAPI + "Please use Option's member function isSome. This will be removed towards Arrow 2.0", - ReplaceWith("isSome(predicate)") - ) - public inline fun exists(predicate: (A) -> Boolean): Boolean { - contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } - return fold({ false }, predicate) - } - - /** - * Returns the $option's value if this option is nonempty '''and''' the predicate - * $p returns true when applied to this $option's value. - * Otherwise, returns null. - * - * Example: - * ```kotlin - * import arrow.core.Some - * import arrow.core.None - * import arrow.core.Option - * - * fun main() { - * Some(12).exists { it > 10 } // Result: 12 - * Some(7).exists { it > 10 } // Result: null - * - * val none: Option = None - * none.exists { it > 10 } // Result: null - * } - * ``` - * - */ - @Deprecated( - NicheAPI + "Prefer Kotlin nullable syntax instead", - ReplaceWith("getOrNull()?.takeIf(predicate)") - ) - public inline fun findOrNull(predicate: (A) -> Boolean): A? { - contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } - return when (this) { - is Some -> if (predicate(value)) value else null - is None -> null - } - } - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("fold({ ifEmpty }, f)") - ) - public inline fun foldMap(MB: Monoid, f: (A) -> B): B = - fold({ MB.empty() }, f) - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("fold({ initial }) { operation(initial, it) }") - ) - public inline fun foldLeft(initial: B, operation: (B, A) -> B): B = - when (this) { - is Some -> operation(initial, value) - is None -> initial - } - - @Deprecated(NicheAPI + "Prefer using a simple fold, or when expression") - public fun padZip(other: Option): Option> = - align(other) { ior -> - ior.fold( - { it to null }, - { null to it }, - { a, b -> a to b } - ) - } - - @Deprecated(NicheAPI + "Prefer using a simple fold, or when expression") - public inline fun padZip(other: Option, f: (A?, B?) -> C): Option = - align(other) { ior -> - ior.fold( - { f(it, null) }, - { f(null, it) }, - { a, b -> f(a, b) } - ) - } - - @Deprecated( - NicheAPI + "Prefer when or fold instead", - ReplaceWith("getOrNull()?.let { value -> operation(initial(value), value) }") - ) - public inline fun reduceOrNull(initial: (A) -> B, operation: (acc: B, A) -> B): B? = - when (this) { - is None -> null - is Some -> operation(initial(value), value) - } - - @Deprecated( - NicheAPI + "Prefer using the Option DSL or map", - ReplaceWith("map { List(n) { it } }") - ) - public fun replicate(n: Int): Option> = - if (n <= 0) Some(emptyList()) else map { a -> List(n) { a } } - public inline fun toEither(ifEmpty: () -> L): Either { contract { callsInPlace(ifEmpty, InvocationKind.AT_MOST_ONCE) } return fold({ ifEmpty().left() }, { it.right() }) @@ -1072,35 +531,6 @@ public sealed class Option { public fun toList(): List = fold(::emptyList) { listOf(it) } - @Deprecated( - RedundantAPI + "Replace with map with Unit", - ReplaceWith("map { }") - ) - public fun void(): Option = - map { } - - @Deprecated( - NicheAPI + "Prefer using the Option DSL or map", - ReplaceWith("map { left to it }") - ) - public fun pairLeft(left: L): Option> = this.map { left to it } - - @Deprecated( - NicheAPI + "Prefer using the Option DSL or map", - ReplaceWith("map { it to right }") - ) - public fun pairRight(right: R): Option> = this.map { it to right } - - @Deprecated( - NicheAPI + "Prefer using the Option DSL or flatMap", - ReplaceWith("flatMap { value }") - ) - public infix fun and(value: Option): Option = if (isEmpty()) { - None - } else { - value - } - override fun toString(): String = fold( { "Option.None" }, { "Option.Some($it)" } @@ -1108,29 +538,13 @@ public sealed class Option { } public object None : Option() { - @Deprecated( - "Duplicated API. Please use Option's member function isNone. This will be removed towards Arrow 2.0", - replaceWith = ReplaceWith("isNone()") - ) - public override fun isEmpty(): Boolean = true - override fun toString(): String = "Option.None" } public data class Some(val value: T) : Option() { - @Deprecated( - "Duplicated API. Please use Option's member function isNone. This will be removed towards Arrow 2.0", - replaceWith = ReplaceWith("isNone()") - ) - public override fun isEmpty(): Boolean = false - override fun toString(): String = "Option.Some($value)" - public companion object { - @PublishedApi - @Deprecated("Unused, will be removed from bytecode in Arrow 2.x.x", ReplaceWith("Some(Unit)")) - internal val unit: Option = Some(Unit) - } + public companion object } /** @@ -1144,26 +558,6 @@ public inline fun Option.getOrElse(default: () -> T): T { return fold({ default() }, ::identity) } -/** - * Returns this option's if the option is nonempty, otherwise - * returns another option provided lazily by `default`. - * - * @param alternative the default option if this is empty. - */ -@Deprecated( - NicheAPI + "Prefer using the recover method", - ReplaceWith("recover { alternative().bind() }", "arrow.core.recover") -) -public inline fun Option.orElse(alternative: () -> Option): Option = - recover { alternative().bind() } - -@Deprecated( - NicheAPI + "Prefer using the recover method", - ReplaceWith("recover { value.bind() }", "arrow.core.recover") -) -public infix fun Option.or(value: Option): Option = - recover { value.bind() } - public fun T?.toOption(): Option = this?.let { Some(it) } ?: None /** Run the [Effect] by returning [Option] of [A], or [None] if raised with [None]. */ @@ -1172,60 +566,10 @@ public suspend fun Effect.toOption(): Option = option { invoke() /** Run the [EagerEffect] by returning [Option] of [A], or [None] if raised with [None]. */ public fun EagerEffect.toOption(): Option = option { invoke() } -@Deprecated( - NicheAPI + "Prefer using if-else statement", - ReplaceWith( - "if (this) { Some(f()) } else { None }", - "arrow.core.None", - "arrow.core.Some" - ) -) -public inline fun Boolean.maybe(f: () -> A): Option { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return if (this) { - Some(f()) - } else { - None - } -} - public fun A.some(): Option = Some(this) public fun none(): Option = None -@Deprecated(SemigroupDeprecation, ReplaceWith("fold(none()) { x, y -> x.combine(y){a1, a2 -> a1 + a2} }")) -public fun Iterable>.combineAll(MA: Monoid): Option = - fold(none()) { x, y -> x.combine(y, MA::combine) } - -@Deprecated("use getOrElse instead", ReplaceWith("getOrElse { empty }")) -public fun Option.combineAll(MA: Monoid): A = - getOrElse { MA.empty() } - -@Deprecated( - RedundantAPI + "Prefer if-else statement inside option DSL, or replace with explicit flatMap", - ReplaceWith( - "this.flatMap { b -> b.takeIf(predicate)?.let(::Some) ?: None.also(error) }", - "arrow.core.Some", - "arrow.core.None" - ) -) -public inline fun Option.ensure(error: () -> Unit, predicate: (A) -> Boolean): Option { - contract { - callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) - callsInPlace(error, InvocationKind.AT_MOST_ONCE) - } - return when (this) { - is Some -> - if (predicate(value)) this - else { - error() - None - } - - is None -> this - } -} - /** * Returns an Option containing all elements that are instances of specified type parameter [B]. */ @@ -1237,168 +581,9 @@ public inline fun Option<*>.filterIsInstance(): Option = } } -@Deprecated( - NicheAPI + "Prefer using the orElse method", - ReplaceWith( - "recover { f(Unit) }", - "arrow.core.recover" - ) -) -public inline fun Option.handleError(f: (Unit) -> A): Option { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return recover { f(Unit) } -} - -@Deprecated( - NicheAPI + "Prefer using the orElse method", - ReplaceWith( - "recover { f(Unit).bind() }", - "arrow.core.recover" - ) -) -public inline fun Option.handleErrorWith(f: (Unit) -> Option): Option { - contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - return recover { f(Unit).bind() } -} - public fun Option>.flatten(): Option = flatMap(::identity) -@Deprecated( - NicheAPI + "Prefer using the Option DSL or explicit fold with some", - ReplaceWith( - "fold({ fe(Unit) }, fb).some()", - "arrow.core.some" - ) -) -public inline fun Option.redeem(fe: (Unit) -> B, fb: (A) -> B): Option { - contract { - callsInPlace(fe, InvocationKind.AT_MOST_ONCE) - callsInPlace(fb, InvocationKind.AT_MOST_ONCE) - } - return fold({ fe(Unit) }, fb).some() -} - -@Deprecated( - NicheAPI + "Prefer using the Option DSL or explicit flatMap with orElse", - ReplaceWith( - "flatMap(fb).recover { fe(Unit).bind() }", - "arrow.core.recover" - ) -) -public inline fun Option.redeemWith(fe: (Unit) -> Option, fb: (A) -> Option): Option { - contract { - callsInPlace(fe, InvocationKind.AT_MOST_ONCE) - callsInPlace(fb, InvocationKind.AT_MOST_ONCE) - } - return flatMap(fb).recover { fe(Unit).bind() } -} - -@Deprecated( - NicheAPI + "Prefer using the Option DSL or map", - ReplaceWith("this.map { a -> List(n) { a }.fold(initial){a1, a2 -> a1 + a2} }") -) -public fun Option.replicate(n: Int, MA: Monoid): Option = - map { a -> List(n) { a }.fold(MA.empty(), MA::combine) } - -@Deprecated( - NicheAPI + "Prefer using the Option DSL or explicit flatmap", - ReplaceWith( - "flatMap { it.fold({ None }, { a -> Some(a) }) }", - "arrow.core.None", "arrow.core.Some" - ) -) -public fun Option>.rethrow(): Option = - flatMap { it.fold({ None }, { a -> Some(a) }) } - -@Deprecated(NicheAPI + "Prefer using a simple fold, or when expression") -public fun Option.salign(SA: Semigroup, b: Option): Option = - align(b) { - it.fold(::identity, ::identity) { a, b -> - SA.run { a.combine(b) } - } - } - -/** - * Separate the inner [Either] value into the [Either.Left] and [Either.Right]. - * - * @receiver Option of Either - * @return a tuple containing Option of [Either.Left] and another Option of its [Either.Right] value. - */ -@Deprecated( - NicheAPI + "Prefer using the Option DSL, or explicit fold or when", - ReplaceWith( - "fold({ None to None }) { either -> either.fold, Option>>({ Some(it) to None }, { None to Some(it) }) }", - "arrow.core.None", "arrow.core.Some", "arrow.core.Option" - ) -) -public fun Option>.separateEither(): Pair, Option> = - fold({ None to None }) { either -> - either.fold( - { Some(it) to None }, - { None to Some(it) } - ) - } - -@Deprecated(NicheAPI + "Prefer using a when expression") -public fun Option>.unalign(): Pair, Option> = - unalign(::identity) - -@Deprecated(NicheAPI + "Prefer using a when expression") -public inline fun Option.unalign(f: (C) -> Ior): Pair, Option> = - when (val option = this.map(f)) { - is None -> None to None - is Some -> when (val v = option.value) { - is Ior.Left -> Some(v.value) to None - is Ior.Right -> None to Some(v.value) - is Ior.Both -> Some(v.leftValue) to Some(v.rightValue) - } - } - -@Deprecated( - NicheAPI + "Prefer using the Option DSL or explicit map", - ReplaceWith( - "map { iterable -> iterable.fold(MA) }", - "arrow.typeclasses.Monoid" - ) -) -public fun Option>.unite(MA: Monoid): Option = - map { iterable -> - iterable.fold(MA) - } - -@Deprecated( - NicheAPI + "Prefer using the Option DSL or explicit flatMap", - ReplaceWith( - "flatMap { either -> either.fold>({ None }, ::Some) }", - "arrow.core.Option", "arrow.core.Some", "arrow.core.None" - ) -) -public fun Option>.uniteEither(): Option = - flatMap { either -> - either.fold({ None }, { b -> Some(b) }) - } - -@Deprecated( - NicheAPI + "Prefer using fold, when or Option DSL", - ReplaceWith( - "fold({ None to None }, { (a, b) -> Some(a) to Some(b) })", - "arrow.core.Option", "arrow.core.Some", "arrow.core.None" - ) -) -public fun Option>.unzip(): Pair, Option> = - fold({ None to None }, { (a, b) -> Some(a) to Some(b) }) - -@Deprecated( - NicheAPI + "Prefer using fold, when or Option DSL", - ReplaceWith( - "fold({ None to None }, { f(it).let { (a, b) -> Some(a) to Some(b) } })", - "arrow.core.Option", "arrow.core.Some", "arrow.core.None" - ) -) -public inline fun Option.unzip(f: (C) -> Pair): Pair, Option> = - fold({ None to None }, { f(it).let { (a, b) -> Some(a) to Some(b) } }) - /** * Given [A] is a sub type of [B], re-type this value from Option to Option * @@ -1417,7 +602,7 @@ public inline fun Option.unzip(f: (C) -> Pair): Pair + * */ public fun Option.widen(): Option = this @@ -1433,10 +618,6 @@ public fun Option.combine(other: Option, combine: (A, A) -> A): Option None -> other } -@Deprecated(SemigroupDeprecation, ReplaceWith("this.combine(b){a1, a2 -> a1 + a2}")) -public fun Option.combine(SGA: Semigroup, b: Option): Option = - combine(b, SGA::combine) - public operator fun > Option.compareTo(other: Option): Int = fold( { other.fold({ 0 }, { -1 }) }, { a1 -> @@ -1464,7 +645,7 @@ public operator fun > Option.compareTo(other: Option): I * fallback shouldBe Some(5) * } * ``` - * + * * * * When shifting a new error [None] into the [Option]: @@ -1485,7 +666,7 @@ public operator fun > Option.compareTo(other: Option): I * error.recover { failure().bind() } shouldBe none() * } * ``` - * + * * */ public inline fun Option.recover(recover: OptionRaise.(None) -> A): Option = diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Pair.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Pair.kt index 9fea3c74ed9..8ee2e2f6f3d 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Pair.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Pair.kt @@ -3,9 +3,6 @@ package arrow.core -import arrow.typeclasses.Semigroup -import arrow.typeclasses.SemigroupDeprecation -import arrow.typeclasses.combine import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -14,14 +11,3 @@ public operator fun , B : Comparable> Pair.compareTo( return if (first == 0) second.compareTo(other.second) else first } - - -@Deprecated( - "$SemigroupDeprecation\n$NicheAPI", - ReplaceWith( - "Pair(SA.combine(first, b.first), SB.combine(second, b.second))", - "arrow.typeclasses.combine" - ) -) -public fun Pair.combine(SA: Semigroup, SB: Semigroup, b: Pair): Pair = - Pair(SA.combine(first, b.first), SB.combine(second, b.second)) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Result.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Result.kt index c64f4dea181..9c9cf5e1fe5 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Result.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Result.kt @@ -8,14 +8,6 @@ import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract -internal const val deprecateZip: String = - "Prefer using the inline result DSL + bind(). Please, be aware that all the errors are no longer accumulated, just the first error found is considered." + - "In case you think this behaviour should stay, please provide feedback and your use-case on https://github.com/arrow-kt/arrow/issues" - -@PublishedApi -internal inline val UnitResult: Result - inline get() = success(Unit) - /** * Compose a [transform] operation on the success value [A] into [B] whilst flattening [Result]. * @see mapCatching if you want run a function that catches and maps with `(A) -> B` @@ -29,13 +21,8 @@ public inline fun Result.flatMap(transform: (value: A) -> Result): * Compose a recovering [transform] operation on the failure value [Throwable] whilst flattening [Result]. * @see recoverCatching if you want run a function that catches and maps recovers with `(Throwable) -> A`. */ -public inline fun Result.handleErrorWith(transform: (throwable: Throwable) -> Result): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return when (val exception = exceptionOrNull()) { - null -> this - else -> transform(exception) - } -} +public inline fun Result.handleErrorWith(transform: (throwable: Throwable) -> Result): Result = + recoverCatching { transform(it).getOrThrow() } /** * Compose both: @@ -54,284 +41,3 @@ public inline fun Result.redeemWith( } return fold(transform, handleErrorWith) } - -/** - * Combines n-arity independent [Result] values with a [transform] function. - */ -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip(b: Result, transform: (A, B) -> C): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip( - b, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult - ) { a, b, _, _, _, _, _, _, _, _ -> transform(a, b) } -} - -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip(b: Result, c: Result, transform: (A, B, C) -> D): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip( - b, - c, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult - ) { a, b, c, _, _, _, _, _, _, _ -> transform(a, b, c) } -} - -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind(), d.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip( - b: Result, - c: Result, - d: Result, - transform: (A, B, C, D) -> E -): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip( - b, - c, - d, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult, - UnitResult - ) { a, b, c, d, _, _, _, _, _, _ -> transform(a, b, c, d) } -} - -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind(), d.bind(), e.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip( - b: Result, - c: Result, - d: Result, - e: Result, - transform: (A, B, C, D, E) -> F -): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip(b, c, d, e, UnitResult, UnitResult, UnitResult, UnitResult, UnitResult) { a, b, c, d, e, f, _, _, _, _ -> - transform( - a, - b, - c, - d, - e - ) - } -} - -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip( - b: Result, - c: Result, - d: Result, - e: Result, - f: Result, - transform: (A, B, C, D, E, F) -> G -): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip(b, c, d, e, f, UnitResult, UnitResult, UnitResult, UnitResult) { a, b, c, d, e, f, _, _, _, _ -> - transform( - a, - b, - c, - d, - e, - f - ) - } -} - -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip( - b: Result, - c: Result, - d: Result, - e: Result, - f: Result, - g: Result, - transform: (A, B, C, D, E, F, G) -> H -): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip(b, c, d, e, f, g, UnitResult, UnitResult, UnitResult) { a, b, c, d, e, f, g, _, _, _ -> - transform( - a, - b, - c, - d, - e, - f, - g - ) - } -} - -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip( - b: Result, - c: Result, - d: Result, - e: Result, - f: Result, - g: Result, - h: Result, - transform: (A, B, C, D, E, F, G, H) -> I -): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip(b, c, d, e, f, g, h, UnitResult, UnitResult) { a, b, c, d, e, f, g, h, _, _ -> - transform( - a, - b, - c, - d, - e, - f, - g, - h - ) - } -} - -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip( - b: Result, - c: Result, - d: Result, - e: Result, - f: Result, - g: Result, - h: Result, - i: Result, - transform: (A, B, C, D, E, F, G, H, I) -> J -): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zip(b, c, d, e, f, g, h, i, UnitResult) { a, b, c, d, e, f, g, h, i, _ -> - transform( - a, - b, - c, - d, - e, - f, - g, - h, - i - ) - } -} - -@Suppress("UNCHECKED_CAST") -@Deprecated( - deprecateZip, - ReplaceWith( - "result {transform(this.bind(), b.bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), k.bind()) }", - "arrow.core.raise.result" - ) -) -public inline fun Result.zip( - b: Result, - c: Result, - d: Result, - e: Result, - f: Result, - g: Result, - h: Result, - i: Result, - j: Result, - transform: (A, B, C, D, E, F, G, H, I, J) -> K, -): Result { - contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return if (isSuccess && b.isSuccess && c.isSuccess && d.isSuccess && e.isSuccess && f.isSuccess && g.isSuccess && h.isSuccess && i.isSuccess && j.isSuccess) - success( - transform( - getOrNull() as A, - b.getOrNull() as B, - c.getOrNull() as C, - d.getOrNull() as D, - e.getOrNull() as E, - f.getOrNull() as F, - g.getOrNull() as G, - h.getOrNull() as H, - i.getOrNull() as I, - j.getOrNull() as J - ) - ) else - composeErrors( - exceptionOrNull(), - b.exceptionOrNull(), - c.exceptionOrNull(), - d.exceptionOrNull(), - e.exceptionOrNull(), - f.exceptionOrNull(), - g.exceptionOrNull(), - h.exceptionOrNull(), - i.exceptionOrNull(), - j.exceptionOrNull(), - )!!.let(::failure) -} - -@PublishedApi -internal fun composeErrors(vararg other: Throwable?): Throwable? = - other.reduceOrNull { a, b -> - Nullable.zip(a, b, Throwable::addSuppressed) - a ?: b - } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt index 7bec84c9f94..a8044ce575d 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt @@ -9,13 +9,7 @@ import arrow.core.Either.Left import arrow.core.Either.Right import arrow.core.raise.RaiseAccumulate import arrow.core.raise.fold -import arrow.typeclasses.Monoid -import arrow.typeclasses.MonoidDeprecation -import arrow.typeclasses.Semigroup -import arrow.typeclasses.SemigroupDeprecation -import arrow.typeclasses.combine import kotlin.experimental.ExperimentalTypeInference -import kotlin.jvm.JvmName /** Adds [kotlin.sequences.zip] support for 3 parameters */ public fun Sequence.zip( @@ -341,27 +335,7 @@ private fun alignRec( } } -@Deprecated("use fold instead", ReplaceWith("fold(MA)", "arrow.core.fold")) -public fun Sequence.combineAll(MA: Monoid): A = - fold(MA) - -@Deprecated( - "This function is actually terminal. Use crosswalk(f:A -> List) instead.", - ReplaceWith("this.crosswalk{a -> f(a).toList()}") -) -public fun Sequence.crosswalk(f: (A) -> Sequence): Sequence> = - fold(emptySequence()) { bs, a -> - f(a).align(bs) { ior -> - ior.fold( - { sequenceOf(it) }, - ::identity, - { l, r -> sequenceOf(l) + r } - ) - } - } - @OverloadResolutionByLambdaReturnType -@JvmName("crosswalkT") public fun Sequence.crosswalk(f: (A) -> Iterable): List> = fold(emptyList()) { bs, a -> f(a).align(bs) { ior -> @@ -373,35 +347,6 @@ public fun Sequence.crosswalk(f: (A) -> Iterable): List> = } } - -@Deprecated( - "This function is actually terminal. Use crosswalk(f:A -> List) instead.", - ReplaceWith("this.crosswalk{a -> f(a).toList()}") -) -public fun Sequence.crosswalkMap(f: (A) -> Map): Map> = - fold(emptyMap()) { bs, a -> - f(a).align(bs) { (_, ior) -> - ior.fold( - { sequenceOf(it) }, - ::identity, - { l, r -> sequenceOf(l) + r } - ) - } - } - -@Deprecated( - "This function is actually terminal. Use crosswalkNullList(f) instead.", - ReplaceWith("this.crosswalk{a -> f(a).toList()}") -) -public fun Sequence.crosswalkNull(f: (A) -> B?): Sequence? = - fold?>(emptySequence()) { bs, a -> - Ior.fromNullables(f(a), bs)?.fold( - { sequenceOf(it) }, - ::identity, - { l, r -> sequenceOf(l) + r } - ) - } - public fun Sequence.crosswalkNullList(f: (A) -> B?): List? = fold?>(emptyList()) { bs, a -> Ior.fromNullables(f(a), bs)?.fold( @@ -414,53 +359,6 @@ public fun Sequence.crosswalkNullList(f: (A) -> B?): List? = public fun Sequence>.flatten(): Sequence = flatMap(::identity) -@Deprecated( - "$MonoidDeprecation\n$NicheAPI", - ReplaceWith("this.fold(initial){ acc, a -> acc + a }", "arrow.core.sequence") -) -public fun Sequence.fold(MA: Monoid): A = MA.run { - this@fold.fold(empty()) { acc, a -> - acc.combine(a) - } -} - -@Deprecated( - "$MonoidDeprecation\n$NicheAPI", - ReplaceWith("this.fold(initial){ acc, a -> acc + f(a) }") -) -public fun Sequence.foldMap(MB: Monoid, f: (A) -> B): B = MB.run { - this@foldMap.fold(empty()) { acc, a -> - acc.combine(f(a)) - } -} - -/** - * Logical conditional. The equivalent of Prolog's soft-cut. - * If its first argument succeeds at all, then the results will be - * fed into the success branch. Otherwise, the failure branch is taken. - * - * ```kotlin - * import arrow.core.ifThen - * - * fun main(args: Array) { - * //sampleStart - * val result = - * sequenceOf(1,2,3).ifThen(sequenceOf("empty")) { i -> - * sequenceOf("$i, ${i + 1}") - * } - * //sampleEnd - * println(result.toList()) - * } - * ``` - * - */ -@Deprecated( - "Use flatMap and ifEmpty instead.\n$NicheAPI", - ReplaceWith("flatMap(ffa).ifEmpty { fb }") -) -public fun Sequence.ifThen(fb: Sequence, ffa: (A) -> Sequence): Sequence = - flatMap(ffa).ifEmpty { fb } - /** * Interleaves the elements of `this` [Sequence] with those of [other] [Sequence]. * Elements of `this` and [other] are taken in turn, and the resulting list is the concatenation of the interleaved elements. @@ -476,7 +374,7 @@ public fun Sequence.ifThen(fb: Sequence, ffa: (A) -> Sequence): * tags.interleave(numbers).toList() shouldBe listOf("#", 0, "#", 1, "#", 2, "#", "#") * } * ``` - * + * * */ public fun Sequence.interleave(other: Sequence): Sequence = @@ -512,7 +410,7 @@ public fun Sequence.interleave(other: Sequence): Sequence = * println("both = $both") * } * ``` - * + * */ public fun Sequence.leftPadZip(other: Sequence, fab: (A?, B) -> C): Sequence = padZip(other) { a: A?, b: B? -> b?.let { fab(a, it) } }.mapNotNull(::identity) @@ -537,7 +435,7 @@ public fun Sequence.leftPadZip(other: Sequence, fab: (A?, B) -> * println("noPadding = $noPadding") * } * ``` - * + * */ public fun Sequence.leftPadZip(other: Sequence): Sequence> = this.leftPadZip(other) { a, b -> a to b } @@ -568,7 +466,7 @@ public fun Sequence.once(): Sequence = * println("noPadding = $noPadding") * } * ``` - * + * */ public fun Sequence.padZip(other: Sequence): Sequence> = alignRec( @@ -597,7 +495,7 @@ public fun Sequence.padZip(other: Sequence): Sequence> * println("noPadding = $noPadding") * } * ``` - * + * */ public fun Sequence.padZip(other: Sequence, fa: (A?, B?) -> C): Sequence = alignRec( @@ -608,18 +506,6 @@ public fun Sequence.padZip(other: Sequence, fa: (A?, B?) -> C): { a, b -> fa(a, b) } ) -@Deprecated( - "$SemigroupDeprecation\n$NicheAPI", - ReplaceWith("Sequence> { List>(n) { this }.iterator() }") -) -public fun Sequence.replicate(n: Int): Sequence> = - Sequence { List(n) { this@replicate }.iterator() } - -@Deprecated(NicheAPI) -public fun Sequence.replicate(n: Int, MA: Monoid): Sequence = - if (n <= 0) sequenceOf(MA.empty()) - else this@replicate.zip(replicate(n - 1, MA)) { a, xs -> MA.run { a + xs } } - /** * Returns a [Sequence] containing the result of applying some transformation `(A, B?) -> C` * on a zip, excluding all cases where the left value is null. @@ -640,7 +526,7 @@ public fun Sequence.replicate(n: Int, MA: Monoid): Sequence = * println("both = $both") * } * ``` - * + * */ public fun Sequence.rightPadZip(other: Sequence, fa: (A, B?) -> C): Sequence = other.leftPadZip(this) { a, b -> fa(b, a) } @@ -665,7 +551,7 @@ public fun Sequence.rightPadZip(other: Sequence, fa: (A, B?) -> * println("noPadding = $noPadding") * } * ``` - * + * */ public fun Sequence.rightPadZip(other: Sequence): Sequence> = this.rightPadZip(other) { a, b -> a to b } @@ -679,28 +565,8 @@ public fun Sequence.salign( ): Sequence = align(other) { it.fold(::identity, ::identity, combine) } -/** - * aligns two structures and combine them with the given [Semigroup.append] - */ -@Deprecated(SemigroupDeprecation, ReplaceWith("salign(other, {a, b -> a + b})", "arrow.typeclasses.combine")) -public fun Sequence.salign( - SG: Semigroup, - other: Sequence -): Sequence = - salign(other, SG::combine) - -/** - * Separate the inner [Either] values into the [Either.Left] and [Either.Right]. - * - * @receiver Iterable of [Either] - * @return a tuple containing Sequence with [Either.Left] and another Sequence with its [Either.Right] values. - */ -@Deprecated( - "This function is actually terminal. Use separateEitherToPair instead.", - ReplaceWith("separateEitherToPair()") -) -public fun Sequence>.separateEither(): Pair, Sequence> = - fold(sequenceOf() to sequenceOf()) { (lefts, rights), either -> +public fun Sequence>.separateEitherToPair(): Pair, List> = + fold(listOf() to listOf()) { (lefts, rights), either -> when (either) { is Left -> lefts + either.value to rights is Right -> lefts to rights + either.value @@ -710,28 +576,9 @@ public fun Sequence>.separateEither(): Pair, Seq public fun Sequence>.sequence(): Either> = traverse(::identity) -@Deprecated( - "sequenceEither is being renamed to sequence to simplify the Arrow API", - ReplaceWith("sequence().map { it.asSequence() }", "arrow.core.sequence") -) -public fun Sequence>.sequenceEither(): Either> = - sequence().map { it.asSequence() } - public fun Sequence>.sequence(): Option> = traverse(::identity) -@Deprecated( - "sequenceOption is being renamed to sequence to simplify the Arrow API", - ReplaceWith("sequence().map { it.asSequence() }", "arrow.core.sequence") -) -public fun Sequence>.sequenceOption(): Option> = - sequence().map { it.asSequence() } - -@Deprecated("some is being deprecated in favor of map", ReplaceWith("map { generateSequence { this } }")) -public fun Sequence.some(): Sequence> = - if (none()) emptySequence() - else map { generateSequence { it } } - /** * attempt to split the computation, giving access to the first result. * @@ -747,7 +594,7 @@ public fun Sequence.some(): Sequence> = * emptySequence().split() shouldBe null * } * ``` - * + * * */ public fun Sequence.split(): Pair, A>? = @@ -775,13 +622,6 @@ public fun Sequence.traverse(f: (A) -> Either): Either Sequence.traverseEither(f: (A) -> Either): Either> = - traverse(f).map { it.asSequence() } - @OptIn(ExperimentalTypeInference::class) @OverloadResolutionByLambdaReturnType public fun Sequence.traverse(f: (A) -> Option): Option> { @@ -798,13 +638,6 @@ public fun Sequence.traverse(f: (A) -> Option): Option> { return Some(acc) } -@Deprecated( - "traverseOption is being renamed to traverse to simplify the Arrow API", - ReplaceWith("traverse(f).map { it.asSequence() }", "arrow.core.traverse") -) -public fun Sequence.traverseOption(f: (A) -> Option): Option> = - traverse(f).map { it.asSequence() } - public fun Sequence.mapOrAccumulate( combine: (Error, Error) -> Error, @BuilderInference transform: RaiseAccumulate.(A) -> B @@ -841,7 +674,7 @@ public fun Sequence.mapOrAccumulate( * println("(${result.first}, ${result.second})") * } * ``` - * + * */ public fun Sequence>.unalignToPair(): Pair, List> = fold(emptyList() to emptyList()) { (l, r), x -> @@ -852,14 +685,6 @@ public fun Sequence>.unalignToPair(): Pair, List> = ) } - -@Deprecated( - "This function is actually terminal. Use unalignToPair instead.", - ReplaceWith("unalignToPair(fa)") -) -public fun Sequence.unalign(fa: (C) -> Ior): Pair, Sequence> = - map(fa).unalign() - /** * after applying the given function, splits the resulting union shaped structure into its components parts * @@ -874,22 +699,11 @@ public fun Sequence.unalign(fa: (C) -> Ior): Pair * println("(${result.first.toList()}, ${result.second.toList()})") * } * ``` - * + * */ public fun Sequence.unalignToPair(fa: (C) -> Ior): Pair, List> = map(fa).unalignToPair() -@Deprecated( - NicheAPI + "Prefer using flatMap + fold", - ReplaceWith( - "flatMap { either -> either.fold>({ emptySequence() }, { b -> sequenceOf(b) }) }" - ) -) -public fun Sequence>.uniteEither(): Sequence = - flatMap { either -> - either.fold({ emptySequence() }, { b -> sequenceOf(b) }) - } - /** * Fair conjunction. Similarly to interleave * @@ -903,22 +717,13 @@ public fun Sequence>.uniteEither(): Sequence = * println(result.toList()) * } * ``` - * + * */ public fun Sequence.unweave(ffa: (A) -> Sequence): Sequence = split()?.let { (fa, a) -> ffa(a).interleave(fa.unweave(ffa)) } ?: emptySequence() -@Deprecated( - "This function is actually terminal. Use unzipToPair instead.", - ReplaceWith("unzipToPair()") -) -public fun Sequence>.unzip(): Pair, Sequence> = - fold(emptySequence() to emptySequence()) { (l, r), x -> - l + x.first to r + x.second - } - /** * unzips the structure holding the resulting elements in an `Pair` * @@ -932,21 +737,13 @@ public fun Sequence>.unzip(): Pair, Sequence> = * println("(${result.first}, ${result.second})") * } * ``` - * + * */ public fun Sequence>.unzipToPair(): Pair, List> = fold(emptyList() to emptyList()) { (l, r), x -> l + x.first to r + x.second } - -@Deprecated( - "This function is actually terminal. Use unzipToPair instead.", - ReplaceWith("unzipToPair(fc)") -) -public fun Sequence.unzip(fc: (C) -> Pair): Pair, Sequence> = - map(fc).unzip() - /** * after applying the given function unzip the resulting structure into its elements. * @@ -965,19 +762,11 @@ public fun Sequence.unzip(fc: (C) -> Pair): Pair, * println("(${result.first}, ${result.second})") * } * ``` - * + * */ public fun Sequence.unzipToPair(fc: (C) -> Pair): Pair, List> = map(fc).unzipToPair() - -@Deprecated( - "void is being deprecated in favor of simple Iterable.map.\n$NicheAPI", - ReplaceWith("map { }") -) -public fun Sequence.void(): Sequence = - map { Unit } - /** * Given [A] is a subtype of [B], re-type this value from Sequence to Sequence * @@ -989,7 +778,7 @@ public fun Sequence.void(): Sequence = * val result: Sequence = original.widen() * } * ``` - * + * */ public fun Sequence.widen(): Sequence = this @@ -1012,7 +801,7 @@ public fun Sequence.widen(): Sequence = * .toList() shouldBe listOf(0, 2, 4, 6, 8) * } * ``` - * + * * */ public fun Sequence>.filterOption(): Sequence = diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt index e66fb94a0b0..d4ed66d3b32 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt @@ -2,18 +2,8 @@ package arrow.core -import arrow.typeclasses.SemigroupDeprecation -import kotlin.experimental.ExperimentalTypeInference -import arrow.typeclasses.Monoid -import arrow.typeclasses.Semigroup -import kotlin.collections.flatMap as _flatMap import arrow.core.raise.RaiseAccumulate -import arrow.core.raise.either import arrow.core.raise.fold -import arrow.core.raise.nullable -import arrow.core.raise.option -import arrow.typeclasses.Semigroup -import arrow.typeclasses.combine import kotlin.experimental.ExperimentalTypeInference /** @@ -263,72 +253,6 @@ public fun Map.flatMap(f: (Map.Entry) -> Map): Map, Either>> { m -> either> { m.mapValues { (_, a) -> f(a).bind() } } }", - "arrow.core.raise.either" - ) -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Map.traverse(f: (A) -> Either): Either> = - let { m -> either { m.mapValues { (_, a) -> f(a).bind() } } } - -@Deprecated( - "Traverse for Either is being deprecated in favor of Either DSL + Map.mapValues.\n$NicheAPI", - ReplaceWith( - "let, Either>> { m -> either> { m.mapValues { (_, a) -> f(a).bind() } } }", - "arrow.core.raise.either" - ) -) -public inline fun Map.traverseEither(f: (A) -> Either): Either> = - let { m -> either { m.mapValues { (_, a) -> f(a).bind() } } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the either DSL.", - ReplaceWith("let>, Either>> { m -> either> { m.bindAll() } }", "arrow.core.raise.either") -) -public fun Map>.sequence(): Either> = - let { m -> either { m.bindAll() } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the either DSL.", - ReplaceWith( - "let>, Either>> { m -> either> { m.bindAll() } }", - "arrow.core.raise.either" - ) -) -public fun Map>.sequenceEither(): Either> = - let { m -> either { m.bindAll() } } - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate({e1, e2 -> e1 + e2}) { f(it.value).bind() }.toValidated()", - "arrow.core.mapOrAccumulate", - "arrow.typeclasses.combine" - ) -) -public inline fun Map.traverseValidated( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - mapOrAccumulate(semigroup::combine) { f(it.value).bind() }.toValidated() - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "this.mapOrAccumulate({e1, e2 -> e1 + e2}) { f(it.value).bind() }.toValidated()", - "arrow.core.mapOrAccumulate" - ) -) -public inline fun Map.traverse( - semigroup: Semigroup, - f: (A) -> Validated -): Validated> = - mapOrAccumulate(semigroup::combine) { f(it.value).bind() }.toValidated() - public inline fun Map.mapOrAccumulate( combine: (E, E) -> E, @BuilderInference transform: RaiseAccumulate.(Map.Entry) -> B @@ -354,77 +278,6 @@ public inline fun Map.mapOrAccumulate( return left.toNonEmptyListOrNull()?.left() ?: right.right() } -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate, A>({e1, e2 -> e1 + e2}) { it.value.bind() }.toValidated()", - "arrow.core.mapOrAccumulate", - "arrow.typeclasses.combine" - ) -) -public fun Map>.sequenceValidated(semigroup: Semigroup): Validated> = - sequence(semigroup) - -@Deprecated( - ValidatedDeprMsg + "Use the mapOrAccumulate API instead", - ReplaceWith( - "mapOrAccumulate, A>({e1, e2 -> e1 + e2}) { it.value.bind() }.toValidated()", - "arrow.core.mapOrAccumulate", - "arrow.typeclasses.combine" - ) -) -public fun Map>.sequence(semigroup: Semigroup): Validated> = - mapOrAccumulate(semigroup::combine) { it.value.bind() }.toValidated() - -@Deprecated( - "Traverse for Option is being deprecated in favor of Option DSL + Map.mapValues.\n$NicheAPI", - ReplaceWith( - "let, Option>> { m -> option> { m.mapValues { (_, a) -> f(a).bind() } } }", - "arrow.core.raise.option" - ) -) -@OptIn(ExperimentalTypeInference::class) -@OverloadResolutionByLambdaReturnType -public inline fun Map.traverse(f: (A) -> Option): Option> = - let { m -> option { m.mapValues { (_, a) -> f(a).bind() } } } - -@Deprecated( - "Traverse for Option is being deprecated in favor of Option DSL + Map.mapValues.\n$NicheAPI", - ReplaceWith( - "let, Option>> { m -> option> { m.mapValues { (_, a) -> f(a).bind() } } }", - "arrow.core.raise.option" - ) -) -public inline fun Map.traverseOption(f: (A) -> Option): Option> = - let { m -> option { m.mapValues { (_, a) -> f(a).bind() } } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the option DSL.", - ReplaceWith( - "let>, Option>> { m -> option> { m.bindAll() } }", - "arrow.core.raise.option" - ) -) -public fun Map>.sequenceOption(): Option> = - let { m -> option { m.bindAll() } } - -@Deprecated( - "The sequence extension function is being deprecated in favor of the option DSL.", - ReplaceWith( - "let>, Option>> { m -> option> { m.bindAll() } }", - "arrow.core.raise.option" - ) -) -public fun Map>.sequence(): Option> = - let { m -> option { m.bindAll() } } - -@Deprecated( - "Void is being deprecated in favor of simple Map.mapValues.\n$NicheAPI", - ReplaceWith("this.mapValues { }") -) -public fun Map.void(): Map = - mapValues { } - public fun Map.widen(): Map = this @@ -435,13 +288,6 @@ public fun Map.mapNotNull(transform: (Map.Entry) -> B?): M } } -@Deprecated( - "filterMap is being deprecated in favor of mapNotNull to align with Kotlin Std naming.", - ReplaceWith("mapNotNull { (_, a) -> f(a) }", "arrow.core.mapNotNull") -) -public fun Map.filterMap(f: (A) -> B?): Map = - mapNotNull { (_, a) -> f(a) } - public fun Map>.filterOption(): Map = buildMap { this@filterOption.forEach { (key, option) -> @@ -508,13 +354,6 @@ private class Entry(override val key: K, override val value: V) : Map.Entr public fun Map.salign(other: Map, combine: (A, A) -> A): Map = padZip(other, { _, a -> a }, { _, b -> b }) { _, a, b -> combine(a, b) } -@Deprecated( - "${SemigroupDeprecation}\n use align instead", - ReplaceWith("salign(other){a1, a2 -> a1 + a2}") -) -public fun Map.salign(SG: Semigroup, other: Map): Map = - salign(other, SG::combine) - /** * Align two structures as in zip, but filling in blanks with null. */ @@ -524,6 +363,7 @@ public fun Map.padZip(other: Map): Map> = public fun Map.padZip(other: Map, fa: (K, A?, B?) -> C): Map = padZip(other, { k, a -> fa(k, a, null) }, { k, b -> fa(k, null, b) }) { k, a, b -> fa(k, a, b) } +@Suppress("UNCHECKED_CAST") public inline fun Map.padZip( other: Map, left: (K, A) -> C, @@ -660,33 +500,8 @@ public fun Map.combine(other: Map, combine: (A, A) -> A): Map if (size < other.size) fold(other) { my, (k, b) -> my + Pair(k, my[k]?.let { combine(b, it) } ?: b) } else other.fold(this@combine) { my, (k, a) -> my + Pair(k, my[k]?.let { combine(a, it) } ?: a) } -@Deprecated(SemigroupDeprecation, ReplaceWith("combine(b){a1, a2 -> a1 + a2}")) -public fun Map.combine(SG: Semigroup, b: Map): Map = - combine(b, SG::combine) - -@Deprecated( - "Use fold & Map.combine instead.\n$NicheAPI", - ReplaceWith( - "fold(emptyMap()) { acc, map -> acc.combine(map){a1, a2 -> a1 + a2} }", - "arrow.core.combine" - ) -) -public fun Iterable>.combineAll(SG: Semigroup): Map = - fold(emptyMap()) { acc, map -> acc.combine(map, SG::combine) } - public inline fun Map.fold(initial: B, operation: (acc: B, Map.Entry) -> B): B { var accumulator = initial forEach { accumulator = operation(accumulator, it) } return accumulator } - -@Deprecated("Use fold instead foldLeft", ReplaceWith("fold(b, f)")) -public inline fun Map.foldLeft(b: B, f: (B, Map.Entry) -> B): B = - fold(b, f) - -@Deprecated("Internal method will be removed from binary in 2.0.0") -internal fun Pair?.asIterable(): Iterable> = - when (this) { - null -> emptyList() - else -> listOf(this) - } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt index e21f197db7a..c7171e1793e 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt @@ -1,8 +1,5 @@ package arrow.core -import arrow.typeclasses.Semigroup -import arrow.typeclasses.SemigroupDeprecation - public inline fun identity(a: A): A = a /** @@ -20,11 +17,3 @@ internal object EmptyValue { public inline fun combine(first: Any?, second: T, combine: (T, T) -> T): T = if (first === EmptyValue) second else combine(first as T, second) } - -/** - * Like [Semigroup.maybeCombine] but for using with [EmptyValue] - */ -@PublishedApi -@Deprecated(SemigroupDeprecation, ReplaceWith("EmptyValue.combine(first, second) { x, y -> x.combine(y) }", "arrow.core.EmptyValue")) -internal fun Semigroup.emptyCombine(first: Any?, second: T): T = - EmptyValue.combine(first, second) { x, y -> x.combine(y) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt index 949e205b0c0..b4dea848be8 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt @@ -367,7 +367,7 @@ import kotlin.jvm.JvmName * import arrow.core.raise.fold * import arrow.fx.coroutines.ExitCase * import arrow.fx.coroutines.guaranteeCase - * import arrow.fx.coroutines.parTraverse + * import arrow.fx.coroutines.parMap * import io.kotest.assertions.fail * import io.kotest.matchers.shouldBe * import io.kotest.matchers.types.shouldBeTypeOf @@ -385,7 +385,7 @@ import kotlin.jvm.JvmName * val error = "Error" * val exits = (0..3).map { CompletableDeferred() } * effect> { - * (0..4).parTraverse { index -> + * (0..4).parMap { index -> * if (index == 4) raise(error) * else awaitExitCase(exits[index]) * } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Mappers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Mappers.kt index 9e0e27830f5..9cee45a235c 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Mappers.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Mappers.kt @@ -6,7 +6,6 @@ import arrow.core.Either import arrow.core.Ior import arrow.core.Option import arrow.core.Some -import arrow.core.identity import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName @@ -18,18 +17,6 @@ public fun EagerEffect.toEither(): Either = eithe public suspend fun Effect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } public fun EagerEffect.toIor(): Ior = fold({ Ior.Left(it) }) { Ior.Right(it) } -@Deprecated( - "orNull is being renamed to getOrNull to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("getOrNull()", "arrow.core.raise.getOrNull") -) -public suspend fun Effect.orNull(): A? = getOrElse { null } - -@Deprecated( - "orNull is being renamed to getOrNull to be more consistent with the Kotlin Standard Library naming", - ReplaceWith("getOrNull()", "arrow.core.raise.getOrNull") -) -public fun EagerEffect.orNull(): A? = getOrElse { null } - /** Run the [Effect] by returning [A], or `null` if raised with [Error]. */ public suspend fun Effect.getOrNull(): A? = getOrElse { null } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt index f63059ba75b..0277d86d4ad 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt @@ -1,5 +1,4 @@ @file:OptIn(ExperimentalTypeInference::class, ExperimentalContracts::class) -@file:Suppress("DEPRECATION") @file:JvmMultifileClass @file:JvmName("RaiseKt") @@ -8,9 +7,6 @@ package arrow.core.raise import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.NonEmptySet -import arrow.core.Validated -import arrow.core.ValidatedDeprMsg -import arrow.core.continuations.EffectScope import arrow.core.getOrElse import arrow.core.identity import arrow.core.nonFatalOrThrow @@ -93,7 +89,6 @@ public annotation class RaiseDSL * import arrow.core.raise.effect * import arrow.core.raise.ior * import arrow.core.raise.toEither - * import arrow.typeclasses.Semigroup * import io.kotest.matchers.shouldBe * * fun Raise.failure(): Int = raise("failed") diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt index a1c39c3dd39..c460fff22b1 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt @@ -10,10 +10,7 @@ import arrow.core.EmptyValue.combine import arrow.core.EmptyValue.unbox import arrow.core.NonEmptyList import arrow.core.NonEmptySet -import arrow.core.Validated -import arrow.core.ValidatedDeprMsg import arrow.core.collectionSizeOrDefault -import arrow.core.ValidatedNel import arrow.core.mapOrAccumulate import arrow.core.nonEmptyListOf import arrow.core.toNonEmptyListOrNull diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt index 217939f2966..1508f74119d 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt @@ -11,7 +11,6 @@ import arrow.core.test.suspendFunThatReturnsAnyRight import arrow.core.test.suspendFunThatReturnsEitherAnyOrAnyOrThrows import arrow.core.test.suspendFunThatThrows import arrow.core.test.testLaws -import arrow.typeclasses.Monoid import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -60,7 +59,7 @@ class EitherTest : StringSpec({ "tap applies effects returning the original value" { checkAll(Arb.either(Arb.long(), Arb.int())) { either -> var effect = 0 - val res = either.tap { effect += 1 } + val res = either.onRight { effect += 1 } val expected = when (either) { is Left -> 0 is Right -> 1 @@ -73,7 +72,7 @@ class EitherTest : StringSpec({ "tapLeft applies effects returning the original value" { checkAll(Arb.either(Arb.long(), Arb.int())) { either -> var effect = 0 - val res = either.tapLeft { effect += 1 } + val res = either.onLeft { effect += 1 } val expected = when (either) { is Left -> 1 is Right -> 0 @@ -92,74 +91,31 @@ class EitherTest : StringSpec({ left.fold({ it + 2 }, { it + 1 }) shouldBe b + 2 } } - - "foldLeft should return initial if Left and apply op if Right" { - checkAll(Arb.intSmall(), Arb.intSmall(), Arb.intSmall()) { a, b, c -> - Right(a).foldLeft(c, Int::plus) shouldBe c + a - Left(b).foldLeft(c, Int::plus) shouldBe c - } - } - - "foldMap should return the empty of the inner type if Left and apply op if Right" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val left: Either = Left(b) - - Right(a).foldMap(Monoid.int()) { it + 1 } shouldBe a + 1 - left.foldMap(Monoid.int()) { it + 1 } shouldBe Monoid.int().empty() - } - } - - "bifoldLeft should apply first op if Left and apply second op if Right" { - checkAll(Arb.intSmall(), Arb.intSmall(), Arb.intSmall()) { a, b, c -> - Right(a).bifoldLeft(c, Int::plus, Int::times) shouldBe a * c - Left(b).bifoldLeft(c, Int::plus, Int::times) shouldBe b + c - } - } - - "bifoldMap should apply first op if Left and apply second op if Right" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val right: Either = Right(a) - val left: Either = Left(b) - - right.bifoldMap(Monoid.int(), { it + 2 }, { it + 1 }) shouldBe a + 1 - left.bifoldMap(Monoid.int(), { it + 2 }, { it + 1 }) shouldBe b + 2 - } - } - - "fromNullable should lift value as a Right if it is not null" { - checkAll(Arb.int()) { a: Int -> - Either.fromNullable(a) shouldBe Right(a) - } - } - - "fromNullable should lift value as a Left(Unit) if it is null" { - Either.fromNullable(null) shouldBe Left(Unit) - } - - "empty should return a Right of the empty of the inner type" { - Right(Monoid.string().empty()) shouldBe Monoid.either(Monoid.string(), Monoid.string()).empty() - } - + "combine two rights should return a right of the combine of the inners" { checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - Monoid.string().run { Right(a.combine(b)) } shouldBe Right(a).combine( - Monoid.string(), - Monoid.string(), - Right(b) + Right(a + b) shouldBe Right(a).combine( + Right(b), + Int::plus, + String::plus ) } } "combine two lefts should return a left of the combine of the inners" { checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - Monoid.string().run { Left(a.combine(b)) } shouldBe Left(a).combine(Monoid.string(), Monoid.string(), Left(b)) + Left(a + b) shouldBe Left(a).combine( + Left(b), + String::plus, + Int::plus + ) } } "combine a right and a left should return left" { checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - Left(a) shouldBe Left(a).combine(Monoid.string(), Monoid.string(), Right(b)) - Left(a) shouldBe Right(b).combine(Monoid.string(), Monoid.string(), Left(a)) + Left(a) shouldBe Left(a).combine(Right(b), String::plus, String::plus) + Left(a) shouldBe Right(b).combine(Left(a), String::plus, String::plus) } } @@ -170,111 +126,31 @@ class EitherTest : StringSpec({ } } - "orNull should return value" { + "getOrNull should return value" { checkAll(Arb.int()) { a: Int -> - Right(a).orNull() shouldBe a + Right(a).getOrNull() shouldBe a } } - "orNone should return Some(value)" { + "getOrNone should return Some(value)" { checkAll(Arb.int()) { a: Int -> - Right(a).orNone() shouldBe Some(a) + Right(a).getOrNone() shouldBe Some(a) } } - "orNone should return None when left" { + "getOrNone should return None when left" { checkAll(Arb.string()) { a: String -> - Left(a).orNone() shouldBe None - } - } - - "getOrHandle should return value" { - checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> - Right(a).getOrHandle { b } shouldBe a - Left(a).getOrHandle { it + b } shouldBe a + b - } - } - - "filterOrElse should filter values" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val left: Either = Left(a) - - Right(a).filterOrElse({ it > a - 1 }, { b }) shouldBe Right(a) - Right(a).filterOrElse({ it > a + 1 }, { b }) shouldBe Left(b) - left.filterOrElse({ it > a - 1 }, { b }) shouldBe Left(a) - left.filterOrElse({ it > a + 1 }, { b }) shouldBe Left(a) - } - } - - "filterOrOther should filter values" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val left: Either = Left(a) - - Right(a).filterOrOther({ it > a - 1 }, { b + a }) shouldBe Right(a) - Right(a).filterOrOther({ it > a + 1 }, { b + a }) shouldBe Left(b + a) - left.filterOrOther({ it > a - 1 }, { b + a }) shouldBe Left(a) - left.filterOrOther({ it > a + 1 }, { b + a }) shouldBe Left(a) - } - } - - "leftIfNull should return Left if Right value is null of if Either is Left" { - checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> - Right(a).leftIfNull { b } shouldBe Right(a) - Right(null).leftIfNull { b } shouldBe Left(b) - Left(a).leftIfNull { b } shouldBe Left(a) - } - } - - "exists should apply predicate to Right only" { - checkAll(Arb.intSmall()) { a -> - val left: Either = Left(a) - - Right(a).exists { it > a - 1 } shouldBe true - !Right(a).exists { it > a + 1 } shouldBe true - !left.exists { it > a - 1 } shouldBe true - !left.exists { it > a + 1 } shouldBe true - } - } - - "rightIfNotNull should return Left if value is null or Right of value when not null" { - checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> - null.rightIfNotNull { b } shouldBe Left(b) - a.rightIfNotNull { b } shouldBe Right(a) + Left(a).getOrNone() shouldBe None } } - - "rightIfNull should return Left if value is not null or Right of value when null" { - checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> - a.rightIfNull { b } shouldBe Left(b) - null.rightIfNull { b } shouldBe Right(null) - } - } - + "swap should interchange values" { checkAll(Arb.int()) { a: Int -> Left(a).swap() shouldBe Right(a) Right(a).swap() shouldBe Left(a) } } - - "orNull should convert" { - checkAll(Arb.int()) { a: Int -> - val left: Either = Left(a) - - Right(a).orNull() shouldBe a - left.orNull() shouldBe null - } - } - - "contains should check value" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - require(Right(a).contains(a)) { "Expected ${Right(a)}.contains($a) to be true, but it was false." } - if (a != b) require(!Right(a).contains(b)) { "Expected ${Right(a)}.contains($b) to be false, but it was true." } - else require(Right(a).contains(b)) { "Expected ${Right(a)}.contains($b) to be true, but it was false." } - require(!Left(a).contains(a)) { "Expected ${Left(a)}.contains($a) to be false, but it was true." } - } - } - + "map should alter right instance only" { checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> val right: Either = Right(a) @@ -294,40 +170,6 @@ class EitherTest : StringSpec({ left.mapLeft { it + 1 } shouldBe Left(b + 1) } } - - "bimap should alter left or right instance accordingly" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val right: Either = Right(a) - val left: Either = Left(b) - - right.bimap({ it + 2 }, { it + 1 }) shouldBe Right(a + 1) - left.bimap({ it + 2 }, { it + 1 }) shouldBe Left(b + 2) - } - } - - "replicate should return Right(empty list) when n <= 0" { - checkAll( - Arb.nonPositiveInt(), - Arb.int(0..100) - ) { n: Int, a: Int -> - val expected: Either> = Right(emptyList()) - - Right(a).replicate(n) shouldBe expected - - - Left(a).replicate(n) shouldBe expected - } - } - - "replicate should return Right(list of repeated value size n) when Right and n is positive" { - checkAll( - Arb.int(1..10), - Arb.int() - ) { n: Int, a: Int -> - Right(a).replicate(n) shouldBe Right(List(n) { a }) - Left(a).replicate(n) shouldBe Left(a) - } - } "flatMap should map right instance only" { checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> @@ -338,19 +180,12 @@ class EitherTest : StringSpec({ left.flatMap { Right(it + 1) } shouldBe left } } - - "conditionally should create right instance only if test is true" { - checkAll(Arb.boolean(), Arb.int(), Arb.string()) { t: Boolean, i: Int, s: String -> - val expected = if (t) Right(i) else Left(s) - Either.conditionally(t, { s }, { i }) shouldBe expected - } - } - + "handleErrorWith should handle left instance otherwise return Right" { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - Left(a).handleErrorWith { Right(b) } shouldBe Right(b) - Right(a).handleErrorWith { Right(b) } shouldBe Right(a) - Left(a).handleErrorWith { Left(b) } shouldBe Left(b) + Left(a).recover { Right(b).bind() } shouldBe Right(b) + Right(a).recover { Right(a + 1).bind() } shouldBe Right(a) + Left(a).recover { Left(b).bind() } shouldBe Left(b) } } @@ -362,82 +197,6 @@ class EitherTest : StringSpec({ val exception = Exception("Boom!") Either.catch { throw exception } shouldBe Left(exception) } - - "catchAndFlatten should return Right(result) when f does not throw" { - Either.catchAndFlatten { Right(1) } shouldBe Right(1) - } - - "catchAndFlatten should return Left(result) when f throws" { - val exception = Exception("Boom!") - Either.catchAndFlatten { throw exception } shouldBe Left(exception) - } - - "resolve should yield a result when deterministic functions are used as handlers" { - checkAll( - Arb.suspendFunThatReturnsEitherAnyOrAnyOrThrows(), - Arb.any() - ) { f: suspend () -> Either, returnObject: Any -> - val result = - Either.resolve( - f = { f() }, - success = { a -> handleWithPureFunction(a, returnObject) }, - error = { e -> handleWithPureFunction(e, returnObject) }, - throwable = { t -> handleWithPureFunction(t, returnObject) }, - unrecoverableState = { handleWithPureFunction(it) } - ) - result shouldBe returnObject - } - } - - "resolve should yield a result when an exception is thrown in the success supplied function" { - checkAll( - Arb.suspendFunThatReturnsAnyRight(), - Arb.any() - ) { f: suspend () -> Either, returnObject: Any -> - val result = - Either.resolve( - f = { f() }, - success = { throwException(it) }, - error = { e -> handleWithPureFunction(e, returnObject) }, - throwable = { t -> handleWithPureFunction(t, returnObject) }, - unrecoverableState = { handleWithPureFunction(it) } - ) - result shouldBe returnObject - } - } - - "resolve should yield a result when an exception is thrown in the error supplied function" { - checkAll( - Arb.suspendFunThatReturnsAnyLeft(), - Arb.any() - ) { f: suspend () -> Either, returnObject: Any -> - val result = - Either.resolve( - f = { f() }, - success = { a -> handleWithPureFunction(a, returnObject) }, - error = { throwException(it) }, - throwable = { t -> handleWithPureFunction(t, returnObject) }, - unrecoverableState = { handleWithPureFunction(it) } - ) - result shouldBe returnObject - } - } - - "resolve should throw a Throwable when any exception is thrown in the throwable supplied function" { - checkAll( - Arb.suspendFunThatThrows() - ) { f: suspend () -> Either -> - shouldThrow { - Either.resolve( - f = { f() }, - success = { throwException(it) }, - error = { throwException(it) }, - throwable = { throwException(it) }, - unrecoverableState = { handleWithPureFunction(it) } - ) - } - } - } "zipOrAccumulate results in all Right transformed, or all Left combined according to combine" { checkAll( diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt index d07ae288d2d..9fecb075e01 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt @@ -3,7 +3,6 @@ package arrow.core import arrow.core.test.ior import arrow.core.test.laws.SemigroupLaws import arrow.core.test.testLaws -import arrow.typeclasses.Semigroup import io.kotest.core.spec.style.StringSpec import io.kotest.data.forAll import io.kotest.data.row @@ -26,73 +25,6 @@ class IorTest : StringSpec({ }, ARB) ) - val nullableLongSemigroup = - Semigroup { a, b -> Nullable.zip(a, b) { aa, bb -> aa + bb } } - - "zip identity" { - checkAll(Arb.ior(Arb.long().orNull(), Arb.int().orNull())) { ior -> - val res = ior.zip(nullableLongSemigroup, Ior.Right(Unit)) { a, _ -> a } - res shouldBe ior - } - } - - "zip is derived from flatMap" { - checkAll( - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()), - Arb.ior(Arb.long().orNull(), Arb.int().orNull()) - ) { a, b, c, d, e, f, g, h, i, j -> - val res = a.zip( - nullableLongSemigroup, - b, c, d, e, f, g, h, i, j - ) { a, b, c, d, e, f, g, h, i, j -> - Nullable.zip( - a, - b, - c, - d, - e, - f, - g, - h, - i, - j - ) { a, b, c, d, e, f, g, h, i, j -> a + b + c + d + e + f + g + h + i + j } - } - - val expected = listOf(a, b, c, d, e, f, g, h, i, j) - .fold, Ior>(Ior.Right(0)) { acc, ior -> - val mid = acc.flatMap(nullableLongSemigroup) { a -> ior.map { b -> Nullable.zip(a, b) { a, b -> a + b } } } - mid - } - - res shouldBe expected - } - } - - "zip should combine left values in correct order" { - Ior.Both("fail1", -1).zip( - Semigroup.string(), - Ior.Left("fail2"), - Ior.Right(-1) - ) { _, _, _ -> "success!" } shouldBe Ior.Left("fail1fail2") - } - - "bimap() should allow modify both value" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - Ior.Right(b).bimap({ "5" }, { a * 2 }) shouldBe Ior.Right(a * 2) - Ior.Left(a).bimap({ a * 3 }, { "5" }) shouldBe Ior.Left(a * 3) - Ior.Both(a, b).bimap({ 2 }, { "power of $it" }) shouldBe Ior.Both(2, "power of $b") - } - } - "map() should just right side of an Ior" { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).map { l: String -> l.length } shouldBe Ior.Left(a) @@ -130,14 +62,6 @@ class IorTest : StringSpec({ } } - "padNull() should return the correct Pair of nullables" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - Ior.Left(a).padNull() shouldBe Pair(a, null) - Ior.Right(b).padNull() shouldBe Pair(null, b) - Ior.Both(a, b).padNull() shouldBe Pair(a, b) - } - } - "toEither() should convert values into a valid Either" { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).toEither() shouldBe Either.Left(a) @@ -146,14 +70,6 @@ class IorTest : StringSpec({ } } - "orNull() should convert right values into a nullable" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - Ior.Left(a).orNull() shouldBe null - Ior.Right(b).orNull() shouldBe b - Ior.Both(a, b).orNull() shouldBe b - } - } - "getOrNull() should convert right values into a nullable, or return null if left" { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).getOrNull() shouldBe null @@ -192,36 +108,6 @@ class IorTest : StringSpec({ } } - "lift(f) should apply the input function to an Ior correctly" { - checkAll(Arb.string()) { a: String -> - val f = Ior.lift { s: String -> "Hello $s" } - f(Ior.Right(a)) shouldBe Ior.Right("Hello $a") - } - } - - "lift(fa, fb) should apply the input functions to an Ior correctly" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - val fa = { s1: String -> "Hello $s1" } - val fb = { s2: String -> s2.length } - val f = Ior.lift(fa, fb) - f(Ior.Right(b)) shouldBe Ior.Right(b.length) - f(Ior.Left(a)) shouldBe Ior.Left("Hello $a") - f(Ior.Both(a, b)) shouldBe Ior.Both("Hello $a", b.length) - } - } - - "foldLeft should fold an Ior correctly" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val left = Ior.Left(a) - val right = Ior.Right(b) - val both = Ior.Both(a, b) - val f = { c: Int, b: String -> c + b.length } - left.foldLeft(0, f) shouldBe 0 - right.foldLeft(0, f) shouldBe b.length - both.foldLeft(0, f) shouldBe b.length - } - } - "getOrElse() should return value" { checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> Ior.Right(a).getOrElse { b } shouldBe a diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index 2ae7b3e730e..d698ad6634f 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -2,9 +2,7 @@ package arrow.core import arrow.core.test.either import arrow.core.test.ior -import arrow.core.test.functionAToB import arrow.core.test.option -import arrow.typeclasses.Semigroup import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.nulls.shouldBeNull import io.kotest.matchers.nulls.shouldNotBeNull @@ -207,16 +205,16 @@ class IterableTest : StringSpec({ checkAll(Arb.list(Arb.boolean()), Arb.list(Arb.boolean())) { a, b -> a.align(b).take(min(a.size, b.size)).forEach { - it.isBoth shouldBe true + it.isBoth() shouldBe true } } checkAll(Arb.list(Arb.boolean()), Arb.list(Arb.boolean())) { a, b -> a.align(b).drop(min(a.size, b.size)).forEach { if (a.size < b.size) { - it.isRight shouldBe true + it.isRight() shouldBe true } else { - it.isLeft shouldBe true + it.isLeft() shouldBe true } } } @@ -287,13 +285,13 @@ class IterableTest : StringSpec({ "filterOption" { checkAll(Arb.list(Arb.option(Arb.int()))) { listOfOption -> - listOfOption.filterOption() shouldBe listOfOption.mapNotNull { it.orNull() } + listOfOption.filterOption() shouldBe listOfOption.mapNotNull { it.getOrNull() } } } "flattenOption" { checkAll(Arb.list(Arb.option(Arb.int()))) { listOfOption -> - listOfOption.flattenOption() shouldBe listOfOption.mapNotNull { it.orNull() } + listOfOption.flattenOption() shouldBe listOfOption.mapNotNull { it.getOrNull() } } } @@ -357,12 +355,6 @@ class IterableTest : StringSpec({ } } - "salign" { - checkAll(Arb.list(Arb.int())) { xs -> - xs.salign(Semigroup.int(), xs) shouldBe xs.map { it + it } - } - } - "reduceOrNull is compatible with reduce from stdlib" { checkAll(Arb.list(Arb.string())) { xs -> diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt index 84ec2f8119d..ab4a5b474c1 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt @@ -10,7 +10,6 @@ import arrow.core.test.map2 import arrow.core.test.map3 import arrow.core.test.option import arrow.core.test.testLaws -import arrow.typeclasses.Semigroup import io.kotest.core.spec.style.StringSpec import io.kotest.inspectors.forAll import io.kotest.inspectors.forAllValues @@ -179,8 +178,8 @@ class MapKTest : StringSpec({ ) { (a,b),f,g -> - val l = a.mapValues{ f(it.value)}.align(b.mapValues{g(it.value)}) - val r = a.align(b).mapValues { it.value.bimap(f,g)} + val l = a.mapValues{ f(it.value) }.align(b.mapValues{ g(it.value) }) + val r = a.align(b).mapValues { it.value.map(g).mapLeft(f) } l shouldBe r } @@ -409,26 +408,15 @@ class MapKTest : StringSpec({ checkAll( Arb.map2(Arb.int(), Arb.intSmall(), Arb.intSmall()) ) { (a, b) -> - a.salign(Semigroup.int(), b) shouldBe a.align(b) {it.value.fold(::identity, ::identity) { a, b -> a + b } } + a.salign(b, Int::plus) shouldBe a.align(b) {it.value.fold(::identity, ::identity) { a, b -> a + b } } } } - "void" { - checkAll( - Arb.map(Arb.intSmall(), Arb.intSmall()) - ) { a -> - val result = a.void() - - result.keys shouldBe a.keys - result.forAllValues { it shouldBe Unit } - } - } - - "filterMap" { + "mapNotNull" { checkAll( Arb.map(Arb.int(), Arb.boolean()) ) { xs -> - val rs = xs.filterMap { if(it) true else null } + val rs = xs.mapNotNull { (_, pred) -> if(pred) true else null } xs.forAll { if (it.value) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index 9f2e99a13e1..e7e148467c7 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -4,7 +4,6 @@ import arrow.core.test.laws.SemigroupLaws import arrow.core.test.nonEmptyList import arrow.core.test.stackSafeIteration import arrow.core.test.testLaws -import arrow.typeclasses.Semigroup import io.kotest.assertions.withClue import io.kotest.core.spec.style.StringSpec import io.kotest.inspectors.shouldForAll diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt index 464f6e5cfd8..98d3f0b85f2 100755 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt @@ -54,7 +54,7 @@ class OptionTest : StringSpec({ "tap applies effects returning the original value" { checkAll(Arb.option(Arb.long())) { option -> var effect = 0 - val res = option.tap { effect += 1 } + val res = option.onSome { effect += 1 } val expected = when (option) { is Some -> 1 is None -> 0 @@ -67,7 +67,7 @@ class OptionTest : StringSpec({ "tapNone applies effects returning the original value" { checkAll(Arb.option(Arb.long())) { option -> var effect = 0 - val res = option.tapNone { effect += 1 } + val res = option.onNone { effect += 1 } val expected = when (option) { is Some -> 0 is None -> 1 @@ -95,9 +95,9 @@ class OptionTest : StringSpec({ none.getOrElse { "java" } shouldBe "java" } - "orNull" { - some.orNull() shouldNotBe null - none.orNull() shouldBe null + "getOrNull" { + some.getOrNull() shouldNotBe null + none.getOrNull() shouldBe null } "map" { @@ -105,20 +105,6 @@ class OptionTest : StringSpec({ none.map(String::uppercase) shouldBe None } - "zip" { - checkAll(Arb.int()) { a: Int -> - val op: Option = a.some() - some.zip(op) { a, b -> a + b } shouldBe Some("kotlin$a") - none.zip(op) { a, b -> a + b } shouldBe None - some.zip(op) shouldBe Some(Pair("kotlin", a)) - } - } - - "mapNotNull" { - some.mapNotNull { it.toIntOrNull() } shouldBe None - some.mapNotNull { it.uppercase() } shouldBe Some("KOTLIN") - } - "fold" { some.fold({ 0 }) { it.length } shouldBe 6 none.fold({ 0 }) { it.length } shouldBe 0 @@ -129,27 +115,6 @@ class OptionTest : StringSpec({ none.flatMap { Some(it.uppercase()) } shouldBe None } - "align" { - some align some shouldBe Some(Ior.Both("kotlin", "kotlin")) - some align none shouldBe Some(Ior.Left("kotlin")) - none align some shouldBe Some(Ior.Right("kotlin")) - none align none shouldBe None - - some.align(some) { "$it" } shouldBe Some("Ior.Both(kotlin, kotlin)") - some.align(none) { "$it" } shouldBe Some("Ior.Left(kotlin)") - none.align(some) { "$it" } shouldBe Some("Ior.Right(kotlin)") - none.align(none) { "$it" } shouldBe None - - val nullable = null.some() - some align nullable shouldBe Some(Ior.Both("kotlin", null)) - nullable align some shouldBe Some(Ior.Both(null, "kotlin")) - nullable align nullable shouldBe Some(Ior.Both(null, null)) - - some.align(nullable) { "$it" } shouldBe Some("Ior.Both(kotlin, null)") - nullable.align(some) { "$it" } shouldBe Some("Ior.Both(null, kotlin)") - nullable.align(nullable) { "$it" } shouldBe Some("Ior.Both(null, null)") - } - "filter" { some.filter { it == "java" } shouldBe None none.filter { it == "java" } shouldBe None @@ -176,23 +141,6 @@ class OptionTest : StringSpec({ noneAny.filterIsInstance() shouldBe None } - "exists" { - some.exists { it.startsWith('k') } shouldBe true - some.exists { it.startsWith('j') } shouldBe false - none.exists { it.startsWith('k') } shouldBe false - } - - "all" { - some.all { it.startsWith('k') } shouldBe true - some.all { it.startsWith('j') } shouldBe false - none.all { it.startsWith('k') } shouldBe true - } - - "orElse" { - some.orElse { Some("java") } shouldBe Some("kotlin") - none.orElse { Some("java") } shouldBe Some("java") - } - "toList" { some.toList() shouldBe listOf("kotlin") none.toList() shouldBe listOf() @@ -302,44 +250,12 @@ class OptionTest : StringSpec({ nullableList.elementAtOrNone(index = 3 - 1) shouldBe Some(null) } - "and" { - val x = Some(2) - val y = Some("Foo") - x and y shouldBe Some("Foo") - x and None shouldBe None - None and x shouldBe None - None and None shouldBe None - } - - "or" { - val x = Some(2) - val y = Some(100) - x or y shouldBe Some(2) - x or None shouldBe Some(2) - None or x shouldBe Some(2) - None or None shouldBe None - } - "toLeftOption" { 1.leftIor().leftOrNull() shouldBe 1 2.rightIor().leftOrNull() shouldBe null (1 to 2).bothIor().leftOrNull() shouldBe 1 } - "pairLeft" { - val some: Option = Some(2) - val none: Option = None - some.pairLeft("key") shouldBe Some("key" to 2) - none.pairLeft("key") shouldBe None - } - - "pairRight" { - val some: Option = Some(2) - val none: Option = None - some.pairRight("right") shouldBe Some(2 to "right") - none.pairRight("right") shouldBe None - } - "Option>.toMap()" { val some: Option> = Some("key" to "value") val none: Option> = None @@ -374,14 +290,6 @@ class OptionTest : StringSpec({ } } - "lift" { - val f: (Int) -> String = { a -> a.toString() } - val lifted = Option.lift(f) - checkAll(Arb.int()) { a: Int -> - lifted(Some(a)) shouldBe Some(a.toString()) - } - } - "isNone should return true if None and false if Some" { none.isNone() shouldBe true none.isSome() shouldBe false @@ -392,11 +300,6 @@ class OptionTest : StringSpec({ some.isNone() shouldBe false } - "getOrNull" { - none.getOrNull() shouldBe null - some.getOrNull() shouldBe "kotlin" - } - "isSome with predicate" { some.isSome { it.startsWith('k') } shouldBe true some.isSome { it.startsWith('j') } shouldBe false @@ -410,25 +313,6 @@ class OptionTest : StringSpec({ } } - "unzip Some values" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - val op: Option> = Pair(a, b).toOption() - op.unzip() shouldBe Pair(Option(a), Option(b)) - } - } - - "unzip None values" { - val op: Option> = None - op.unzip() shouldBe Pair(None, None) - } - - "unzip with function" { - val f: (Int) -> Pair = { c -> Pair(c.toString(), c.toLong()) } - checkAll(Arb.int()) { c: Int -> - Option(c).unzip(f) shouldBe Pair(Option(c.toString()), Option(c.toLong())) - } - } - "widen" { checkAll(Arb.string()) { a: String -> val widen: Option = Option(a).widen() diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt index 171db884835..ab155a5547e 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt @@ -4,7 +4,6 @@ import arrow.core.test.laws.MonoidLaws import arrow.core.test.option import arrow.core.test.sequence import arrow.core.test.testLaws -import arrow.typeclasses.Semigroup import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.sequences.shouldBeEmpty import io.kotest.property.Arb diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt index 67a3c3fb3cf..1eae62c99ce 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt @@ -2,7 +2,6 @@ package arrow.core.raise import arrow.core.Either import arrow.core.Ior -import arrow.typeclasses.Semigroup import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt index 5d32836bbc4..0da9d2304aa 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt @@ -45,14 +45,12 @@ class MappersSpec : StringSpec({ "effect - getOrNull" { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> - effect { a.bind() }.orNull() shouldBe a.getOrNull() effect { a.bind() }.getOrNull() shouldBe a.getOrNull() } } "eagerEffect - getOrNull" { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> - eagerEffect { a.bind() }.orNull() shouldBe a.getOrNull() eagerEffect { a.bind() }.getOrNull() shouldBe a.getOrNull() } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index 0114ccd7b70..8aaea6cd455 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -1,7 +1,6 @@ package arrow.core.test import arrow.core.Either -import arrow.core.Endo import arrow.core.Ior import arrow.core.NonEmptyList import arrow.core.NonEmptySet @@ -67,8 +66,6 @@ fun Arb.Companion.intSmall(factor: Int = 10000): Arb = fun Arb.Companion.longSmall(): Arb = Arb.long((Long.MIN_VALUE / 100000L)..(Long.MAX_VALUE / 100000L)) -fun Arb.Companion.endo(arb: Arb): Arb> = arb.map { a: A -> Endo { a } } - fun Arb.Companion.option(arb: Arb): Arb> = arb.orNull().map { it.toOption() } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/IorUsage.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/IorUsage.java index de771c5e38f..e68c26f6344 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/IorUsage.java +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/IorUsage.java @@ -1,13 +1,9 @@ package arrow.core; -import kotlin.jvm.functions.Function1; - public class IorUsage { public void testUsage() { Ior, Integer> bothNel = Ior.bothNel(1, 2); Ior fromNullables = Ior.fromNullables(1, null); - Function1, Ior> lift = Ior.lift((b) -> b.toUpperCase()); - Function1, Ior> lift1 = Ior.lift((a) -> a + 1, (b) -> b.toUpperCase()); } } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/OptionUsage.java b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/OptionUsage.java index 23eb4be20b0..81c296a2386 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/OptionUsage.java +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/OptionUsage.java @@ -1,17 +1,9 @@ package arrow.core; -import kotlin.jvm.functions.Function1; - public class OptionUsage { public void testUsage() { Option fromNullable = Option.fromNullable(null); - Option.tryCatch((throwable) -> { - throwable.printStackTrace(); - return None.INSTANCE; - }, () -> 1); - Option invoke = Option.invoke(1); - Function1, Option> lift = Option.lift((a) -> a.toUpperCase()); } } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt new file mode 100644 index 00000000000..b6d7af378af --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from ErrorHandlers.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEffectError01 + +import arrow.core.raise.effect +import arrow.core.raise.recover + +object User +object Error + +val error = effect { raise(Error) } // Raise(error) + +val a = error.recover { error -> User } // Success(User) +val b = error.recover { error -> raise("other-failure") } // Raise(other-failure) +val c = error.recover { error -> throw RuntimeException("BOOM") } // Exception(BOOM) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt new file mode 100644 index 00000000000..a6bab641af9 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-02.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from ErrorHandlers.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEffectError02 + +import arrow.core.raise.effect +import arrow.core.raise.catch + +object User +object Error + +val exception = effect { throw RuntimeException("BOOM") } // Exception(BOOM) + +val a = exception.catch { error -> error.message?.length ?: -1 } // Success(5) +val b = exception.catch { raise(Error) } // Raise(error) +val c = exception.catch { throw RuntimeException("other-failure") } // Exception(other-failure) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt new file mode 100644 index 00000000000..a3d574108af --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-03.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from ErrorHandlers.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEffectError03 + +import arrow.core.raise.effect +import arrow.core.raise.catch + +object User +object Error + +val x = effect { + throw IllegalArgumentException("builder missed args") +}.catch { raise(Error) } + +val y = effect { + throw IllegalArgumentException("builder missed args") +}.catch { raise(Error) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt new file mode 100644 index 00000000000..313a4846eda --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither01 + +import arrow.core.andThen + +val throwsSomeStuff: (Int) -> Double = {x -> x.toDouble()} +val throwsOtherThings: (Double) -> String = {x -> x.toString()} +val moreThrowing: (String) -> List = {x -> listOf(x)} +val magic = throwsSomeStuff.andThen(throwsOtherThings).andThen(moreThrowing) +fun main() { + println ("magic = $magic") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt new file mode 100644 index 00000000000..d9f0dfa712f --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-02.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither02 + +import arrow.core.Either + +val left: Either = + Either.Left("Something went wrong") +fun main() { + println(left) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt new file mode 100644 index 00000000000..32c1b919271 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-03.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither03 + +import arrow.core.Either +import arrow.core.flatMap + +val right: Either = Either.Right(5) +val value = right.flatMap{ Either.Right(it + 1) } +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt new file mode 100644 index 00000000000..002655609b2 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-04.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither04 + +import arrow.core.Either +import arrow.core.flatMap + +val left: Either = Either.Left("Something went wrong") +val value = left.flatMap{ Either.Right(it + 1) } +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt new file mode 100644 index 00000000000..90c14927889 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-05.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither05 + +import arrow.core.Either +import arrow.core.flatMap + +fun parse(s: String): Int = + if (s.matches(Regex("-?[0-9]+"))) s.toInt() + else throw NumberFormatException("$s is not a valid integer.") + +fun reciprocal(i: Int): Double = + if (i == 0) throw IllegalArgumentException("Cannot take reciprocal of 0.") + else 1.0 / i + +fun stringify(d: Double): String = d.toString() diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt new file mode 100644 index 00000000000..3bcaf31e093 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-06.kt @@ -0,0 +1,21 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither06 + +import arrow.core.Either +import arrow.core.flatMap +import arrow.core.left +import arrow.core.right + +// Either Style +fun parse(s: String): Either = + if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) + else Either.Left(NumberFormatException("$s is not a valid integer.")) + +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0.")) + else Either.Right(1.0 / i) + +fun stringify(d: Double): String = d.toString() + +fun magic(s: String): Either = + parse(s).flatMap { reciprocal(it) }.map { stringify(it) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt new file mode 100644 index 00000000000..71cf5d27d22 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-07.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither07 + +import arrow.core.Either + +fun parse(s: String): Either = + if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) + else Either.Left(NumberFormatException("$s is not a valid integer.")) + +val notANumber = parse("Not a number") +val number2 = parse("2") +fun main() { + println("notANumber = $notANumber") + println("number2 = $number2") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt new file mode 100644 index 00000000000..67c0390ef19 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-08.kt @@ -0,0 +1,27 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither08 + +import arrow.core.Either +import arrow.core.flatMap + +fun parse(s: String): Either = + if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) + else Either.Left(NumberFormatException("$s is not a valid integer.")) + +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0.")) + else Either.Right(1.0 / i) + +fun stringify(d: Double): String = d.toString() + +fun magic(s: String): Either = + parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } + +val magic0 = magic("0") +val magic1 = magic("1") +val magicNotANumber = magic("Not a number") +fun main() { + println("magic0 = $magic0") + println("magic1 = $magic1") + println("magicNotANumber = $magicNotANumber") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt new file mode 100644 index 00000000000..824832efff8 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-09.kt @@ -0,0 +1,31 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither09 + +import arrow.core.Either +import arrow.core.flatMap + +fun parse(s: String): Either = + if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) + else Either.Left(NumberFormatException("$s is not a valid integer.")) + +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(IllegalArgumentException("Cannot take reciprocal of 0.")) + else Either.Right(1.0 / i) + +fun stringify(d: Double): String = d.toString() + +fun magic(s: String): Either = + parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } + +val x = magic("2") +val value = when(x) { + is Either.Left -> when (x.value) { + is NumberFormatException -> "Not a number!" + is IllegalArgumentException -> "Can't take reciprocal of 0!" + else -> "Unknown error" + } + is Either.Right -> "Got reciprocal: ${x.value}" +} +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt new file mode 100644 index 00000000000..fc1ae99d530 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-10.kt @@ -0,0 +1,24 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither10 + +import arrow.core.Either +import arrow.core.flatMap +// Either with ADT Style + +sealed class Error { + object NotANumber : Error() + object NoZeroReciprocal : Error() +} + +fun parse(s: String): Either = + if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) + else Either.Left(Error.NotANumber) + +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(Error.NoZeroReciprocal) + else Either.Right(1.0 / i) + +fun stringify(d: Double): String = d.toString() + +fun magic(s: String): Either = + parse(s).flatMap{reciprocal(it)}.map{ stringify(it) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt new file mode 100644 index 00000000000..86ee196c7b6 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-11.kt @@ -0,0 +1,35 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither11 + +import arrow.core.Either +import arrow.core.flatMap + +sealed class Error { + object NotANumber : Error() + object NoZeroReciprocal : Error() +} + +fun parse(s: String): Either = + if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt()) + else Either.Left(Error.NotANumber) + +fun reciprocal(i: Int): Either = + if (i == 0) Either.Left(Error.NoZeroReciprocal) + else Either.Right(1.0 / i) + +fun stringify(d: Double): String = d.toString() + +fun magic(s: String): Either = + parse(s).flatMap{ reciprocal(it) }.map{ stringify(it) } + +val x = magic("2") +val value = when(x) { + is Either.Left -> when (x.value) { + is Error.NotANumber -> "Not a number!" + is Error.NoZeroReciprocal -> "Can't take reciprocal of 0!" + } + is Either.Right -> "Got reciprocal: ${x.value}" +} +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt new file mode 100644 index 00000000000..7dbf4740624 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-12.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither12 + +import arrow.core.Either + +fun potentialThrowingCode(): String = throw RuntimeException("Blow up!") + +suspend fun makeSureYourLogicDoesNotHaveSideEffects(): Either = + Either.catch { potentialThrowingCode() }.mapLeft { Error.SpecificError } +suspend fun main() { + println("makeSureYourLogicDoesNotHaveSideEffects().isLeft() = ${makeSureYourLogicDoesNotHaveSideEffects().isLeft()}") +} + +sealed class Error { + object SpecificError : Error() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt new file mode 100644 index 00000000000..b3851242533 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-13.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither13 + +import arrow.core.Either + +val r : Either = Either.Right(7) +val rightMapLeft = r.mapLeft {it + 1} +val l: Either = Either.Left(7) +val leftMapLeft = l.mapLeft {it + 1} +fun main() { + println("rightMapLeft = $rightMapLeft") + println("leftMapLeft = $leftMapLeft") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt new file mode 100644 index 00000000000..f5153c6f75e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-14.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither14 + +import arrow.core.Either.Left +import arrow.core.Either + +val r: Either = Either.Right(7) +val swapped = r.swap() +fun main() { + println("swapped = $swapped") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt new file mode 100644 index 00000000000..08d98cd01ae --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-15.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither15 + +import arrow.core.right + +val right7 = + 7.right() +fun main() { + println(right7) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt new file mode 100644 index 00000000000..31b96ed3baa --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-16.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither16 + +import arrow.core.left + + val leftHello = + "hello".left() +fun main() { + println(leftHello) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt new file mode 100644 index 00000000000..b763ad081ea --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-17.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither17 + +import arrow.core.left +import arrow.core.getOrElse + +val x = "hello".left() +val value = x.getOrElse { "$it world!" } +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt new file mode 100644 index 00000000000..937affcc8b7 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-18.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither18 + +import arrow.core.Either +import arrow.core.right + +val x : Either = 7.right() +val fold = x.fold({ 1 }, { it + 3 }) +fun main() { + println("fold = $fold") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt new file mode 100644 index 00000000000..3bd0d3e2be9 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-19.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither19 + +import arrow.core.Either +import arrow.core.left + +val y : Either = 7.left() +val fold = y.fold({ 1 }, { it + 3 }) +fun main() { + println("fold = $fold") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt new file mode 100644 index 00000000000..b11511507ae --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-20.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither20 + +import arrow.core.Either +import arrow.core.getOrElse + +val r: Either = Either.Left(NumberFormatException()) +val httpStatusCode = r.getOrElse { + when(it) { + is NumberFormatException -> 400 + else -> 500 + } +} +fun main() { + println("httpStatusCode = $httpStatusCode") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt new file mode 100644 index 00000000000..d0cb72297fa --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-21.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither21 + +import arrow.core.Either +import arrow.core.Either.Left +import arrow.core.Either.Right +import io.kotest.matchers.shouldBe + +fun test() { + Left(12).isLeft { it > 10 } shouldBe true + Left(7).isLeft { it > 10 } shouldBe false + + val right: Either = Right("Hello World") + right.isLeft { it > 10 } shouldBe false +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt new file mode 100644 index 00000000000..88279959a9e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-22.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither22 + +import arrow.core.Either +import arrow.core.Either.Left +import arrow.core.Either.Right +import io.kotest.matchers.shouldBe + +fun test() { + Right(12).isRight { it > 10 } shouldBe true + Right(7).isRight { it > 10 } shouldBe false + + val left: Either = Left("Hello World") + left.isRight { it > 10 } shouldBe false +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt new file mode 100644 index 00000000000..da9319d6bba --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-23.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither23 + +import arrow.core.Either +import io.kotest.matchers.shouldBe +import io.kotest.assertions.fail + +fun test() { + Either.Right(1) + .fold({ fail("Cannot be left") }, { it + 1 }) shouldBe 2 + + Either.Left(RuntimeException("Boom!")) + .fold({ -1 }, { fail("Cannot be right") }) shouldBe -1 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt new file mode 100644 index 00000000000..237cc244793 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-24.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither24 + +import arrow.core.Either +import io.kotest.matchers.shouldBe + +fun test() { + Either.Left("left").swap() shouldBe Either.Right("left") + Either.Right("right").swap() shouldBe Either.Left("right") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt new file mode 100644 index 00000000000..53d4d881ae9 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-25.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither25 + +import arrow.core.Either +import io.kotest.matchers.shouldBe + +fun test() { + Either.Right(12).map { _: Int ->"flower" } shouldBe Either.Right("flower") + Either.Left(12).map { _: Nothing -> "flower" } shouldBe Either.Left(12) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt new file mode 100644 index 00000000000..58c09865931 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-26.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither26 + +import arrow.core.Either +import io.kotest.matchers.shouldBe + +fun test() { + Either.Right(12).mapLeft { _: Nothing -> "flower" } shouldBe Either.Right(12) + Either.Left(12).mapLeft { _: Int -> "flower" } shouldBe Either.Left("flower") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt new file mode 100644 index 00000000000..4d89b543074 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-27.kt @@ -0,0 +1,9 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither27 + +import arrow.core.Either +import io.kotest.matchers.shouldBe + +fun test() { + Either.Right(1).onRight(::println) shouldBe Either.Right(1) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt new file mode 100644 index 00000000000..d813d97be64 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-28.kt @@ -0,0 +1,9 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither28 + +import arrow.core.Either +import io.kotest.matchers.shouldBe + +fun test() { + Either.Left(2).onLeft(::println) shouldBe Either.Left(2) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt new file mode 100644 index 00000000000..5d84da6fd75 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-29.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither29 + +import arrow.core.Either +import io.kotest.matchers.shouldBe + +fun test() { + Either.Right(12).getOrNull() shouldBe 12 + Either.Left(12).getOrNull() shouldBe null +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt new file mode 100644 index 00000000000..a7079e5990c --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-30.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither30 + +import arrow.core.Either +import io.kotest.matchers.shouldBe + +fun test() { + Either.Right(12).leftOrNull() shouldBe null + Either.Left(12).leftOrNull() shouldBe 12 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt new file mode 100644 index 00000000000..e97cc18b45e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-31.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither31 + +import arrow.core.Either +import arrow.core.Some +import arrow.core.None +import io.kotest.matchers.shouldBe + +fun test() { + Either.Right(12).getOrNone() shouldBe Some(12) + Either.Left(12).getOrNone() shouldBe None +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt new file mode 100644 index 00000000000..02f9c6d1dcf --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-32.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither32 + +import arrow.core.Either +import arrow.core.getOrElse +import io.kotest.matchers.shouldBe + +fun test() { + Either.Left(12) getOrElse { it + 5 } shouldBe 17 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt new file mode 100644 index 00000000000..6d1bc2c0694 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-33.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither33 + +import arrow.core.Either.Left +import arrow.core.Either.Right +import arrow.core.merge + +fun test() { + Right(12).merge() // Result: 12 + Left(12).merge() // Result: 12 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt new file mode 100644 index 00000000000..1bacd88ffa1 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither34 + +import arrow.core.* + +fun main(args: Array) { + //sampleStart + val string: Either = "Hello".right() + val chars: Either = + string.widen() + //sampleEnd + println(chars) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt new file mode 100644 index 00000000000..3703db7da68 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither35 + +import arrow.core.Either +import arrow.core.recover +import io.kotest.matchers.shouldBe + +fun test() { + val error: Either = Either.Left("error") + val fallback: Either = error.recover { it.length } + fallback shouldBe Either.Right(5) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt new file mode 100644 index 00000000000..026cd08d0f9 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither36 + +import arrow.core.Either +import arrow.core.recover +import io.kotest.matchers.shouldBe + +fun test() { + val error: Either = Either.Left("error") + val listOfErrors: Either, Int> = error.recover { raise(it.toList()) } + listOfErrors shouldBe Either.Left(listOf('e', 'r', 'r', 'o', 'r')) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt new file mode 100644 index 00000000000..b2d8cbf42ca --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt @@ -0,0 +1,21 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleEither37 + +import arrow.core.Either +import arrow.core.catch +import io.kotest.assertions.throwables.shouldThrowUnit +import io.kotest.matchers.shouldBe + +fun test() { + val left: Either = Either.catch { throw RuntimeException("Boom!") } + + val caught: Either = left.catch { _: RuntimeException -> 1 } + val failure: Either = left.catch { _: RuntimeException -> raise("failure") } + + shouldThrowUnit { + val caught2: Either = left.catch { _: IllegalStateException -> 1 } + } + + caught shouldBe Either.Right(1) + failure shouldBe Either.Left("failure") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-01.kt new file mode 100644 index 00000000000..ea0c4e2d6a9 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-01.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor01 + +import arrow.core.Ior + +fun main() { + Ior.Left("tulip").isLeft() // Result: true + Ior.Right("venus fly-trap").isLeft() // Result: false + Ior.Both("venus", "fly-trap").isLeft() // Result: false +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-02.kt new file mode 100644 index 00000000000..8e909d18ff8 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-02.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor02 + +import arrow.core.Ior + +fun main() { + Ior.Left("tulip").isRight() // Result: false + Ior.Right("venus fly-trap").isRight() // Result: true + Ior.Both("venus", "fly-trap").isRight() // Result: false +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-03.kt new file mode 100644 index 00000000000..06db465d06c --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-03.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor03 + +import arrow.core.Ior + +fun main() { + Ior.Left("tulip").isBoth() // Result: false + Ior.Right("venus fly-trap").isBoth() // Result: false + Ior.Both("venus", "fly-trap").isBoth() // Result: true +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-04.kt new file mode 100644 index 00000000000..6a71161d52d --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-04.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor04 + +import arrow.core.Ior + +fun main() { + Ior.Right(12).map { "flower" } // Result: Right("flower") + Ior.Left(12).map { "flower" } // Result: Left(12) + Ior.Both(12, "power").map { "flower $it" } // Result: Both(12, "flower power") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-05.kt new file mode 100644 index 00000000000..e3fc45dd583 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-05.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor05 + +import arrow.core.Ior + +fun main() { + Ior.Right(12).mapLeft { "flower" } // Result: Right(12) + Ior.Left(12).mapLeft { "flower" } // Result: Left("power") + Ior.Both(12, "power").mapLeft { "flower $it" } // Result: Both("flower 12", "power") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-06.kt new file mode 100644 index 00000000000..bfcabdf9925 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-06.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor06 + +import arrow.core.Ior + +fun main() { + Ior.Left("left").swap() // Result: Right("left") + Ior.Right("right").swap() // Result: Left("right") + Ior.Both("left", "right").swap() // Result: Both("right", "left") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-07.kt new file mode 100644 index 00000000000..1b670363d6e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-07.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor07 + +import arrow.core.Ior + +fun main() { + Ior.Right(12).toEither() // Result: Either.Right(12) + Ior.Left(12).toEither() // Result: Either.Left(12) + Ior.Both("power", 12).toEither() // Result: Either.Right(12) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-08.kt new file mode 100644 index 00000000000..9a01a122772 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-08.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor08 + +import arrow.core.Ior + +fun main() { + val right = Ior.Right(12).leftOrNull() // Result: null + val left = Ior.Left(12).leftOrNull() // Result: 12 + val both = Ior.Both(12, "power").leftOrNull() // Result: 12 + println("right = $right") + println("left = $left") + println("both = $both") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-09.kt new file mode 100644 index 00000000000..e1a5469e45e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-09.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor09 + +import arrow.core.Ior + +fun main() { + val right: Ior = Ior.Right(12) + right.isLeft { it > 10 } // Result: false + Ior.Both(12, 7).isLeft { it > 10 } // Result: false + Ior.Left(12).isLeft { it > 10 } // Result: true +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-10.kt new file mode 100644 index 00000000000..b54e4846b28 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-10.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor10 + +import arrow.core.Ior + +fun main() { + Ior.Right(12).isRight { it > 10 } // Result: false + Ior.Both(12, 7).isRight { it > 10 } // Result: false + val left: Ior = Ior.Left(12) + left.isRight { it > 10 } // Result: true +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-11.kt new file mode 100644 index 00000000000..89f849c1541 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-11.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor11 + +import arrow.core.Ior + +fun main() { + val right: Ior = Ior.Right(12) + right.isBoth( {it > 10}, {it > 6 }) // Result: false + Ior.Both(12, 7).isBoth( {it > 10}, {it > 6 })// Result: true + val left: Ior = Ior.Left(12) + left.isBoth ( {it > 10}, {it > 6 }) // Result: false +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt new file mode 100644 index 00000000000..8bd57d483da --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Ior.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIor12 + +import arrow.core.* + +fun main(args: Array) { + //sampleStart + val string: Ior = Ior.Right("Hello") + val chars: Ior = + string.widen() + //sampleEnd + println(chars) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-01.kt new file mode 100644 index 00000000000..ec7c5b7cd2a --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-01.kt @@ -0,0 +1,19 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable01 + +import arrow.core.left +import arrow.core.leftNel +import arrow.core.nonEmptyListOf +import arrow.core.mapOrAccumulate +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2, 3, 4).mapOrAccumulate({ a, b -> "$a, $b" }) { i -> + when(i) { + 1 -> "Either - $i".left().bind() + 2 -> "EitherNel - $i".leftNel().bindNel() + 3 -> raise("Raise - $i") + else -> withNel { raise(nonEmptyListOf("RaiseNel - $i")) } + } + } shouldBe "Either - 1, EitherNel - 2, Raise - 3, RaiseNel - 4".left() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-02.kt new file mode 100644 index 00000000000..6158cc8a53a --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-02.kt @@ -0,0 +1,19 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable02 + +import arrow.core.left +import arrow.core.leftNel +import arrow.core.nonEmptyListOf +import arrow.core.mapOrAccumulate +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2, 3, 4).mapOrAccumulate { i -> + when(i) { + 1 -> "Either - $i".left().bind() + 2 -> "EitherNel - $i".leftNel().bindNel() + 3 -> raise("Raise - $i") + else -> withNel { raise(nonEmptyListOf("RaiseNel - $i")) } + } + } shouldBe nonEmptyListOf("Either - 1", "EitherNel - 2", "Raise - 3", "RaiseNel - 4").left() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-03.kt new file mode 100644 index 00000000000..c3f551edb53 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-03.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable03 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2).padZip(listOf("a")) shouldBe listOf(1 to "a", 2 to null) + listOf(1).padZip(listOf("a", "b")) shouldBe listOf(1 to "a", null to "b") + listOf(1, 2).padZip(listOf("a", "b")) shouldBe listOf(1 to "a", 2 to "b") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-04.kt new file mode 100644 index 00000000000..541b9fdf4cf --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-04.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable04 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2).padZip(listOf("a")) { l, r -> l to r } shouldBe listOf(1 to "a", 2 to null) + listOf(1).padZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a", null to "b") + listOf(1, 2).padZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a", 2 to "b") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-05.kt new file mode 100644 index 00000000000..a92d7717375 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-05.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable05 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2).leftPadZip(listOf("a")) { l, r -> l to r } shouldBe listOf(1 to "a") + listOf(1).leftPadZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a", null to "b") + listOf(1, 2).leftPadZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a", 2 to "b") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-06.kt new file mode 100644 index 00000000000..2d6c20ecd68 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-06.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable06 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2).leftPadZip(listOf("a")) shouldBe listOf(1 to "a") + listOf(1).leftPadZip(listOf("a", "b")) shouldBe listOf(1 to "a", null to "b") + listOf(1, 2).leftPadZip(listOf("a", "b")) shouldBe listOf(1 to "a", 2 to "b") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-07.kt new file mode 100644 index 00000000000..7504f76304f --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-07.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable07 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2).rightPadZip(listOf("a")) { l, r -> l to r } shouldBe listOf(1 to "a", 2 to null) + listOf(1).rightPadZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a") + listOf(1, 2).rightPadZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a", 2 to "b") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-08.kt new file mode 100644 index 00000000000..a71ff1b56ea --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-08.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable08 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2).rightPadZip(listOf("a")) shouldBe listOf(1 to "a", 2 to null) + listOf(1).rightPadZip(listOf("a", "b")) shouldBe listOf(1 to "a") + listOf(1, 2).rightPadZip(listOf("a", "b")) shouldBe listOf(1 to "a", 2 to "b") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-09.kt new file mode 100644 index 00000000000..5010b43d280 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-09.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable09 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf("A", "B").align(listOf(1, 2, 3)) { + "$it" + } shouldBe listOf("Ior.Both(A, 1)", "Ior.Both(B, 2)", "Ior.Right(3)") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-10.kt new file mode 100644 index 00000000000..b0257db7711 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-10.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable10 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf("A", "B") + .align(listOf(1, 2, 3)) shouldBe listOf(Ior.Both("A", 1), Ior.Both("B", 2), Ior.Right(3)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-11.kt new file mode 100644 index 00000000000..fc8c31b148e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-11.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable11 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf("A" to 1, "B" to 2) + .unzip() shouldBe Pair(listOf("A", "B"), listOf(1, 2)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-12.kt new file mode 100644 index 00000000000..0fbcba62844 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-12.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable12 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf("A:1", "B:2", "C:3").unzip { e -> + e.split(":").let { + it.first() to it.last() + } + } shouldBe Pair(listOf("A", "B", "C"), listOf("1", "2", "3")) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-13.kt new file mode 100644 index 00000000000..1e604b08ce7 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-13.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable13 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf( + Pair("A", 1).bothIor(), + Pair("B", 2).bothIor(), + "C".leftIor() + ).separateIor() shouldBe Pair(listOf("A", "B", "C"), listOf(1, 2)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-14.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-14.kt new file mode 100644 index 00000000000..cfd124b3a0b --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-14.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable14 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf(1, 2, 3, 4).unalign { + if(it % 2 == 0) it.rightIor() + else it.leftIor() + } shouldBe Pair(listOf(1, null, 3, null), listOf(null, 2, null, 4)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-15.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-15.kt new file mode 100644 index 00000000000..7a74ad97ce8 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-15.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable15 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + emptyList().split() shouldBe null + listOf("A", "B", "C").split() shouldBe Pair(listOf("B", "C"), "A") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-16.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-16.kt new file mode 100644 index 00000000000..1068086df6e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-16.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable16 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + val list1 = listOf(1, 2, 3) + val list2 = listOf(4, 5, 6, 7, 8) + list1.interleave(list2) shouldBe listOf(1, 4, 2, 5, 3, 6, 7, 8) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-17.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-17.kt new file mode 100644 index 00000000000..97027702741 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-17.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable17 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + val ints = listOf(1, 2) + val res = ints.unweave { i -> listOf(i, i + 1, i + 2) } + res shouldBe listOf(1, 2, 2, 3, 3, 4) + res shouldBe ints.interleave(ints.flatMap { listOf(it + 1, it + 2) }) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-18.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-18.kt new file mode 100644 index 00000000000..6112994de79 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-iterable-18.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleIterable18 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + listOf("A".left(), 2.right(), "C".left(), 4.right()) + .separateEither() shouldBe Pair(listOf("A", "C"), listOf(2, 4)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-01.kt new file mode 100644 index 00000000000..ff40232b905 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-01.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap01 + +import arrow.core.zip +import io.kotest.matchers.shouldBe + +fun test() { + mapOf(1 to "A", 2 to "B") + .zip(mapOf(1 to "1", 2 to "2", 3 to "3")) shouldBe mapOf(1 to Pair("A", "1"), 2 to Pair("B", "2")) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt new file mode 100644 index 00000000000..c7c4ffdd2e6 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap02 + +import arrow.core.zip +import io.kotest.matchers.shouldBe + +fun test() { + mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) { + key, a, b -> "$a ~ $b" + } shouldBe mapOf(1 to "A ~ 1", 2 to "B ~ 2") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-03.kt new file mode 100644 index 00000000000..c8d632be61b --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-03.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap03 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + val res = mapOf(1 to 1, 2 to 2).align(mapOf(1 to "1", 2 to "2", 3 to "3")) + res shouldBe mapOf(1 to Ior.Both(1, "1"), 2 to Ior.Both(2, "2"), 3 to Ior.Right("3")) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-04.kt new file mode 100644 index 00000000000..08d4ae550ec --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-04.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap04 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + mapOf("1" to 1, "2" to 2) + .align(mapOf("1" to 1, "2" to 2, "3" to 3)) { (_, a) -> + "$a" + } shouldBe mapOf("1" to "Ior.Both(1, 1)", "2" to Ior.Both(2, 2), "3" to Ior.Right(3)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-05.kt new file mode 100644 index 00000000000..e489bcd6f86 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-05.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap05 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + mapOf( + "first" to Ior.Both("A", 1), + "second" to Ior.Both("B", 2), + "third" to Ior.Left("C") + ).unalign() shouldBe Pair(mapOf("first" to "A", "second" to "B", "third" to "C"), mapOf("first" to 1, "second" to 2)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-06.kt new file mode 100644 index 00000000000..28fc91ae064 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-06.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap06 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + mapOf("1" to 1, "2" to 2, "3" to 3) + .unalign { (key, value) -> + when(key) { + "1" -> Ior.Left(value) + "2" -> Ior.Right(key) + else -> Ior.Both(value, key) + } + } shouldBe Pair(mapOf("1" to 1, "3" to 3), mapOf("2" to 2, "3" to 3)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-07.kt new file mode 100644 index 00000000000..041dde05499 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-07.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap07 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + mapOf( + "first" to ("A" to 1), + "second" to ("B" to 2) + ).unzip() shouldBe Pair(mapOf("first" to "A", "second" to "B"), mapOf("first" to 1, "second" to 2)) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-08.kt new file mode 100644 index 00000000000..20dbbdf89c1 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-08.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from map.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMap08 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + mapOf("first" to "A:1", "second" to "B:2", "third" to "C:3").unzip { (_, e) -> + e.split(":").let { + it.first() to it.last() + } + } shouldBe Pair( + mapOf("first" to "A", "second" to "B", "third" to "C"), + mapOf("first" to "1", "second" to "2", "third" to "3") + ) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-memoization-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-memoization-01.kt new file mode 100644 index 00000000000..cda809e4e34 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-memoization-01.kt @@ -0,0 +1,19 @@ +// This file was automatically generated from memoization.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMemoization01 + +import arrow.core.memoize +fun someWorkIntensiveFunction(someParam: Int): String = "$someParam" + +fun main() { + //sampleStart + val memoizedF = ::someWorkIntensiveFunction.memoize() + + // The first invocation will store the argument and result in a cache inside the `memoizedF` reference. + val value1 = memoizedF(42) + // This second invocation won't really call the `someWorkIntensiveFunction` function + //but retrieve the result from the previous invocation instead. + val value2 = memoizedF(42) + + //sampleEnd + println("$value1 $value2") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-01.kt new file mode 100644 index 00000000000..ac3f0223b3c --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-01.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from NonEmptyList.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonemptylist01 + +import arrow.core.nonEmptyListOf +import arrow.core.toNonEmptyListOrNull + +fun main() { + println(nonEmptyListOf(1, 2, 3, 4, 5)) + println(listOf(1, 2, 3).toNonEmptyListOrNull()) + println(emptyList().toNonEmptyListOrNull()) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-02.kt new file mode 100644 index 00000000000..8c6a37acb50 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-02.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from NonEmptyList.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonemptylist02 + +import arrow.core.nonEmptyListOf + +val value = + nonEmptyListOf(1, 2, 3, 4, 5).head +fun main() { + println(value) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-03.kt new file mode 100644 index 00000000000..9e1736be11a --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-03.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from NonEmptyList.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonemptylist03 + +import arrow.core.NonEmptyList +import arrow.core.nonEmptyListOf + +fun sumNel(nel: NonEmptyList): Int = + nel.foldLeft(0) { acc, n -> acc + n } +val value = sumNel(nonEmptyListOf(1, 1, 1, 1)) +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-04.kt new file mode 100644 index 00000000000..ff4cf7e26b5 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-04.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from NonEmptyList.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonemptylist04 + +import arrow.core.nonEmptyListOf + +val value = + nonEmptyListOf(1, 1, 1, 1).map { it + 1 } +fun main() { + println(value) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-05.kt new file mode 100644 index 00000000000..2815eb54f62 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-05.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from NonEmptyList.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonemptylist05 + +import arrow.core.NonEmptyList +import arrow.core.nonEmptyListOf + +val nelOne: NonEmptyList = nonEmptyListOf(1, 2, 3) +val nelTwo: NonEmptyList = nonEmptyListOf(4, 5) + +val value = nelOne.flatMap { one -> + nelTwo.map { two -> + one + two + } +} +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-06.kt new file mode 100644 index 00000000000..496faabb2d4 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonemptylist-06.kt @@ -0,0 +1,20 @@ +// This file was automatically generated from NonEmptyList.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonemptylist06 + +import arrow.core.NonEmptyList +import arrow.core.nonEmptyListOf +import kotlin.random.Random + +data class Person(val id: Long, val name: String, val year: Int) + +// Note each NonEmptyList is of a different type +val nelId: NonEmptyList = nonEmptyListOf(Random.nextLong(), Random.nextLong()) +val nelName: NonEmptyList = nonEmptyListOf("William Alvin Howard", "Haskell Curry") +val nelYear: NonEmptyList = nonEmptyListOf(1926, 1900) + +val value = nelId.zip(nelName, nelYear) { id, name, year -> + Person(id, name, year) +} +fun main() { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt new file mode 100644 index 00000000000..32ebd78ac2e --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt @@ -0,0 +1,28 @@ +// This file was automatically generated from NonFatal.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonfatal01 + +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 { + Either.Right(unsafeFunction(1)) + } catch (t: Throwable) { + if (NonFatal(t)) { + Either.Left(t) + } else { + throw t + } + } + //sampleEnd + println(nonFatal) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt new file mode 100644 index 00000000000..07bf2372556 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt @@ -0,0 +1,24 @@ +// This file was automatically generated from nonFatalOrThrow.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleNonfatalorthrow01 + +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 { + Either.Right(unsafeFunction(1)) + } catch (t: Throwable) { + Either.Left(t.nonFatalOrThrow()) + } + //sampleEnd + println(nonFatal) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-01.kt new file mode 100644 index 00000000000..fb48ae937cf --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-01.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption01 + +import arrow.core.Option +import arrow.core.Some +import arrow.core.none + +val someValue: Option = Some("I am wrapped in something") +val emptyValue: Option = none() +fun main() { + println("value = $someValue") + println("emptyValue = $emptyValue") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-02.kt new file mode 100644 index 00000000000..1432d694e9f --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-02.kt @@ -0,0 +1,9 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption02 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some + +fun maybeItWillReturnSomething(flag: Boolean): Option = + if (flag) Some("Found value") else None diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-03.kt new file mode 100644 index 00000000000..6da22ce3726 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-03.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption03 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.core.getOrElse + +fun maybeItWillReturnSomething(flag: Boolean): Option = + if (flag) Some("Found value") else None + +val value1 = + maybeItWillReturnSomething(true) + .getOrElse { "No value" } +fun main() { + println(value1) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-04.kt new file mode 100644 index 00000000000..7c12966a132 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-04.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption04 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.core.getOrElse + +fun maybeItWillReturnSomething(flag: Boolean): Option = + if (flag) Some("Found value") else None + +val value2 = + maybeItWillReturnSomething(false) + .getOrElse { "No value" } +fun main() { + println(value2) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-05.kt new file mode 100644 index 00000000000..a361ab589a3 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-05.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption05 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some + +fun maybeItWillReturnSomething(flag: Boolean): Option = + if (flag) Some("Found value") else None + + //sampleStart +val valueSome = maybeItWillReturnSomething(true) is None +val valueNone = maybeItWillReturnSomething(false) is None +fun main() { + println("valueSome = $valueSome") + println("valueNone = $valueNone") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-06.kt new file mode 100644 index 00000000000..58aabd86f00 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-06.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption06 + +import arrow.core.Option + +val myString: String? = "Nullable string" +val option: Option = Option.fromNullable(myString) +fun main () { + println("option = $option") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-07.kt new file mode 100644 index 00000000000..e1db8c17a18 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-07.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption07 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some + +val someValue: Option = Some(20.0) +val value = when(someValue) { + is Some -> someValue.value + is None -> 0.0 +} +fun main () { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-08.kt new file mode 100644 index 00000000000..724583e8baa --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-08.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption08 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some + +val noValue: Option = None +val value = when(noValue) { + is Some -> noValue.value + is None -> 0.0 +} +fun main () { + println("value = $value") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-09.kt new file mode 100644 index 00000000000..d7a653b6594 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-09.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption09 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some + +val number: Option = Some(3) +val noNumber: Option = None +val mappedResult1 = number.map { it * 1.5 } +val mappedResult2 = noNumber.map { it * 1.5 } +fun main () { + println("number = $number") + println("noNumber = $noNumber") + println("mappedResult1 = $mappedResult1") + println("mappedResult2 = $mappedResult2") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-10.kt new file mode 100644 index 00000000000..d40b355b33f --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-10.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption10 + +import arrow.core.Option +import arrow.core.Some + +val fold = + Some(3).fold({ 1 }, { it * 3 }) +fun main () { + println(fold) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-11.kt new file mode 100644 index 00000000000..9d6fb8aabf3 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-11.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption11 + +import arrow.core.Option +import arrow.core.none + +val fold = + none().fold({ 1 }, { it * 3 }) +fun main () { + println(fold) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-12.kt new file mode 100644 index 00000000000..52ce79b7e47 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-12.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption12 + +import arrow.core.some +import arrow.core.none + + val some = 1.some() + val none = none() +fun main () { + println("some = $some") + println("none = $none") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-13.kt new file mode 100644 index 00000000000..b7a2ebd9291 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-13.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption13 + +import arrow.core.toOption + +val nullString: String? = null +val valueFromNull = nullString.toOption() + +val helloString: String? = "Hello" +val valueFromStr = helloString.toOption() +fun main () { + println("valueFromNull = $valueFromNull") + println("valueFromStr = $valueFromStr") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-14.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-14.kt new file mode 100644 index 00000000000..589ff874dd1 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-14.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption14 + +import arrow.core.firstOrNone +import arrow.core.toOption +import arrow.core.Option + +val foxMap = mapOf(1 to "The", 2 to "Quick", 3 to "Brown", 4 to "Fox") + +val empty = foxMap.entries.firstOrNull { it.key == 5 }?.value.let { it?.toCharArray() }.toOption() +val filled = Option.fromNullable(foxMap.entries.firstOrNull { it.key == 5 }?.value.let { it?.toCharArray() }) + +fun main() { + println("empty = $empty") + println("filled = $filled") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-15.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-15.kt new file mode 100644 index 00000000000..26350e3c3cd --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-15.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption15 + +import arrow.core.Some + +fun main() { +val value = + //sampleStart + Some(1).map { it + 1 } + //sampleEnd + println(value) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-16.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-16.kt new file mode 100644 index 00000000000..104c2c779d4 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-16.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption16 + +import arrow.core.Some +import arrow.core.none + +fun main() { + Some(12).onNone { println("flower") } // Result: Some(12) + none().onNone { println("flower") } // Result: prints "flower" and returns: None +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt new file mode 100644 index 00000000000..edcc11f59aa --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-17.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption17 + +import arrow.core.Some +import arrow.core.none + +fun main() { + Some(12).onSome { println("flower") } // Result: prints "flower" and returns: Some(12) + none().onSome { println("flower") } // Result: None +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt new file mode 100644 index 00000000000..4011251b9ba --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-18.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption18 + +import arrow.core.Some +import arrow.core.None +import arrow.core.Option + +fun main() { + Some(12).isSome { it > 10 } // Result: true + Some(7).isSome { it > 10 } // Result: false + + val none: Option = None + none.isSome { it > 10 } // Result: false +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt new file mode 100644 index 00000000000..3420045fd5a --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-19.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption19 + +import arrow.core.None +import arrow.core.Some +import io.kotest.matchers.shouldBe + +fun test() { + Some(12).getOrNull() shouldBe 12 + None.getOrNull() shouldBe null +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt new file mode 100644 index 00000000000..861cfe12561 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt @@ -0,0 +1,3 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption20 + diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt new file mode 100644 index 00000000000..29e610af12b --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption21 + +import arrow.core.Option +import arrow.core.none +import arrow.core.Some +import arrow.core.recover +import io.kotest.matchers.shouldBe + +fun test() { + val error: Option = none() + val fallback: Option = error.recover { 5 } + fallback shouldBe Some(5) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt new file mode 100644 index 00000000000..da330d95bd4 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleOption22 + +import arrow.core.Option +import arrow.core.none +import arrow.core.Some +import arrow.core.recover +import io.kotest.matchers.shouldBe + +fun test() { + val error: Option = none() + fun fallback(): Option = Some(5) + fun failure(): Option = none() + + error.recover { fallback().bind() } shouldBe Some(5) + error.recover { failure().bind() } shouldBe none() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-01.kt new file mode 100644 index 00000000000..655ca71b031 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-01.kt @@ -0,0 +1,18 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise01 + +import arrow.core.raise.Effect +import arrow.core.raise.effect +import arrow.core.raise.ensureNotNull +import arrow.core.raise.ensure + +object EmptyPath + +fun readFile(path: String): Effect = effect { + if (path.isEmpty()) raise(EmptyPath) else Unit +} + +fun readFile2(path: String?): Effect = effect { + ensureNotNull(path) { EmptyPath } + ensure(path.isNotEmpty()) { EmptyPath } +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-02.kt new file mode 100644 index 00000000000..a545c054327 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-02.kt @@ -0,0 +1,52 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise02 + +import arrow.core.Either +import arrow.core.Ior +import arrow.core.None +import arrow.core.raise.Effect +import arrow.core.raise.effect +import arrow.core.raise.fold +import arrow.core.raise.toEither +import arrow.core.raise.toIor +import arrow.core.raise.toOption +import arrow.core.raise.ensureNotNull +import arrow.core.raise.ensure +import io.kotest.matchers.collections.shouldNotBeEmpty +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeInstanceOf +import java.io.File +import java.io.FileNotFoundException + +@JvmInline +value class Content(val body: List) + +sealed interface FileError +@JvmInline value class SecurityError(val msg: String?) : FileError +@JvmInline value class FileNotFound(val path: String) : FileError +object EmptyPath : FileError { + override fun toString() = "EmptyPath" +} + +fun readFile(path: String?): Effect = effect { + ensureNotNull(path) { EmptyPath } + ensure(path.isNotEmpty()) { EmptyPath } + try { + val lines = File(path).readLines() + Content(lines) + } catch (e: FileNotFoundException) { + raise(FileNotFound(path)) + } catch (e: SecurityException) { + raise(SecurityError(e.message)) + } +} + +suspend fun main() { + readFile("").toEither() shouldBe Either.Left(EmptyPath) + readFile("gradle.properties").toIor() shouldBe Ior.Left(FileNotFound("gradle.properties")) + readFile("README.MD").toOption { None } shouldBe None + + readFile("build.gradle.kts").fold({ _: FileError -> null }, { it }) + .shouldBeInstanceOf() + .body.shouldNotBeEmpty() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-03.kt new file mode 100644 index 00000000000..d3d3f2b9b26 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-03.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise03 + +import arrow.core.Either +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.core.raise.Effect +import arrow.core.raise.fold +import arrow.core.identity + +suspend fun Effect.toEither(): Either = + fold({ Either.Left(it) }) { Either.Right(it) } + +suspend fun Effect.toOption(): Option = + fold(::identity) { Some(it) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt new file mode 100644 index 00000000000..6fa5fe86c21 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt @@ -0,0 +1,55 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise04 + +import arrow.core.raise.Effect +import arrow.core.raise.effect +import arrow.core.raise.recover +import arrow.core.raise.catch + +val failed: Effect = + effect { raise("failed") } + +val default: Effect = + failed.recover { -1 } + +val resolved: Effect = + failed.recover { it.length } + +val default2: Effect = default +val resolved2: Effect = resolved + +val newError: Effect, Int> = + failed.recover { str -> + raise(str.reversed().toList()) + } + +val newException: Effect = + failed.recover { str -> throw RuntimeException(str) } + +val foreign = effect { + throw RuntimeException("BOOM!") +} + +val default3: Effect = + foreign.catch { -1 } + +val resolved3: Effect = + foreign.catch { it.message?.length ?: -1 } + +val default4: Effect = + foreign + .recover { -1 } + .catch { -2 } + +val default5: Effect = + foreign + .catch { ex: RuntimeException -> -1 } + .catch { ex: java.sql.SQLException -> -2 } + +suspend fun java.sql.SQLException.isForeignKeyViolation(): Boolean = true + +val rethrown: Effect = + failed.catch { ex: java.sql.SQLException -> + if(ex.isForeignKeyViolation()) raise("foreign key violation") + else throw ex + } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-05.kt new file mode 100644 index 00000000000..1f0e3c079ab --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-05.kt @@ -0,0 +1,25 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise05 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import arrow.fx.coroutines.ExitCase +import arrow.fx.coroutines.guaranteeCase +import arrow.fx.coroutines.parZip +import io.kotest.assertions.fail +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeTypeOf +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.awaitCancellation + +suspend fun awaitExitCase(exit: CompletableDeferred): A = + guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) } + + suspend fun main() { + val error = "Error" + val exit = CompletableDeferred() + effect { + parZip({ awaitExitCase(exit) }, { raise(error) }) { a: Int, b: Int -> a + b } + }.fold({ it shouldBe error }, { fail("Int can never be the result") }) + exit.await().shouldBeTypeOf() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-06.kt new file mode 100644 index 00000000000..13230c58403 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-06.kt @@ -0,0 +1,32 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise06 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import arrow.fx.coroutines.ExitCase +import arrow.fx.coroutines.guaranteeCase +import arrow.fx.coroutines.parMap +import io.kotest.assertions.fail +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeTypeOf +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.awaitCancellation + +suspend fun awaitExitCase(exit: CompletableDeferred): A = + guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) } + +suspend fun CompletableDeferred.getOrNull(): A? = + if (isCompleted) await() else null + +suspend fun main() { + val error = "Error" + val exits = (0..3).map { CompletableDeferred() } + effect> { + (0..4).parMap { index -> + if (index == 4) raise(error) + else awaitExitCase(exits[index]) + } + }.fold({ msg -> msg shouldBe error }, { fail("Int can never be the result") }) + // It's possible not all parallel task got launched, and in those cases awaitCancellation never ran + exits.forEach { exit -> exit.getOrNull()?.shouldBeTypeOf() } +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-07.kt new file mode 100644 index 00000000000..4cfab8f778c --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-07.kt @@ -0,0 +1,31 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise07 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import arrow.core.merge +import arrow.fx.coroutines.ExitCase +import arrow.fx.coroutines.guaranteeCase +import arrow.fx.coroutines.raceN +import io.kotest.assertions.fail +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeTypeOf +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.awaitCancellation + +suspend fun awaitExitCase(exit: CompletableDeferred): A = + guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) } + +suspend fun CompletableDeferred.getOrNull(): A? = + if (isCompleted) await() else null + +suspend fun main() { + val error = "Error" + val exit = CompletableDeferred() + effect { + raceN({ awaitExitCase(exit) }) { raise(error) } + .merge() // Flatten Either result from race into Int + }.fold({ msg -> msg shouldBe error }, { fail("Int can never be the result") }) + // It's possible not all parallel task got launched, and in those cases awaitCancellation never ran + exit.getOrNull()?.shouldBeTypeOf() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt new file mode 100644 index 00000000000..7f52b2e77e1 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt @@ -0,0 +1,29 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise08 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import arrow.fx.coroutines.ExitCase +import arrow.fx.coroutines.bracketCase +import io.kotest.assertions.fail +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeTypeOf +import kotlinx.coroutines.CompletableDeferred +import java.io.BufferedReader +import java.io.File + +suspend fun main() { + val error = "Error" + val exit = CompletableDeferred() + effect { + bracketCase( + acquire = { File("build.gradle.kts").bufferedReader() }, + use = { reader: BufferedReader -> raise(error) }, + release = { reader, exitCase -> + reader.close() + exit.complete(exitCase) + } + ) + }.fold({ it shouldBe error }, { fail("Int can never be the result") }) + exit.await().shouldBeTypeOf() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-09.kt new file mode 100644 index 00000000000..9c10cee48f5 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-09.kt @@ -0,0 +1,34 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise09 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import arrow.fx.coroutines.ExitCase +import arrow.fx.coroutines.ResourceScope +import arrow.fx.coroutines.autoCloseable +import arrow.fx.coroutines.resourceScope +import io.kotest.assertions.fail +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeTypeOf +import kotlinx.coroutines.CompletableDeferred +import java.io.BufferedReader +import java.io.File + +suspend fun main() { + val error = "Error" + val exit = CompletableDeferred() + + suspend fun ResourceScope.bufferedReader(path: String): BufferedReader = + autoCloseable { File(path).bufferedReader() }.also { + onRelease { exitCase -> exit.complete(exitCase) } + } + + resourceScope { + effect { + val reader = bufferedReader("build.gradle.kts") + raise(error) + reader.lineSequence().count() + }.fold({ it shouldBe error }, { fail("Int can never be the result") }) + } + exit.await().shouldBeTypeOf() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-10.kt new file mode 100644 index 00000000000..2b6cb033364 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-10.kt @@ -0,0 +1,59 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise10 + +import arrow.core.raise.Effect +import arrow.core.raise.effect +import arrow.core.raise.fold +import arrow.core.raise.ensureNotNull +import arrow.core.raise.ensure +import arrow.fx.coroutines.ExitCase +import arrow.fx.coroutines.guaranteeCase +import io.kotest.assertions.fail +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeInstanceOf +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import java.io.File +import java.io.FileNotFoundException + +@JvmInline +value class Content(val body: List) + +sealed interface FileError +@JvmInline value class SecurityError(val msg: String?) : FileError +@JvmInline value class FileNotFound(val path: String) : FileError +object EmptyPath : FileError { + override fun toString() = "EmptyPath" +} + +fun readFile(path: String?): Effect = effect { + ensureNotNull(path) { EmptyPath } + ensure(path.isNotEmpty()) { EmptyPath } + try { + val lines = File(path).readLines() + Content(lines) + } catch (e: FileNotFoundException) { + raise(FileNotFound(path)) + } catch (e: SecurityException) { + raise(SecurityError(e.message)) + } +} + +suspend fun awaitExitCase(exit: CompletableDeferred): A = + guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) } + +suspend fun main() { + val exit = CompletableDeferred() + effect { + withContext(Dispatchers.IO) { + val job = launch { awaitExitCase(exit) } + val content = readFile("failure").bind() + job.join() + content.body.size + } + }.fold({ e -> e shouldBe FileNotFound("failure") }, { fail("Int can never be the result") }) + exit.await().shouldBeInstanceOf() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-11.kt new file mode 100644 index 00000000000..977cdcbf0df --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-11.kt @@ -0,0 +1,21 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise11 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import io.kotest.assertions.fail +import io.kotest.matchers.collections.shouldBeIn +import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope + +suspend fun main() { + val errorA = "ErrorA" + val errorB = "ErrorB" + coroutineScope { + effect { + val fa = async { raise(errorA) } + val fb = async { raise(errorB) } + fa.await() + fb.await() + }.fold({ error -> error shouldBeIn listOf(errorA, errorB) }, { fail("Int can never be the result") }) + } +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-12.kt new file mode 100644 index 00000000000..023cc118777 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-12.kt @@ -0,0 +1,22 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise12 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import io.kotest.assertions.fail +import io.kotest.matchers.shouldBe +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch + +suspend fun main() { + val errorA = "ErrorA" + val errorB = "ErrorB" + val int = 45 + effect { + coroutineScope { + launch { raise(errorA) } + launch { raise(errorB) } + int + } + }.fold({ fail("Raise can never finish") }, { it shouldBe int }) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-13.kt new file mode 100644 index 00000000000..f60a06a4235 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-13.kt @@ -0,0 +1,25 @@ +// This file was automatically generated from Effect.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaise13 + +import arrow.core.raise.effect +import arrow.core.raise.fold +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope + +suspend fun main() { + + effect Unit> { + suspend { raise("error") } + }.fold({ }, { leakedRaise -> leakedRaise.invoke() }) + + val leakedAsync = coroutineScope Deferred> { + suspend { + async { + println("I am never going to run, until I get called invoked from outside") + } + } + } + + leakedAsync.invoke().await() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-01.kt new file mode 100644 index 00000000000..163c7db7da3 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-01.kt @@ -0,0 +1,10 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl01 + +import arrow.core.raise.Raise +import arrow.core.raise.recover + +fun Raise.failure(): Int = raise("failed") + +fun recovered(): Int = + recover({ failure() }) { _: String -> 1 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-02.kt new file mode 100644 index 00000000000..001739d0d76 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-02.kt @@ -0,0 +1,25 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl02 + +import arrow.core.getOrElse +import arrow.core.left +import arrow.core.raise.Raise +import arrow.core.raise.effect +import arrow.core.raise.recover +import arrow.core.raise.getOrElse +import io.kotest.matchers.shouldBe + +fun Raise.failure(): Int = raise("failed") + +fun Raise>.recovered(): Int = + recover({ failure() }) { msg: String -> raise(msg.toList()) } + +suspend fun Raise>.recovered2(): Int = + effect { failure() } getOrElse { msg: String -> raise(msg.toList()) } + +fun Raise>.recovered3(): Int = + "failed".left() getOrElse { msg: String -> raise(msg.toList()) } + +fun test(): Unit { + recover({ "failed".left().bind() }) { 1 } shouldBe "failed".left().getOrElse { 1 } +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-03.kt new file mode 100644 index 00000000000..8ec23467cf1 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-03.kt @@ -0,0 +1,29 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl03 + +import arrow.core.Either +import arrow.core.Ior +import arrow.core.raise.Effect +import arrow.core.raise.Raise +import arrow.core.raise.either +import arrow.core.raise.effect +import arrow.core.raise.ior +import arrow.core.raise.toEither +import io.kotest.matchers.shouldBe + +fun Raise.failure(): Int = raise("failed") + +suspend fun test() { + val either: Either = + either { failure() } + + val effect: Effect = + effect { failure() } + + val ior: Ior = + ior(String::plus) { failure() } + + either shouldBe Either.Left("failed") + effect.toEither() shouldBe Either.Left("failed") + ior shouldBe Ior.Left("failed") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-04.kt new file mode 100644 index 00000000000..1a56e06b736 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-04.kt @@ -0,0 +1,23 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl04 + +import arrow.core.Either +import arrow.core.getOrElse +import arrow.core.raise.Raise +import arrow.core.raise.either +import arrow.core.raise.recover +import arrow.core.recover +import arrow.core.right +import io.kotest.matchers.shouldBe + +fun Raise.failure(): Int = raise("failed") + +fun test() { + val failure: Either = either { failure() } + + failure.recover { _: String -> 1.right().bind() } shouldBe Either.Right(1) + + failure.recover { msg: String -> raise(msg.toList()) } shouldBe Either.Left(listOf('f', 'a', 'i', 'l', 'e', 'd')) + + recover({ failure.bind() }) { 1 } shouldBe failure.getOrElse { 1 } +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt new file mode 100644 index 00000000000..83d6ebd0359 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt @@ -0,0 +1,19 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl05 + +import arrow.core.Either +import arrow.core.right +import arrow.core.raise.either +import arrow.core.raise.recover +import io.kotest.matchers.shouldBe + +fun test() { + val one: Either = 1.right() + val left: Either = Either.Left("failed") + + either { + val x = one.bind() + val y = recover({ left.bind() }) { failure : String -> 1 } + x + y + } shouldBe Either.Right(2) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt new file mode 100644 index 00000000000..73ef8a21ede --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl06 + +import arrow.core.Either +import arrow.core.raise.either +import arrow.core.raise.recover +import io.kotest.matchers.shouldBe + +fun test() { + recover({ raise("failed") }) { str -> str.length } shouldBe 6 + + either { + recover({ raise("failed") }) { str -> raise(-1) } + } shouldBe Either.Left(-1) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-07.kt new file mode 100644 index 00000000000..26d34d1d4d4 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-07.kt @@ -0,0 +1,20 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl07 + +import arrow.core.raise.recover +import arrow.core.raise.Raise +import io.kotest.matchers.shouldBe + +fun test() { + recover( + { raise("failed") }, + { str -> str.length } + ) { t -> t.message ?: -1 } shouldBe 6 + + fun Raise.boom(): Int = throw RuntimeException("BOOM") + + recover( + { boom() }, + { str -> str.length } + ) { t -> t.message?.length ?: -1 } shouldBe 4 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-08.kt new file mode 100644 index 00000000000..e707cecdabc --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-08.kt @@ -0,0 +1,20 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl08 + +import arrow.core.raise.recover +import arrow.core.raise.Raise +import io.kotest.matchers.shouldBe + +fun test() { + recover( + { raise("failed") }, + { str -> str.length } + ) { t -> t.message ?: -1 } shouldBe 6 + + fun Raise.boom(): Int = throw RuntimeException("BOOM") + + recover( + { boom() }, + { str -> str.length } + ) { t: RuntimeException -> t.message?.length ?: -1 } shouldBe 4 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt new file mode 100644 index 00000000000..cbf67703845 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt @@ -0,0 +1,21 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl09 + +import arrow.core.Either +import arrow.core.raise.either +import arrow.core.raise.catch +import io.kotest.matchers.shouldBe + +fun test() { + catch({ throw RuntimeException("BOOM") }) { t -> + "fallback" + } shouldBe "fallback" + + fun fetchId(): Int = throw RuntimeException("BOOM") + + either { + catch({ fetchId() }) { t -> + raise("something went wrong: ${t.message}") + } + } shouldBe Either.Left("something went wrong: BOOM") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt new file mode 100644 index 00000000000..94834cbbb6d --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt @@ -0,0 +1,21 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleRaiseDsl10 + +import arrow.core.Either +import arrow.core.raise.either +import arrow.core.raise.catch +import io.kotest.matchers.shouldBe + +fun test() { + catch({ throw RuntimeException("BOOM") }) { t -> + "fallback" + } shouldBe "fallback" + + fun fetchId(): Int = throw RuntimeException("BOOM") + + either { + catch({ fetchId() }) { t: RuntimeException -> + raise("something went wrong: ${t.message}") + } + } shouldBe Either.Left("something went wrong: BOOM") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-01.kt new file mode 100644 index 00000000000..6257919c325 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-01.kt @@ -0,0 +1,22 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence01 + +import arrow.core.align +import arrow.core.Ior +import arrow.core.Ior.Both +import arrow.core.Ior.Left +import arrow.core.Ior.Right +import io.kotest.matchers.shouldBe + +fun test() { + fun Ior.visualise(): String = + fold({ "$it<" }, { ">$it" }, { a, b -> "$a<>$b" }) + + sequenceOf("A", "B").align(sequenceOf(1, 2, 3)) { ior -> + ior.visualise() + }.toList() shouldBe listOf("A<>1", "B<>2", ">3") + + sequenceOf("A", "B", "C").align(sequenceOf(1, 2)) { ior -> + ior.visualise() + }.toList() shouldBe listOf("A<>1", "B<>2", "C<") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-02.kt new file mode 100644 index 00000000000..d2a7f9f10a6 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-02.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence02 + +import arrow.core.align +import arrow.core.Ior.Both +import arrow.core.Ior.Left +import arrow.core.Ior.Right +import io.kotest.matchers.shouldBe + +fun test() { + sequenceOf("A", "B") + .align(sequenceOf(1, 2, 3)).toList() shouldBe listOf(Both("A", 1), Both("B", 2), Right(3)) + + sequenceOf("A", "B", "C") + .align(sequenceOf(1, 2)).toList() shouldBe listOf(Both("A", 1), Both("B", 2), Left("C")) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-03.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-03.kt new file mode 100644 index 00000000000..7edba50e1e9 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-03.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence03 + +import arrow.core.* +import io.kotest.matchers.shouldBe + +fun test() { + val tags = generateSequence { "#" }.take(5) + val numbers = generateSequence(0) { it + 1 }.take(3) + tags.interleave(numbers).toList() shouldBe listOf("#", 0, "#", 1, "#", 2, "#", "#") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-04.kt new file mode 100644 index 00000000000..f9b1b426629 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-04.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence04 + +import arrow.core.leftPadZip + +val left = sequenceOf(1, 2).leftPadZip(sequenceOf(3)) { l, r -> l?.plus(r) ?: r } // Result: [4] +val right = sequenceOf(1).leftPadZip(sequenceOf(3, 4)) { l, r -> l?.plus(r) ?: r } // Result: [4, 4] +val both = sequenceOf(1, 2).leftPadZip(sequenceOf(3, 4)) { l, r -> l?.plus(r) ?: r } // Result: [4, 6] + +fun main() { + println("left = $left") + println("right = $right") + println("both = $both") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-05.kt new file mode 100644 index 00000000000..f14ccc16a99 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-05.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence05 + +import arrow.core.leftPadZip + +val padRight = sequenceOf(1, 2).leftPadZip(sequenceOf("a")) // Result: [Pair(1, "a")] +val padLeft = sequenceOf(1).leftPadZip(sequenceOf("a", "b")) // Result: [Pair(1, "a"), Pair(null, "b")] +val noPadding = sequenceOf(1, 2).leftPadZip(sequenceOf("a", "b")) // Result: [Pair(1, "a"), Pair(2, "b")] + +fun main() { + println("padRight = $padRight") + println("padLeft = $padLeft") + println("noPadding = $noPadding") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-06.kt new file mode 100644 index 00000000000..9ae4ac63b87 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-06.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence06 + +import arrow.core.padZip + +val padRight = sequenceOf(1, 2).padZip(sequenceOf("a")) // Result: [Pair(1, "a"), Pair(2, null)] +val padLeft = sequenceOf(1).padZip(sequenceOf("a", "b")) // Result: [Pair(1, "a"), Pair(null, "b")] +val noPadding = sequenceOf(1, 2).padZip(sequenceOf("a", "b")) // Result: [Pair(1, "a"), Pair(2, "b")] + +fun main() { + println("padRight = $padRight") + println("padLeft = $padLeft") + println("noPadding = $noPadding") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-07.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-07.kt new file mode 100644 index 00000000000..e600cdd2254 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-07.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence07 + +import arrow.core.padZip + +val padZipRight = sequenceOf(1, 2).padZip(sequenceOf(3)) { l, r -> (l?:0) + (r?:0) } // Result: [4, 2] +val padZipLeft = sequenceOf(1).padZip(sequenceOf(3, 4)) { l, r -> (l?:0) + (r?:0) } // Result: [4, 4] +val noPadding = sequenceOf(1, 2).padZip(sequenceOf(3, 4)) { l, r -> (l?:0) + (r?:0) } // Result: [4, 6] + +fun main() { + println("padZipRight = $padZipRight") + println("padZipLeft = $padZipLeft") + println("noPadding = $noPadding") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-08.kt new file mode 100644 index 00000000000..d3c757b1c0c --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-08.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence08 + +import arrow.core.rightPadZip + +val left = sequenceOf(1, 2).rightPadZip(sequenceOf(3)) { l, r -> l + (r?:0) } // Result: [4, 2] +val right = sequenceOf(1).rightPadZip(sequenceOf(3, 4)) { l, r -> l + (r?:0) } // Result: [4] +val both = sequenceOf(1, 2).rightPadZip(sequenceOf(3, 4)) { l, r -> l + (r?:0) } // Result: [4, 6] + +fun main() { + println("left = $left") + println("right = $right") + println("both = $both") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-09.kt new file mode 100644 index 00000000000..1e2c93bd8b7 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-09.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence09 + +import arrow.core.rightPadZip + +val padRight = sequenceOf(1, 2).rightPadZip(sequenceOf("a")) // Result: [Pair(1, "a"), Pair(2, null)] +val padLeft = sequenceOf(1).rightPadZip(sequenceOf("a", "b")) // Result: [Pair(1, "a")] +val noPadding = sequenceOf(1, 2).rightPadZip(sequenceOf("a", "b")) // Result: [Pair(1, "a"), Pair(2, "b")] + +fun main() { + println("padRight = $padRight") + println("padLeft = $padLeft") + println("noPadding = $noPadding") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-10.kt new file mode 100644 index 00000000000..c4afea225e2 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-10.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence10 + +import arrow.core.split +import io.kotest.matchers.shouldBe + +fun test() { + sequenceOf("A", "B", "C").split()?.let { (tail, head) -> + head shouldBe "A" + tail.toList() shouldBe listOf("B", "C") + } + emptySequence().split() shouldBe null +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt new file mode 100644 index 00000000000..27bcd9edf28 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence11 + +import arrow.core.bothIor +import arrow.core.leftIor +import arrow.core.unalignToPair + +fun main(args: Array) { + //sampleStart + val result = sequenceOf(("A" to 1).bothIor(), ("B" to 2).bothIor(), "C".leftIor()).unalignToPair() + //sampleEnd + println("(${result.first}, ${result.second})") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt new file mode 100644 index 00000000000..970a59256f5 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt @@ -0,0 +1,12 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence12 + +import arrow.core.leftIor +import arrow.core.unalignToPair + +fun main(args: Array) { + //sampleStart + val result = sequenceOf(1, 2, 3).unalignToPair { it.leftIor() } + //sampleEnd + println("(${result.first.toList()}, ${result.second.toList()})") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt new file mode 100644 index 00000000000..2fe0df59e49 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence13 + +import arrow.core.unweave + +fun main(args: Array) { + //sampleStart + val result = sequenceOf(1,2,3).unweave { i -> sequenceOf("$i, ${i + 1}") } + //sampleEnd + println(result.toList()) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt new file mode 100644 index 00000000000..910baa8d020 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt @@ -0,0 +1,11 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence14 + +import arrow.core.unzipToPair + +fun main(args: Array) { + //sampleStart + val result = sequenceOf("A" to 1, "B" to 2).unzipToPair() + //sampleEnd + println("(${result.first}, ${result.second})") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt new file mode 100644 index 00000000000..20b2c51a95f --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence15 + +import arrow.core.unzipToPair + +fun main(args: Array) { + //sampleStart + val result = + sequenceOf("A:1", "B:2", "C:3").unzipToPair { e -> + e.split(":").let { + it.first() to it.last() + } + } + //sampleEnd + println("(${result.first}, ${result.second})") +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt new file mode 100644 index 00000000000..f85ad833147 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt @@ -0,0 +1,9 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence16 + +import arrow.core.widen + +fun main(args: Array) { + val original: Sequence = sequenceOf("Hello World") + val result: Sequence = original.widen() +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt new file mode 100644 index 00000000000..dfb3ab6b47b --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt @@ -0,0 +1,15 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleSequence17 + +import arrow.core.None +import arrow.core.Some +import arrow.core.filterOption +import io.kotest.matchers.shouldBe + +fun test() { +generateSequence(0) { it + 1 } + .map { if (it % 2 == 0) Some(it) else None } + .filterOption() + .take(5) + .toList() shouldBe listOf(0, 2, 4, 6, 8) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt new file mode 100644 index 00000000000..406d7612658 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt @@ -0,0 +1,69 @@ +// This file was automatically generated from Either.kt by Knit tool. Do not edit. +package arrow.core.examples.test + +import io.kotest.core.spec.style.StringSpec + +class EitherKnitTest : StringSpec({ + "ExampleEither21" { + arrow.core.examples.exampleEither21.test() + } + + "ExampleEither22" { + arrow.core.examples.exampleEither22.test() + } + + "ExampleEither23" { + arrow.core.examples.exampleEither23.test() + } + + "ExampleEither25" { + arrow.core.examples.exampleEither25.test() + } + + "ExampleEither26" { + arrow.core.examples.exampleEither26.test() + } + + "ExampleEither27" { + arrow.core.examples.exampleEither27.test() + } + + "ExampleEither28" { + arrow.core.examples.exampleEither28.test() + } + + "ExampleEither29" { + arrow.core.examples.exampleEither29.test() + } + + "ExampleEither30" { + arrow.core.examples.exampleEither30.test() + } + + "ExampleEither31" { + arrow.core.examples.exampleEither31.test() + } + + "ExampleEither32" { + arrow.core.examples.exampleEither32.test() + } + + "ExampleEither33" { + arrow.core.examples.exampleEither33.test() + } + + "ExampleEither35" { + arrow.core.examples.exampleEither35.test() + } + + "ExampleEither36" { + arrow.core.examples.exampleEither36.test() + } + + "ExampleEither37" { + arrow.core.examples.exampleEither37.test() + } + +}) { + override fun timeout(): Long = 1000 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt new file mode 100644 index 00000000000..e1c7ad1e96c --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt @@ -0,0 +1,77 @@ +// This file was automatically generated from Iterable.kt by Knit tool. Do not edit. +package arrow.core.examples.test + +import io.kotest.core.spec.style.StringSpec + +class IterableKnitTest : StringSpec({ + "ExampleIterable01" { + arrow.core.examples.exampleIterable01.test() + } + + "ExampleIterable02" { + arrow.core.examples.exampleIterable02.test() + } + + "ExampleIterable03" { + arrow.core.examples.exampleIterable03.test() + } + + "ExampleIterable04" { + arrow.core.examples.exampleIterable04.test() + } + + "ExampleIterable05" { + arrow.core.examples.exampleIterable05.test() + } + + "ExampleIterable06" { + arrow.core.examples.exampleIterable06.test() + } + + "ExampleIterable07" { + arrow.core.examples.exampleIterable07.test() + } + + "ExampleIterable08" { + arrow.core.examples.exampleIterable08.test() + } + + "ExampleIterable09" { + arrow.core.examples.exampleIterable09.test() + } + + "ExampleIterable10" { + arrow.core.examples.exampleIterable10.test() + } + + "ExampleIterable11" { + arrow.core.examples.exampleIterable11.test() + } + + "ExampleIterable12" { + arrow.core.examples.exampleIterable12.test() + } + + "ExampleIterable13" { + arrow.core.examples.exampleIterable13.test() + } + + "ExampleIterable14" { + arrow.core.examples.exampleIterable14.test() + } + + "ExampleIterable15" { + arrow.core.examples.exampleIterable15.test() + } + + "ExampleIterable16" { + arrow.core.examples.exampleIterable16.test() + } + + "ExampleIterable18" { + arrow.core.examples.exampleIterable18.test() + } + +}) { + override fun timeout(): Long = 1000 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt new file mode 100644 index 00000000000..b53549e94d6 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from Option.kt by Knit tool. Do not edit. +package arrow.core.examples.test + +import io.kotest.core.spec.style.StringSpec + +class OptionKnitTest : StringSpec({ + "ExampleOption21" { + arrow.core.examples.exampleOption21.test() + } + + "ExampleOption22" { + arrow.core.examples.exampleOption22.test() + } + +}) { + override fun timeout(): Long = 1000 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt new file mode 100644 index 00000000000..3ce2fe3b1ec --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt @@ -0,0 +1,45 @@ +// This file was automatically generated from Raise.kt by Knit tool. Do not edit. +package arrow.core.examples.test + +import io.kotest.core.spec.style.StringSpec + +class RaiseKnitTest : StringSpec({ + "ExampleRaiseDsl02" { + arrow.core.examples.exampleRaiseDsl02.test() + } + + "ExampleRaiseDsl03" { + arrow.core.examples.exampleRaiseDsl03.test() + } + + "ExampleRaiseDsl04" { + arrow.core.examples.exampleRaiseDsl04.test() + } + + "ExampleRaiseDsl05" { + arrow.core.examples.exampleRaiseDsl05.test() + } + + "ExampleRaiseDsl06" { + arrow.core.examples.exampleRaiseDsl06.test() + } + + "ExampleRaiseDsl07" { + arrow.core.examples.exampleRaiseDsl07.test() + } + + "ExampleRaiseDsl08" { + arrow.core.examples.exampleRaiseDsl08.test() + } + + "ExampleRaiseDsl09" { + arrow.core.examples.exampleRaiseDsl09.test() + } + + "ExampleRaiseDsl10" { + arrow.core.examples.exampleRaiseDsl10.test() + } + +}) { + override fun timeout(): Long = 1000 +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt new file mode 100644 index 00000000000..789cef676ae --- /dev/null +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt @@ -0,0 +1,29 @@ +// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. +package arrow.core.examples.test + +import io.kotest.core.spec.style.StringSpec + +class SequenceKnitTest : StringSpec({ + "ExampleSequence01" { + arrow.core.examples.exampleSequence01.test() + } + + "ExampleSequence02" { + arrow.core.examples.exampleSequence02.test() + } + + "ExampleSequence03" { + arrow.core.examples.exampleSequence03.test() + } + + "ExampleSequence10" { + arrow.core.examples.exampleSequence10.test() + } + + "ExampleSequence17" { + arrow.core.examples.exampleSequence17.test() + } + +}) { + override fun timeout(): Long = 1000 +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index 1d7692ec4f9..bf009349a01 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -11,70 +11,6 @@ public final class arrow/fx/coroutines/BracketKt { public static final fun runReleaseAndRethrow (Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class arrow/fx/coroutines/BuildersKt { - public static final fun never (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun unit (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class arrow/fx/coroutines/CircuitBreaker { - public static final field Companion Larrow/fx/coroutines/CircuitBreaker$Companion; - public synthetic fun (Ljava/util/concurrent/atomic/AtomicReference;IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun awaitClose (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun doOnClosed (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/CircuitBreaker; - public final fun doOnHalfOpen (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/CircuitBreaker; - public final fun doOnOpen (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/CircuitBreaker; - public final fun doOnRejectedTask (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/CircuitBreaker; - public final fun protectEither (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun protectOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun state ()Larrow/fx/coroutines/CircuitBreaker$State; -} - -public final class arrow/fx/coroutines/CircuitBreaker$Companion { - public final fun of (IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun of$default (Larrow/fx/coroutines/CircuitBreaker$Companion;IDDDLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public final fun of-3c68mSE (IJDJLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun of-3c68mSE$default (Larrow/fx/coroutines/CircuitBreaker$Companion;IJDJLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/fx/coroutines/CircuitBreaker$ExecutionRejected : java/lang/Throwable { - public fun (Ljava/lang/String;Larrow/fx/coroutines/CircuitBreaker$State;)V - public final fun getReason ()Ljava/lang/String; - public final fun getState ()Larrow/fx/coroutines/CircuitBreaker$State; -} - -public abstract class arrow/fx/coroutines/CircuitBreaker$State { -} - -public final class arrow/fx/coroutines/CircuitBreaker$State$Closed : arrow/fx/coroutines/CircuitBreaker$State { - public fun (I)V - public fun equals (Ljava/lang/Object;)Z - public final fun getFailures ()I - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/fx/coroutines/CircuitBreaker$State$HalfOpen : arrow/fx/coroutines/CircuitBreaker$State { - public fun (D)V - public synthetic fun (JLkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun equals (Ljava/lang/Object;)Z - public final fun getResetTimeout-UwyO8pc ()J - public final fun getResetTimeoutNanos ()D - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class arrow/fx/coroutines/CircuitBreaker$State$Open : arrow/fx/coroutines/CircuitBreaker$State { - public fun (JD)V - public synthetic fun (JJLkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun equals (Ljava/lang/Object;)Z - public final fun getExpiresAt ()J - public final fun getResetTimeout-UwyO8pc ()J - public final fun getResetTimeoutNanos ()D - public final fun getStartedAt ()J - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - public final class arrow/fx/coroutines/CountDownLatch { public fun (J)V public final fun await (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -136,7 +72,6 @@ public final class arrow/fx/coroutines/FlowExtensions { public static final fun parMapUnordered (Lkotlinx/coroutines/flow/Flow;ILkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow; public static synthetic fun parMapUnordered$default (Lkotlinx/coroutines/flow/Flow;ILkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow; public static final fun repeat (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow; - public static final fun retry (Lkotlinx/coroutines/flow/Flow;Larrow/fx/coroutines/Schedule;)Lkotlinx/coroutines/flow/Flow; } public final class arrow/fx/coroutines/ParMapKt { @@ -154,61 +89,6 @@ public final class arrow/fx/coroutines/ParMapKt { public static synthetic fun parMapOrAccumulate$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } -public final class arrow/fx/coroutines/ParTraverse { - public static final fun parSequence (Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequence (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequence$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceEither (Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceEither (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceEither$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceEitherN (Ljava/lang/Iterable;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceEitherN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceEitherN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceEitherNScoped (Ljava/lang/Iterable;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceEitherNScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceEitherNScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceEitherScoped (Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceEitherScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceEitherScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceN (Ljava/lang/Iterable;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceNScoped (Ljava/lang/Iterable;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceNScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceNScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceResult (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceResult$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceResultN (Ljava/lang/Iterable;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceResultN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceResultN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceResultNScoped (Ljava/lang/Iterable;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceResultNScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceResultNScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceResultScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceResultScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parSequenceScoped (Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parSequenceScoped (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parSequenceScoped$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverse (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverse$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverseEither (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverseEither (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverseEither$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverseEitherN (Ljava/lang/Iterable;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverseEitherN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverseEitherN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverseN (Ljava/lang/Iterable;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverseN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverseN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverseResult (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverseResult (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverseResult$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun parTraverseResultN (Ljava/lang/Iterable;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun parTraverseResultN (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun parTraverseResultN$default (Ljava/lang/Iterable;Lkotlin/coroutines/CoroutineContext;ILkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; -} - public final class arrow/fx/coroutines/ParZipKt { public static final fun parZip (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function10;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun parZip (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function11;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -271,17 +151,6 @@ public final class arrow/fx/coroutines/ParZipOrAccumulateKt { public static final fun parZipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class arrow/fx/coroutines/Platform { - public static final field INSTANCE Larrow/fx/coroutines/Platform; - public final fun composeErrors (Ljava/lang/Throwable;Ljava/lang/Object;)Ljava/lang/Throwable; - public final fun composeErrors (Ljava/lang/Throwable;Ljava/lang/Throwable;)Ljava/lang/Throwable; - public final fun composeErrors (Ljava/lang/Throwable;Ljava/util/List;)Ljava/lang/Throwable; - public final fun composeErrors (Ljava/lang/Throwable;[Ljava/lang/Throwable;)Ljava/lang/Throwable; - public final fun composeErrors (Ljava/util/List;)Ljava/lang/Throwable; - public final fun composeErrors-GZgkXh4 (Ljava/util/List;)Ljava/lang/Throwable; - public final fun composeErrorsNullable (Ljava/lang/Throwable;Ljava/lang/Throwable;)Ljava/lang/Throwable; -} - public final class arrow/fx/coroutines/PredefKt { public static final fun timeInMillis ()J } @@ -381,127 +250,6 @@ public final class arrow/fx/coroutines/ResourceScope$DefaultImpls { public static fun releaseCase (Larrow/fx/coroutines/ResourceScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public abstract class arrow/fx/coroutines/Schedule { - public static final field Companion Larrow/fx/coroutines/Schedule$Companion; - public final fun and (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public abstract fun andThen (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public abstract fun check (Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public abstract fun choose (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public final fun collect ()Larrow/fx/coroutines/Schedule; - public final fun combine (Larrow/fx/coroutines/Schedule;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public abstract fun combineNanos (Larrow/fx/coroutines/Schedule;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun compose (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public final fun const (Ljava/lang/Object;)Larrow/fx/coroutines/Schedule; - public abstract fun contramap (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun delay (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun delayed (Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public final fun delayedNanos (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun dimap (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule; - public final fun doUntil (Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public final fun doWhile (Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public final fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public abstract fun foldLazy (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public abstract fun forever ()Larrow/fx/coroutines/Schedule; - public final fun jittered (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule; - public final fun jittered (Lkotlin/random/Random;)Larrow/fx/coroutines/Schedule; - public static synthetic fun jittered$default (Larrow/fx/coroutines/Schedule;Lkotlin/random/Random;ILjava/lang/Object;)Larrow/fx/coroutines/Schedule; - public final fun jitteredDuration (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule; - public abstract fun log (Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public abstract fun logInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public abstract fun logOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public abstract fun map (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule; - public final fun modify (Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public abstract fun modifyNanos (Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public abstract fun not ()Larrow/fx/coroutines/Schedule; - public final fun or (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public abstract fun pipe (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public final fun repeat (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun repeatAsFlow (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun repeatOrElse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun repeatOrElseAsFlow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun repeatOrElseEither (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun repeatOrElseEitherAsFlow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun untilInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun untilOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun void ()Larrow/fx/coroutines/Schedule; - public final fun whileInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun whileOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun zip (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public abstract fun zip (Larrow/fx/coroutines/Schedule;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun zipLeft (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public final fun zipRight (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; -} - -public final class arrow/fx/coroutines/Schedule$Companion { - public final fun collect ()Larrow/fx/coroutines/Schedule; - public final fun decision ()Larrow/fx/coroutines/Schedule; - public final fun delayInNanos ()Larrow/fx/coroutines/Schedule; - public final fun delayedDuration (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public final fun delayedNanos (Larrow/fx/coroutines/Schedule;)Larrow/fx/coroutines/Schedule; - public final fun doUntil (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun doWhile (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun duration ()Larrow/fx/coroutines/Schedule; - public final fun exponential (DD)Larrow/fx/coroutines/Schedule; - public static synthetic fun exponential$default (Larrow/fx/coroutines/Schedule$Companion;DDILjava/lang/Object;)Larrow/fx/coroutines/Schedule; - public final fun exponential-VtjQ1oo (JD)Larrow/fx/coroutines/Schedule; - public static synthetic fun exponential-VtjQ1oo$default (Larrow/fx/coroutines/Schedule$Companion;JDILjava/lang/Object;)Larrow/fx/coroutines/Schedule; - public final fun fibonacci (D)Larrow/fx/coroutines/Schedule; - public final fun fibonacci-LRDsOJo (J)Larrow/fx/coroutines/Schedule; - public final fun forever ()Larrow/fx/coroutines/Schedule; - public final fun identity ()Larrow/fx/coroutines/Schedule; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Larrow/fx/coroutines/Schedule; - public final fun linear (D)Larrow/fx/coroutines/Schedule; - public final fun linear-LRDsOJo (J)Larrow/fx/coroutines/Schedule; - public final fun logInput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun logOutput (Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun never ()Larrow/fx/coroutines/Schedule; - public final fun once ()Larrow/fx/coroutines/Schedule; - public final fun recurs (I)Larrow/fx/coroutines/Schedule; - public final fun spaced (D)Larrow/fx/coroutines/Schedule; - public final fun spaced-LRDsOJo (J)Larrow/fx/coroutines/Schedule; - public final fun unfold (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule; - public final fun unfoldLazy (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule; - public final fun unit ()Larrow/fx/coroutines/Schedule; -} - -public final class arrow/fx/coroutines/Schedule$Decision { - public static final field Companion Larrow/fx/coroutines/Schedule$Decision$Companion; - public fun (ZDLjava/lang/Object;Lkotlin/jvm/functions/Function0;)V - public final fun bimap (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule$Decision; - public final fun combine (Larrow/fx/coroutines/Schedule$Decision;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule$Decision; - public final fun combineNanos (Larrow/fx/coroutines/Schedule$Decision;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Larrow/fx/coroutines/Schedule$Decision; - public final fun component1 ()Z - public final fun component2 ()D - public final fun component3 ()Ljava/lang/Object; - public final fun component4 ()Lkotlin/jvm/functions/Function0; - public final fun copy (ZDLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; - public static synthetic fun copy$default (Larrow/fx/coroutines/Schedule$Decision;ZDLjava/lang/Object;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Larrow/fx/coroutines/Schedule$Decision; - public fun equals (Ljava/lang/Object;)Z - public final fun getCont ()Z - public final fun getDelayInNanos ()D - public final fun getDuration-UwyO8pc ()J - public final fun getFinish ()Lkotlin/jvm/functions/Function0; - public final fun getState ()Ljava/lang/Object; - public fun hashCode ()I - public final fun map (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule$Decision; - public final fun mapLeft (Lkotlin/jvm/functions/Function1;)Larrow/fx/coroutines/Schedule$Decision; - public final fun not ()Larrow/fx/coroutines/Schedule$Decision; - public fun toString ()Ljava/lang/String; -} - -public final class arrow/fx/coroutines/Schedule$Decision$Companion { - public final fun cont (DLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; - public final fun cont-KLykuaI (JLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; - public final fun done (DLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; - public final fun done-KLykuaI (JLjava/lang/Object;Lkotlin/jvm/functions/Function0;)Larrow/fx/coroutines/Schedule$Decision; -} - -public final class arrow/fx/coroutines/ScheduleKt { - public static final fun retry (Larrow/fx/coroutines/Schedule;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun retryOrElse (Larrow/fx/coroutines/Schedule;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun retryOrElseEither (Larrow/fx/coroutines/Schedule;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - public abstract interface annotation class arrow/fx/coroutines/ScopeDSL : java/lang/annotation/Annotation { } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt index 49d428462bc..003c405fdb3 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt @@ -20,11 +20,11 @@ import kotlin.coroutines.EmptyCoroutineContext * ```kotlin * import arrow.core.Either * import arrow.fx.coroutines.* - * import kotlinx.coroutines.suspendCancellableCoroutine + * import kotlinx.coroutines.awaitCancellation * * suspend fun main(): Unit { * suspend fun loser(): Int = - * guaranteeCase({ never() }) { exitCase -> + * guaranteeCase({ awaitCancellation() }) { exitCase -> * println("I can never win the race. Finished with $exitCase.") * } * @@ -62,11 +62,11 @@ public suspend inline fun raceN(crossinline fa: suspend CoroutineScope.() * import arrow.core.Either * import arrow.fx.coroutines.* * import kotlinx.coroutines.Dispatchers - * import kotlinx.coroutines.suspendCancellableCoroutine + * import kotlinx.coroutines.awaitCancellation * * suspend fun main(): Unit { * suspend fun loser(): Int = - * guaranteeCase({ never() }) { exitCase -> + * guaranteeCase({ awaitCancellation() }) { exitCase -> * println("I can never win the race. Finished with $exitCase.") * } * diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt index fc300bc3417..380a2ab846b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt @@ -309,7 +309,7 @@ public interface ResourceScope { @ResourceDSL public suspend infix fun Resource.release(release: suspend (A) -> Unit): A { val a = bind() - return install({ a }) { a, _ -> release(a) } + return install({ a }) { aa, _ -> release(aa) } } /** Composes a [releaseCase] action to a [Resource] value before binding. */ @@ -477,7 +477,9 @@ public suspend fun Resource.allocated(): Pair Un is ExitCase.Cancelled -> e.exception is ExitCase.Failure -> e.failure } - Platform.composeErrors(original, suppressed)?.let { throw it } + original?.apply { + suppressed?.let(::addSuppressed) + }?.let { throw it } } return Pair(allocated, release) } @@ -500,7 +502,9 @@ private value class ResourceScopeImpl( if (ex != ExitCase.Completed) { val e = cancelAll(ex) val e2 = kotlin.runCatching { release(a, ex) }.exceptionOrNull() - Platform.composeErrors(e, e2)?.let { throw it } + e?.apply { + e2?.let(::addSuppressed) + }?.let { throw it } } }) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt index 0586041de64..ee3f2ab3adb 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt @@ -28,55 +28,6 @@ import kotlinx.coroutines.flow.zip import kotlin.time.Duration import kotlin.time.ExperimentalTime -/** - * Retries collection of the given flow when an exception occurs in the upstream flow based on a decision by the [schedule]. - * This operator is *transparent* to exceptions that occur in downstream flow and does not retry on exceptions that are thrown - * to cancel the flow. - * - * @see [Schedule] for how to build a schedule. - * - * ```kotlin - * import kotlinx.coroutines.flow.* - * import arrow.fx.coroutines.* - * suspend fun main(): Unit { - * var counter = 0 - * val flow = flow { - * emit(counter) - * if (++counter <= 5) throw RuntimeException("Bang!") - * } - * //sampleStart - * val sum = flow.retry(Schedule.recurs(5)) - * .reduce(Int::plus) - * //sampleEnd - * println(sum) - * } - * ``` - * - * - * @param schedule - the [Schedule] used for retrying the collection of the flow - */ -@Deprecated(deprecatedInFavorOfArrowFxResilience, ReplaceWith("retry", "arrow.fx.resilience.retry")) -public fun Flow.retry(schedule: Schedule): Flow = flow { - (schedule as Schedule.ScheduleImpl) - var dec: Schedule.Decision - var state: Any? = schedule.initialState() - - val retryWhen = retryWhen { cause, _ -> - dec = schedule.update(cause, state) - state = dec.state - - if (dec.cont) { - delay((dec.delayInNanos / 1_000_000).toLong()) - true - } else { - false - } - } - retryWhen.collect { - emit(it) - } -} - /** * Like [map], but will evaluate [transform] in parallel, emitting the results * downstream in **the same order as the input stream**. The number of concurrent effects @@ -106,7 +57,7 @@ public fun Flow.retry(schedule: Schedule): Flow = flo * } * //sampleEnd * ``` - * + * * The upstream `source` runs concurrently with downstream `parMap`, and thus the upstream * concurrently runs, "prefetching", the next element. i.e. * @@ -123,7 +74,7 @@ public fun Flow.retry(schedule: Schedule): Flow = flo * //sampleEnd * } * ``` - * + * * * `1, 2, 3` will be emitted from `source` but only "Processing 1" & "Processing 2" will get printed. */ @@ -179,7 +130,7 @@ public inline fun Flow.parMap( * } * //sampleEnd * ``` - * + * */ @FlowPreview public inline fun Flow.parMapUnordered( diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt index ea723a38b17..3b0f50738dd 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt @@ -32,7 +32,7 @@ class CyclicBarrierSpec : StringSpec({ "awaiting all in parallel resumes all coroutines" { checkAll(Arb.int(1, 100)) { i -> val barrier = CyclicBarrier(i) - (0 until i).parTraverse { barrier.await() } + (0 until i).parMap { barrier.await() } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt index 55164617e45..87295ea68d1 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt @@ -1,10 +1,7 @@ package arrow.fx.coroutines import io.kotest.assertions.fail -import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.longs.shouldBeGreaterThanOrEqual -import io.kotest.matchers.longs.shouldBeLessThan import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf import io.kotest.property.Arb @@ -23,7 +20,6 @@ import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.reduce import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toSet @@ -32,41 +28,11 @@ import kotlinx.coroutines.test.advanceTimeBy import kotlinx.coroutines.test.currentTime import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withTimeoutOrNull -import kotlin.time.Duration.Companion.milliseconds @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) @ExperimentalTime class FlowTest : StringSpec({ - "Retry - flow fails" { - val bang = RuntimeException("Bang!") - - checkAll(Arb.int(), Arb.positiveInt(10)) { a, n -> - var counter = 0 - val e = assertThrowable { - flow { - emit(a) - if (++counter <= 11) throw bang - }.retry(Schedule.recurs(n)) - .collect() - } - e shouldBe bang - } - } - - "Retry - flow succeeds" { - checkAll(Arb.int(), Arb.int(5, 10)) { a, n -> - var counter = 0 - val sum = flow { - emit(a) - if (++counter <= 5) throw RuntimeException("Bang!") - }.retry(Schedule.recurs(n)) - .reduce { acc, int -> acc + int } - - sum shouldBe a * 6 - } - } - "parMap - concurrency = 1 - identity" { checkAll(Arb.flow(Arb.int())) { flow -> flow.parMap(1) { it } @@ -257,33 +223,7 @@ class FlowTest : StringSpec({ ex2.shouldBeTypeOf() } } - - "Retry - schedule with delay" { - runTest { - checkAll(Arb.int(), Arb.int(100, 1000)) { a, delayMs -> - val start = currentTime - val timestamps = mutableListOf() - shouldThrow { - flow { - emit(a) - timestamps.add(currentTime) - throw RuntimeException("Bang!") - } - .retry(Schedule.recurs(2) and Schedule.spaced(delayMs.milliseconds)) - .collect() - } - timestamps.size shouldBe 3 - - // total run should be between start time + delay * 3 AND start + tolerance % - val min = start + (delayMs * 2) - val max = min + delayMs / 10 - - timestamps.last() shouldBeGreaterThanOrEqual min - timestamps.last() shouldBeLessThan max - } - } - } - + "fixedDelay" { runTest { checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> 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 index 6355ae3461f..887dc41a809 100644 --- 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 @@ -23,7 +23,7 @@ import kotlin.time.Duration * ```kotlin * import arrow.fx.coroutines.executor * import arrow.fx.coroutines.resourceScope - * import arrow.fx.coroutines.parTraverse + * import arrow.fx.coroutines.parMap * import java.util.concurrent.Executors * import java.util.concurrent.atomic.AtomicInteger * import kotlin.math.max @@ -39,7 +39,7 @@ import kotlin.time.Duration * } * } * - * listOf(1, 2, 3, 4, 5).parTraverse(pool) { i -> + * listOf(1, 2, 3, 4, 5).parMap(pool) { i -> * println("#$i running on ${Thread.currentThread().name}") * } * } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt new file mode 100644 index 00000000000..ecec44ced00 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt @@ -0,0 +1,25 @@ +// This file was automatically generated from Bracket.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleBracket01 + +import arrow.fx.coroutines.* + +class File(url: String) { + fun open(): File = this + fun close(): Unit {} + override fun toString(): String = "This file contains some interesting content!" +} + +suspend fun openFile(uri: String): File = File(uri).open() +suspend fun closeFile(file: File): Unit = file.close() +suspend fun fileToString(file: File): String = file.toString() + +suspend fun main(): Unit { + //sampleStart + val res = bracket( + acquire = { openFile("data.json") }, + use = { file -> fileToString(file) }, + release = { file: File -> closeFile(file) } + ) + //sampleEnd + println(res) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt new file mode 100644 index 00000000000..dfa4131c13e --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt @@ -0,0 +1,32 @@ +// This file was automatically generated from Bracket.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleBracket02 + +import arrow.fx.coroutines.* + +class File(url: String) { + fun open(): File = this + fun close(): Unit {} +} + +suspend fun File.content(): String = + "This file contains some interesting content!" +suspend fun openFile(uri: String): File = File(uri).open() +suspend fun closeFile(file: File): Unit = file.close() + +suspend fun main(): Unit { + //sampleStart + val res = bracketCase( + acquire = { openFile("data.json") }, + use = { file -> file.content() }, + release = { file, exitCase -> + when (exitCase) { + is ExitCase.Completed -> println("File closed with $exitCase") + is ExitCase.Cancelled -> println("Program cancelled with $exitCase") + is ExitCase.Failure -> println("Program failed with $exitCase") + } + closeFile(file) + } + ) + //sampleEnd + println(res) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-01.kt new file mode 100644 index 00000000000..9bcd7615eb9 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-01.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from flow.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleFlow01 + +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.flow.collect +import arrow.fx.coroutines.parMap + +suspend fun main(): Unit { + flowOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .parMap { a -> + delay(100) + a + }.toList() // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-02.kt new file mode 100644 index 00000000000..8f814f47bb1 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-02.kt @@ -0,0 +1,3 @@ +// This file was automatically generated from flow.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleFlow02 + diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-03.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-03.kt new file mode 100644 index 00000000000..0f9ef5e5074 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-03.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from flow.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleFlow03 + +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.flow.collect +import arrow.fx.coroutines.parMapUnordered + +suspend fun main(): Unit { + flowOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .parMapUnordered { a -> + delay(100) + a + }.toList() // [3, 5, 4, 6, 2, 8, 7, 1, 9, 10] +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-01.kt new file mode 100644 index 00000000000..5eec01067b4 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-01.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip01 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" } + ) { a, b -> + "$a\n$b" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-02.kt new file mode 100644 index 00000000000..9cbaf3685f9 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-02.kt @@ -0,0 +1,18 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip02 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" } + ) { a, b -> + "$a\n$b" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-03.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-03.kt new file mode 100644 index 00000000000..a7864c75d12 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-03.kt @@ -0,0 +1,17 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip03 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" } + ) { a, b, c -> + "$a\n$b\n$c" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-04.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-04.kt new file mode 100644 index 00000000000..81fc59abafb --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-04.kt @@ -0,0 +1,19 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip04 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" } + ) { a, b, c -> + "$a\n$b\n$c" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-05.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-05.kt new file mode 100644 index 00000000000..551fc0e9660 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-05.kt @@ -0,0 +1,18 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip05 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d -> + "$a\n$b\n$c\n$d" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-06.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-06.kt new file mode 100644 index 00000000000..39517221fbe --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-06.kt @@ -0,0 +1,20 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip06 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d -> + "$a\n$b\n$c\n$d" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-07.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-07.kt new file mode 100644 index 00000000000..eaf9edb42bd --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-07.kt @@ -0,0 +1,19 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip07 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e -> + "$a\n$b\n$c\n$d\n$e" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-08.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-08.kt new file mode 100644 index 00000000000..e2ad9acb2bd --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-08.kt @@ -0,0 +1,21 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip08 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e -> + "$a\n$b\n$c\n$d\n$e" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-09.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-09.kt new file mode 100644 index 00000000000..f7167e7ee41 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-09.kt @@ -0,0 +1,20 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip09 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, f -> + "$a\n$b\n$c\n$d\n$e\n$f" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-10.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-10.kt new file mode 100644 index 00000000000..dcf789da892 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-10.kt @@ -0,0 +1,22 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip10 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, g -> + "$a\n$b\n$c\n$d\n$e\n$g" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-11.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-11.kt new file mode 100644 index 00000000000..abce49edfbd --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-11.kt @@ -0,0 +1,21 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip11 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" }, + { "Seventh one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, g, h -> + "$a\n$b\n$c\n$d\n$e\n$g\n$h" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-12.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-12.kt new file mode 100644 index 00000000000..b0b8166f40e --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-12.kt @@ -0,0 +1,23 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip12 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" }, + { "Seventh one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, f, g -> + "$a\n$b\n$c\n$d\n$e\n$f\n$g" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-13.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-13.kt new file mode 100644 index 00000000000..03aa4798bd8 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-13.kt @@ -0,0 +1,22 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip13 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" }, + { "Seventh one is on ${Thread.currentThread().name}" }, + { "Eighth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, f, g, h -> + "$a\n$b\n$c\n$d\n$e\n$f\n$g\n$h" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-14.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-14.kt new file mode 100644 index 00000000000..df31d5e515d --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-14.kt @@ -0,0 +1,24 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip14 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" }, + { "Seventh one is on ${Thread.currentThread().name}" }, + fh = { "Eighth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, f, g, h -> + "$a\n$b\n$c\n$d\n$e\n$f\n$g\n$h" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-15.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-15.kt new file mode 100644 index 00000000000..2d04e3aa724 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-15.kt @@ -0,0 +1,23 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip15 + +import arrow.fx.coroutines.* + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" }, + { "Seventh one is on ${Thread.currentThread().name}" }, + { "Eighth one is on ${Thread.currentThread().name}" }, + fi = { "Ninth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, f, g, h, i-> + "$a\n$b\n$c\n$d\n$e\n$f\n$g\n$h\n$i" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-16.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-16.kt new file mode 100644 index 00000000000..18edea217ba --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-parzip-16.kt @@ -0,0 +1,25 @@ +// This file was automatically generated from ParZip.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleParzip16 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers + +suspend fun main(): Unit { + //sampleStart + val result = parZip( + Dispatchers.IO, + { "First one is on ${Thread.currentThread().name}" }, + { "Second one is on ${Thread.currentThread().name}" }, + { "Third one is on ${Thread.currentThread().name}" }, + { "Fourth one is on ${Thread.currentThread().name}" }, + { "Fifth one is on ${Thread.currentThread().name}" }, + { "Sixth one is on ${Thread.currentThread().name}" }, + { "Seventh one is on ${Thread.currentThread().name}" }, + { "Eighth one is on ${Thread.currentThread().name}" }, + fi = { "Ninth one is on ${Thread.currentThread().name}" } + ) { a, b, c, d, e, f, g, h, i-> + "$a\n$b\n$c\n$d\n$e\n$f\n$g\n$h\n$i" + } + //sampleEnd + println(result) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-01.kt new file mode 100644 index 00000000000..3715cc0cf35 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-01.kt @@ -0,0 +1,22 @@ +// This file was automatically generated from Race2.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleRace201 + +import arrow.core.Either +import arrow.fx.coroutines.* +import kotlinx.coroutines.awaitCancellation + +suspend fun main(): Unit { + suspend fun loser(): Int = + guaranteeCase({ awaitCancellation() }) { exitCase -> + println("I can never win the race. Finished with $exitCase.") + } + + val winner = raceN({ loser() }, { 5 }) + + val res = when(winner) { + is Either.Left -> "Never always loses race" + is Either.Right -> "Race was won with ${winner.value}" + } + //sampleEnd + println(res) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-02.kt new file mode 100644 index 00000000000..56d84882932 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-race2-02.kt @@ -0,0 +1,23 @@ +// This file was automatically generated from Race2.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleRace202 + +import arrow.core.Either +import arrow.fx.coroutines.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.awaitCancellation + +suspend fun main(): Unit { + suspend fun loser(): Int = + guaranteeCase({ awaitCancellation() }) { exitCase -> + println("I can never win the race. Finished with $exitCase.") + } + + val winner = raceN(Dispatchers.IO, { loser() }, { 5 }) + + val res = when(winner) { + is Either.Left -> "Never always loses race" + is Either.Right -> "Race was won with ${winner.value}" + } + //sampleEnd + println(res) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt new file mode 100644 index 00000000000..93ee7786688 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-01.kt @@ -0,0 +1,27 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource01 + +class UserProcessor { + fun start(): Unit = println("Creating UserProcessor") + fun shutdown(): Unit = println("Shutting down UserProcessor") +} + +class DataSource { + fun connect(): Unit = println("Connecting dataSource") + fun close(): Unit = println("Closed dataSource") +} + +class Service(val db: DataSource, val userProcessor: UserProcessor) { + suspend fun processData(): List = throw RuntimeException("I'm going to leak resources by not closing them") +} + +suspend fun main(): Unit { + val userProcessor = UserProcessor().also { it.start() } + val dataSource = DataSource().also { it.connect() } + val service = Service(dataSource, userProcessor) + + service.processData() + + dataSource.close() + userProcessor.shutdown() +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt new file mode 100644 index 00000000000..9d0a4061988 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-02.kt @@ -0,0 +1,28 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource02 + +import java.io.Closeable + +class UserProcessor : Closeable { + fun start(): Unit = println("Creating UserProcessor") + override fun close(): Unit = println("Shutting down UserProcessor") +} + +class DataSource : Closeable { + fun connect(): Unit = println("Connecting dataSource") + override fun close(): Unit = println("Closed dataSource") +} + +class Service(val db: DataSource, val userProcessor: UserProcessor) { + suspend fun processData(): List = throw RuntimeException("I'm going to leak resources by not closing them") +} + +suspend fun main(): Unit { + UserProcessor().use { userProcessor -> + userProcessor.start() + DataSource().use { dataSource -> + dataSource.connect() + Service(dataSource, userProcessor).processData() + } + } +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt new file mode 100644 index 00000000000..2d977c79930 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-03.kt @@ -0,0 +1,44 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource03 + +import arrow.fx.coroutines.Resource +import arrow.fx.coroutines.resource +import arrow.fx.coroutines.resourceScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class UserProcessor { + suspend fun start(): Unit = withContext(Dispatchers.IO) { println("Creating UserProcessor") } + suspend fun shutdown(): Unit = withContext(Dispatchers.IO) { + println("Shutting down UserProcessor") + } +} + +class DataSource { + fun connect(): Unit = println("Connecting dataSource") + fun close(): Unit = println("Closed dataSource") +} + +class Service(val db: DataSource, val userProcessor: UserProcessor) { + suspend fun processData(): List = throw RuntimeException("I'm going to leak resources by not closing them") +} + +val userProcessor: Resource = resource({ + UserProcessor().also { it.start() } +}) { p, _ -> p.shutdown() } + +val dataSource: Resource = resource({ + DataSource().also { it.connect() } +}) { ds, exitCase -> + println("Releasing $ds with exit: $exitCase") + withContext(Dispatchers.IO) { ds.close() } +} + +val service: Resource = resource { + Service(dataSource.bind(), userProcessor.bind()) +} + +suspend fun main(): Unit = resourceScope { + val data = service.bind().processData() + println(data) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt new file mode 100644 index 00000000000..aab22cf814e --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-04.kt @@ -0,0 +1,34 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource04 + +import arrow.fx.coroutines.ResourceScope +import arrow.fx.coroutines.Resource +import arrow.fx.coroutines.resource +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class UserProcessor { + suspend fun start(): Unit = withContext(Dispatchers.IO) { println("Creating UserProcessor") } + suspend fun shutdown(): Unit = withContext(Dispatchers.IO) { + println("Shutting down UserProcessor") + } +} + +suspend fun ResourceScope.userProcessor(): UserProcessor = + install({ UserProcessor().also { it.start() } }) { processor, _ -> + processor.shutdown() + } + +val userProcessor: Resource = resource { + val x: UserProcessor = install( + { UserProcessor().also { it.start() } }, + { processor, _ -> processor.shutdown() } + ) + x +} + +val userProcessor2: Resource = resource({ + UserProcessor().also { it.start() } +}) { processor, _ -> processor.shutdown() } + +val userProcessor3: Resource = ResourceScope::userProcessor diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt new file mode 100644 index 00000000000..ce20f638266 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-05.kt @@ -0,0 +1,38 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource05 + +import arrow.fx.coroutines.ResourceScope +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.parZip +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class UserProcessor { + suspend fun start(): Unit = withContext(Dispatchers.IO) { println("Creating UserProcessor") } + suspend fun shutdown(): Unit = withContext(Dispatchers.IO) { + println("Shutting down UserProcessor") + } +} + +class DataSource { + suspend fun connect(): Unit = withContext(Dispatchers.IO) { println("Connecting dataSource") } + suspend fun close(): Unit = withContext(Dispatchers.IO) { println("Closed dataSource") } +} + +class Service(val db: DataSource, val userProcessor: UserProcessor) { + suspend fun processData(): List = (0..10).map { "Processed : $it" } +} + +suspend fun ResourceScope.userProcessor(): UserProcessor = + install({ UserProcessor().also { it.start() } }){ p,_ -> p.shutdown() } + +suspend fun ResourceScope.dataSource(): DataSource = + install({ DataSource().also { it.connect() } }) { ds, _ -> ds.close() } + +suspend fun main(): Unit = resourceScope { + val service = parZip({ userProcessor() }, { dataSource() }) { userProcessor, ds -> + Service(ds, userProcessor) + } + val data = service.processData() + println(data) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt new file mode 100644 index 00000000000..9a1bd665e14 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-06.kt @@ -0,0 +1,20 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource06 + +import arrow.fx.coroutines.resourceScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class DataSource { + suspend fun connect(): Unit = withContext(Dispatchers.IO) { println("Connecting dataSource") } + suspend fun close(): Unit = withContext(Dispatchers.IO) { println("Closed dataSource") } + suspend fun users(): List = listOf("User-1", "User-2", "User-3") +} + +suspend fun main(): Unit = resourceScope { + val dataSource = install({ + DataSource().also { it.connect() } + }) { ds, _ -> ds.close() } + + println("Using data source: ${dataSource.users()}") +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt new file mode 100644 index 00000000000..161326cdab0 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-07.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource07 + +import arrow.fx.coroutines.resource +import arrow.fx.coroutines.resourceScope + +val resource = resource { + install({ 42.also { println("Getting expensive resource") } }) { r, exitCase -> + println("Releasing expensive resource: $r, exit: $exitCase") + } +} + +suspend fun main(): Unit = resourceScope { + val res = resource.bind() + println("Expensive resource under use! $res") +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt new file mode 100644 index 00000000000..43f2a268f06 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt @@ -0,0 +1,24 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource08 + +import arrow.fx.coroutines.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* +import java.nio.file.Path +import kotlin.io.path.* + +fun Flow.writeAll(path: Path): Flow = + closeable { path.toFile().outputStream() } + .asFlow() + .flatMapConcat { writer -> map { writer.write(it) } } + .flowOn(Dispatchers.IO) + +fun Path.readAll(): Flow = flow { + useLines { lines -> emitAll(lines.asFlow()) } +} + +suspend fun main() { + Path.of("example.kt") + .readAll() + .collect(::println) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt new file mode 100644 index 00000000000..c2642bb90dd --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-09.kt @@ -0,0 +1,18 @@ +// This file was automatically generated from Resource.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResource09 + +import arrow.fx.coroutines.* +import arrow.fx.coroutines.ExitCase.Companion.ExitCase + +val resource = + resource({ "Acquire" }) { _, exitCase -> println("Release $exitCase") } + +suspend fun main(): Unit { + val (acquired: String, release: suspend (ExitCase) -> Unit) = resource.allocated() + try { + /** Do something with A */ + release(ExitCase.Completed) + } catch(e: Throwable) { + release(ExitCase(e)) + } +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt new file mode 100644 index 00000000000..ccbf303048e --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-01.kt @@ -0,0 +1,26 @@ +// This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResourceextensions01 + +import arrow.fx.coroutines.executor +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.parMap +import java.util.concurrent.Executors +import java.util.concurrent.atomic.AtomicInteger +import kotlin.math.max + +suspend fun main(): Unit { + resourceScope { + val pool = executor { + val ctr = AtomicInteger(0) + val size = max(2, Runtime.getRuntime().availableProcessors()) + Executors.newFixedThreadPool(size) { r -> + Thread(r, "computation-${ctr.getAndIncrement()}") + .apply { isDaemon = true } + } + } + + listOf(1, 2, 3, 4, 5).parMap(pool) { i -> + println("#$i running on ${Thread.currentThread().name}") + } + } +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt new file mode 100644 index 00000000000..af4c56052c4 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-02.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResourceextensions02 + +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.closeable +import java.io.FileInputStream + +suspend fun copyFile(src: String, dest: String): Unit = + resourceScope { + val a: FileInputStream = closeable { FileInputStream(src) } + val b: FileInputStream = closeable { FileInputStream(dest) } + /** read from `a` and write to `b`. **/ + } // Both resources will be closed accordingly to their #close methods diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt new file mode 100644 index 00000000000..cbdf566e457 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-03.kt @@ -0,0 +1,13 @@ +// This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResourceextensions03 + +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.autoCloseable +import java.io.FileInputStream + +suspend fun copyFile(src: String, dest: String): Unit = + resourceScope { + val a: FileInputStream = autoCloseable { FileInputStream(src) } + val b: FileInputStream = autoCloseable { FileInputStream(dest) } + /** read from [a] and write to [b]. **/ + } // Both resources will be closed accordingly to their #close methods diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt new file mode 100644 index 00000000000..82a7d7c1ae0 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-04.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResourceextensions04 + +import arrow.fx.coroutines.resourceScope +import arrow.fx.coroutines.singleThreadContext +import kotlinx.coroutines.withContext +import kotlinx.coroutines.ExecutorCoroutineDispatcher + +suspend fun main(): Unit = resourceScope { + val single: ExecutorCoroutineDispatcher = singleThreadContext("single") + withContext(single) { + println("I am running on ${Thread.currentThread().name}") + } +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt new file mode 100644 index 00000000000..9b7080d25a3 --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resourceextensions-05.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from ResourceExtensions.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleResourceextensions05 + +import arrow.fx.coroutines.fixedThreadPoolContext +import arrow.fx.coroutines.resourceScope +import kotlinx.coroutines.withContext +import kotlinx.coroutines.ExecutorCoroutineDispatcher + +suspend fun main(): Unit = resourceScope { + val pool: ExecutorCoroutineDispatcher = fixedThreadPoolContext(8, "custom-pool") + withContext(pool) { + println("I am running on ${Thread.currentThread().name}") + } +} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt index ad3dc1b103f..38264295207 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt @@ -1,6 +1,6 @@ package arrow.fx.stm -import arrow.fx.coroutines.parTraverse +import arrow.fx.coroutines.parMap import arrow.fx.coroutines.parZip import arrow.fx.stm.internal.BlockedIndefinitely import io.kotest.assertions.throwables.shouldThrow @@ -246,7 +246,7 @@ class STMTest : StringSpec({ parZip( { // producers - (0..4).parTraverse { + (0..4).parMap { for (i in (it * 20 + 1)..(it * 20 + 20)) { atomically { tq.write(i) } } diff --git a/arrow-libs/optics/arrow-optics/api/arrow-optics.api b/arrow-libs/optics/arrow-optics/api/arrow-optics.api index 9a570cb45a7..c1de5f193bc 100644 --- a/arrow-libs/optics/arrow-optics/api/arrow-optics.api +++ b/arrow-libs/optics/arrow-optics/api/arrow-optics.api @@ -1,6 +1,6 @@ public abstract interface class arrow/optics/Copy { public abstract fun inside (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)V - public abstract fun set (Larrow/optics/PSetter;Ljava/lang/Object;)V + public abstract fun set (Larrow/optics/PTraversal;Ljava/lang/Object;)V public abstract fun transform (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)V } @@ -12,141 +12,23 @@ public final class arrow/optics/CopyKt { public static final fun copy (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } -public abstract interface class arrow/optics/Fold { - public static final field Companion Larrow/optics/Fold$Companion; - public abstract fun all (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public abstract fun any (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public abstract fun choice (Larrow/optics/Fold;)Larrow/optics/Fold; - public abstract fun combineAll (Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun compose (Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun either ()Larrow/optics/Fold; - public abstract fun exists (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public abstract fun findOrNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun firstOrNull (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun fold (Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun getAll (Ljava/lang/Object;)Ljava/util/List; - public abstract fun isEmpty (Ljava/lang/Object;)Z - public abstract fun isNotEmpty (Ljava/lang/Object;)Z - public static fun iterable ()Larrow/optics/Fold; - public abstract fun lastOrNull (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun left ()Larrow/optics/Fold; - public static fun list ()Larrow/optics/Fold; - public static fun map ()Larrow/optics/Fold; - public static fun nonEmptyList ()Larrow/optics/Fold; - public static fun option ()Larrow/optics/Fold; - public static fun pair ()Larrow/optics/Fold; - public abstract fun plus (Larrow/optics/Fold;)Larrow/optics/Fold; - public abstract fun right ()Larrow/optics/Fold; - public static fun sequence ()Larrow/optics/Fold; - public abstract fun size (Ljava/lang/Object;)I - public static fun string ()Larrow/optics/Fold; - public static fun triple ()Larrow/optics/Fold; - public static fun tuple10 ()Larrow/optics/Fold; - public static fun tuple4 ()Larrow/optics/Fold; - public static fun tuple5 ()Larrow/optics/Fold; - public static fun tuple6 ()Larrow/optics/Fold; - public static fun tuple7 ()Larrow/optics/Fold; - public static fun tuple8 ()Larrow/optics/Fold; - public static fun tuple9 ()Larrow/optics/Fold; -} - -public final class arrow/optics/Fold$Companion { - public final fun codiagonal ()Larrow/optics/Fold; - public final fun either ()Larrow/optics/Fold; - public final fun id ()Larrow/optics/Fold; - public final fun iterable ()Larrow/optics/Fold; - public final fun list ()Larrow/optics/Fold; - public final fun map ()Larrow/optics/Fold; - public final fun nonEmptyList ()Larrow/optics/Fold; - public final fun option ()Larrow/optics/Fold; - public final fun pair ()Larrow/optics/Fold; - public final fun select (Lkotlin/jvm/functions/Function1;)Larrow/optics/Fold; - public final fun sequence ()Larrow/optics/Fold; - public final fun string ()Larrow/optics/Fold; - public final fun triple ()Larrow/optics/Fold; - public final fun tuple10 ()Larrow/optics/Fold; - public final fun tuple4 ()Larrow/optics/Fold; - public final fun tuple5 ()Larrow/optics/Fold; - public final fun tuple6 ()Larrow/optics/Fold; - public final fun tuple7 ()Larrow/optics/Fold; - public final fun tuple8 ()Larrow/optics/Fold; - public final fun tuple9 ()Larrow/optics/Fold; - public final fun void ()Larrow/optics/Fold; -} - -public final class arrow/optics/Fold$DefaultImpls { - public static fun all (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/Fold;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun combineAll (Larrow/optics/Fold;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/Fold;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun exists (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun firstOrNull (Larrow/optics/Fold;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/Fold;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/Fold;Ljava/lang/Object;)Ljava/util/List; - public static fun isEmpty (Larrow/optics/Fold;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/Fold;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/Fold;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/Fold;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun right (Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun size (Larrow/optics/Fold;Ljava/lang/Object;)I -} - -public abstract interface class arrow/optics/Getter : arrow/optics/Fold { - public static final field Companion Larrow/optics/Getter$Companion; - public abstract fun choice (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun compose (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun first ()Larrow/optics/Getter; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun left ()Larrow/optics/Getter; - public abstract fun plus (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun right ()Larrow/optics/Getter; - public abstract fun second ()Larrow/optics/Getter; - public abstract fun split (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun zip (Larrow/optics/Getter;)Larrow/optics/Getter; -} - -public final class arrow/optics/Getter$Companion { - public final fun codiagonal ()Larrow/optics/Getter; - public final fun id ()Larrow/optics/Getter; -} - -public final class arrow/optics/Getter$DefaultImpls { - public static fun all (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/Getter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun combineAll (Larrow/optics/Getter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/Getter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun exists (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun first (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun firstOrNull (Larrow/optics/Getter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/Getter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/Getter;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/Getter;Ljava/lang/Object;)Ljava/util/List; - public static fun isEmpty (Larrow/optics/Getter;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/Getter;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/Getter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun plus (Larrow/optics/Getter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun right (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun second (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun size (Larrow/optics/Getter;Ljava/lang/Object;)I - public static fun split (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun zip (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; +public final class arrow/optics/Every { + public static final field INSTANCE Larrow/optics/Every; + public static final fun either ()Larrow/optics/PTraversal; + public static final fun list ()Larrow/optics/PTraversal; + public static final fun map ()Larrow/optics/PTraversal; + public static final fun nonEmptyList ()Larrow/optics/PTraversal; + public static final fun option ()Larrow/optics/PTraversal; + public static final fun pair ()Larrow/optics/PTraversal; + public static final fun sequence ()Larrow/optics/PTraversal; + public static final fun string ()Larrow/optics/PTraversal; + public static final fun triple ()Larrow/optics/PTraversal; + public static final fun tuple4 ()Larrow/optics/PTraversal; + public static final fun tuple5 ()Larrow/optics/PTraversal; + public static final fun tuple6 ()Larrow/optics/PTraversal; + public static final fun tuple7 ()Larrow/optics/PTraversal; + public static final fun tuple8 ()Larrow/optics/PTraversal; + public static final fun tuple9 ()Larrow/optics/PTraversal; } public final class arrow/optics/ListKt { @@ -160,231 +42,16 @@ public final class arrow/optics/ListKt { public abstract interface annotation class arrow/optics/OpticsCopyMarker : java/lang/annotation/Annotation { } -public final class arrow/optics/OptionalGetterKt { - public static final fun OptionalGetter (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; -} - public final class arrow/optics/OptionalKt { public static final fun Optional (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/POptional; } -public abstract interface class arrow/optics/PEvery : arrow/optics/Fold, arrow/optics/PSetter, arrow/optics/PTraversal { - public static final field Companion Larrow/optics/PEvery$Companion; - public abstract fun compose (Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun either ()Larrow/optics/PEvery; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun getEvery (Larrow/optics/PIso;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/PLens;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/POptional;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/PPrism;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun getEvery (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun list ()Larrow/optics/PEvery; - public static fun map ()Larrow/optics/PEvery; - public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun nonEmptyList ()Larrow/optics/PEvery; - public static fun option ()Larrow/optics/PEvery; - public static fun pair ()Larrow/optics/PEvery; - public abstract fun plus (Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun sequence ()Larrow/optics/PEvery; - public static fun string ()Larrow/optics/PEvery; - public static fun triple ()Larrow/optics/PEvery; - public static fun tuple10 ()Larrow/optics/PEvery; - public static fun tuple4 ()Larrow/optics/PEvery; - public static fun tuple5 ()Larrow/optics/PEvery; - public static fun tuple6 ()Larrow/optics/PEvery; - public static fun tuple7 ()Larrow/optics/PEvery; - public static fun tuple8 ()Larrow/optics/PEvery; - public static fun tuple9 ()Larrow/optics/PEvery; -} - -public final class arrow/optics/PEvery$Companion { - public final fun either ()Larrow/optics/PEvery; - public final fun from (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/PEvery; - public final fun list ()Larrow/optics/PEvery; - public final fun map ()Larrow/optics/PEvery; - public final fun nonEmptyList ()Larrow/optics/PEvery; - public final fun option ()Larrow/optics/PEvery; - public final fun pair ()Larrow/optics/PEvery; - public final fun sequence ()Larrow/optics/PEvery; - public final fun string ()Larrow/optics/PEvery; - public final fun triple ()Larrow/optics/PEvery; - public final fun tuple10 ()Larrow/optics/PEvery; - public final fun tuple4 ()Larrow/optics/PEvery; - public final fun tuple5 ()Larrow/optics/PEvery; - public final fun tuple6 ()Larrow/optics/PEvery; - public final fun tuple7 ()Larrow/optics/PEvery; - public final fun tuple8 ()Larrow/optics/PEvery; - public final fun tuple9 ()Larrow/optics/PEvery; -} - -public final class arrow/optics/PEvery$DefaultImpls { - public static fun all (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PEvery;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun choice (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun combineAll (Larrow/optics/PEvery;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun exists (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun firstOrNull (Larrow/optics/PEvery;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PEvery;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/PEvery;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PPrism;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun isEmpty (Larrow/optics/PEvery;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/PEvery;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/PEvery;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PEvery;)Larrow/optics/Fold; - public static fun lift (Larrow/optics/PEvery;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/PEvery;)Larrow/optics/Fold; - public static fun set (Larrow/optics/PEvery;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun size (Larrow/optics/PEvery;Ljava/lang/Object;)I -} - -public abstract interface class arrow/optics/PIso : arrow/optics/Fold, arrow/optics/Getter, arrow/optics/PEvery, arrow/optics/PLens, arrow/optics/POptional, arrow/optics/PPrism, arrow/optics/PSetter, arrow/optics/PTraversal { - public static final field Companion Larrow/optics/PIso$Companion; - public abstract fun compose (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun eitherToPValidated ()Larrow/optics/PIso; - public static fun eitherToValidated ()Larrow/optics/PIso; - public abstract fun first ()Larrow/optics/PIso; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; - public abstract fun left ()Larrow/optics/PIso; - public static fun listToOptionNel ()Larrow/optics/PIso; - public static fun listToPOptionNel ()Larrow/optics/PIso; - public static fun mapToSet ()Larrow/optics/PIso; - public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun nullableToOption ()Larrow/optics/PIso; - public static fun nullableToPOption ()Larrow/optics/PIso; - public static fun optionToEither ()Larrow/optics/PIso; - public static fun optionToNullable ()Larrow/optics/PIso; - public static fun optionToPEither ()Larrow/optics/PIso; - public static fun optionToPNullable ()Larrow/optics/PIso; - public abstract fun plus (Larrow/optics/PIso;)Larrow/optics/PIso; - public abstract fun reverse ()Larrow/optics/PIso; - public abstract fun reverseGet (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun right ()Larrow/optics/PIso; - public abstract fun second ()Larrow/optics/PIso; - public abstract fun set (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun split (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun stringToList ()Larrow/optics/PIso; - public static fun validatedToEither ()Larrow/optics/PIso; - public static fun validatedToPEither ()Larrow/optics/PIso; -} - -public final class arrow/optics/PIso$Companion { - public final fun eitherToPValidated ()Larrow/optics/PIso; - public final fun eitherToValidated ()Larrow/optics/PIso; - public final fun id ()Larrow/optics/PIso; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/optics/PIso; - public final fun listToOptionNel ()Larrow/optics/PIso; - public final fun listToPOptionNel ()Larrow/optics/PIso; - public final fun mapToSet ()Larrow/optics/PIso; - public final fun nullableToOption ()Larrow/optics/PIso; - public final fun nullableToPOption ()Larrow/optics/PIso; - public final fun optionToEither ()Larrow/optics/PIso; - public final fun optionToNullable ()Larrow/optics/PIso; - public final fun optionToPEither ()Larrow/optics/PIso; - public final fun optionToPNullable ()Larrow/optics/PIso; - public final fun stringToList ()Larrow/optics/PIso; - public final fun validatedToEither ()Larrow/optics/PIso; - public final fun validatedToPEither ()Larrow/optics/PIso; -} - -public final class arrow/optics/PIso$DefaultImpls { - public static fun all (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun choice (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun choice (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/PIso;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun choice (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun combineAll (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun compose (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/PIso;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun exists (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun first (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun firstOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun getOrModify (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/core/Either; - public static fun getOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun isEmpty (Larrow/optics/PIso;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/PIso;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun lift (Larrow/optics/PIso;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun liftNullable (Larrow/optics/PIso;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun modify (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun modifyNullable (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun plus (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/PIso;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun reverse (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun right (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun second (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun set (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun set (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun setNullable (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun size (Larrow/optics/PIso;Ljava/lang/Object;)I - public static fun split (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun split (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun split (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun zip (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; -} - -public abstract interface class arrow/optics/PLens : arrow/optics/Getter, arrow/optics/PEvery, arrow/optics/POptional, arrow/optics/PSetter, arrow/optics/PTraversal { +public abstract interface class arrow/optics/PLens : arrow/optics/POptional { public static final field Companion Larrow/optics/PLens$Companion; public abstract fun choice (Larrow/optics/PLens;)Larrow/optics/PLens; public abstract fun compose (Larrow/optics/PLens;)Larrow/optics/PLens; public abstract fun first ()Larrow/optics/PLens; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; public static fun nonEmptyListHead ()Larrow/optics/PLens; @@ -397,6 +64,7 @@ public abstract interface class arrow/optics/PLens : arrow/optics/Getter, arrow/ public abstract fun second ()Larrow/optics/PLens; public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun split (Larrow/optics/PLens;)Larrow/optics/PLens; + public static fun stringToList ()Larrow/optics/PLens; public static fun tripleFirst ()Larrow/optics/PLens; public static fun triplePFirst ()Larrow/optics/PLens; public static fun triplePSecond ()Larrow/optics/PLens; @@ -407,7 +75,7 @@ public abstract interface class arrow/optics/PLens : arrow/optics/Getter, arrow/ public final class arrow/optics/PLens$Companion { public final fun codiagonal ()Larrow/optics/PLens; - public final fun id ()Larrow/optics/PIso; + public final fun id ()Larrow/optics/PLens; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/PLens; public final fun nonEmptyListHead ()Larrow/optics/PLens; public final fun nonEmptyListTail ()Larrow/optics/PLens; @@ -415,6 +83,7 @@ public final class arrow/optics/PLens$Companion { public final fun pairPFirst ()Larrow/optics/PLens; public final fun pairPSecond ()Larrow/optics/PLens; public final fun pairSecond ()Larrow/optics/PLens; + public final fun stringToList ()Larrow/optics/PLens; public final fun tripleFirst ()Larrow/optics/PLens; public final fun triplePFirst ()Larrow/optics/PLens; public final fun triplePSecond ()Larrow/optics/PLens; @@ -426,75 +95,53 @@ public final class arrow/optics/PLens$Companion { public final class arrow/optics/PLens$DefaultImpls { public static fun all (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; public static fun choice (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun choice (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun combineAll (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun compose (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun compose (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun compose (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun compose (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun exists (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun findOrNull (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun first (Larrow/optics/PLens;)Larrow/optics/PLens; public static fun firstOrNull (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun fold (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PPrism;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; + public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrModify (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/core/Either; public static fun getOrNull (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/lang/Object; public static fun isEmpty (Larrow/optics/PLens;Ljava/lang/Object;)Z public static fun isNotEmpty (Larrow/optics/PLens;Ljava/lang/Object;)Z public static fun lastOrNull (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PLens;)Larrow/optics/Getter; public static fun lift (Larrow/optics/PLens;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun modify (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun plus (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun plus (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun plus (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun plus (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/PLens;)Larrow/optics/Getter; public static fun second (Larrow/optics/PLens;)Larrow/optics/PLens; public static fun setNullable (Larrow/optics/PLens;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun size (Larrow/optics/PLens;Ljava/lang/Object;)I - public static fun split (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; public static fun split (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun zip (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; } -public abstract interface class arrow/optics/POptional : arrow/optics/PEvery, arrow/optics/POptionalGetter, arrow/optics/PSetter, arrow/optics/PTraversal { +public abstract interface class arrow/optics/POptional : arrow/optics/PTraversal { public static final field Companion Larrow/optics/POptional$Companion; public abstract fun choice (Larrow/optics/POptional;)Larrow/optics/POptional; public abstract fun compose (Larrow/optics/POptional;)Larrow/optics/POptional; public abstract fun first ()Larrow/optics/POptional; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; + public abstract fun getOrNull (Ljava/lang/Object;)Ljava/lang/Object; public static fun listHead ()Larrow/optics/POptional; public static fun listTail ()Larrow/optics/POptional; public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun modifyNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun notNull ()Larrow/optics/POptional; public static fun nullable ()Larrow/optics/POptional; public abstract fun plus (Larrow/optics/POptional;)Larrow/optics/POptional; public abstract fun second ()Larrow/optics/POptional; @@ -504,10 +151,11 @@ public abstract interface class arrow/optics/POptional : arrow/optics/PEvery, ar public final class arrow/optics/POptional$Companion { public final fun codiagonal ()Larrow/optics/POptional; - public final fun id ()Larrow/optics/PIso; + public final fun id ()Larrow/optics/POptional; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/POptional; public final fun listHead ()Larrow/optics/POptional; public final fun listTail ()Larrow/optics/POptional; + public final fun notNull ()Larrow/optics/POptional; public final fun nullable ()Larrow/optics/POptional; public final fun void ()Larrow/optics/POptional; } @@ -515,109 +163,42 @@ public final class arrow/optics/POptional$Companion { public final class arrow/optics/POptional$DefaultImpls { public static fun all (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun choice (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun combineAll (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun compose (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun compose (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun exists (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun findOrNull (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun first (Larrow/optics/POptional;)Larrow/optics/POptional; public static fun firstOrNull (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun fold (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PPrism;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; + public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrNull (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/lang/Object; public static fun isEmpty (Larrow/optics/POptional;Ljava/lang/Object;)Z public static fun isNotEmpty (Larrow/optics/POptional;Ljava/lang/Object;)Z public static fun lastOrNull (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/POptional;)Larrow/optics/Fold; public static fun lift (Larrow/optics/POptional;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun modify (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun plus (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun plus (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/POptional;)Larrow/optics/Fold; public static fun second (Larrow/optics/POptional;)Larrow/optics/POptional; public static fun setNullable (Larrow/optics/POptional;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun size (Larrow/optics/POptional;Ljava/lang/Object;)I } -public abstract interface class arrow/optics/POptionalGetter : arrow/optics/Fold { - public static final field Companion Larrow/optics/POptionalGetter$Companion; - public abstract fun choice (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public abstract fun compose (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; - public abstract fun first ()Larrow/optics/POptionalGetter; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; - public abstract fun getOrNull (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun plus (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public abstract fun second ()Larrow/optics/POptionalGetter; -} - -public final class arrow/optics/POptionalGetter$Companion { - public final fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; - public final fun id ()Larrow/optics/PIso; - public final fun invoke (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; -} - -public final class arrow/optics/POptionalGetter$DefaultImpls { - public static fun all (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/POptionalGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/POptionalGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun combineAll (Larrow/optics/POptionalGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/POptionalGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/POptionalGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun exists (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun first (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun firstOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/POptionalGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/POptionalGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/util/List; - public static fun getOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun isEmpty (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/POptionalGetter;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/POptionalGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/POptionalGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun right (Larrow/optics/POptionalGetter;)Larrow/optics/Fold; - public static fun second (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun size (Larrow/optics/POptionalGetter;Ljava/lang/Object;)I -} - -public abstract interface class arrow/optics/PPrism : arrow/optics/PEvery, arrow/optics/POptional, arrow/optics/POptionalGetter, arrow/optics/PSetter, arrow/optics/PTraversal { +public abstract interface class arrow/optics/PPrism : arrow/optics/POptional { public static final field Companion Larrow/optics/PPrism$Companion; public abstract fun compose (Larrow/optics/PPrism;)Larrow/optics/PPrism; public static fun eitherLeft ()Larrow/optics/PPrism; public static fun eitherRight ()Larrow/optics/PPrism; public abstract fun first ()Larrow/optics/PPrism; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; public abstract fun left ()Larrow/optics/PPrism; public abstract fun liftNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; @@ -637,7 +218,7 @@ public abstract interface class arrow/optics/PPrism : arrow/optics/PEvery, arrow public final class arrow/optics/PPrism$Companion { public final fun eitherLeft ()Larrow/optics/PPrism; public final fun eitherRight ()Larrow/optics/PPrism; - public final fun id ()Larrow/optics/PIso; + public final fun id ()Larrow/optics/PPrism; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/optics/PPrism; public final fun none ()Larrow/optics/PPrism; public final fun only (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Larrow/optics/PPrism; @@ -651,34 +232,21 @@ public final class arrow/optics/PPrism$Companion { public final class arrow/optics/PPrism$DefaultImpls { public static fun all (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun choice (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun combineAll (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun compose (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun compose (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun exists (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun findOrNull (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun first (Larrow/optics/PPrism;)Larrow/optics/PPrism; public static fun firstOrNull (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun fold (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; + public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrNull (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/lang/Object; public static fun isEmpty (Larrow/optics/PPrism;Ljava/lang/Object;)Z @@ -689,12 +257,8 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun liftNullable (Larrow/optics/PPrism;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun modify (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun plus (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun plus (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun right (Larrow/optics/PPrism;)Larrow/optics/PPrism; public static fun second (Larrow/optics/PPrism;)Larrow/optics/PPrism; @@ -703,41 +267,27 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun size (Larrow/optics/PPrism;Ljava/lang/Object;)I } -public abstract interface class arrow/optics/PSetter { - public static final field Companion Larrow/optics/PSetter$Companion; - public abstract fun choice (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun compose (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun plus (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/optics/PSetter$Companion { - public final fun codiagonal ()Larrow/optics/PSetter; - public final fun id ()Larrow/optics/PSetter; -} - -public final class arrow/optics/PSetter$DefaultImpls { - public static fun choice (Larrow/optics/PSetter;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun compose (Larrow/optics/PSetter;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun lift (Larrow/optics/PSetter;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun plus (Larrow/optics/PSetter;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun set (Larrow/optics/PSetter;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class arrow/optics/PTraversal : arrow/optics/PSetter { +public abstract interface class arrow/optics/PTraversal { public static final field Companion Larrow/optics/PTraversal$Companion; + public abstract fun all (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public abstract fun any (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public abstract fun choice (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public abstract fun compose (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun either ()Larrow/optics/PTraversal; - public abstract fun getEvery (Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public abstract fun getEvery (Larrow/optics/PIso;)Larrow/optics/PTraversal; + public abstract fun exists (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public abstract fun findOrNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun firstOrNull (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun getAll (Ljava/lang/Object;)Ljava/util/List; public abstract fun getEvery (Larrow/optics/PLens;)Larrow/optics/PTraversal; public abstract fun getEvery (Larrow/optics/POptional;)Larrow/optics/PTraversal; public abstract fun getEvery (Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public abstract fun getEvery (Larrow/optics/PSetter;)Larrow/optics/PSetter; public abstract fun getEvery (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public abstract fun isEmpty (Ljava/lang/Object;)Z + public abstract fun isNotEmpty (Ljava/lang/Object;)Z + public abstract fun lastOrNull (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun list ()Larrow/optics/PTraversal; public static fun map ()Larrow/optics/PTraversal; public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -745,7 +295,6 @@ public abstract interface class arrow/optics/PTraversal : arrow/optics/PSetter { public static fun option ()Larrow/optics/PTraversal; public static fun pPair ()Larrow/optics/PTraversal; public static fun pTriple ()Larrow/optics/PTraversal; - public static fun pTuple10 ()Larrow/optics/PTraversal; public static fun pTuple4 ()Larrow/optics/PTraversal; public static fun pTuple5 ()Larrow/optics/PTraversal; public static fun pTuple6 ()Larrow/optics/PTraversal; @@ -755,9 +304,10 @@ public abstract interface class arrow/optics/PTraversal : arrow/optics/PSetter { public static fun pair ()Larrow/optics/PTraversal; public abstract fun plus (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun sequence ()Larrow/optics/PTraversal; + public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun size (Ljava/lang/Object;)I public static fun string ()Larrow/optics/PTraversal; public static fun triple ()Larrow/optics/PTraversal; - public static fun tuple10 ()Larrow/optics/PTraversal; public static fun tuple4 ()Larrow/optics/PTraversal; public static fun tuple5 ()Larrow/optics/PTraversal; public static fun tuple6 ()Larrow/optics/PTraversal; @@ -785,7 +335,6 @@ public final class arrow/optics/PTraversal$Companion { public final fun option ()Larrow/optics/PTraversal; public final fun pPair ()Larrow/optics/PTraversal; public final fun pTriple ()Larrow/optics/PTraversal; - public final fun pTuple10 ()Larrow/optics/PTraversal; public final fun pTuple4 ()Larrow/optics/PTraversal; public final fun pTuple5 ()Larrow/optics/PTraversal; public final fun pTuple6 ()Larrow/optics/PTraversal; @@ -796,7 +345,6 @@ public final class arrow/optics/PTraversal$Companion { public final fun sequence ()Larrow/optics/PTraversal; public final fun string ()Larrow/optics/PTraversal; public final fun triple ()Larrow/optics/PTraversal; - public final fun tuple10 ()Larrow/optics/PTraversal; public final fun tuple4 ()Larrow/optics/PTraversal; public final fun tuple5 ()Larrow/optics/PTraversal; public final fun tuple6 ()Larrow/optics/PTraversal; @@ -807,21 +355,26 @@ public final class arrow/optics/PTraversal$Companion { } public final class arrow/optics/PTraversal$DefaultImpls { - public static fun choice (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; + public static fun all (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun any (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun choice (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun compose (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PIso;)Larrow/optics/PTraversal; + public static fun exists (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun findOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun firstOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/lang/Object; + public static fun fold (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; + public static fun getAll (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/util/List; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PLens;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/POptional;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun isEmpty (Larrow/optics/PTraversal;Ljava/lang/Object;)Z + public static fun isNotEmpty (Larrow/optics/PTraversal;Ljava/lang/Object;)Z + public static fun lastOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/lang/Object; public static fun lift (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun plus (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun set (Larrow/optics/PTraversal;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun size (Larrow/optics/PTraversal;Ljava/lang/Object;)I } public final class arrow/optics/PrismKt { @@ -829,13 +382,8 @@ public final class arrow/optics/PrismKt { } public final class arrow/optics/dsl/AtKt { - public static final fun at (Larrow/optics/Fold;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/Fold; - public static final fun at (Larrow/optics/Getter;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/Getter; - public static final fun at (Larrow/optics/PIso;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PLens; public static final fun at (Larrow/optics/PLens;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PLens; public static final fun at (Larrow/optics/POptional;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun at (Larrow/optics/PPrism;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun at (Larrow/optics/PSetter;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PSetter; public static final fun at (Larrow/optics/PTraversal;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PTraversal; } @@ -849,44 +397,28 @@ public final class arrow/optics/dsl/EitherKt { } public final class arrow/optics/dsl/EveryKt { - public static final fun every (Larrow/optics/Fold;Larrow/optics/PEvery;)Larrow/optics/Fold; - public static final fun every (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/PSetter;Larrow/optics/PEvery;)Larrow/optics/PSetter; - public static final fun every (Larrow/optics/PTraversal;Larrow/optics/PEvery;)Larrow/optics/PTraversal; + public static final fun every (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; } public final class arrow/optics/dsl/IndexKt { - public static final fun index (Larrow/optics/Fold;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/Fold; - public static final fun index (Larrow/optics/PIso;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun index (Larrow/optics/PLens;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; public static final fun index (Larrow/optics/POptional;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun index (Larrow/optics/PPrism;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun index (Larrow/optics/PSetter;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/PSetter; public static final fun index (Larrow/optics/PTraversal;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/PTraversal; } +public final class arrow/optics/dsl/NullableKt { + public static final fun getNotNull (Larrow/optics/POptional;)Larrow/optics/POptional; + public static final fun getNotNull (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; +} + public final class arrow/optics/dsl/OptionKt { - public static final fun getSome (Larrow/optics/Fold;)Larrow/optics/Fold; - public static final fun getSome (Larrow/optics/PIso;)Larrow/optics/PPrism; - public static final fun getSome (Larrow/optics/PLens;)Larrow/optics/POptional; public static final fun getSome (Larrow/optics/POptional;)Larrow/optics/POptional; - public static final fun getSome (Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static final fun getSome (Larrow/optics/PSetter;)Larrow/optics/PSetter; public static final fun getSome (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; } public abstract interface class arrow/optics/typeclasses/At { public static final field Companion Larrow/optics/typeclasses/At$Companion; - public abstract fun at (Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public abstract fun at (Larrow/optics/Getter;Ljava/lang/Object;)Larrow/optics/Getter; - public abstract fun at (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/PLens; public abstract fun at (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/PLens; public abstract fun at (Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun at (Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun at (Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public abstract fun at (Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; public abstract fun at (Ljava/lang/Object;)Larrow/optics/PLens; public static fun map ()Larrow/optics/typeclasses/At; @@ -894,19 +426,13 @@ public abstract interface class arrow/optics/typeclasses/At { } public final class arrow/optics/typeclasses/At$Companion { - public final fun fromIso (Larrow/optics/typeclasses/At;Larrow/optics/PIso;)Larrow/optics/typeclasses/At; public final fun map ()Larrow/optics/typeclasses/At; public final fun set ()Larrow/optics/typeclasses/At; } public final class arrow/optics/typeclasses/At$DefaultImpls { - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/Getter;Ljava/lang/Object;)Larrow/optics/Getter; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/PLens; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/PLens; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; } @@ -927,7 +453,6 @@ public abstract interface class arrow/optics/typeclasses/Cons { } public final class arrow/optics/typeclasses/Cons$Companion { - public final fun fromIso (Larrow/optics/typeclasses/Cons;Larrow/optics/PIso;)Larrow/optics/typeclasses/Cons; public final fun invoke (Larrow/optics/PPrism;)Larrow/optics/typeclasses/Cons; public final fun list ()Larrow/optics/typeclasses/Cons; public final fun string ()Larrow/optics/typeclasses/Cons; @@ -942,7 +467,7 @@ public final class arrow/optics/typeclasses/Cons$DefaultImpls { public abstract interface class arrow/optics/typeclasses/FilterIndex { public static final field Companion Larrow/optics/typeclasses/FilterIndex$Companion; - public abstract fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/PEvery; + public abstract fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/PTraversal; public static fun list ()Larrow/optics/typeclasses/FilterIndex; public static fun map ()Larrow/optics/typeclasses/FilterIndex; public static fun nonEmptyList ()Larrow/optics/typeclasses/FilterIndex; @@ -951,7 +476,6 @@ public abstract interface class arrow/optics/typeclasses/FilterIndex { } public final class arrow/optics/typeclasses/FilterIndex$Companion { - public final fun fromIso (Larrow/optics/typeclasses/FilterIndex;Larrow/optics/PIso;)Larrow/optics/typeclasses/FilterIndex; public final fun list ()Larrow/optics/typeclasses/FilterIndex; public final fun map ()Larrow/optics/typeclasses/FilterIndex; public final fun nonEmptyList ()Larrow/optics/typeclasses/FilterIndex; @@ -961,19 +485,9 @@ public final class arrow/optics/typeclasses/FilterIndex$Companion { public abstract interface class arrow/optics/typeclasses/Index { public static final field Companion Larrow/optics/typeclasses/Index$Companion; - public abstract fun get (Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public abstract fun get (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun get (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public abstract fun get (Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun get (Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun get (Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public abstract fun get (Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; - public abstract fun index (Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public abstract fun index (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun index (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public abstract fun index (Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun index (Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun index (Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public abstract fun index (Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; public abstract fun index (Ljava/lang/Object;)Larrow/optics/POptional; public static fun list ()Larrow/optics/typeclasses/Index; @@ -984,7 +498,6 @@ public abstract interface class arrow/optics/typeclasses/Index { } public final class arrow/optics/typeclasses/Index$Companion { - public final fun fromIso (Larrow/optics/typeclasses/Index;Larrow/optics/PIso;)Larrow/optics/typeclasses/Index; public final fun list ()Larrow/optics/typeclasses/Index; public final fun map ()Larrow/optics/typeclasses/Index; public final fun nonEmptyList ()Larrow/optics/typeclasses/Index; @@ -993,19 +506,9 @@ public final class arrow/optics/typeclasses/Index$Companion { } public final class arrow/optics/typeclasses/Index$DefaultImpls { - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; } @@ -1022,7 +525,6 @@ public abstract interface class arrow/optics/typeclasses/Snoc { } public final class arrow/optics/typeclasses/Snoc$Companion { - public final fun fromIso (Larrow/optics/typeclasses/Snoc;Larrow/optics/PIso;)Larrow/optics/typeclasses/Snoc; public final fun invoke (Larrow/optics/PPrism;)Larrow/optics/typeclasses/Snoc; public final fun list ()Larrow/optics/typeclasses/Snoc; public final fun string ()Larrow/optics/typeclasses/Snoc; diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt index 2ed1cb1edec..194061d594d 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt @@ -9,9 +9,6 @@ import arrow.core.Tuple6 import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 -import arrow.core.fold -import arrow.core.foldMap -import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic public object Every { @@ -19,14 +16,7 @@ public object Every { * [Traversal] for [List] that focuses in each [A] of the source [List]. */ @JvmStatic - public fun list(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: List, map: (focus: A) -> A): List = - source.map(map) - - override fun foldMap(M: Monoid, source: List, map: (focus: A) -> R): R = - source.foldMap(M, map) - } + public fun list(): Traversal, A> = Traversal.list() /** * [Traversal] for [Either] that has focus in each [Either.Right]. @@ -36,27 +26,11 @@ public object Every { */ @JvmStatic public fun either(): Traversal, R> = - object : Traversal, R> { - override fun modify(source: Either, map: (focus: R) -> R): Either = - source.map(map) - - override fun foldMap(M: Monoid, source: Either, map: (focus: R) -> A): A = - source.fold({ M.empty() }, map) - } + Traversal.either() @JvmStatic public fun map(): Traversal, V> = - object : Traversal, V> { - override fun modify(source: Map, map: (focus: V) -> V): Map = - source.mapValues { (_, v) -> map(v) } - - override fun foldMap(M: Monoid, source: Map, map: (focus: V) -> R): R = - M.run { - source.fold(empty()) { acc, (_, v) -> - acc.combine(map(v))} - } - } - + Traversal.map() /** * [Traversal] for [NonEmptyList] that has focus in each [A]. @@ -66,13 +40,7 @@ public object Every { */ @JvmStatic public fun nonEmptyList(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: NonEmptyList, map: (focus: A) -> A): NonEmptyList = - source.map(map) - - override fun foldMap(M: Monoid, source: NonEmptyList, map: (focus: A) -> R): R = - source.foldMap(M, map) - } + Traversal.nonEmptyList() /** * [Traversal] for [Option] that has focus in each [arrow.core.Some]. @@ -82,24 +50,11 @@ public object Every { */ @JvmStatic public fun option(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Option, map: (focus: A) -> A): Option = - source.map(map) - - override fun foldMap(M: Monoid, source: Option, map: (focus: A) -> R): R = - source.fold({ M.empty() }, map) - } + Traversal.option() @JvmStatic public fun sequence(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Sequence, map: (focus: A) -> A): Sequence = - source.map(map) - - override fun foldMap(M: Monoid, source: Sequence, map: (focus: A) -> R): R = - - source.foldMap(M, map) - } + Traversal.sequence() /** * [Traversal] for [String] that focuses in each [Char] of the source [String]. @@ -109,166 +64,61 @@ public object Every { */ @JvmStatic public fun string(): Traversal = - object : Traversal { - override fun modify(source: String, map: (focus: Char) -> Char): String = - source.map(map).joinToString(separator = "") - - override fun foldMap(M: Monoid, source: String, map: (focus: Char) -> R): R = - M.run { - source.fold(empty()) { acc, char -> acc.combine(map(char)) } - } - } + Traversal.string() /** * [Traversal] to focus into the first and second value of a [Pair] */ @JvmStatic public fun pair(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Pair, map: (focus: A) -> A): Pair = - Pair(map(source.first), map(source.second)) - - override fun foldMap(M: Monoid, source: Pair, map: (focus: A) -> R): R = - listOf(source.first, source.second) - .foldMap(M, map) - } + Traversal.pair() /** * [Traversal] to focus into the first, second and third value of a [Triple] */ @JvmStatic public fun triple(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Triple, map: (focus: A) -> A): Triple = - Triple(map(source.first), map(source.second), map(source.third)) - - override fun foldMap(M: Monoid, source: Triple, map: (focus: A) -> R): R = - listOf(source.first, source.second, source.third) - .foldMap(M, map) - } + Traversal.triple() /** * [Traversal] to focus into the first, second, third and fourth value of a [arrow.core.Tuple4] */ @JvmStatic public fun tuple4(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Tuple4, map: (focus: A) -> A): Tuple4 = - Tuple4(map(source.first), map(source.second), map(source.third), map(source.fourth)) - - override fun foldMap(M: Monoid, source: Tuple4, map: (focus: A) -> R): R = - listOf(source.first, source.second, source.third, source.fourth) - .foldMap(M, map) - } + Traversal.tuple4() /** * [PTraversal] to focus into the first, second, third, fourth and fifth value of a [arrow.core.Tuple5] */ @JvmStatic public fun tuple5(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Tuple5, map: (focus: A) -> A): Tuple5 = - Tuple5(map(source.first), map(source.second), map(source.third), map(source.fourth), map(source.fifth)) - - override fun foldMap(M: Monoid, source: Tuple5, map: (focus: A) -> R): R = - listOf(source.first, source.second, source.third, source.fourth, source.fifth) - .foldMap(M, map) - } + Traversal.tuple5() /** * [Traversal] to focus into the first, second, third, fourth, fifth and sixth value of a [arrow.core.Tuple6] */ @JvmStatic public fun tuple6(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Tuple6, map: (focus: A) -> A): Tuple6 = - Tuple6( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth) - ) - - override fun foldMap(M: Monoid, source: Tuple6, map: (focus: A) -> R): R = - listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth) - .foldMap(M, map) - } + Traversal.tuple6() /** * [Traversal] to focus into the first, second, third, fourth, fifth, sixth and seventh value of a [arrow.core.Tuple7] */ @JvmStatic public fun tuple7(): Traversal, A> = - object : Traversal, A> { - override fun modify(source: Tuple7, map: (focus: A) -> A): Tuple7 = - Tuple7( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh) - ) - - override fun foldMap(M: Monoid, source: Tuple7, map: (focus: A) -> R): R = - listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh) - .foldMap(M, map) - } + Traversal.tuple7() /** * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh and eight value of a [arrow.core.Tuple8] */ @JvmStatic public fun tuple8(): Traversal, A> = - object : Traversal, A> { - override fun modify( - source: Tuple8, - map: (focus: A) -> A - ): Tuple8 = - Tuple8( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh), - map(source.eighth) - ) - - override fun foldMap(M: Monoid, source: Tuple8, map: (focus: A) -> R): R = - listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth) - .foldMap(M, map) - } + Traversal.tuple8() /** * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight and ninth value of a [arrow.core.Tuple9] */ @JvmStatic public fun tuple9(): Traversal, A> = - object : Traversal, A> { - override fun modify( - source: Tuple9, - map: (focus: A) -> A - ): Tuple9 = - Tuple9( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh), - map(source.eighth), - map(source.ninth) - ) - - override fun foldMap(M: Monoid, source: Tuple9, map: (focus: A) -> R): R = - listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth, source.ninth) - .foldMap(M, map) - } - + Traversal.tuple9() } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt index c4d9ac0cd8e..2f9b0a42d7a 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt @@ -3,7 +3,6 @@ package arrow.optics import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.identity -import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic /** @@ -37,7 +36,7 @@ public interface PLens : POptional { override fun getOrModify(source: S): Either = Either.Right(get(source)) - override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R = + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = map(get(source)) /** diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt index ce56e2240a5..1f720a17469 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt @@ -9,7 +9,6 @@ import arrow.core.getOrElse import arrow.core.identity import arrow.core.prependTo import arrow.core.toOption -import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic /** @@ -78,8 +77,8 @@ public interface POptional : PTraversal { public fun getOrNull(source: S): A? = getOrModify(source).getOrNull() - override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R = - getOrModify(source).map(map).getOrElse { M.empty() } + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + getOrModify(source).map(map).getOrElse { initial } /** * Modify the focus of a [POptional] with a function [map] diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index 93e005c51b5..6ce60de76c8 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -11,7 +11,6 @@ import arrow.core.flatMap import arrow.core.identity import arrow.core.left import arrow.core.right -import arrow.typeclasses.Monoid import kotlin.jvm.JvmName import kotlin.jvm.JvmStatic @@ -43,8 +42,8 @@ public interface PPrism : POptional { public fun reverseGet(focus: B): T - override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R = - getOrNull(source)?.let(map) ?: M.empty() + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + getOrNull(source)?.let(map) ?: initial /** * Modify the focus of a [PPrism] with a function diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt index dbc8591f8bc..a38d61cc1d9 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt @@ -10,7 +10,6 @@ import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 import arrow.core.identity -import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic /** @@ -35,7 +34,8 @@ public interface PTraversal { /** * Map each target to a type R and use a Monoid to fold the results */ - public fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R + public fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R + /** * Modify polymorphically the focus of a [PTraversal] with a function [map]. @@ -59,15 +59,19 @@ public interface PTraversal { */ public fun choice(other: PTraversal): PTraversal, Either, A, B> = object : PTraversal, Either, A, B> { - override fun foldMap(M: Monoid, source: Either, map: (A) -> R): R = - source.fold( - { a -> this@PTraversal.foldMap(M, a, map) }, - { u -> other.foldMap(M, u, map) } - ) + override fun foldMap( + initial: R, + combine: (R, R) -> R, + source: Either, + map: (focus: A) -> R + ): R = source.fold( + { a -> this@PTraversal.foldMap(initial, combine, a, map) }, + { u -> other.foldMap(initial, combine, u, map) } + ) override fun modify(source: Either, map: (focus: A) -> B): Either = source.fold( - { a -> Either.Left(this.modify(a, map)) }, + { a -> Either.Left(this@PTraversal.modify(a, map)) }, { u -> Either.Right(other.modify(u, map)) } ) } @@ -77,11 +81,11 @@ public interface PTraversal { */ public infix fun compose(other: PTraversal): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, source: S, map: (C) -> R): R = - this@PTraversal.foldMap(M, source) { c -> other.foldMap(M, c, map) } + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: C) -> R): R = + this@PTraversal.foldMap(initial, combine, source) { c -> other.foldMap(initial, combine, c, map) } override fun modify(source: S, map: (focus: C) -> D): T = - this.modify(source) { b -> other.modify(b, map) } + this@PTraversal.modify(source) { b -> other.modify(b, map) } } public operator fun plus(other: PTraversal): PTraversal = @@ -91,25 +95,25 @@ public interface PTraversal { * Calculate the number of targets */ public fun size(source: S): Int = - foldMap(Monoid.int(), source) { 1 } + foldMap(0, Int::plus, source) { 1 } /** * Check if all targets satisfy the predicate */ public fun all(source: S, predicate: (focus: A) -> Boolean): Boolean = - foldMap(Monoid.boolean(), source, predicate) + foldMap(true, Boolean::and, source, predicate) /** * Returns `true` if at least one focus matches the given [predicate]. */ public fun any(source: S, predicate: (focus: A) -> Boolean): Boolean = - foldMap(Monoid.booleanOr(), source, predicate) + foldMap(false, Boolean::or, source, predicate) /** * Check if there is no target */ public fun isEmpty(source: S): Boolean = - foldMap(Monoid.boolean(), source) { false } + foldMap(true, { _, _ -> false }, source) { false } /** * Check if there is at least one target @@ -120,75 +124,44 @@ public interface PTraversal { /** * Get the first target or null */ - @Suppress("UNCHECKED_CAST") - public fun firstOrNull(source: S): A? { - val fold = ::fold as (Monoid, S) -> Any? - val res = fold(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (a === EMPTY_VALUE) b else a - }, source) - return EMPTY_VALUE.unbox(res) - } + public fun firstOrNull(source: S): A? = + EMPTY_VALUE.unbox(foldMap(EMPTY_VALUE, { x, y -> if (x === EMPTY_VALUE) y else x }, source, ::identity)) /** * Get the last target or null */ - @Suppress("UNCHECKED_CAST") - public fun lastOrNull(source: S): A? { - val fold = ::fold as (Monoid, S) -> Any? - val res = fold(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (b !== EMPTY_VALUE) b else a - }, source) - return EMPTY_VALUE.unbox(res) - } - - /** - * Fold using the given [Monoid] instance. - */ - public fun fold(M: Monoid<@UnsafeVariance A>, source: S): A = - foldMap(M, source, ::identity) + public fun lastOrNull(source: S): A? = + EMPTY_VALUE.unbox(foldMap(EMPTY_VALUE, { x, y -> if (y != EMPTY_VALUE) y else x }, source, ::identity)) /** - * Alias for fold. + * Fold using the given [initial] value and [combine] function. */ - @Deprecated("use fold instead", ReplaceWith("fold(M, source)")) - public fun combineAll(M: Monoid<@UnsafeVariance A>, source: S): A = - fold(M, source) + public fun fold(initial: A, combine: (A, A) -> A, source: S): A = + foldMap(initial, combine, source, ::identity) /** * Get all targets of the [Traversal] */ public fun getAll(source: S): List = - foldMap(Monoid.list(), source, ::listOf) + foldMap(emptyList(), { x, y -> x + y }, source) { listOf(it) } /** * Find the first element matching the predicate, if one exists. */ - public fun findOrNull(source: S, predicate: (focus: A) -> Boolean): A? { - val res = foldMap(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (a === EMPTY_VALUE) b else a - }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } - return EMPTY_VALUE.unbox(res) - } + public fun findOrNull(source: S, predicate: (focus: A) -> Boolean): A? = + EMPTY_VALUE.unbox( + foldMap(EMPTY_VALUE, { x, y -> if (x == EMPTY_VALUE) y else x }, source) { focus -> + if (predicate(focus)) focus else EMPTY_VALUE + } + ) /** * Check whether at least one element satisfies the predicate. * * If there are no elements, the result is false. */ - public fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean { - val res = foldMap(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (a === EMPTY_VALUE) b else a - }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } - return res !== EMPTY_VALUE - } + public fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean = + any(source, predicate) public companion object { @@ -196,16 +169,16 @@ public interface PTraversal { public fun codiagonal(): Traversal, S> = object : Traversal, S> { - override fun foldMap(M: Monoid, source: Either, map: (focus: S) -> R): R = + override fun foldMap(initial: R, combine: (R, R) -> R, source: Either, map: (focus: S) -> R): R = source.fold( { a -> map(a) }, { u -> map(u) } ) override fun modify(source: Either, map: (focus: S) -> S): Either = - source.bimap(map, map) + source.map(map).mapLeft(map) } - // Traversal { s, f -> s.mapLeft(f).map(f) } + // Traversal { s, f -> s.mapLeft(f).map(f) } /** * [PTraversal] that points to nothing @@ -222,10 +195,11 @@ public interface PTraversal { set: (B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)))) - override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), s) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine(f(get1(s)), f(get2(s))) + + override fun modify(s: S, transform: (focus: A) -> B): T = + set(transform(get1(s)), transform(get2(s)), s) } public operator fun invoke( @@ -235,8 +209,9 @@ public interface PTraversal { set: (B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine(combine(f(get1(s)), f(get2(s))), f(get3(s))) + override fun modify(s: S, f: (focus: A) -> B): T = set(f(get1(s)), f(get2(s)), f(get3(s)), s) } @@ -249,8 +224,9 @@ public interface PTraversal { set: (B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get4(s))) + override fun modify(s: S, f: (focus: A) -> B): T = set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), s) } @@ -264,8 +240,9 @@ public interface PTraversal { set: (B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))) + override fun modify(s: S, f: (focus: A) -> B): T = set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), s) } @@ -280,8 +257,9 @@ public interface PTraversal { set: (B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine(combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), f(get6(s))) + override fun modify(s: S, f: (focus: A) -> B): T = set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), s) } @@ -297,8 +275,12 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine( + combine(combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), f(get6(s))), + f(get7(s)) + ) + override fun modify(s: S, f: (focus: A) -> B): T = set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), s) } @@ -315,8 +297,16 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine( + combine( + combine( + combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), + f(get6(s)) + ), f(get7(s)) + ), f(get8(s)) + ) + override fun modify(s: S, f: (focus: A) -> B): T = set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), s) } @@ -334,10 +324,31 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine( + combine( + combine( + combine( + combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), + f(get6(s)) + ), f(get7(s)) + ), f(get8(s)) + ), f(get9(s)) + ) + override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), s) + set( + f(get1(s)), + f(get2(s)), + f(get3(s)), + f(get4(s)), + f(get5(s)), + f(get6(s)), + f(get7(s)), + f(get8(s)), + f(get9(s)), + s + ) } public operator fun invoke( @@ -354,10 +365,36 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = - M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), f(get10(s)))) + override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + combine( + combine( + combine( + combine( + combine( + combine( + combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), + f(get5(s)) + ), f(get6(s)) + ), f(get7(s)) + ), f(get8(s)) + ), f(get9(s)) + ), f(get10(s)) + ) + override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), f(get10(s)), s) + set( + f(get1(s)), + f(get2(s)), + f(get3(s)), + f(get4(s)), + f(get5(s)), + f(get6(s)), + f(get7(s)), + f(get8(s)), + f(get9(s)), + f(get10(s)), + s + ) } /** diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt index d388ecd9b19..90fb95731ab 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt @@ -6,7 +6,6 @@ import arrow.core.toNonEmptyListOrNull import arrow.optics.Every import arrow.optics.PLens import arrow.optics.Traversal -import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic /** @@ -32,9 +31,8 @@ public fun interface FilterIndex { public fun list(): FilterIndex, Int, A> = FilterIndex { p -> object : Traversal, A> { - override fun foldMap(M: Monoid, source: List, map: (A) -> R): R = M.run { - source.foldIndexed(empty()) { index, acc, a -> if (p(index)) acc.combine(map(a)) else acc } - } + override fun foldMap(initial: R, combine: (R, R) -> R, source: List, map: (A) -> R): R = + source.foldIndexed(initial) { index, acc, a -> if (p(index)) combine(acc, map(a)) else acc } override fun modify(source: List, map: (focus: A) -> A): List = source.mapIndexed { index, a -> if (p(index)) map(a) else a } @@ -45,11 +43,10 @@ public fun interface FilterIndex { public fun map(): FilterIndex, K, V> = FilterIndex { p -> object : Traversal, V> { - override fun foldMap(M: Monoid, source: Map, map: (V) -> R): R = M.run { - source.entries.fold(empty()) { acc, (k, v) -> - if (p(k)) acc.combine(map(v)) else acc + override fun foldMap(initial: R, combine: (R, R) -> R, source: Map, map: (V) -> R): R = + source.entries.fold(initial) { acc, (k, v) -> + if (p(k)) combine(acc, map(v)) else acc } - } override fun modify(source: Map, map: (focus: V) -> V): Map = source.mapValues { (k, v) -> if (p(k)) map(v) else v } @@ -63,11 +60,10 @@ public fun interface FilterIndex { public fun nonEmptyList(): FilterIndex, Int, A> = FilterIndex { p -> object : Traversal, A> { - override fun foldMap(M: Monoid, source: NonEmptyList, map: (A) -> R): R = M.run { - source.foldIndexed(empty()) { index, acc, r -> - if (p(index)) acc.combine(map(r)) else acc + override fun foldMap(initial: R, combine: (R, R) -> R, source: NonEmptyList, map: (A) -> R): R = + source.foldIndexed(initial) { index, acc, r -> + if (p(index)) combine(acc, map(r)) else acc } - } override fun modify(source: NonEmptyList, map: (focus: A) -> A): NonEmptyList = source.mapIndexed { index, a -> if (p(index)) map(a) else a }.toNonEmptyListOrNull() @@ -79,11 +75,10 @@ public fun interface FilterIndex { public fun sequence(): FilterIndex, Int, A> = FilterIndex { p -> object : Traversal, A> { - override fun foldMap(M: Monoid, source: Sequence, map: (A) -> R): R = M.run { - source.foldIndexed(empty()) { index, acc, a -> - if (p(index)) acc.combine(map(a)) else acc + override fun foldMap(initial: R, combine: (R, R) -> R, source: Sequence, map: (A) -> R): R = + source.foldIndexed(initial) { index, acc, a -> + if (p(index)) combine(acc, map(a)) else acc } - } override fun modify(source: Sequence, map: (focus: A) -> A): Sequence = source.mapIndexed { index, a -> if (p(index)) map(a) else a } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt index 125d64834b3..8d6ab4356e0 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt @@ -1,7 +1,6 @@ package arrow.optics.typeclasses import arrow.core.Either -import arrow.core.Nullable import arrow.core.left import arrow.core.right import arrow.optics.Optional @@ -69,7 +68,9 @@ public fun interface Snoc { Snoc { object : Prism, Pair, A>> { override fun getOrModify(source: List): Either, Pair, A>> = - Nullable.zip(source.dropLast(1), source.lastOrNull(), ::Pair)?.right() ?: source.left() + source.lastOrNull()?.let { last -> + Pair(source.dropLast(1), last) + }?.right() ?: source.left() override fun reverseGet(focus: Pair, A>): List = focus.first + focus.second diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt index c8cf0676b64..9ec3610600e 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt @@ -38,13 +38,6 @@ class LensTest : StringSpec({ aGen = Arb.token(), bGen = Arb.string(), funcGen = Arb.functionAToB(Arb.string()), - ), - - SetterLaws( - setter = Lens.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()), ) ) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt index 06d0083f67e..6ed820b71ce 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt @@ -22,13 +22,6 @@ class TraversalTest : StringSpec({ aGen = Arb.list(Arb.int()), bGen = Arb.int(), funcGen = Arb.functionAToB(Arb.int()), - ), - - SetterLaws( - setter = Traversal.list(), - aGen = Arb.list(Arb.int()), - bGen = Arb.int(), - funcGen = Arb.functionAToB(Arb.int()), ) ) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt index 225969060aa..f8f43972b4e 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt @@ -25,12 +25,6 @@ class ListTest : StringSpec({ aGen = Arb.list(Arb.int()), bGen = Arb.int(), funcGen = Arb.functionAToB(Arb.int()), - ), - SetterLaws( - setter = Optional.listHead(), - aGen = Arb.list(Arb.int()), - bGen = Arb.int(), - funcGen = Arb.functionAToB(Arb.int()), ) ) @@ -44,14 +38,4 @@ class ListTest : StringSpec({ ) ) - testLaws( - "Iso list to Option Nel - ", - IsoLaws( - iso = Iso.listToOptionNel(), - aGen = Arb.list(Arb.int()), - bGen = Arb.option(Arb.nonEmptyList(Arb.int())), - funcGen = Arb.functionAToB(Arb.option(Arb.nonEmptyList(Arb.int()))), - ) - ) - }) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt index feaa4684ec1..14cd7504033 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt @@ -31,25 +31,4 @@ class OptionTest : StringSpec({ funcGen = Arb.functionAToB(Arb.constant(Unit)), ) ) - - testLaws( - "Iso option to nullable - ", - IsoLaws( - iso = Iso.optionToNullable().reverse(), - aGen = Arb.int().orNull(), - bGen = Arb.option(Arb.int()), - funcGen = Arb.functionAToB(Arb.option(Arb.int())) - ) - ) - - testLaws( - "Iso option to either - ", - IsoLaws( - iso = Iso.optionToEither(), - aGen = Arb.option(Arb.int()), - bGen = Arb.either(Arb.constant(Unit), Arb.int()), - funcGen = Arb.functionAToB(Arb.either(Arb.constant(Unit), Arb.int())), - ) - ) - }) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt index 7def4fbd1e1..19cb340714f 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt @@ -94,7 +94,7 @@ class TupleTest : StringSpec({ testLaws( "Traversal tuple4 - ", - TraversalLaws.laws( + TraversalLaws( traversal = Traversal.tuple4(), aGen = Arb.tuple4(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), bGen = Arb.boolean(), @@ -104,7 +104,7 @@ class TupleTest : StringSpec({ testLaws( "Traversal tuple5 - ", - TraversalLaws.laws( + TraversalLaws( traversal = Traversal.tuple5(), aGen = Arb.tuple5(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), bGen = Arb.boolean(), @@ -114,7 +114,7 @@ class TupleTest : StringSpec({ testLaws( "Traversal tuple6 - ", - TraversalLaws.laws( + TraversalLaws( traversal = Traversal.tuple6(), aGen = Arb.tuple6(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), bGen = Arb.boolean(), @@ -124,7 +124,7 @@ class TupleTest : StringSpec({ testLaws( "Traversal tuple7 - ", - TraversalLaws.laws( + TraversalLaws( traversal = Traversal.tuple7(), aGen = Arb.tuple7( Arb.boolean(), @@ -142,7 +142,7 @@ class TupleTest : StringSpec({ testLaws( "Traversal tuple8 - ", - TraversalLaws.laws( + TraversalLaws( traversal = Traversal.tuple8(), aGen = Arb.tuple8( Arb.boolean(), @@ -161,7 +161,7 @@ class TupleTest : StringSpec({ testLaws( "Traversal tuple9 - ", - TraversalLaws.laws( + TraversalLaws( traversal = Traversal.tuple9(), aGen = Arb.tuple9( Arb.boolean(), From 1e4daef76554891e729a4090726b1fa5ee0db0ce Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Thu, 30 Mar 2023 21:25:10 +0200 Subject: [PATCH 032/114] Fix :arrow-optics-ksp-plugin:compileKotlin --- .../main/kotlin/arrow/optics/plugin/internals/dsl.kt | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt index b8c14ec0bf0..3267d8b26d7 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt @@ -12,16 +12,6 @@ fun generateLensDsl(ele: ADT, optic: DataClassDsl): Snippet { ) } -fun generateOptionalDsl(ele: ADT, optic: DataClassDsl): Snippet { - val (className, import) = resolveClassName(ele) - return Snippet( - `package` = ele.packageName, - name = ele.simpleName, - content = processOptionalSyntax(ele, optic, className), - imports = setOf(import) - ) -} - fun generatePrismDsl(ele: ADT, isoOptic: SealedClassDsl): Snippet { val (className, import) = resolveClassName(ele) return Snippet( @@ -77,7 +67,6 @@ private fun processPrismSyntax(ele: ADT, dsl: SealedClassDsl, className: String) |""".trimMargin() } } -} private fun resolveClassName(ele: ADT): Pair = if (hasPackageCollisions(ele)) { val classNameAlias = ele.sourceClassName.replace(".", "") From 9ccb65dd451389df2e26a55327e491b22194521b Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Fri, 31 Mar 2023 00:02:43 +0200 Subject: [PATCH 033/114] Fix Every instances --- .../commonMain/kotlin/arrow/optics/Every.kt | 243 ++++++++++++++++-- 1 file changed, 222 insertions(+), 21 deletions(-) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt index 194061d594d..cb772845b37 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt @@ -9,6 +9,7 @@ import arrow.core.Tuple6 import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 +import arrow.core.fold import kotlin.jvm.JvmStatic public object Every { @@ -16,7 +17,13 @@ public object Every { * [Traversal] for [List] that focuses in each [A] of the source [List]. */ @JvmStatic - public fun list(): Traversal, A> = Traversal.list() + public fun list(): Traversal, A> = object : Traversal, A> { + override fun foldMap(initial: R, combine: (R, R) -> R, source: List, map: (focus: A) -> R): R = + source.fold(initial) { acc, a -> combine(acc, map(a)) } + + override fun modify(source: List, map: (focus: A) -> A): List = + source.map(map) + } /** * [Traversal] for [Either] that has focus in each [Either.Right]. @@ -25,12 +32,24 @@ public object Every { * @return [Traversal] with source [Either] and focus every [Either.Right] of the source. */ @JvmStatic - public fun either(): Traversal, R> = - Traversal.either() + public fun either(): Traversal, A> = object : Traversal, A> { + override fun foldMap(initial: R, combine: (R, R) -> R, source: Either, map: (focus: A) -> R): R = + source.fold({ initial }) { combine(initial, map(it)) } + + override fun modify(source: Either, map: (focus: A) -> A): Either = + source.map(map) + } @JvmStatic - public fun map(): Traversal, V> = - Traversal.map() + public fun map(): Traversal, V> = object : Traversal, V> { + override fun foldMap(initial: R, combine: (R, R) -> R, source: Map, map: (focus: V) -> R): R = + source.fold(initial) { acc, (_, v) -> + combine(acc, map(v)) + } + + override fun modify(source: Map, map: (focus: V) -> V): Map = + source.mapValues { (_, v) -> map(v) } + } /** * [Traversal] for [NonEmptyList] that has focus in each [A]. @@ -39,8 +58,15 @@ public object Every { * @return [Traversal] with source [NonEmptyList] and focus every [A] of the source. */ @JvmStatic - public fun nonEmptyList(): Traversal, A> = - Traversal.nonEmptyList() + public fun nonEmptyList(): Traversal, A> = object : Traversal, A> { + override fun foldMap(initial: R, combine: (R, R) -> R, source: NonEmptyList, map: (focus: A) -> R): R = + source.fold(initial) { acc, a -> + combine(acc, map(a)) + } + + override fun modify(source: NonEmptyList, map: (focus: A) -> A): NonEmptyList = + source.map(map) + } /** * [Traversal] for [Option] that has focus in each [arrow.core.Some]. @@ -49,12 +75,24 @@ public object Every { * @return [Traversal] with source [Option] and focus in every [arrow.core.Some] of the source. */ @JvmStatic - public fun option(): Traversal, A> = - Traversal.option() + public fun option(): Traversal, A> = object : Traversal, A> { + override fun foldMap(initial: R, combine: (R, R) -> R, source: Option, map: (focus: A) -> R): R = + source.fold({ initial }) { combine(initial, map(it)) } + + override fun modify(source: Option, map: (focus: A) -> A): Option = + source.map(map) + } @JvmStatic - public fun sequence(): Traversal, A> = - Traversal.sequence() + public fun sequence(): Traversal, A> = object : Traversal, A> { + override fun foldMap(initial: R, combine: (R, R) -> R, source: Sequence, map: (focus: A) -> R): R = + source.fold(initial) { acc, a -> + combine(acc, map(a)) + } + + override fun modify(source: Sequence, map: (focus: A) -> A): Sequence = + source.map(map) + } /** * [Traversal] for [String] that focuses in each [Char] of the source [String]. @@ -63,62 +101,225 @@ public object Every { * @return [Traversal] with source [String] and foci every [Char] in the source. */ @JvmStatic - public fun string(): Traversal = - Traversal.string() + public fun string(): Traversal = object : Traversal { + override fun foldMap(initial: R, combine: (R, R) -> R, source: String, map: (focus: Char) -> R): R = + source.fold(initial) { acc, a -> + combine(acc, map(a)) + } + + override fun modify(source: String, map: (focus: Char) -> Char): String = + source.map(map).joinToString(separator = "") + } /** * [Traversal] to focus into the first and second value of a [Pair] */ @JvmStatic public fun pair(): Traversal, A> = - Traversal.pair() + object : Traversal, A> { + override fun modify(source: Pair, map: (focus: A) -> A): Pair = + Pair(map(source.first), map(source.second)) + + override fun foldMap(initial: R, combine: (R, R) -> R, source: Pair, map: (focus: A) -> R): R = + combine(map(source.first), map(source.second)) + } /** * [Traversal] to focus into the first, second and third value of a [Triple] */ @JvmStatic public fun triple(): Traversal, A> = - Traversal.triple() + object : Traversal, A> { + override fun modify(source: Triple, map: (focus: A) -> A): Triple = + Triple(map(source.first), map(source.second), map(source.third)) + + override fun foldMap(initial: R, combine: (R, R) -> R, source: Triple, map: (focus: A) -> R): R = + combine(combine(map(source.first), map(source.second)), map(source.third)) + } /** * [Traversal] to focus into the first, second, third and fourth value of a [arrow.core.Tuple4] */ @JvmStatic public fun tuple4(): Traversal, A> = - Traversal.tuple4() + object : Traversal, A> { + override fun foldMap(initial: R, combine: (R, R) -> R, source: Tuple4, map: (focus: A) -> R): R = + combine(combine(combine(map(source.first), map(source.second)), map(source.third)), map(source.fourth)) + + override fun modify(source: Tuple4, map: (focus: A) -> A): Tuple4 = + Tuple4(map(source.first), map(source.second), map(source.third), map(source.fourth)) + } /** * [PTraversal] to focus into the first, second, third, fourth and fifth value of a [arrow.core.Tuple5] */ @JvmStatic public fun tuple5(): Traversal, A> = - Traversal.tuple5() + object : Traversal, A> { + override fun foldMap( + initial: R, + combine: (R, R) -> R, + source: Tuple5, + map: (focus: A) -> R + ): R = + combine( + combine(combine(combine(map(source.first), map(source.second)), map(source.third)), map(source.fourth)), + map(source.fifth) + ) + + override fun modify(source: Tuple5, map: (focus: A) -> A): Tuple5 = + Tuple5(map(source.first), map(source.second), map(source.third), map(source.fourth), map(source.fifth)) + } /** * [Traversal] to focus into the first, second, third, fourth, fifth and sixth value of a [arrow.core.Tuple6] */ @JvmStatic public fun tuple6(): Traversal, A> = - Traversal.tuple6() + object : Traversal, A> { + override fun foldMap( + initial: R, + combine: (R, R) -> R, + source: Tuple6, + map: (focus: A) -> R + ): R = + combine( + combine( + combine( + combine(combine(map(source.first), map(source.second)), map(source.third)), + map(source.fourth) + ), map(source.fifth) + ), map(source.sixth) + ) + + override fun modify(source: Tuple6, map: (focus: A) -> A): Tuple6 = + Tuple6( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth) + ) + } /** * [Traversal] to focus into the first, second, third, fourth, fifth, sixth and seventh value of a [arrow.core.Tuple7] */ @JvmStatic public fun tuple7(): Traversal, A> = - Traversal.tuple7() + object : Traversal, A> { + override fun foldMap( + initial: R, + combine: (R, R) -> R, + source: Tuple7, + map: (focus: A) -> R + ): R = + combine( + combine( + combine( + combine( + combine(combine(map(source.first), map(source.second)), map(source.third)), + map(source.fourth) + ), map(source.fifth) + ), map(source.sixth) + ), map(source.seventh) + ) + + override fun modify(source: Tuple7, map: (focus: A) -> A): Tuple7 = + Tuple7( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth), + map(source.seventh) + ) + } /** * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh and eight value of a [arrow.core.Tuple8] */ @JvmStatic public fun tuple8(): Traversal, A> = - Traversal.tuple8() + object : Traversal, A> { + override fun foldMap( + initial: R, + combine: (R, R) -> R, + source: Tuple8, + map: (focus: A) -> R + ): R = + combine( + combine( + combine( + combine( + combine( + combine(combine(map(source.first), map(source.second)), map(source.third)), + map(source.fourth) + ), map(source.fifth) + ), map(source.sixth) + ), map(source.seventh) + ), map(source.eighth) + ) + + override fun modify( + source: Tuple8, + map: (focus: A) -> A + ): Tuple8 = + Tuple8( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth), + map(source.seventh), + map(source.eighth) + ) + } /** * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight and ninth value of a [arrow.core.Tuple9] */ @JvmStatic public fun tuple9(): Traversal, A> = - Traversal.tuple9() + object : Traversal, A> { + override fun foldMap( + initial: R, + combine: (R, R) -> R, + source: Tuple9, + map: (focus: A) -> R + ): R = + combine( + combine( + combine( + combine( + combine( + combine( + combine(combine(map(source.first), map(source.second)), map(source.third)), + map(source.fourth) + ), map(source.fifth) + ), map(source.sixth) + ), map(source.seventh) + ), map(source.eighth) + ), map(source.ninth) + ) + + override fun modify( + source: Tuple9, + map: (focus: A) -> A + ): Tuple9 = + Tuple9( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth), + map(source.seventh), + map(source.eighth), + map(source.ninth) + ) + } } From 531deb1e46e0703b4453e1b7caec6c2433649e87 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Fri, 31 Mar 2023 15:10:31 +0200 Subject: [PATCH 034/114] Move functions to arrow functions (#3014) --- arrow-libs/core/arrow-core/api/arrow-core.api | 604 ----------------- arrow-libs/core/arrow-core/build.gradle.kts | 1 + .../arrow-functions/api/arrow-functions.api | 611 ++++++++++++++++++ .../core/arrow-functions/build.gradle.kts | 68 ++ .../core/arrow-functions/gradle.properties | 4 + .../core/arrow-functions/knit.properties | 6 + .../core/arrow-functions/knit.test.template | 15 + .../kotlin/arrow/core/composition.kt | 10 + .../commonMain/kotlin/arrow/core/currying.kt | 0 .../kotlin/arrow/core/memoization.kt | 0 .../commonMain/kotlin/arrow/core/partials.kt | 0 .../kotlin/arrow/core/AndThenTests.kt | 15 +- .../kotlin/arrow/core/FunctionSyntaxTest.kt | 158 +++++ .../kotlin/arrow/core/KotestConfig.kt | 12 + .../kotlin/arrow/core/MemoizationTest.kt | 220 +++++++ .../kotlin/arrow/core/composition-js.kt | 13 + .../kotlin/arrow/core/composition-jvm.kt | 256 ++++++++ .../kotlin/examples/example-memoization-01.kt | 19 + .../kotlin/arrow/core/composition-native.kt | 13 + .../commonMain/kotlin/arrow/optics/Prism.kt | 2 +- settings.gradle.kts | 3 + 21 files changed, 1422 insertions(+), 608 deletions(-) create mode 100644 arrow-libs/core/arrow-functions/api/arrow-functions.api create mode 100644 arrow-libs/core/arrow-functions/build.gradle.kts create mode 100644 arrow-libs/core/arrow-functions/gradle.properties create mode 100644 arrow-libs/core/arrow-functions/knit.properties create mode 100644 arrow-libs/core/arrow-functions/knit.test.template create mode 100644 arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/composition.kt rename arrow-libs/core/{arrow-core => arrow-functions}/src/commonMain/kotlin/arrow/core/currying.kt (100%) rename arrow-libs/core/{arrow-core => arrow-functions}/src/commonMain/kotlin/arrow/core/memoization.kt (100%) rename arrow-libs/core/{arrow-core => arrow-functions}/src/commonMain/kotlin/arrow/core/partials.kt (100%) rename arrow-libs/core/{arrow-core => arrow-functions}/src/commonTest/kotlin/arrow/core/AndThenTests.kt (87%) create mode 100644 arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt create mode 100644 arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt create mode 100644 arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt create mode 100644 arrow-libs/core/arrow-functions/src/jsMain/kotlin/arrow/core/composition-js.kt create mode 100644 arrow-libs/core/arrow-functions/src/jvmMain/kotlin/arrow/core/composition-jvm.kt create mode 100644 arrow-libs/core/arrow-functions/src/jvmTest/kotlin/examples/example-memoization-01.kt create mode 100644 arrow-libs/core/arrow-functions/src/nativeMain/kotlin/arrow/core/composition-native.kt diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 8c8c946c2b7..7b98a9688ab 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -31,92 +31,6 @@ public final class arrow/core/Composition { public static final fun compose (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; } -public final class arrow/core/Currying { - public static final fun curried (Lkotlin/jvm/functions/Function10;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function11;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function12;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function13;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function14;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function15;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function16;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function17;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function18;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function19;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function20;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function21;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function22;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function6;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function7;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function8;)Lkotlin/jvm/functions/Function1; - public static final fun curried (Lkotlin/jvm/functions/Function9;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function10;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function11;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function12;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function13;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function14;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function15;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function16;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function17;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function18;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function19;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function20;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function21;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function22;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function6;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function7;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function8;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/Function9;)Lkotlin/jvm/functions/Function1; - public static final fun curriedEffect (Lkotlin/jvm/functions/FunctionN;)Lkotlin/jvm/functions/Function1; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function10; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function11; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function12; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function13; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function14; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function15; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function16; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function17; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function18; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function19; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function20; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function21; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function22; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function2; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function3; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function5; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function6; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function7; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function8; - public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function9; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function10; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function11; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function12; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function13; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function14; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function15; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function16; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function17; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function18; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function19; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function20; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function21; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function22; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function3; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function5; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function6; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function7; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function8; - public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function9; -} - public abstract class arrow/core/Either { public static final field Companion Larrow/core/Either$Companion; public static final fun catch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; @@ -396,15 +310,6 @@ public final class arrow/core/MapKt { public static final fun zip (Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/functions/Function3;)Ljava/util/Map; } -public final class arrow/core/Memoization { - public static final fun memoize (Lkotlin/jvm/functions/Function0;)Lkotlin/jvm/functions/Function0; - public static final fun memoize (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun memoize (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; - public static final fun memoize (Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function3; - public static final fun memoize (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; - public static final fun memoize (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function5; -} - public final class arrow/core/NonEmptyList : java/util/List, kotlin/jvm/internal/markers/KMappedMarker { public static final field Companion Larrow/core/NonEmptyList$Companion; public fun add (ILjava/lang/Object;)V @@ -603,515 +508,6 @@ public final class arrow/core/OptionKt { public static final fun widen (Larrow/core/Option;)Larrow/core/Option; } -public final class arrow/core/Partials { - public static final fun partially1 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially1 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially1 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially1 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially1 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially1 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially1 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially1 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially1 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially1 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially1 (Lkotlin/jvm/functions/Function1;Ljava/lang/Object;)Lkotlin/jvm/functions/Function0; - public static final fun partially1 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially1 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially1 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially1 (Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; - public static final fun partially1 (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; - public static final fun partially1 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; - public static final fun partially1 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially1 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially1 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially1 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially1 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially10 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially10 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially10 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially10 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially10 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially10 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially10 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially10 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially10 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially10 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially10 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially10 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially10 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially10Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially10Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially11 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially11 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially11 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially11 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially11 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially11 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially11 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially11 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially11 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially11 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially11 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially11 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially11Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially11Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially12 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially12 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially12 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially12 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially12 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially12 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially12 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially12 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially12 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially12 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially12 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially12Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially12Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially13 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially13 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially13 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially13 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially13 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially13 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially13 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially13 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially13 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially13 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially13Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially13Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially14 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially14 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially14 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially14 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially14 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially14 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially14 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially14 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially14 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially14Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially14Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially15 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially15 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially15 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially15 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially15 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially15 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially15 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially15 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially15Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially15Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially15Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially15Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially15Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially15Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially15Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially15Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially16 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially16 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially16 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially16 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially16 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially16 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially16 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially16Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially16Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially16Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially16Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially16Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially16Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially16Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially17 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially17 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially17 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially17 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially17 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially17 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially17Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially17Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially17Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially17Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially17Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially17Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially18 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially18 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially18 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially18 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially18 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially18Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially18Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially18Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially18Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially18Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially19 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially19 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially19 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially19 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially19Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially19Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially19Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially19Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially1Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially1Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially2 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially2 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially2 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially2 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially2 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially2 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially2 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially2 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially2 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially2 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially2 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially2 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially2 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially2 (Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; - public static final fun partially2 (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; - public static final fun partially2 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; - public static final fun partially2 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially2 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially2 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially2 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially2 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially20 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially20 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially20 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially20Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially20Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially20Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially21 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially21 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially21Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially21Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially22 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially22Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially2Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially2Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially3 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially3 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially3 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially3 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially3 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially3 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially3 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially3 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially3 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially3 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially3 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially3 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially3 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially3 (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; - public static final fun partially3 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; - public static final fun partially3 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially3 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially3 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially3 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially3 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially3Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially3Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially4 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially4 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially4 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially4 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially4 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially4 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially4 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially4 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially4 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially4 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially4 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially4 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially4 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially4 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; - public static final fun partially4 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially4 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially4 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially4 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially4 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially4Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially4Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially5 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially5 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially5 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially5 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially5 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially5 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially5 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially5 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially5 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially5 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially5 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially5 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially5 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially5 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static final fun partially5 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially5 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially5 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially5 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially5Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially5Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially6 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially6 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially6 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially6 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially6 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially6 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially6 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially6 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially6 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially6 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially6 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially6 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially6 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially6 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; - public static final fun partially6 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially6 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially6 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially6Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially6Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially7 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially7 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially7 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially7 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially7 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially7 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially7 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially7 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially7 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially7 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially7 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially7 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially7 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially7 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; - public static final fun partially7 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially7 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially7Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially7Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially8 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially8 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially8 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially8 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially8 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially8 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially8 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially8 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially8 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially8 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially8 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially8 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially8 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially8 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; - public static final fun partially8 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially8Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially8Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; - public static final fun partially9 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially9 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially9 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially9 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially9 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially9 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially9 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially9 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially9 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially9 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially9 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially9 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially9 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially9 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; - public static final fun partially9Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; - public static final fun partially9Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; -} - public final class arrow/core/PredefKt { public static final fun identity (Ljava/lang/Object;)Ljava/lang/Object; } diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index c3bfa00eb8b..cd47dde967b 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -35,6 +35,7 @@ kotlin { commonTest { dependencies { implementation(projects.arrowFxCoroutines) + implementation(projects.arrowFunctions) implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) diff --git a/arrow-libs/core/arrow-functions/api/arrow-functions.api b/arrow-libs/core/arrow-functions/api/arrow-functions.api new file mode 100644 index 00000000000..64c0e7c580c --- /dev/null +++ b/arrow-libs/core/arrow-functions/api/arrow-functions.api @@ -0,0 +1,611 @@ +public final class arrow/core/Composition { + public static final fun andThen (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function0; + public static final fun andThen (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; + public static final fun andThen (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function2; + public static final fun compose (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; +} + +public final class arrow/core/Currying { + public static final fun curried (Lkotlin/jvm/functions/Function10;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function11;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function12;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function13;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function14;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function15;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function16;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function17;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function18;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function19;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function20;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function21;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function22;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function6;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function7;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function8;)Lkotlin/jvm/functions/Function1; + public static final fun curried (Lkotlin/jvm/functions/Function9;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function10;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function11;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function12;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function13;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function14;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function15;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function16;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function17;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function18;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function19;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function20;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function21;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function22;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function6;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function7;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function8;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/Function9;)Lkotlin/jvm/functions/Function1; + public static final fun curriedEffect (Lkotlin/jvm/functions/FunctionN;)Lkotlin/jvm/functions/Function1; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function10; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function11; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function12; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function13; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function14; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function15; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function16; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function17; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function18; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function19; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function20; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function21; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function22; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function2; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function3; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function5; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function6; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function7; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function8; + public static final fun uncurried (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function9; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function10; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function11; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function12; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function13; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function14; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function15; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function16; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function17; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function18; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function19; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function20; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function21; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function22; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function3; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function5; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function6; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function7; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function8; + public static final fun uncurriedEffect (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function9; +} + +public final class arrow/core/Memoization { + public static final fun memoize (Lkotlin/jvm/functions/Function0;)Lkotlin/jvm/functions/Function0; + public static final fun memoize (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; + public static final fun memoize (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; + public static final fun memoize (Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function3; + public static final fun memoize (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; + public static final fun memoize (Lkotlin/jvm/functions/Function5;)Lkotlin/jvm/functions/Function5; +} + +public final class arrow/core/Partials { + public static final fun partially1 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially1 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially1 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially1 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially1 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially1 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially1 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially1 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially1 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially1 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially1 (Lkotlin/jvm/functions/Function1;Ljava/lang/Object;)Lkotlin/jvm/functions/Function0; + public static final fun partially1 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially1 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially1 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially1 (Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; + public static final fun partially1 (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; + public static final fun partially1 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; + public static final fun partially1 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially1 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially1 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially1 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially1 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially10 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially10 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially10 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially10 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially10 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially10 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially10 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially10 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially10 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially10 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially10 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially10 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially10 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially10Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially10Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially11 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially11 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially11 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially11 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially11 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially11 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially11 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially11 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially11 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially11 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially11 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially11 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially11Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially11Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially12 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially12 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially12 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially12 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially12 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially12 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially12 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially12 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially12 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially12 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially12 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially12Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially12Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially13 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially13 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially13 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially13 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially13 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially13 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially13 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially13 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially13 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially13 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially13Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially13Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially14 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially14 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially14 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially14 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially14 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially14 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially14 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially14 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially14 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially14Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially14Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially15 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially15 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially15 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially15 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially15 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially15 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially15 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially15 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially15Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially15Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially15Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially15Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially15Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially15Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially15Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially15Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially16 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially16 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially16 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially16 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially16 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially16 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially16 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially16Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially16Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially16Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially16Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially16Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially16Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially16Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially17 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially17 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially17 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially17 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially17 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially17 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially17Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially17Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially17Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially17Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially17Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially17Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially18 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially18 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially18 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially18 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially18 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially18Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially18Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially18Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially18Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially18Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially19 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially19 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially19 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially19 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially19Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially19Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially19Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially19Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially1Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially1Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially2 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially2 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially2 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially2 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially2 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially2 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially2 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially2 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially2 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially2 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially2 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially2 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially2 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially2 (Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Lkotlin/jvm/functions/Function1; + public static final fun partially2 (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; + public static final fun partially2 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; + public static final fun partially2 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially2 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially2 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially2 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially2 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially20 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially20 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially20 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially20Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially20Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially20Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially21 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially21 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially21Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially21Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially22 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially22Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially2Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially2Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially3 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially3 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially3 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially3 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially3 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially3 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially3 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially3 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially3 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially3 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially3 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially3 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially3 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially3 (Lkotlin/jvm/functions/Function3;Ljava/lang/Object;)Lkotlin/jvm/functions/Function2; + public static final fun partially3 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; + public static final fun partially3 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially3 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially3 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially3 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially3 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially3Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially3Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially4 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially4 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially4 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially4 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially4 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially4 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially4 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially4 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially4 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially4 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially4 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially4 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially4 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially4 (Lkotlin/jvm/functions/Function4;Ljava/lang/Object;)Lkotlin/jvm/functions/Function3; + public static final fun partially4 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially4 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially4 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially4 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially4 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially4Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially4Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially5 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially5 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially5 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially5 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially5 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially5 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially5 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially5 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially5 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially5 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially5 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially5 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially5 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially5 (Lkotlin/jvm/functions/Function5;Ljava/lang/Object;)Lkotlin/jvm/functions/Function4; + public static final fun partially5 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially5 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially5 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially5 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially5Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially5Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially6 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially6 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially6 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially6 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially6 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially6 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially6 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially6 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially6 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially6 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially6 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially6 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially6 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially6 (Lkotlin/jvm/functions/Function6;Ljava/lang/Object;)Lkotlin/jvm/functions/Function5; + public static final fun partially6 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially6 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially6 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially6Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially6Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially7 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially7 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially7 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially7 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially7 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially7 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially7 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially7 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially7 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially7 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially7 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially7 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially7 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially7 (Lkotlin/jvm/functions/Function7;Ljava/lang/Object;)Lkotlin/jvm/functions/Function6; + public static final fun partially7 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially7 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially7Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially7Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially8 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially8 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially8 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially8 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially8 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially8 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially8 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially8 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially8 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially8 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially8 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially8 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially8 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially8 (Lkotlin/jvm/functions/Function8;Ljava/lang/Object;)Lkotlin/jvm/functions/Function7; + public static final fun partially8 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially8Effect (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially8Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; + public static final fun partially9 (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially9 (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially9 (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially9 (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially9 (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially9 (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially9 (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially9 (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially9 (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially9 (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially9 (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially9 (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially9 (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially9 (Lkotlin/jvm/functions/Function9;Ljava/lang/Object;)Lkotlin/jvm/functions/Function8; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function10;Ljava/lang/Object;)Lkotlin/jvm/functions/Function9; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function11;Ljava/lang/Object;)Lkotlin/jvm/functions/Function10; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function12;Ljava/lang/Object;)Lkotlin/jvm/functions/Function11; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function13;Ljava/lang/Object;)Lkotlin/jvm/functions/Function12; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function14;Ljava/lang/Object;)Lkotlin/jvm/functions/Function13; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function15;Ljava/lang/Object;)Lkotlin/jvm/functions/Function14; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function16;Ljava/lang/Object;)Lkotlin/jvm/functions/Function15; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function17;Ljava/lang/Object;)Lkotlin/jvm/functions/Function16; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function18;Ljava/lang/Object;)Lkotlin/jvm/functions/Function17; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function19;Ljava/lang/Object;)Lkotlin/jvm/functions/Function18; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function20;Ljava/lang/Object;)Lkotlin/jvm/functions/Function19; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function21;Ljava/lang/Object;)Lkotlin/jvm/functions/Function20; + public static final fun partially9Effect (Lkotlin/jvm/functions/Function22;Ljava/lang/Object;)Lkotlin/jvm/functions/Function21; + public static final fun partially9Effect (Lkotlin/jvm/functions/FunctionN;Ljava/lang/Object;)Lkotlin/jvm/functions/Function22; +} + diff --git a/arrow-libs/core/arrow-functions/build.gradle.kts b/arrow-libs/core/arrow-functions/build.gradle.kts new file mode 100644 index 00000000000..c3bfa00eb8b --- /dev/null +++ b/arrow-libs/core/arrow-functions/build.gradle.kts @@ -0,0 +1,68 @@ +@file:Suppress("DSL_SCOPE_VIOLATION") + +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id(libs.plugins.kotlin.multiplatform.get().pluginId) + alias(libs.plugins.arrowGradleConfig.kotlin) + alias(libs.plugins.arrowGradleConfig.publish) + alias(libs.plugins.kotest.multiplatform) +} + +apply(from = property("TEST_COVERAGE")) +apply(from = property("ANIMALSNIFFER_MPP")) + +val enableCompatibilityMetadataVariant = + providers.gradleProperty("kotlin.mpp.enableCompatibilityMetadataVariant") + .orNull?.toBoolean() == true + +if (enableCompatibilityMetadataVariant) { + tasks.withType().configureEach { + exclude("**/*") + } +} + +kotlin { + sourceSets { + commonMain { + dependencies { + api(projects.arrowAtomic) + api(projects.arrowAnnotations) + api(libs.kotlin.stdlibCommon) + } + } + if (!enableCompatibilityMetadataVariant) { + commonTest { + dependencies { + implementation(projects.arrowFxCoroutines) + implementation(libs.kotest.frameworkEngine) + implementation(libs.kotest.assertionsCore) + implementation(libs.kotest.property) + } + } + + jvmTest { + dependencies { + runtimeOnly(libs.kotest.runnerJUnit5) + } + } + } + + jvmMain { + dependencies { + implementation(libs.kotlin.stdlib) + } + } + + jsMain { + dependencies { + implementation(libs.kotlin.stdlibJS) + } + } + } +} + +// enables context receivers for Jvm Tests +tasks.named("compileTestKotlinJvm") { + kotlinOptions.freeCompilerArgs += "-Xcontext-receivers" +} diff --git a/arrow-libs/core/arrow-functions/gradle.properties b/arrow-libs/core/arrow-functions/gradle.properties new file mode 100644 index 00000000000..19c64baf9cb --- /dev/null +++ b/arrow-libs/core/arrow-functions/gradle.properties @@ -0,0 +1,4 @@ +# Maven publishing configuration +pom.name=Arrow Functions +# Build configuration +kapt.incremental.apt=false diff --git a/arrow-libs/core/arrow-functions/knit.properties b/arrow-libs/core/arrow-functions/knit.properties new file mode 100644 index 00000000000..c3328691738 --- /dev/null +++ b/arrow-libs/core/arrow-functions/knit.properties @@ -0,0 +1,6 @@ +knit.package=arrow.core.examples +knit.dir=src/jvmTest/kotlin/examples/ + +test.package=arrow.core.examples.test +test.dir=src/jvmTest/kotlin/examples/test/ +test.template=knit.test.template \ No newline at end of file diff --git a/arrow-libs/core/arrow-functions/knit.test.template b/arrow-libs/core/arrow-functions/knit.test.template new file mode 100644 index 00000000000..7b3f20935a9 --- /dev/null +++ b/arrow-libs/core/arrow-functions/knit.test.template @@ -0,0 +1,15 @@ +// This file was automatically generated from ${file.name} by Knit tool. Do not edit. +package ${test.package} + +import io.kotest.core.spec.style.StringSpec + +class ${test.name} : StringSpec({ +<#list cases as case> + "${case.name}" { + ${case.knit.package}.${case.knit.name}.test() + } + + +}) { + override fun timeout(): Long = 1000 +} \ No newline at end of file diff --git a/arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/composition.kt b/arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/composition.kt new file mode 100644 index 00000000000..3e6bb1e896f --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/composition.kt @@ -0,0 +1,10 @@ +@file:JvmName("Composition") + +package arrow.core + +import kotlin.jvm.JvmName + +public expect infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R +public expect infix fun (() -> IP).andThen(f: (IP) -> R): () -> R +public expect infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R +public expect infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/currying.kt b/arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/currying.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/currying.kt rename to arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/currying.kt diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt b/arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/memoization.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/memoization.kt rename to arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/memoization.kt diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/partials.kt b/arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/partials.kt similarity index 100% rename from arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/partials.kt rename to arrow-libs/core/arrow-functions/src/commonMain/kotlin/arrow/core/partials.kt diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/AndThenTests.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/AndThenTests.kt similarity index 87% rename from arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/AndThenTests.kt rename to arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/AndThenTests.kt index 69c5ce0829f..492d12c4aa2 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/AndThenTests.kt +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/AndThenTests.kt @@ -1,16 +1,25 @@ package arrow.core -import arrow.core.test.functionAToB -import arrow.core.test.stackSafeIteration +import io.kotest.common.Platform +import io.kotest.common.platform import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.matchers.shouldBe +import io.kotest.property.arbitrary.arbitrary import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list +import io.kotest.property.arbitrary.next import io.kotest.property.checkAll class AndThenTests : StringSpec({ - val count = stackSafeIteration() + val count = when (platform) { + Platform.JVM -> 200_000 + else -> 1000 + } + + fun Arb.Companion.functionAToB(arb: Arb): Arb<(A) -> B> = arbitrary { random -> + { _: A -> arb.next(random) }.memoize() + } "AndThen0 - compose a chain of functions with andThen should be same with AndThen" { checkAll(Arb.int(), Arb.list(Arb.functionAToB(Arb.int()))) { i, fs -> diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt new file mode 100644 index 00000000000..204cb0f7863 --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt @@ -0,0 +1,158 @@ +package arrow.core + +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +class FunctionSyntaxTest : StringSpec({ + + val sum = { i1: Int, i2: Int -> i1 + i2 } + val add5 = { i: Int -> i + 5 } + val multiplyBy2 = { i: Int -> i * 2 } + + "it should compose function correctly (andThen)" { + val potato = "potato" + val ninja = "ninja" + val get = { potato } + val map = { word: String -> ninja + word } + (get andThen map)() + (ninja + potato) shouldBe (get andThen map)() + } + + "testAndThen" { + val add5andMultiplyBy2 = add5 andThen multiplyBy2 + add5andMultiplyBy2(2) shouldBe 14 + } + + "testAndThen2" { + val sumAndMultiplyBy2 = sum andThen multiplyBy2 + sumAndMultiplyBy2(5, 2) shouldBe 14 + } + + "testCompose" { + val multiplyBy2andAdd5 = add5 compose multiplyBy2 + multiplyBy2andAdd5(2) shouldBe 9 + } + + "testCurrying" { + val sum2ints = { x: Int, y: Int -> x + y } + val curried = sum2ints.curried() + curried(2)(4) shouldBe 6 + val addFive = curried(5) + addFive(7) shouldBe 12 + } + + "testUncurrying" { + val sum2ints: (Int, Int) -> Int = { x, y -> x + y } + val curried: (Int) -> (Int) -> Int = sum2ints.curried() + curried(2)(4) shouldBe 6 + // same type as sum2ints, + curried.uncurried()(2, 4) shouldBe 6 + sum2ints(2, 4) shouldBe 6 + } + + "testCurryingEffect" { + val sum2ints: suspend (Int, Int) -> Int = { x: Int, y: Int -> x + y } + val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() + curried(2)(4) shouldBe 6 + val addFive: suspend (Int) -> Int = curried(5) + addFive(7) shouldBe 12 + } + + "testUncurryingEffect" { + val sum2ints: suspend (Int, Int) -> Int = { x, y -> x + y } + val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() + curried(2)(4) shouldBe 6 + // same type as sum2ints, + curried.uncurried()(2, 4) shouldBe 6 + sum2ints(2, 4) shouldBe 6 + } + + "memoize" { + var counterA = 0 + var counterB = 0 + + val a = { _: Int -> counterA++ } + val b = { _: Int -> counterB++ }.memoize() + + repeat(5) { a(1) } + repeat(5) { b(1) } + + counterA shouldBe 5 + counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once + } + + "memoizeEmpty" { + var counterA = 0 + var counterB = 0 + + val a = { counterA++ } + val b = { counterB++ }.memoize() + + repeat(5) { a() } + repeat(5) { b() } + + counterA shouldBe 5 + counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once + } + + "partially" { + val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10 = sum5ints.partially5(10) + val sum3intsTo15 = sum4intsTo10.partially4(5) + val sum2intsTo17 = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + + val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + + val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + "suspend partially" { + val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10 = sum5ints.partially5(10) + val sum3intsTo15 = sum4intsTo10.partially4(5) + val sum2intsTo17 = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + + val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + + val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + "partials" { + val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10: (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) + val sum3intsTo15: (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) + val sum2intsTo17: (Int, Int) -> Int = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + val helloX: (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + "suspend partials" { + val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10: suspend (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) + val sum3intsTo15: suspend (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) + val sum2intsTo17: suspend (Int, Int) -> Int = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + val helloX: suspend (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + "bind" { + var i = 0 + fun inc(a: Int) { + i += a + } + + val binded = ::inc.partially1(5) + i shouldBe 0 + binded() + i shouldBe 5 + } + +}) diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt new file mode 100644 index 00000000000..ce7f493fad2 --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt @@ -0,0 +1,12 @@ +package arrow.core + +import io.kotest.core.config.AbstractProjectConfig +import io.kotest.property.PropertyTesting +import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds + +class KotestConfig : AbstractProjectConfig() { + override suspend fun beforeProject() { + PropertyTesting.defaultIterationCount = 250 + } +} diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt new file mode 100644 index 00000000000..24478adfc21 --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt @@ -0,0 +1,220 @@ +package arrow.core + +import io.kotest.core.spec.style.StringSpec +import io.kotest.property.checkAll +import io.kotest.matchers.shouldBe +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlin.random.Random + +class MemoizationTest : StringSpec({ + "Memoize races" { + checkAll { + fun sum(): Int = + Random.nextInt(Int.MAX_VALUE) + + val memoized = ::sum.memoize() + + val (first, second) = listOf( + async { memoized() }, + async { memoized() } + ).awaitAll() + + first shouldBe second + } + } + + "Memoize P0 only first execution runs" { + var runs = 0 + fun sum(): Int { + runs++ + return 1 + } + + val memoized = ::sum.memoize() + + memoized() shouldBe 1 + memoized() shouldBe 1 + runs shouldBe 1 + } + + "Memoize P0 nullable" { + var runs = 0 + fun sum(): Int? { + runs++ + return null + } + + val memoized = ::sum.memoize() + + memoized() shouldBe null + memoized() shouldBe null + runs shouldBe 1 + } + + "Memoize P1 only first execution runs" { + var runs = 0 + fun sum(n: Int): Int { + runs++ + return n + 1 + } + + val memoized = ::sum.memoize() + + memoized(1) shouldBe 2 + memoized(1) shouldBe 2 + runs shouldBe 1 + memoized(2) shouldBe 3 + runs shouldBe 2 + memoized(3) shouldBe 4 + runs shouldBe 3 + } + + "Memoize P1 nullable" { + var runs = 0 + fun sum(n: Int): Int? { + runs++ + return null + } + + val memoized = ::sum.memoize() + + memoized(1) shouldBe null + memoized(1) shouldBe null + runs shouldBe 1 + } + + "Memoize P2 only first execution runs" { + var runs = 0 + fun sum(n1: Int, n2: Int): Int { + runs++ + return n1 + n2 + 1 + } + + val memoized = ::sum.memoize() + val result = consecSumResult(2) + 1 + + memoized(1, 2) shouldBe result + memoized(1, 2) shouldBe result + runs shouldBe 1 + memoized(2, 1) shouldBe result + runs shouldBe 2 + memoized(3, 2) shouldBe 6 + runs shouldBe 3 + } + + "Memoize P2 nullable" { + var runs = 0 + fun sum(n: Int, m: Int): Int? { + runs++ + return null + } + + val memoized = ::sum.memoize() + + memoized(1, 2) shouldBe null + memoized(1, 2) shouldBe null + runs shouldBe 1 + } + + "Memoize P3 only first execution runs" { + var runs = 0 + fun sum(n1: Int, n2: Int, n3: Int): Int { + runs++ + return n1 + n2 + n3 + 1 + } + + val memoized = ::sum.memoize() + val result = consecSumResult(3) + 1 + + memoized(1, 2, 3) shouldBe result + memoized(1, 2, 3) shouldBe result + runs shouldBe 1 + memoized(2, 3, 1) shouldBe result + runs shouldBe 2 + memoized(3, 1, 2) shouldBe result + runs shouldBe 3 + } + + "Memoize P3 nullable" { + var runs = 0 + fun sum(a: Int, b: Int, c: Int): Int? { + runs++ + return null + } + + val memoized = ::sum.memoize() + + memoized(1, 2, 3) shouldBe null + memoized(1, 2, 3) shouldBe null + runs shouldBe 1 + } + + "Memoize P4 only first execution runs" { + var runs = 0 + fun sum(n1: Int, n2: Int, n3: Int, n4: Int): Int { + runs++ + return n1 + n2 + n3 + n4 + 1 + } + + val memoized = ::sum.memoize() + val result = consecSumResult(4) + 1 + + memoized(1, 2, 3, 4) shouldBe result + memoized(1, 2, 3, 4) shouldBe result + runs shouldBe 1 + memoized(2, 3, 4, 1) shouldBe result + runs shouldBe 2 + memoized(3, 4, 1, 2) shouldBe result + runs shouldBe 3 + } + + "Memoize P4 nullable" { + var runs = 0 + fun sum(a: Int, b: Int, c: Int, d: Int): Int? { + runs++ + return null + } + + val memoized = ::sum.memoize() + + memoized(1, 2, 3, 4) shouldBe null + memoized(1, 2, 3, 4) shouldBe null + runs shouldBe 1 + } + + "Memoize P5 only first execution runs" { + var runs = 0 + fun sum(n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Int { + runs++ + return n1 + n2 + n3 + n4 + n5 + 1 + } + + val memoized = ::sum.memoize() + val result = consecSumResult(5) + 1 + + memoized(1, 2, 3, 4, 5) shouldBe result + memoized(1, 2, 3, 4, 5) shouldBe result + runs shouldBe 1 + memoized(2, 3, 4, 5, 1) shouldBe result + runs shouldBe 2 + memoized(3, 4, 5, 1, 2) shouldBe result + runs shouldBe 3 + } + + "Memoize P5 nullable" { + var runs = 0 + fun sum(a: Int, b: Int, c: Int, d: Int, e: Int): Int? { + runs++ + return null + } + + val memoized = ::sum.memoize() + + memoized(1, 2, 3, 4, 5) shouldBe null + memoized(1, 2, 3, 4, 5) shouldBe null + runs shouldBe 1 + } +}) + +private fun consecSumResult(n: Int): Int = (n * (n + 1)) / 2 diff --git a/arrow-libs/core/arrow-functions/src/jsMain/kotlin/arrow/core/composition-js.kt b/arrow-libs/core/arrow-functions/src/jsMain/kotlin/arrow/core/composition-js.kt new file mode 100644 index 00000000000..b55950777aa --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/jsMain/kotlin/arrow/core/composition-js.kt @@ -0,0 +1,13 @@ +package arrow.core + +public actual infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R = + { p1, p2 -> f(this(p1, p2)) } + +public actual infix fun (() -> IP).andThen(f: (IP) -> R): () -> R = + { f(this()) } + +public actual infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R = + { p1 -> f(this(p1)) } + +public actual infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R = + { p1 -> this(f(p1)) } diff --git a/arrow-libs/core/arrow-functions/src/jvmMain/kotlin/arrow/core/composition-jvm.kt b/arrow-libs/core/arrow-functions/src/jvmMain/kotlin/arrow/core/composition-jvm.kt new file mode 100644 index 00000000000..2156ea10d38 --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/jvmMain/kotlin/arrow/core/composition-jvm.kt @@ -0,0 +1,256 @@ +@file:JvmName("Composition") + +package arrow.core + +import kotlin.jvm.JvmName + +public actual infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R = + AndThen2(this).andThen(f) + +public actual infix fun (() -> IP).andThen(f: (IP) -> R): () -> R = + AndThen0(this).andThen(f) + +public actual infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R = + AndThen1(this).andThen(f) + +public actual infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R = + AndThen1(this).compose(f) + +/** + * Establishes the maximum stack depth when fusing `andThen` or `compose` calls. + * + * The default is `128`, from which we substract one as an + * optimization. This default has been reached like this: + * + * - according to official docs, the default stack size on 32-bits + * Windows and Linux was 320 KB, whereas for 64-bits it is 1024 KB + * - according to measurements chaining `Function1` references uses + * approximately 32 bytes of stack space on a 64 bits system; + * this could be lower if "compressed oops" is activated + * - therefore a "map fusion" that goes 128 in stack depth can use + * about 4 KB of stack space + */ +private const val maxStackDepthSize = 127 + +private sealed class AndThen0 : () -> A { + + private data class Single(val f: () -> A, val index: Int) : AndThen0() + + private data class Concat(val left: AndThen0, val right: AndThen1) : AndThen0() { + override fun toString(): String = "AndThen.Concat(...)" + } + + fun andThen(g: (A) -> X): AndThen0 = + when (this) { + // Fusing calls up to a certain threshold + is Single -> + if (index != maxStackDepthSize) Single({ g(f()) }, index + 1) + else andThenF(AndThen1(g)) + else -> andThenF(AndThen1(g)) + } + + @Suppress("UNCHECKED_CAST") + override fun invoke(): A = + loop(this as AndThen0, Unit, 0) + + override fun toString(): String = + "AndThen0(...)" + + companion object { + + operator fun invoke(f: () -> A): AndThen0 = + when (f) { + is AndThen0 -> f + else -> Single(f, 0) + } + + @Suppress("UNCHECKED_CAST") + tailrec fun loop(self: AndThen0, current: Any?, joins: Int): A = when (self) { + is Single -> if (joins == 0) self.f() as A else loop(self.f() as AndThen0, null, joins - 1) + is Concat<*, *> -> { + when (val oldLeft = self.left) { + is Single<*> -> { + val left = oldLeft as Single + val newSelf = self.right as AndThen1 + AndThen1.loop(newSelf, left.f(), joins) + } + is Concat<*, *> -> loop( + rotateAccumulate(self.left as AndThen0, self.right as AndThen1), + current, + joins + ) + } + } + } + + @Suppress("UNCHECKED_CAST") + tailrec fun rotateAccumulate( + left: AndThen0, + right: AndThen1 + ): AndThen0 = when (left) { + is Concat<*, *> -> rotateAccumulate( + left.left as AndThen0, + (left.right as AndThen1).andThenF(right) + ) + is Single<*> -> left.andThenF(right) + } + } + + fun andThenF(right: AndThen1): AndThen0 = + Concat(this, right) +} + +private sealed class AndThen1 : (A) -> B { + + private data class Single(val f: (A) -> B, val index: Int) : AndThen1() + + private data class Concat(val left: AndThen1, val right: AndThen1) : AndThen1() { + override fun toString(): String = "AndThen.Concat(...)" + } + + fun andThen(g: (B) -> X): AndThen1 = + when (this) { + // Fusing calls up to a certain threshold + is Single -> + if (index != maxStackDepthSize) Single({ a: A -> g(this(a)) }, index + 1) + else andThenF(AndThen1(g)) + else -> andThenF(AndThen1(g)) + } + + infix fun compose(g: (C) -> A): AndThen1 = + when (this) { + // Fusing calls up to a certain threshold + is Single -> + if (index != maxStackDepthSize) Single({ c: C -> this(g(c)) }, index + 1) + else composeF(AndThen1(g)) + else -> composeF(AndThen1(g)) + } + + @Suppress("UNCHECKED_CAST") + override fun invoke(a: A): B = loop(this as AndThen1, a, 0) + + override fun toString(): String = "AndThen(...)" + + companion object { + + operator fun invoke(f: (A) -> B): AndThen1 = + when (f) { + is AndThen1 -> f + else -> Single(f, 0) + } + + @Suppress("UNCHECKED_CAST") + tailrec fun loop(self: AndThen1, current: Any?, joins: Int): B = when (self) { + is Single -> if (joins == 0) self.f(current) as B else loop( + self.f(current) as AndThen1, + null, + joins - 1 + ) + is Concat<*, *, *> -> { + when (val oldLeft = self.left) { + is Single<*, *> -> { + val left = oldLeft as Single + val newSelf = self.right as AndThen1 + loop(newSelf, left.f(current), joins) + } + is Concat<*, *, *> -> loop( + rotateAccumulate(self.left as AndThen1, self.right as AndThen1), + current, + joins + ) + } + } + } + + @Suppress("UNCHECKED_CAST") + tailrec fun rotateAccumulate( + left: AndThen1, + right: AndThen1 + ): AndThen1 = when (left) { + is Concat<*, *, *> -> rotateAccumulate( + left.left as AndThen1, + (left.right as AndThen1).andThenF(right) + ) + is Single<*, *> -> left.andThenF(right) + } + } + + fun andThenF(right: AndThen1): AndThen1 = + Concat(this, right) + + fun composeF(right: AndThen1): AndThen1 = + Concat(right, this) +} + +private sealed class AndThen2 : (A, B) -> C { + + private data class Single(val f: (A, B) -> C, val index: Int) : AndThen2() + + private data class Concat(val left: AndThen2, val right: AndThen1) : AndThen2() { + override fun toString(): String = "AndThen.Concat(...)" + } + + fun andThen(g: (C) -> X): AndThen2 = + when (this) { + // Fusing calls up to a certain threshold + is Single -> + if (index != maxStackDepthSize) Single({ a: A, b: B -> g(this(a, b)) }, index + 1) + else andThenF(AndThen1(g)) + else -> andThenF(AndThen1(g)) + } + + @Suppress("UNCHECKED_CAST") + override fun invoke(a: A, b: B): C = + loop(this as AndThen2, a, b, 0) + + override fun toString(): String = "AndThen(...)" + + companion object { + + operator fun invoke(f: (A, B) -> C): AndThen2 = + when (f) { + is AndThen2 -> f + else -> Single(f, 0) + } + + @Suppress("UNCHECKED_CAST") + tailrec fun loop(self: AndThen2, currentA: Any?, currentB: Any?, joins: Int): C = + when (self) { + is Single<*, *, *> -> { + val f = self.f as ((Any?, Any?) -> Any?) + if (joins == 0) f(currentA, currentB) as C + else loop(f(currentA, currentB) as AndThen2, null, null, joins - 1) + } + is Concat<*, *, *, *> -> { + when (val oldLeft = self.left) { + is Single<*, *, *> -> { + val left = oldLeft as Single + val newSelf = self.right as AndThen1 + AndThen1.loop(newSelf, left.f(currentA, currentB), joins) + } + is Concat<*, *, *, *> -> loop( + rotateAccumulate(self.left as AndThen2, self.right as AndThen1), + currentA, + currentB, + joins + ) + } + } + } + + @Suppress("UNCHECKED_CAST") + tailrec fun rotateAccumulate( + left: AndThen2, + right: AndThen1 + ): AndThen2 = when (left) { + is Concat<*, *, *, *> -> rotateAccumulate( + left.left as AndThen2, + (left.right as AndThen1).andThenF(right) + ) + is Single<*, *, *> -> left.andThenF(right) + } + } + + fun andThenF(right: AndThen1): AndThen2 = + Concat(this, right) +} diff --git a/arrow-libs/core/arrow-functions/src/jvmTest/kotlin/examples/example-memoization-01.kt b/arrow-libs/core/arrow-functions/src/jvmTest/kotlin/examples/example-memoization-01.kt new file mode 100644 index 00000000000..cda809e4e34 --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/jvmTest/kotlin/examples/example-memoization-01.kt @@ -0,0 +1,19 @@ +// This file was automatically generated from memoization.kt by Knit tool. Do not edit. +package arrow.core.examples.exampleMemoization01 + +import arrow.core.memoize +fun someWorkIntensiveFunction(someParam: Int): String = "$someParam" + +fun main() { + //sampleStart + val memoizedF = ::someWorkIntensiveFunction.memoize() + + // The first invocation will store the argument and result in a cache inside the `memoizedF` reference. + val value1 = memoizedF(42) + // This second invocation won't really call the `someWorkIntensiveFunction` function + //but retrieve the result from the previous invocation instead. + val value2 = memoizedF(42) + + //sampleEnd + println("$value1 $value2") +} diff --git a/arrow-libs/core/arrow-functions/src/nativeMain/kotlin/arrow/core/composition-native.kt b/arrow-libs/core/arrow-functions/src/nativeMain/kotlin/arrow/core/composition-native.kt new file mode 100644 index 00000000000..b55950777aa --- /dev/null +++ b/arrow-libs/core/arrow-functions/src/nativeMain/kotlin/arrow/core/composition-native.kt @@ -0,0 +1,13 @@ +package arrow.core + +public actual infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R = + { p1, p2 -> f(this(p1, p2)) } + +public actual infix fun (() -> IP).andThen(f: (IP) -> R): () -> R = + { f(this()) } + +public actual infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R = + { p1 -> f(this(p1)) } + +public actual infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R = + { p1 -> this(f(p1)) } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index 6ce60de76c8..4922ae54b2b 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -118,7 +118,7 @@ public interface PPrism : POptional { public infix fun compose(other: PPrism): PPrism = PPrism( getOrModify = { s -> getOrModify(s).flatMap { a -> other.getOrModify(a).mapLeft{ set(s, it) } } }, - reverseGet = this::reverseGet compose other::reverseGet + reverseGet = { reverseGet(other.reverseGet(it)) } ) public operator fun plus(other: PPrism): PPrism = diff --git a/settings.gradle.kts b/settings.gradle.kts index b2538d5e4cd..7028dc1aa28 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,6 +33,9 @@ project(":arrow-annotations").projectDir = file("arrow-libs/core/arrow-annotatio include("arrow-core") project(":arrow-core").projectDir = file("arrow-libs/core/arrow-core") +include("arrow-functions") +project(":arrow-functions").projectDir = file("arrow-libs/core/arrow-functions") + include("arrow-atomic") project(":arrow-atomic").projectDir = file("arrow-libs/core/arrow-atomic") From 9ba97f2d26b12c47846d85bef6373a44f2375d44 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 31 Mar 2023 15:49:02 +0200 Subject: [PATCH 035/114] Bring back `Iso` (#3013) * Bring back Iso * API Dump --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../arrow/optics/plugin/DeclarationUtils.kt | 3 + .../arrow/optics/plugin/OpticsProcessor.kt | 2 +- .../arrow/optics/plugin/internals/domain.kt | 10 + .../arrow/optics/plugin/internals/dsl.kt | 38 +++ .../arrow/optics/plugin/internals/errors.kt | 11 +- .../arrow/optics/plugin/internals/iso.kt | 24 ++ .../optics/plugin/internals/processor.kt | 38 ++- .../arrow/optics/plugin/internals/snippets.kt | 2 + .../kotlin/arrow/optics/plugin/IsoTests.kt | 35 +++ .../optics/arrow-optics/api/arrow-optics.api | 100 +++++++- .../src/commonMain/kotlin/arrow/optics/Iso.kt | 230 ++++++++++++++++++ .../commonMain/kotlin/arrow/optics/Lens.kt | 5 +- .../kotlin/arrow/optics/Optional.kt | 2 +- .../commonMain/kotlin/arrow/optics/Prism.kt | 5 +- .../kotlin/arrow/optics/Traversal.kt | 2 +- .../commonTest/kotlin/arrow/optics/IsoTest.kt | 177 ++++++++++++++ .../kotlin/arrow/optics/TestDomain.kt | 14 +- .../kotlin/arrow/optics/std/ListTest.kt | 14 ++ .../kotlin/arrow/optics/std/MapTest.kt | 25 ++ .../kotlin/arrow/optics/std/OptionTest.kt | 25 ++ .../kotlin/arrow/optics/std/StringTest.kt | 25 ++ .../kotlin/arrow/optics/test/laws/IsoLaws.kt | 52 ++++ 22 files changed, 817 insertions(+), 22 deletions(-) create mode 100644 arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/iso.kt create mode 100644 arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt create mode 100644 arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt create mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt create mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt create mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt create mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/DeclarationUtils.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/DeclarationUtils.kt index a126ce33857..bf2e2946650 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/DeclarationUtils.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/DeclarationUtils.kt @@ -11,3 +11,6 @@ val KSClassDeclaration.isSealed val KSClassDeclaration.isData get() = modifiers.contains(Modifier.DATA) + +val KSClassDeclaration.isValue + get() = modifiers.contains(Modifier.VALUE) diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/OpticsProcessor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/OpticsProcessor.kt index 8571b26df52..a19014bcafb 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/OpticsProcessor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/OpticsProcessor.kt @@ -32,7 +32,7 @@ class OpticsProcessor(private val codegen: CodeGenerator, private val logger: KS private fun processClass(klass: KSClassDeclaration) { // check that it is sealed or data - if (!klass.isSealed && !klass.isData) { + if (!klass.isSealed && !klass.isData && !klass.isValue) { logger.error(klass.qualifiedNameOrSimpleName.otherClassTypeErrorMessage, klass) return } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt index b0921975d79..8ad40c86fc9 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt @@ -31,11 +31,14 @@ val KSClassDeclaration.nameWithParentClass: String } enum class OpticsTarget { + ISO, LENS, PRISM, DSL } +typealias IsoTarget = Target.Iso + typealias PrismTarget = Target.Prism typealias LensTarget = Target.Lens @@ -44,13 +47,19 @@ typealias SealedClassDsl = Target.SealedClassDsl typealias DataClassDsl = Target.DataClassDsl +typealias ValueClassDsl = Target.ValueClassDsl + sealed class Target { abstract val foci: List data class Prism(override val foci: List) : Target() data class Lens(override val foci: List) : Target() + data class Iso(override val foci: List) : Target() data class SealedClassDsl(override val foci: List) : Target() data class DataClassDsl(override val foci: List) : Target() + data class ValueClassDsl(val focus: Focus) : Target() { + override val foci = listOf(focus) + } } data class Focus( @@ -70,6 +79,7 @@ data class Focus( } const val Lens = "arrow.optics.Lens" +const val Iso = "arrow.optics.Iso" const val Optional = "arrow.optics.Optional" const val Prism = "arrow.optics.Prism" const val Traversal = "arrow.optics.Traversal" diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt index 3267d8b26d7..28fa76a6299 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt @@ -22,6 +22,16 @@ fun generatePrismDsl(ele: ADT, isoOptic: SealedClassDsl): Snippet { ) } +fun generateIsoDsl(ele: ADT, isoOptic: ValueClassDsl): Snippet { + val (className, import) = resolveClassName(ele) + return Snippet( + `package` = ele.packageName, + name = ele.simpleName, + content = processIsoSyntax(ele, isoOptic, className), + imports = setOf(import) + ) +} + private fun processLensSyntax(ele: ADT, foci: List, className: String): String { return if (ele.typeParameters.isEmpty()) { foci.joinToString(separator = "\n") { focus -> @@ -68,6 +78,34 @@ private fun processPrismSyntax(ele: ADT, dsl: SealedClassDsl, className: String) } } +private fun processIsoSyntax(ele: ADT, dsl: ValueClassDsl, className: String): String = + if (ele.typeParameters.isEmpty()) { + dsl.foci.joinToString(separator = "\n\n") { focus -> + """ + |${ele.visibilityModifierName} inline val $Iso.${focus.paramName}: $Iso inline get() = this + ${className}.${focus.paramName} + |${ele.visibilityModifierName} inline val $Lens.${focus.paramName}: $Lens inline get() = this + ${className}.${focus.paramName} + |${ele.visibilityModifierName} inline val $Optional.${focus.paramName}: $Optional inline get() = this + ${className}.${focus.paramName} + |${ele.visibilityModifierName} inline val $Prism.${focus.paramName}: $Prism inline get() = this + ${className}.${focus.paramName} + |${ele.visibilityModifierName} inline val $Traversal.${focus.paramName}: $Traversal inline get() = this + ${className}.${focus.paramName} + |""".trimMargin() + } + } else { + dsl.foci.joinToString(separator = "\n\n") { focus -> + val sourceClassNameWithParams = focus.refinedType?.qualifiedString() ?: "${ele.sourceClassName}${ele.angledTypeParameters}" + val joinedTypeParams = when { + focus.refinedArguments.isEmpty() -> "" + else -> focus.refinedArguments.joinToString(separator=",") + } + """ + |${ele.visibilityModifierName} inline fun $Iso.${focus.paramName}(): $Iso = this + ${className}.${focus.paramName}() + |${ele.visibilityModifierName} inline fun $Lens.${focus.paramName}(): $Lens = this + ${className}.${focus.paramName}() + |${ele.visibilityModifierName} inline fun $Optional.${focus.paramName}(): $Optional = this + ${className}.${focus.paramName}() + |${ele.visibilityModifierName} inline fun $Prism.${focus.paramName}(): $Prism = this + ${className}.${focus.paramName}() + |${ele.visibilityModifierName} inline fun $Traversal.${focus.paramName}(): $Traversal = this + ${className}.${focus.paramName}() + |""".trimMargin() + } + } + private fun resolveClassName(ele: ADT): Pair = if (hasPackageCollisions(ele)) { val classNameAlias = ele.sourceClassName.replace(".", "") val aliasImport = "import ${ele.sourceClassName} as $classNameAlias" diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt index 2de1dca9c9e..0d0915a0369 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt @@ -5,7 +5,7 @@ val String.otherClassTypeErrorMessage """ |$this cannot be annotated with @optics | ^ - |Only data and sealed classes can be annotated with @optics""".trimMargin() + |Only data, sealed, and value classes can be annotated with @optics""".trimMargin() val String.lensErrorMessage get() = @@ -25,6 +25,15 @@ val String.prismErrorMessage |It is only valid for sealed classes. """.trimMargin() +val String.isoErrorMessage + get() = + """ + |Cannot generate arrow.optics.Iso for $this + | ^ + |arrow.optics.OpticsTarget.ISO is an invalid @optics argument for $this. + |It is only valid for value classes. + """.trimMargin() + val String.noCompanion get() = """ diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/iso.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/iso.kt new file mode 100644 index 00000000000..3d0619f9823 --- /dev/null +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/iso.kt @@ -0,0 +1,24 @@ +package arrow.optics.plugin.internals + +internal fun generateIsos(ele: ADT, target: IsoTarget) = + Snippet(`package` = ele.packageName, name = ele.simpleName, content = processElement(ele, target.foci.first())) + +private fun processElement(adt: ADT, focus: Focus): String { + val sourceClassNameWithParams = "${adt.sourceClassName}${adt.angledTypeParameters}" + val firstLine = when { + adt.typeParameters.isEmpty() -> + "${adt.visibilityModifierName} inline val ${adt.sourceClassName}.Companion.${focus.paramName}: $Iso<${adt.sourceClassName}, ${focus.className}> inline get()" + else -> + "${adt.visibilityModifierName} inline fun ${adt.angledTypeParameters} ${adt.sourceClassName}.Companion.${focus.paramName}(): $Iso<$sourceClassNameWithParams, ${focus.className}>" + } + val fineParamName = focus.paramName.plusIfNotBlank( + prefix = "`", + postfix = "`" + ) + return """ + |$firstLine = $Iso( + | get = { ${adt.sourceName}: $sourceClassNameWithParams -> ${adt.sourceName}.$fineParamName }, + | reverseGet = { $fineParamName: ${focus.className} -> ${adt.sourceClassName}($fineParamName) } + |) + |""".trimMargin() +} diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index 163fdb84f3d..4f9bdc1aa48 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -2,6 +2,7 @@ package arrow.optics.plugin.internals import arrow.optics.plugin.isData import arrow.optics.plugin.isSealed +import arrow.optics.plugin.isValue import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.* import java.util.Locale @@ -15,7 +16,12 @@ internal fun adt(c: KSClassDeclaration, logger: KSPLogger): ADT = OpticsTarget.LENS -> evalAnnotatedDataClass(c, c.qualifiedNameOrSimpleName.lensErrorMessage, logger) .let(::LensTarget) - OpticsTarget.PRISM -> evalAnnotatedPrismElement(c, logger).let(::PrismTarget) + OpticsTarget.ISO -> + evalAnnotatedValueClass(c, c.qualifiedNameOrSimpleName.isoErrorMessage, logger) + .let(::IsoTarget) + OpticsTarget.PRISM -> + evalAnnotatedPrismElement(c, c.qualifiedNameOrSimpleName.prismErrorMessage,logger) + .let(::PrismTarget) OpticsTarget.DSL -> evalAnnotatedDslElement(c, logger) } } @@ -27,6 +33,9 @@ internal fun KSClassDeclaration.targets(): List = isSealed -> listOf(OpticsTarget.PRISM, OpticsTarget.DSL) .filter { targets.isEmpty() || it in targets } + isValue -> + listOf(OpticsTarget.ISO, OpticsTarget.DSL) + .filter { targets.isEmpty() || it in targets } else -> listOf(OpticsTarget.LENS, OpticsTarget.DSL) .filter { targets.isEmpty() || it in targets } @@ -40,6 +49,7 @@ internal fun KSClassDeclaration.targetsFromOpticsAnnotation(): List (arg.value as? ArrayList<*>).orEmpty().mapNotNull { it as? KSType } } ?.mapNotNull { when (it.qualifiedString() ) { + "arrow.optics.OpticsTarget.ISO" -> OpticsTarget.ISO "arrow.optics.OpticsTarget.LENS" -> OpticsTarget.LENS "arrow.optics.OpticsTarget.PRISM" -> OpticsTarget.PRISM "arrow.optics.OpticsTarget.DSL" -> OpticsTarget.DSL @@ -49,6 +59,7 @@ internal fun KSClassDeclaration.targetsFromOpticsAnnotation(): List = when { @@ -61,7 +72,7 @@ internal fun evalAnnotatedPrismElement( ) }.toList() else -> { - logger.error(element.qualifiedNameOrSimpleName.prismErrorMessage, element) + logger.error(errorMessage, element) emptyList() } } @@ -85,6 +96,20 @@ internal fun evalAnnotatedDataClass( } } +internal fun evalAnnotatedValueClass( + element: KSClassDeclaration, + errorMessage: String, + logger: KSPLogger +): List = + when { + element.isValue -> + listOf(Focus(element.getConstructorTypesNames().first(), element.getConstructorParamNames().first())) + else -> { + logger.error(errorMessage, element) + emptyList() + } + } + internal fun evalAnnotatedDslElement(element: KSClassDeclaration, logger: KSPLogger): Target = when { element.isData -> @@ -93,8 +118,13 @@ internal fun evalAnnotatedDslElement(element: KSClassDeclaration, logger: KSPLog .getConstructorTypesNames() .zip(element.getConstructorParamNames(), Focus.Companion::invoke) ) - element.isSealed -> SealedClassDsl(evalAnnotatedPrismElement(element, logger)) - else -> throw IllegalStateException("should only be sealed or data by now") + element.isValue -> + ValueClassDsl( + Focus(element.getConstructorTypesNames().first(), element.getConstructorParamNames().first()) + ) + element.isSealed -> + SealedClassDsl(evalAnnotatedPrismElement(element, element.qualifiedNameOrSimpleName.prismErrorMessage, logger)) + else -> throw IllegalStateException("should only be sealed, data, or value by now") } internal fun KSClassDeclaration.getConstructorTypesNames(): List = diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt index e765602b161..2897c368715 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt @@ -3,10 +3,12 @@ package arrow.optics.plugin.internals internal fun ADT.snippets(): List = targets.map { when (it) { + is IsoTarget -> generateIsos(this, it) is PrismTarget -> generatePrisms(this, it) is LensTarget -> generateLenses(this, it) is SealedClassDsl -> generatePrismDsl(this, it) is DataClassDsl -> generateLensDsl(this, it) + is ValueClassDsl -> generateIsoDsl(this, it) } } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt new file mode 100644 index 00000000000..bba620bab1a --- /dev/null +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt @@ -0,0 +1,35 @@ +package arrow.optics.plugin + +import arrow.optics.plugin.internals.noCompanion +import org.junit.jupiter.api.Test + +class IsoTests { + + @Test + fun `Isos will be generated for value class`() { + """ + |$`package` + |$imports + |@optics @JvmInline + |value class IsoData( + | val field1: String + |) { companion object } + | + |val i: Iso = IsoData.field1 + |val r = i != null + """.evals("r" to true) + } + + @Test + fun `Iso generation requires companion object declaration`() { + """ + |$`package` + |$imports + |@optics @JvmInline + |value class IsoNoCompanion( + | val field1: String + |) + """.failsWith { it.contains("IsoNoCompanion".noCompanion) } + } +} + diff --git a/arrow-libs/optics/arrow-optics/api/arrow-optics.api b/arrow-libs/optics/arrow-optics/api/arrow-optics.api index c1de5f193bc..265de392327 100644 --- a/arrow-libs/optics/arrow-optics/api/arrow-optics.api +++ b/arrow-libs/optics/arrow-optics/api/arrow-optics.api @@ -46,6 +46,98 @@ public final class arrow/optics/OptionalKt { public static final fun Optional (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/POptional; } +public abstract interface class arrow/optics/PIso : arrow/optics/PLens, arrow/optics/PPrism { + public static final field Companion Larrow/optics/PIso$Companion; + public abstract fun compose (Larrow/optics/PIso;)Larrow/optics/PIso; + public abstract fun first ()Larrow/optics/PIso; + public abstract fun foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; + public abstract fun left ()Larrow/optics/PIso; + public static fun listToOptionNel ()Larrow/optics/PIso; + public static fun listToPOptionNel ()Larrow/optics/PIso; + public static fun mapToSet ()Larrow/optics/PIso; + public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun nullableToOption ()Larrow/optics/PIso; + public static fun nullableToPOption ()Larrow/optics/PIso; + public static fun optionToEither ()Larrow/optics/PIso; + public static fun optionToNullable ()Larrow/optics/PIso; + public static fun optionToPEither ()Larrow/optics/PIso; + public static fun optionToPNullable ()Larrow/optics/PIso; + public abstract fun plus (Larrow/optics/PIso;)Larrow/optics/PIso; + public abstract fun reverse ()Larrow/optics/PIso; + public abstract fun reverseGet (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun right ()Larrow/optics/PIso; + public abstract fun second ()Larrow/optics/PIso; + public abstract fun set (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun split (Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun stringToList ()Larrow/optics/PIso; +} + +public final class arrow/optics/PIso$Companion { + public final fun id ()Larrow/optics/PIso; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/optics/PIso; + public final fun listToOptionNel ()Larrow/optics/PIso; + public final fun listToPOptionNel ()Larrow/optics/PIso; + public final fun mapToSet ()Larrow/optics/PIso; + public final fun nullableToOption ()Larrow/optics/PIso; + public final fun nullableToPOption ()Larrow/optics/PIso; + public final fun optionToEither ()Larrow/optics/PIso; + public final fun optionToNullable ()Larrow/optics/PIso; + public final fun optionToPEither ()Larrow/optics/PIso; + public final fun optionToPNullable ()Larrow/optics/PIso; + public final fun stringToList ()Larrow/optics/PIso; +} + +public final class arrow/optics/PIso$DefaultImpls { + public static fun all (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun any (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun choice (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; + public static fun choice (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; + public static fun choice (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun compose (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun compose (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; + public static fun compose (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; + public static fun compose (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PPrism; + public static fun compose (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun exists (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun findOrNull (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun first (Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun firstOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; + public static fun fold (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object; + public static fun foldMap (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun getAll (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/util/List; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun getOrModify (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/core/Either; + public static fun getOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; + public static fun isEmpty (Larrow/optics/PIso;Ljava/lang/Object;)Z + public static fun isNotEmpty (Larrow/optics/PIso;Ljava/lang/Object;)Z + public static fun lastOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; + public static fun left (Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun lift (Larrow/optics/PIso;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; + public static fun liftNullable (Larrow/optics/PIso;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; + public static fun modify (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun modifyNullable (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun plus (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun plus (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; + public static fun plus (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; + public static fun plus (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PPrism; + public static fun plus (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun reverse (Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun right (Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun second (Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun set (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; + public static fun set (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun setNullable (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun size (Larrow/optics/PIso;Ljava/lang/Object;)I + public static fun split (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; + public static fun split (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; +} + public abstract interface class arrow/optics/PLens : arrow/optics/POptional { public static final field Companion Larrow/optics/PLens$Companion; public abstract fun choice (Larrow/optics/PLens;)Larrow/optics/PLens; @@ -75,7 +167,7 @@ public abstract interface class arrow/optics/PLens : arrow/optics/POptional { public final class arrow/optics/PLens$Companion { public final fun codiagonal ()Larrow/optics/PLens; - public final fun id ()Larrow/optics/PLens; + public final fun id ()Larrow/optics/PIso; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/PLens; public final fun nonEmptyListHead ()Larrow/optics/PLens; public final fun nonEmptyListTail ()Larrow/optics/PLens; @@ -151,7 +243,7 @@ public abstract interface class arrow/optics/POptional : arrow/optics/PTraversal public final class arrow/optics/POptional$Companion { public final fun codiagonal ()Larrow/optics/POptional; - public final fun id ()Larrow/optics/POptional; + public final fun id ()Larrow/optics/PIso; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/POptional; public final fun listHead ()Larrow/optics/POptional; public final fun listTail ()Larrow/optics/POptional; @@ -218,7 +310,7 @@ public abstract interface class arrow/optics/PPrism : arrow/optics/POptional { public final class arrow/optics/PPrism$Companion { public final fun eitherLeft ()Larrow/optics/PPrism; public final fun eitherRight ()Larrow/optics/PPrism; - public final fun id ()Larrow/optics/PPrism; + public final fun id ()Larrow/optics/PIso; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/optics/PPrism; public final fun none ()Larrow/optics/PPrism; public final fun only (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Larrow/optics/PPrism; @@ -319,7 +411,7 @@ public abstract interface class arrow/optics/PTraversal { public final class arrow/optics/PTraversal$Companion { public final fun codiagonal ()Larrow/optics/PTraversal; public final fun either ()Larrow/optics/PTraversal; - public final fun id ()Larrow/optics/PTraversal; + public final fun id ()Larrow/optics/PIso; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function10;)Larrow/optics/PTraversal; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function11;)Larrow/optics/PTraversal; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function9;)Larrow/optics/PTraversal; diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt new file mode 100644 index 00000000000..74b120c00e7 --- /dev/null +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt @@ -0,0 +1,230 @@ +package arrow.optics + +import arrow.core.Either +import arrow.core.NonEmptyList +import arrow.core.None +import arrow.core.Option +import arrow.core.Either.Right +import arrow.core.Some +import arrow.core.compose +import arrow.core.identity +import kotlin.jvm.JvmStatic + +/** + * [Iso] is a type alias for [PIso] which fixes the type arguments + * and restricts the [PIso] to monomorphic updates. + */ +public typealias Iso = PIso + +private val stringToList: Iso> = + Iso( + get = CharSequence::toList, + reverseGet = { it.joinToString(separator = "") } + ) + +/** + * An [Iso] is a loss less invertible optic that defines an isomorphism between a type [S] and [A] + * i.e. a data class and its properties represented by TupleN + * + * A (polymorphic) [PIso] is useful when setting or modifying a value for a constructed type + * i.e. PIso, Option, Int?, String?> + * + * An [PIso] is also a valid [PLens], [PPrism] + * + * @param S the source of a [PIso] + * @param T the modified source of a [PIso] + * @param A the focus of a [PIso] + * @param B the modified target of a [PIso] + */ +public interface PIso : PPrism, PLens { + + /** + * Get the focus of a [PIso] + */ + override fun get(source: S): A + + /** + * Get the modified focus of a [PIso] + */ + override fun reverseGet(focus: B): T + + override fun getOrModify(source: S): Either = + Right(get(source)) + + override fun set(source: S, focus: B): T = + set(focus) + + /** + * Modify polymorphically the focus of a [PIso] with a function + */ + override fun modify(source: S, map: (focus: A) -> B): T = + reverseGet(map(get(source))) + + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + map(get(source)) + + /** + * Reverse a [PIso]: the source becomes the target and the target becomes the source + */ + public fun reverse(): PIso = + PIso(this::reverseGet, this::get) + + /** + * Set polymorphically the focus of a [PIso] with a value + */ + public fun set(b: B): T = + reverseGet(b) + + /** + * Pair two disjoint [PIso] + */ + public infix fun split(other: PIso): PIso, Pair, Pair, Pair> = + PIso( + { (a, c) -> get(a) to other.get(c) }, + { (b, d) -> reverseGet(b) to other.reverseGet(d) } + ) + + /** + * Create a pair of the [PIso] and a type [C] + */ + override fun first(): PIso, Pair, Pair, Pair> = Iso( + { (a, c) -> get(a) to c }, + { (b, c) -> reverseGet(b) to c } + ) + + /** + * Create a pair of a type [C] and the [PIso] + */ + override fun second(): PIso, Pair, Pair, Pair> = PIso( + { (c, a) -> c to get(a) }, + { (c, b) -> c to reverseGet(b) } + ) + + /** + * Create a sum of the [PIso] and a type [C] + */ + override fun left(): PIso, Either, Either, Either> = PIso( + { it.mapLeft(this::get) }, + { it.mapLeft(this::reverseGet) } + ) + + /** + * Create a sum of a type [C] and the [PIso] + */ + override fun right(): PIso, Either, Either, Either> = PIso( + { it.map(this::get) }, + { it.map(this::reverseGet) } + ) + + /** + * Compose a [PIso] with a [PIso] + */ + public infix fun compose(other: PIso): PIso = PIso( + other::get compose this::get, + this::reverseGet compose other::reverseGet + ) + + public operator fun plus(other: PIso): PIso = + this compose other + + public companion object { + + /** + * create an [PIso] between any type and itself. + * Id is the zero element of optics composition, for any optic o of type O (e.g. PLens, Prism, POptional, ...): + * o compose Iso.id == o + */ + public fun id(): Iso = Iso(::identity, ::identity) + + /** + * Invoke operator overload to create a [PIso] of type `S` with target `A`. + * Can also be used to construct [Iso] + */ + public operator fun invoke(get: (S) -> (A), reverseGet: (B) -> T): PIso = + object : PIso { + override fun get(source: S): A = get(source) + override fun reverseGet(focus: B): T = reverseGet(focus) + } + + /** + * [PIso] that defines equality between a [List] and [Option] [NonEmptyList] + */ + @JvmStatic + public fun listToPOptionNel(): PIso, List, Option>, Option>> = + PIso( + get = { aas -> if (aas.isEmpty()) None else Some(NonEmptyList(aas.first(), aas.drop(1))) }, + reverseGet = { optNel -> optNel.fold({ emptyList() }, NonEmptyList::all) } + ) + + /** + * [Iso] that defines equality between a [List] and [Option] [NonEmptyList] + */ + @JvmStatic + public fun listToOptionNel(): Iso, Option>> = + listToPOptionNel() + + /** + * [Iso] that defines the equality between a Unit value [Map] and a [Set] with its keys + */ + @JvmStatic + public fun mapToSet(): Iso, Set> = + Iso( + get = { it.keys }, + reverseGet = { keys -> keys.associateWith { } } + ) + + /** + * [PIso] that defines the equality between the nullable platform type and [Option]. + */ + @JvmStatic + public fun nullableToPOption(): PIso, Option> = + PIso( + get = Option.Companion::fromNullable, + reverseGet = { it.fold({ null }, ::identity) } + ) + + @JvmStatic + public fun nullableToOption(): PIso, Option> = + nullableToPOption() + + /** + * [PIso] that defines the equality between [Option] and the nullable platform type. + */ + @JvmStatic + public fun optionToPNullable(): PIso, Option, A?, B?> = + PIso( + get = { it.fold({ null }, ::identity) }, + reverseGet = Option.Companion::fromNullable + ) + + /** + * [PIso] that defines the isomorphic relationship between [Option] and the nullable platform type. + */ + @JvmStatic + public fun optionToNullable(): Iso, A?> = optionToPNullable() + + /** + * [Iso] that defines the equality between and [arrow.core.Option] and [arrow.core.Either] + */ + @JvmStatic + public fun optionToPEither(): PIso, Option, Either, Either> = + PIso( + get = { opt -> opt.fold({ Either.Left(Unit) }, ::Right) }, + reverseGet = { either -> either.fold({ None }, ::Some) } + ) + + /** + * [Iso] that defines the equality between and [arrow.core.Option] and [arrow.core.Either] + */ + @JvmStatic + public fun optionToEither(): Iso, Either> = + optionToPEither() + + /** + * [Iso] that defines equality between String and [List] of [Char] + */ + @JvmStatic + public fun stringToList(): Iso> = + stringToList + } +} diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt index 2f9b0a42d7a..aa054a7bf8e 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt @@ -85,10 +85,7 @@ public interface PLens : POptional { public companion object { - public fun id(): Lens = Lens( - get = { it }, - set = { _, s -> s } - ) + public fun id(): Iso = PIso.id() /** * [PLens] that takes either [S] or [S] and strips the choice of [S]. diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt index 1f720a17469..2557601ed5c 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt @@ -156,7 +156,7 @@ public interface POptional : PTraversal { public companion object { - public fun id(): Optional = PLens.id() + public fun id(): Iso = PIso.id() /** * [POptional] that takes either [S] or [S] and strips the choice of [S]. diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index 4922ae54b2b..ada507dbd72 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -126,10 +126,7 @@ public interface PPrism : POptional { public companion object { - public fun id(): Prism = PPrism( - getOrModify = { it.right() }, - reverseGet = ::identity - ) + public fun id(): Iso = PIso.id() /** * Invoke operator overload to create a [PPrism] of type `S` with focus `A`. diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt index a38d61cc1d9..f17a1c9f22d 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt @@ -165,7 +165,7 @@ public interface PTraversal { public companion object { - public fun id(): Traversal = PLens.id() + public fun id(): Iso = PIso.id() public fun codiagonal(): Traversal, S> = object : Traversal, S> { diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt new file mode 100644 index 00000000000..4f7d0d8d7e8 --- /dev/null +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt @@ -0,0 +1,177 @@ +package arrow.optics + +import arrow.core.Either +import arrow.optics.test.functionAToB +import arrow.optics.test.laws.IsoLaws +import arrow.optics.test.laws.LensLaws +import arrow.optics.test.laws.OptionalLaws +import arrow.optics.test.laws.PrismLaws +import arrow.optics.test.laws.TraversalLaws +import arrow.optics.test.laws.testLaws +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe +import io.kotest.property.Arb +import io.kotest.property.arbitrary.boolean +import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.string +import io.kotest.property.checkAll + +class IsoTest : StringSpec({ + + val aIso: Iso = Iso( + get = { a: SumType.A -> a.string }, + reverseGet = SumType::A + ) + + testLaws( + "Iso token - ", + LensLaws( + lens = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + PrismLaws( + prism = aIso, + aGen = Arb.sumTypeA(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + TraversalLaws( + traversal = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + OptionalLaws( + optional = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + IsoLaws( + iso = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ) + ) + + with(Iso.token()) { + + "asFold should behave as valid Fold: size" { + checkAll(Arb.token()) { token -> + size(token) shouldBe 1 + } + } + + "asFold should behave as valid Fold: nonEmpty" { + checkAll(Arb.token()) { token -> + isNotEmpty(token) shouldBe true + } + } + + "asFold should behave as valid Fold: isEmpty" { + checkAll(Arb.token()) { token -> + !isEmpty(token) shouldBe true + } + } + + "asFold should behave as valid Fold: getAll" { + checkAll(Arb.token()) { token -> + getAll(token) shouldBe listOf(token.value) + } + } + + "asFold should behave as valid Fold: fold" { + checkAll(Arb.token()) { token -> + fold("", { x, y -> x + y }, token) shouldBe token.value + } + } + + "asFold should behave as valid Fold: headOption" { + checkAll(Arb.token()) { token -> + firstOrNull(token) shouldBe token.value + } + } + + "asFold should behave as valid Fold: lastOption" { + checkAll(Arb.token()) { token -> + lastOrNull(token) shouldBe token.value + } + } + } + + "Lifting a function should yield the same result as not yielding" { + checkAll(Arb.token(), Arb.string()) { token, value -> + Iso.token().modify(token) { value } shouldBe Iso.token().lift { value }(token) + } + } + + "Creating a first pair with a type should result in the target to value" { + val first = Iso.token().first() + checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> + first.get(token to int) shouldBe (token.value to int) + } + } + + "Creating a second pair with a type should result in the value to target" { + val second = Iso.token().second() + checkAll(Arb.int(), Arb.token()) { int: Int, token: Token -> + second.get(int to token) shouldBe (int to token.value) + } + } + + "Creating a left with a type should result in a sum target to value" { + val left = Iso.token().left() + checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> + left.get(Either.Left(token)) shouldBe Either.Left(token.value) + left.get(Either.Right(int)) shouldBe Either.Right(int) + } + } + + "Creating a right with a type should result in a sum value to target" { + val left = Iso.token().right() + checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> + left.get(Either.Left(int)) shouldBe Either.Left(int) + left.get(Either.Right(token)) shouldBe Either.Right(token.value) + } + } + + "Finding a target using a predicate within a Iso should be wrapped in the correct option result" { + checkAll(Arb.boolean()) { predicate: Boolean -> + (Iso.token().findOrNull(Token("any value")) { predicate }?.let { true } ?: false) shouldBe predicate + } + } + + "Checking existence predicate over the target should result in same result as predicate" { + checkAll(Arb.boolean()) { predicate: Boolean -> + Iso.token().any(Token("any value")) { predicate } shouldBe predicate + } + } + + "Pairing two disjoint isos together" { + val joinedIso = Iso.token() split Iso.user() + + checkAll(Arb.string()) { tokenValue: String -> + val token = Token(tokenValue) + val user = User(token) + joinedIso.get(token to user) shouldBe (tokenValue to token) + } + } + + "Composing isos should result in an iso of the first iso's value with the second iso's target" { + val composedIso = Iso.user() compose Iso.token() + + checkAll(Arb.string()) { tokenValue: String -> + val token = Token(tokenValue) + val user = User(token) + composedIso.get(user) shouldBe tokenValue + } + } + +}) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt index d861c59f0f9..a6d7f7d9abf 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt @@ -37,9 +37,14 @@ internal fun PLens.Companion.token(): Lens = PLens( { token: Token, value: String -> token.copy(value = value) } ) -internal fun PLens.Companion.user(): Lens = PLens( +internal fun PIso.Companion.token(): Iso = Iso( + { token: Token -> token.value }, + ::Token +) + +internal fun PIso.Companion.user(): Iso = Iso( { user: User -> user.token }, - { user: User, token: Token -> user.copy(token = token) } + ::User ) internal data class Token(val value: String) { @@ -58,6 +63,11 @@ internal data class IncompleteUser(val token: Token?) internal fun Arb.Companion.incompleteUser(): Arb = Arb.constant(IncompleteUser(null)) +internal fun PLens.Companion.user(): Lens = PLens( + { user: User -> user.token }, + { user: User, token: Token -> user.copy(token = token) } +) + internal fun POptional.Companion.incompleteUserToken(): Optional = Optional( getOrModify = { user -> user.token?.right() ?: user.left() }, set = { user, token -> user.copy(token = token) } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt index f8f43972b4e..6f44f00e158 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt @@ -1,10 +1,14 @@ package arrow.optics.std +import arrow.optics.Iso import arrow.optics.Optional import arrow.optics.test.functionAToB +import arrow.optics.test.laws.IsoLaws import arrow.optics.test.laws.OptionalLaws import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws +import arrow.optics.test.nonEmptyList +import arrow.optics.test.option import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.int @@ -38,4 +42,14 @@ class ListTest : StringSpec({ ) ) + testLaws( + "Iso list to Option Nel - ", + IsoLaws( + iso = Iso.listToOptionNel(), + aGen = Arb.list(Arb.int()), + bGen = Arb.option(Arb.nonEmptyList(Arb.int())), + funcGen = Arb.functionAToB(Arb.option(Arb.nonEmptyList(Arb.int()))), + ) + ) + }) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt new file mode 100644 index 00000000000..070d980f532 --- /dev/null +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt @@ -0,0 +1,25 @@ +package arrow.optics.std + +import arrow.optics.Iso +import arrow.optics.test.functionAToB +import arrow.optics.test.laws.IsoLaws +import arrow.optics.test.laws.testLaws +import io.kotest.core.spec.style.StringSpec +import io.kotest.property.Arb +import io.kotest.property.arbitrary.constant +import io.kotest.property.arbitrary.map +import io.kotest.property.arbitrary.set +import io.kotest.property.arbitrary.string + +class MapTest : StringSpec({ + + testLaws( + IsoLaws( + iso = Iso.mapToSet(), + aGen = Arb.map(Arb.string(), Arb.constant(Unit)), + bGen = Arb.set(Arb.string()), + funcGen = Arb.functionAToB(Arb.set(Arb.string())), + ) + ) + +}) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt index 14cd7504033..f00588377c4 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt @@ -1,7 +1,10 @@ package arrow.optics.std +import arrow.optics.Iso import arrow.optics.Prism +import arrow.optics.test.either import arrow.optics.test.functionAToB +import arrow.optics.test.laws.IsoLaws import arrow.optics.test.laws.PrismLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.option @@ -9,6 +12,7 @@ import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.constant import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.orNull class OptionTest : StringSpec({ @@ -31,4 +35,25 @@ class OptionTest : StringSpec({ funcGen = Arb.functionAToB(Arb.constant(Unit)), ) ) + + testLaws( + "Iso option to nullable - ", + IsoLaws( + iso = Iso.optionToNullable().reverse(), + aGen = Arb.int().orNull(), + bGen = Arb.option(Arb.int()), + funcGen = Arb.functionAToB(Arb.option(Arb.int())) + ) + ) + + testLaws( + "Iso option to either - ", + IsoLaws( + iso = Iso.optionToEither(), + aGen = Arb.option(Arb.int()), + bGen = Arb.either(Arb.constant(Unit), Arb.int()), + funcGen = Arb.functionAToB(Arb.either(Arb.constant(Unit), Arb.int())), + ) + ) + }) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt new file mode 100644 index 00000000000..9703d4d3453 --- /dev/null +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt @@ -0,0 +1,25 @@ +package arrow.optics.std + +import arrow.optics.Iso +import arrow.optics.test.laws.IsoLaws +import arrow.optics.test.laws.testLaws +import io.kotest.core.spec.style.StringSpec +import io.kotest.property.Arb +import io.kotest.property.arbitrary.char +import io.kotest.property.arbitrary.list +import io.kotest.property.arbitrary.map +import io.kotest.property.arbitrary.string + +class StringTest : StringSpec({ + + testLaws( + "Iso string to list - ", + IsoLaws( + iso = Iso.stringToList(), + aGen = Arb.string(), + bGen = Arb.list(Arb.char()), + funcGen = Arb.list(Arb.char()).map { list -> { chars: List -> list + chars } }, + ) + ) + +}) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt new file mode 100644 index 00000000000..b48664abd52 --- /dev/null +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt @@ -0,0 +1,52 @@ +package arrow.optics.test.laws + +import arrow.core.compose +import arrow.core.identity +import arrow.optics.Iso +import io.kotest.property.Arb +import io.kotest.property.PropertyContext +import io.kotest.property.checkAll + +data class IsoLaws( + val iso: Iso, + val aGen: Arb, + val bGen: Arb, + val funcGen: Arb<(B) -> B>, + val eqa: (A, A) -> Boolean = { a, b -> a == b }, + val eqb: (B, B) -> Boolean = { a, b -> a == b } +): LawSet { + + override val laws: List = + listOf( + Law("Iso Law: round trip one way") { iso.roundTripOneWay(aGen, eqa) }, + Law("Iso Law: round trip other way") { iso.roundTripOtherWay(bGen, eqb) }, + Law("Iso Law: modify identity is identity") { iso.modifyIdentity(aGen, eqa) }, + Law("Iso Law: compose modify") { iso.composeModify(aGen, funcGen, eqa) }, + Law("Iso Law: consitent set with modify") { iso.consistentSetModify(aGen, bGen, eqa) } + ) + + private suspend fun Iso.roundTripOneWay(aGen: Arb, eq: (A, A) -> Boolean): PropertyContext = + checkAll(100, aGen) { a -> + reverseGet(get(a)).equalUnderTheLaw(a, eq) + } + + private suspend fun Iso.roundTripOtherWay(bGen: Arb, eq: (B, B) -> Boolean): PropertyContext = + checkAll(100, bGen) { b -> + get(reverseGet(b)).equalUnderTheLaw(b, eq) + } + + private suspend fun Iso.modifyIdentity(aGen: Arb, eq: (A, A) -> Boolean): PropertyContext = + checkAll(100, aGen) { a -> + modify(a, ::identity).equalUnderTheLaw(a, eq) + } + + private suspend fun Iso.composeModify(aGen: Arb, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext = + checkAll(100, aGen, funcGen, funcGen) { a, f, g -> + modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq) + } + + private suspend fun Iso.consistentSetModify(aGen: Arb, bGen: Arb, eq: (A, A) -> Boolean): PropertyContext = + checkAll(100, aGen, bGen) { a, b -> + set(b).equalUnderTheLaw(modify(a) { b }, eq) + } +} From b230b448b090713cbc3eb20b771ea6757c5dd8f6 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Mon, 3 Apr 2023 09:19:08 +0200 Subject: [PATCH 036/114] Update BOM (#3019) --- arrow-libs/stack/build.gradle.kts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arrow-libs/stack/build.gradle.kts b/arrow-libs/stack/build.gradle.kts index 4435af4134a..a40777fba34 100644 --- a/arrow-libs/stack/build.gradle.kts +++ b/arrow-libs/stack/build.gradle.kts @@ -10,15 +10,15 @@ group = property("projects.group").toString() dependencies { constraints { api("io.arrow-kt:arrow-annotations:$version") - api("io.arrow-kt:arrow-continuations:$version") + api("io.arrow-kt:arrow-atomic:$version") api("io.arrow-kt:arrow-core:$version") + api("io.arrow-kt:arrow-functions:$version") api("io.arrow-kt:arrow-core-retrofit:$version") - api("io.arrow-kt:arrow-core-test:$version") api("io.arrow-kt:arrow-fx-coroutines:$version") - api("io.arrow-kt:arrow-fx-coroutines-test:$version") api("io.arrow-kt:arrow-fx-stm:$version") - api("io.arrow-kt:arrow-meta:$version") + api("io.arrow-kt:arrow-resilience:$version") api("io.arrow-kt:arrow-optics:$version") - api("io.arrow-kt:arrow-optics-test:$version") + api("io.arrow-kt:arrow-optics-reflect:$version") + api("io.arrow-kt:arrow-optics-ksp-plugin:$version") } } From f410ec5ae95250ee0f5c481957765dbb5d16cbad Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Mon, 3 Apr 2023 10:27:56 +0200 Subject: [PATCH 037/114] Fix andThen duplication (#3020) --- arrow-libs/core/arrow-core/api/arrow-core.api | 7 - .../kotlin/arrow/core/composition.kt | 10 - .../kotlin/arrow/core/composition-js.kt | 13 - .../kotlin/arrow/core/composition-jvm.kt | 256 ------------------ .../kotlin/arrow/core/composition-native.kt | 13 - .../src/commonMain/kotlin/arrow/optics/Iso.kt | 6 +- .../commonMain/kotlin/arrow/optics/Prism.kt | 1 - .../kotlin/arrow/optics/test/laws/IsoLaws.kt | 3 +- .../kotlin/arrow/optics/test/laws/LensLaws.kt | 3 +- .../arrow/optics/test/laws/OptionalLaws.kt | 3 +- .../arrow/optics/test/laws/PrismLaws.kt | 3 +- .../arrow/optics/test/laws/TraversalLaws.kt | 3 +- 12 files changed, 7 insertions(+), 314 deletions(-) delete mode 100644 arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/composition.kt delete mode 100644 arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/composition-js.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/composition-jvm.kt delete mode 100644 arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/composition-native.kt diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 0df36228a49..c2342398ed7 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -24,13 +24,6 @@ public final class arrow/core/ComparisonKt { public static final fun sort (S[S)Ljava/util/List; } -public final class arrow/core/Composition { - public static final fun andThen (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function0; - public static final fun andThen (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static final fun andThen (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function2; - public static final fun compose (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; -} - public abstract class arrow/core/Either { public static final field Companion Larrow/core/Either$Companion; public static final fun catch (Lkotlin/jvm/functions/Function0;)Larrow/core/Either; diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/composition.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/composition.kt deleted file mode 100644 index 3e6bb1e896f..00000000000 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/composition.kt +++ /dev/null @@ -1,10 +0,0 @@ -@file:JvmName("Composition") - -package arrow.core - -import kotlin.jvm.JvmName - -public expect infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R -public expect infix fun (() -> IP).andThen(f: (IP) -> R): () -> R -public expect infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R -public expect infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R diff --git a/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/composition-js.kt b/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/composition-js.kt deleted file mode 100644 index b55950777aa..00000000000 --- a/arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/composition-js.kt +++ /dev/null @@ -1,13 +0,0 @@ -package arrow.core - -public actual infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R = - { p1, p2 -> f(this(p1, p2)) } - -public actual infix fun (() -> IP).andThen(f: (IP) -> R): () -> R = - { f(this()) } - -public actual infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R = - { p1 -> f(this(p1)) } - -public actual infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R = - { p1 -> this(f(p1)) } diff --git a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/composition-jvm.kt b/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/composition-jvm.kt deleted file mode 100644 index 2156ea10d38..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/composition-jvm.kt +++ /dev/null @@ -1,256 +0,0 @@ -@file:JvmName("Composition") - -package arrow.core - -import kotlin.jvm.JvmName - -public actual infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R = - AndThen2(this).andThen(f) - -public actual infix fun (() -> IP).andThen(f: (IP) -> R): () -> R = - AndThen0(this).andThen(f) - -public actual infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R = - AndThen1(this).andThen(f) - -public actual infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R = - AndThen1(this).compose(f) - -/** - * Establishes the maximum stack depth when fusing `andThen` or `compose` calls. - * - * The default is `128`, from which we substract one as an - * optimization. This default has been reached like this: - * - * - according to official docs, the default stack size on 32-bits - * Windows and Linux was 320 KB, whereas for 64-bits it is 1024 KB - * - according to measurements chaining `Function1` references uses - * approximately 32 bytes of stack space on a 64 bits system; - * this could be lower if "compressed oops" is activated - * - therefore a "map fusion" that goes 128 in stack depth can use - * about 4 KB of stack space - */ -private const val maxStackDepthSize = 127 - -private sealed class AndThen0 : () -> A { - - private data class Single(val f: () -> A, val index: Int) : AndThen0() - - private data class Concat(val left: AndThen0, val right: AndThen1) : AndThen0() { - override fun toString(): String = "AndThen.Concat(...)" - } - - fun andThen(g: (A) -> X): AndThen0 = - when (this) { - // Fusing calls up to a certain threshold - is Single -> - if (index != maxStackDepthSize) Single({ g(f()) }, index + 1) - else andThenF(AndThen1(g)) - else -> andThenF(AndThen1(g)) - } - - @Suppress("UNCHECKED_CAST") - override fun invoke(): A = - loop(this as AndThen0, Unit, 0) - - override fun toString(): String = - "AndThen0(...)" - - companion object { - - operator fun invoke(f: () -> A): AndThen0 = - when (f) { - is AndThen0 -> f - else -> Single(f, 0) - } - - @Suppress("UNCHECKED_CAST") - tailrec fun loop(self: AndThen0, current: Any?, joins: Int): A = when (self) { - is Single -> if (joins == 0) self.f() as A else loop(self.f() as AndThen0, null, joins - 1) - is Concat<*, *> -> { - when (val oldLeft = self.left) { - is Single<*> -> { - val left = oldLeft as Single - val newSelf = self.right as AndThen1 - AndThen1.loop(newSelf, left.f(), joins) - } - is Concat<*, *> -> loop( - rotateAccumulate(self.left as AndThen0, self.right as AndThen1), - current, - joins - ) - } - } - } - - @Suppress("UNCHECKED_CAST") - tailrec fun rotateAccumulate( - left: AndThen0, - right: AndThen1 - ): AndThen0 = when (left) { - is Concat<*, *> -> rotateAccumulate( - left.left as AndThen0, - (left.right as AndThen1).andThenF(right) - ) - is Single<*> -> left.andThenF(right) - } - } - - fun andThenF(right: AndThen1): AndThen0 = - Concat(this, right) -} - -private sealed class AndThen1 : (A) -> B { - - private data class Single(val f: (A) -> B, val index: Int) : AndThen1() - - private data class Concat(val left: AndThen1, val right: AndThen1) : AndThen1() { - override fun toString(): String = "AndThen.Concat(...)" - } - - fun andThen(g: (B) -> X): AndThen1 = - when (this) { - // Fusing calls up to a certain threshold - is Single -> - if (index != maxStackDepthSize) Single({ a: A -> g(this(a)) }, index + 1) - else andThenF(AndThen1(g)) - else -> andThenF(AndThen1(g)) - } - - infix fun compose(g: (C) -> A): AndThen1 = - when (this) { - // Fusing calls up to a certain threshold - is Single -> - if (index != maxStackDepthSize) Single({ c: C -> this(g(c)) }, index + 1) - else composeF(AndThen1(g)) - else -> composeF(AndThen1(g)) - } - - @Suppress("UNCHECKED_CAST") - override fun invoke(a: A): B = loop(this as AndThen1, a, 0) - - override fun toString(): String = "AndThen(...)" - - companion object { - - operator fun invoke(f: (A) -> B): AndThen1 = - when (f) { - is AndThen1 -> f - else -> Single(f, 0) - } - - @Suppress("UNCHECKED_CAST") - tailrec fun loop(self: AndThen1, current: Any?, joins: Int): B = when (self) { - is Single -> if (joins == 0) self.f(current) as B else loop( - self.f(current) as AndThen1, - null, - joins - 1 - ) - is Concat<*, *, *> -> { - when (val oldLeft = self.left) { - is Single<*, *> -> { - val left = oldLeft as Single - val newSelf = self.right as AndThen1 - loop(newSelf, left.f(current), joins) - } - is Concat<*, *, *> -> loop( - rotateAccumulate(self.left as AndThen1, self.right as AndThen1), - current, - joins - ) - } - } - } - - @Suppress("UNCHECKED_CAST") - tailrec fun rotateAccumulate( - left: AndThen1, - right: AndThen1 - ): AndThen1 = when (left) { - is Concat<*, *, *> -> rotateAccumulate( - left.left as AndThen1, - (left.right as AndThen1).andThenF(right) - ) - is Single<*, *> -> left.andThenF(right) - } - } - - fun andThenF(right: AndThen1): AndThen1 = - Concat(this, right) - - fun composeF(right: AndThen1): AndThen1 = - Concat(right, this) -} - -private sealed class AndThen2 : (A, B) -> C { - - private data class Single(val f: (A, B) -> C, val index: Int) : AndThen2() - - private data class Concat(val left: AndThen2, val right: AndThen1) : AndThen2() { - override fun toString(): String = "AndThen.Concat(...)" - } - - fun andThen(g: (C) -> X): AndThen2 = - when (this) { - // Fusing calls up to a certain threshold - is Single -> - if (index != maxStackDepthSize) Single({ a: A, b: B -> g(this(a, b)) }, index + 1) - else andThenF(AndThen1(g)) - else -> andThenF(AndThen1(g)) - } - - @Suppress("UNCHECKED_CAST") - override fun invoke(a: A, b: B): C = - loop(this as AndThen2, a, b, 0) - - override fun toString(): String = "AndThen(...)" - - companion object { - - operator fun invoke(f: (A, B) -> C): AndThen2 = - when (f) { - is AndThen2 -> f - else -> Single(f, 0) - } - - @Suppress("UNCHECKED_CAST") - tailrec fun loop(self: AndThen2, currentA: Any?, currentB: Any?, joins: Int): C = - when (self) { - is Single<*, *, *> -> { - val f = self.f as ((Any?, Any?) -> Any?) - if (joins == 0) f(currentA, currentB) as C - else loop(f(currentA, currentB) as AndThen2, null, null, joins - 1) - } - is Concat<*, *, *, *> -> { - when (val oldLeft = self.left) { - is Single<*, *, *> -> { - val left = oldLeft as Single - val newSelf = self.right as AndThen1 - AndThen1.loop(newSelf, left.f(currentA, currentB), joins) - } - is Concat<*, *, *, *> -> loop( - rotateAccumulate(self.left as AndThen2, self.right as AndThen1), - currentA, - currentB, - joins - ) - } - } - } - - @Suppress("UNCHECKED_CAST") - tailrec fun rotateAccumulate( - left: AndThen2, - right: AndThen1 - ): AndThen2 = when (left) { - is Concat<*, *, *, *> -> rotateAccumulate( - left.left as AndThen2, - (left.right as AndThen1).andThenF(right) - ) - is Single<*, *, *> -> left.andThenF(right) - } - } - - fun andThenF(right: AndThen1): AndThen2 = - Concat(this, right) -} diff --git a/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/composition-native.kt b/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/composition-native.kt deleted file mode 100644 index b55950777aa..00000000000 --- a/arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/composition-native.kt +++ /dev/null @@ -1,13 +0,0 @@ -package arrow.core - -public actual infix fun ((P1, P2) -> IP).andThen(f: (IP) -> R): (P1, P2) -> R = - { p1, p2 -> f(this(p1, p2)) } - -public actual infix fun (() -> IP).andThen(f: (IP) -> R): () -> R = - { f(this()) } - -public actual infix fun ((P1) -> IP).andThen(f: (IP) -> R): (P1) -> R = - { p1 -> f(this(p1)) } - -public actual infix fun ((IP) -> R).compose(f: (P1) -> IP): (P1) -> R = - { p1 -> this(f(p1)) } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt index 74b120c00e7..21f2f678eab 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt @@ -6,7 +6,6 @@ import arrow.core.None import arrow.core.Option import arrow.core.Either.Right import arrow.core.Some -import arrow.core.compose import arrow.core.identity import kotlin.jvm.JvmStatic @@ -120,9 +119,8 @@ public interface PIso : PPrism, PLens { * Compose a [PIso] with a [PIso] */ public infix fun compose(other: PIso): PIso = PIso( - other::get compose this::get, - this::reverseGet compose other::reverseGet - ) + { s -> other.get(get(s)) } + ) { d -> reverseGet(other.reverseGet(d)) } public operator fun plus(other: PIso): PIso = this compose other diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index ada507dbd72..1807b1ed6a6 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -6,7 +6,6 @@ import arrow.core.Either.Right import arrow.core.None import arrow.core.Option import arrow.core.Some -import arrow.core.compose import arrow.core.flatMap import arrow.core.identity import arrow.core.left diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt index b48664abd52..b1cac3fee70 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/IsoLaws.kt @@ -1,6 +1,5 @@ package arrow.optics.test.laws -import arrow.core.compose import arrow.core.identity import arrow.optics.Iso import io.kotest.property.Arb @@ -42,7 +41,7 @@ data class IsoLaws( private suspend fun Iso.composeModify(aGen: Arb, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext = checkAll(100, aGen, funcGen, funcGen) { a, f, g -> - modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq) + modify(modify(a, f), g).equalUnderTheLaw(modify(a) { g(f(it)) }, eq) } private suspend fun Iso.consistentSetModify(aGen: Arb, bGen: Arb, eq: (A, A) -> Boolean): PropertyContext = diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/LensLaws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/LensLaws.kt index 0b687d8db58..6d5cd7e93d7 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/LensLaws.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/LensLaws.kt @@ -1,6 +1,5 @@ package arrow.optics.test.laws -import arrow.core.compose import arrow.core.identity import arrow.optics.Lens import io.kotest.property.Arb @@ -67,7 +66,7 @@ data class LensLaws( private suspend fun lensComposeModify(lensGen: Arb>, aGen: Arb, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext = checkAll(100, lensGen, aGen, funcGen, funcGen) { lens, a, f, g -> lens.run { - modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq) + modify(modify(a, f), g).equalUnderTheLaw(modify(a) { g(f(it)) }, eq) } } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/OptionalLaws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/OptionalLaws.kt index 5bd11edd042..95c4e429b55 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/OptionalLaws.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/OptionalLaws.kt @@ -1,6 +1,5 @@ package arrow.optics.test.laws -import arrow.core.compose import arrow.core.identity import arrow.optics.Optional import io.kotest.property.Arb @@ -94,7 +93,7 @@ data class OptionalLaws( checkAll(100, optionalGen, aGen, funcGen, funcGen) { optional, a, f, g -> optional.run { modify(modify(a, f), g) - .equalUnderTheLaw(modify(a, g compose f), eq) + .equalUnderTheLaw(modify(a) { g(f(it)) }, eq) } } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/PrismLaws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/PrismLaws.kt index 64b41f5ea8d..aec60e8fa3d 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/PrismLaws.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/PrismLaws.kt @@ -1,6 +1,5 @@ package arrow.optics.test.laws -import arrow.core.compose import arrow.core.identity import arrow.optics.Prism import io.kotest.property.Arb @@ -43,7 +42,7 @@ data class PrismLaws( private suspend fun Prism.composeModify(aGen: Arb, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext = checkAll(100, aGen, funcGen, funcGen) { a, f, g -> - modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq) + modify(modify(a, f), g).equalUnderTheLaw(modify(a) { g(f(it)) }, eq) } private suspend fun Prism.consistentSetModify(aGen: Arb, bGen: Arb, eq: (A, A) -> Boolean): PropertyContext = diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/TraversalLaws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/TraversalLaws.kt index 152e7e62497..28c718856dc 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/TraversalLaws.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/TraversalLaws.kt @@ -1,6 +1,5 @@ package arrow.optics.test.laws -import arrow.core.compose import arrow.core.identity import arrow.optics.Traversal import io.kotest.property.Arb @@ -45,6 +44,6 @@ data class TraversalLaws( funcGen ) { a, f, g -> modify(modify(a, f), g) - .equalUnderTheLaw(modify(a, g compose f), eq) + .equalUnderTheLaw(modify(a) { g(f(it)) }, eq) } } From 8a55a06d1a98e5ff737e1ad3f8e9c00c0a6cd668 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Mon, 3 Jul 2023 10:52:43 +0200 Subject: [PATCH 038/114] Fix Knit --- .../src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt | 2 +- .../src/jvmTest/kotlin/examples/example-resource-08.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt index 380a2ab846b..3626d8d5934 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt @@ -422,7 +422,7 @@ public fun resource( * } * * suspend fun main() { - * Path.of("example.kt") + * Path("example.kt") * .readAll() * .collect(::println) * } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt index 43f2a268f06..75766ca0c09 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-resource-08.kt @@ -18,7 +18,7 @@ fun Path.readAll(): Flow = flow { } suspend fun main() { - Path.of("example.kt") + Path("example.kt") .readAll() .collect(::println) } From f93ac0ae3268add66a87349d8acd1ecaf4d16eaa Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Wed, 5 Jul 2023 11:08:27 +0200 Subject: [PATCH 039/114] Fix weird problem with value classes --- .../kotlin/arrow/core/NonEmptyList.kt | 12 ++++++++++++ .../kotlin/arrow/core/NonEmptySet.kt | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index 5378b98a2b5..436c6f175ec 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -179,6 +179,14 @@ public value class NonEmptyList @PublishedApi internal constructor( else -> head } + @Suppress("OVERRIDE_BY_INLINE") + public override inline fun distinct(): NonEmptyList = + NonEmptyList(all.distinct()) + + @Suppress("OVERRIDE_BY_INLINE") + public override inline fun distinctBy(selector: (A) -> K): NonEmptyList = + NonEmptyList(all.distinctBy(selector)) + @Suppress("OVERRIDE_BY_INLINE") public override inline fun map(transform: (A) -> B): NonEmptyList = NonEmptyList(all.map(transform)) @@ -187,6 +195,10 @@ public value class NonEmptyList @PublishedApi internal constructor( public override inline fun flatMap(transform: (A) -> NonEmptyCollection): NonEmptyList = NonEmptyList(all.flatMap(transform)) + @Suppress("OVERRIDE_BY_INLINE") + public override inline fun mapIndexed(transform: (index:Int, A) -> B): NonEmptyList = + NonEmptyList(all.mapIndexed(transform)) + public operator fun plus(l: NonEmptyList<@UnsafeVariance A>): NonEmptyList = this + l.all diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt index c879ad3b448..2dcfe12d677 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptySet.kt @@ -32,6 +32,24 @@ public value class NonEmptySet private constructor( @Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS") override fun hashCode(): Int = elements.hashCode() + + public override fun distinct(): NonEmptyList = + NonEmptyList(elements.distinct()) + + public override fun distinctBy(selector: (A) -> K): NonEmptyList = + NonEmptyList(elements.distinctBy(selector)) + + public override fun map(transform: (A) -> B): NonEmptyList = + NonEmptyList(elements.map(transform)) + + public override fun flatMap(transform: (A) -> NonEmptyCollection): NonEmptyList = + NonEmptyList(elements.flatMap(transform)) + + public override fun mapIndexed(transform: (index:Int, A) -> B): NonEmptyList = + NonEmptyList(elements.mapIndexed(transform)) + + override fun zip(other: NonEmptyCollection): NonEmptyList> = + NonEmptyList(elements.zip(other)) } public fun nonEmptySetOf(first: A, vararg rest: A): NonEmptySet = From 81adc524e57002349d4ecb221218a2ef8fe38301 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Wed, 5 Jul 2023 11:11:25 +0200 Subject: [PATCH 040/114] Update API docs --- arrow-libs/core/arrow-core/api/arrow-core.api | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index a36d2f681fa..ea3d85c443b 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -510,8 +510,9 @@ public final class arrow/core/NonEmptySet : arrow/core/NonEmptyCollection, java/ public fun toString ()Ljava/lang/String; public static fun toString-impl (Ljava/util/Set;)Ljava/lang/String; public final synthetic fun unbox-impl ()Ljava/util/Set; - public fun zip (Larrow/core/NonEmptyCollection;)Larrow/core/NonEmptyCollection; - public static fun zip-impl (Ljava/util/Set;Larrow/core/NonEmptyCollection;)Larrow/core/NonEmptyCollection; + public synthetic fun zip (Larrow/core/NonEmptyCollection;)Larrow/core/NonEmptyCollection; + public fun zip-0-xjo5U (Larrow/core/NonEmptyCollection;)Ljava/util/List; + public static fun zip-0-xjo5U (Ljava/util/Set;Larrow/core/NonEmptyCollection;)Ljava/util/List; } public final class arrow/core/NonEmptySetKt { From 6524b172e2f60c8a5aa30b3cb9638d22642b5f38 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Mon, 10 Jul 2023 13:43:38 +0200 Subject: [PATCH 041/114] Update publish workflow Following the instructions in https://github.com/arrow-kt/arrow/pull/3090#issuecomment-1628697141 --- .github/workflows/publish.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 710222f14ae..b4d2c421136 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -42,8 +42,7 @@ jobs: - name: assemble uses: gradle/gradle-build-action@v2 with: -# arguments: assemble -Pversion=${{ inputs.version }} -Pkotlin.mpp.enableCompatibilityMetadataVariant=true - arguments: assemble -Pversion=2.0.0-SNAPSHOT -Pkotlin.mpp.enableCompatibilityMetadataVariant=true + arguments: assemble -Psemver.stage=snapshot -Psemver.scope=major - name: Upload reports if: failure() @@ -55,4 +54,4 @@ jobs: - name: Publish next major SNAPSHOT version uses: gradle/gradle-build-action@v2 with: - arguments: -Pkotlin.mpp.enableCompatibilityMetadataVariant=true -Pversion=2.0.0-SNAPSHOT publishToSonatype closeSonatypeStagingRepository + arguments: -Psemver.stage=snapshot -Psemver.scope=major publishToSonatype closeSonatypeStagingRepository From 1f4b2dab9b893dcc13e87df99cccc505f8333ef6 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Mon, 10 Jul 2023 14:25:30 +0200 Subject: [PATCH 042/114] No closing repo on snapshot --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b4d2c421136..f34a2295bc2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -54,4 +54,4 @@ jobs: - name: Publish next major SNAPSHOT version uses: gradle/gradle-build-action@v2 with: - arguments: -Psemver.stage=snapshot -Psemver.scope=major publishToSonatype closeSonatypeStagingRepository + arguments: -Psemver.stage=snapshot -Psemver.scope=major publishToSonatype From 797bcbe892ec2d61262a94b337f2fa7cb530609c Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Tue, 29 Aug 2023 12:25:44 +0200 Subject: [PATCH 043/114] knit --- .../kotlin/arrow/fx/coroutines/flow.kt | 2 +- .../jvmTest/kotlin/examples/example-flow-04.kt | 16 ++++++++++++++++ .../arrow/optics/plugin/internals/processor.kt | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-04.kt diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt index db3f6212738..d12aa01c3ad 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt @@ -168,7 +168,7 @@ public inline fun Flow.parMapUnordered( * } * //sampleEnd * ``` - * + * */ @FlowPreview @ExperimentalCoroutinesApi diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-04.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-04.kt new file mode 100644 index 00000000000..8968edc20ad --- /dev/null +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-flow-04.kt @@ -0,0 +1,16 @@ +// This file was automatically generated from flow.kt by Knit tool. Do not edit. +package arrow.fx.coroutines.examples.exampleFlow04 + +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.flow.collect +import arrow.fx.coroutines.parMapNotNullUnordered + +suspend fun main(): Unit { + flowOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .parMapNotNullUnordered { a -> + delay(100) + a.takeIf { a % 2 == 0 } + }.toList() // [4, 6, 2, 8, 10] +} diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index 4b9e833143b..b42b9a8e97e 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -47,11 +47,11 @@ internal fun KSClassDeclaration.targets(): List = .filter { targets.isEmpty() || it in targets } else -> if (targets.isEmpty()) { - listOf(OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.OPTIONAL, OpticsTarget.DSL) + listOf(OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL) } else { targets.filter { when (it) { - OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.OPTIONAL, OpticsTarget.DSL -> true + OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL -> true else -> false } } From e60b62799659e5d6cff8d7730d350a70750d20c4 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 30 Aug 2023 09:31:21 +0200 Subject: [PATCH 044/114] Fix optics tests --- .../optics/plugin/internals/processor.kt | 24 +++++++------------ .../kotlin/arrow/optics/plugin/Compilation.kt | 8 +++++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index b42b9a8e97e..ac05262e74b 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -22,12 +22,15 @@ internal fun adt(c: KSClassDeclaration, logger: KSPLogger): ADT = OpticsTarget.LENS -> evalAnnotatedDataClass(c, c.qualifiedNameOrSimpleName.lensErrorMessage, logger) .let(::LensTarget) + OpticsTarget.ISO -> evalAnnotatedValueClass(c, c.qualifiedNameOrSimpleName.isoErrorMessage, logger) .let(::IsoTarget) + OpticsTarget.PRISM -> evalAnnotatedPrismElement(c, c.qualifiedNameOrSimpleName.prismErrorMessage, logger) .let(::PrismTarget) + OpticsTarget.DSL -> evalAnnotatedDslElement(c, logger) } }, @@ -37,25 +40,16 @@ internal fun KSClassDeclaration.targets(): List = targetsFromOpticsAnnotation().let { targets -> when { isSealed -> - if (targets.isEmpty()) { - listOf(OpticsTarget.PRISM, OpticsTarget.DSL) - } else { - targets.filter { it == OpticsTarget.PRISM || it == OpticsTarget.DSL } - } + listOf(OpticsTarget.PRISM, OpticsTarget.DSL) + .filter { targets.isEmpty() || it in targets } + isValue -> listOf(OpticsTarget.ISO, OpticsTarget.DSL) .filter { targets.isEmpty() || it in targets } + else -> - if (targets.isEmpty()) { - listOf(OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL) - } else { - targets.filter { - when (it) { - OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL -> true - else -> false - } - } - } + listOf(OpticsTarget.LENS, OpticsTarget.DSL) + .filter { targets.isEmpty() || it in targets } } } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt index 37380de368a..f2c70b03b2a 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt @@ -28,12 +28,16 @@ fun String.compilationFails() { fun String.compilationSucceeds(allWarningsAsErrors: Boolean = false) { val compilationResult = compile(this, allWarningsAsErrors = allWarningsAsErrors) - Assertions.assertThat(compilationResult.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + Assertions.assertThat(compilationResult.exitCode) + .withFailMessage(compilationResult.messages) + .isEqualTo(KotlinCompilation.ExitCode.OK) } fun String.evals(thing: Pair) { val compilationResult = compile(this) - Assertions.assertThat(compilationResult.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + Assertions.assertThat(compilationResult.exitCode) + .withFailMessage(compilationResult.messages) + .isEqualTo(KotlinCompilation.ExitCode.OK) val classesDirectory = compilationResult.outputDirectory val (variable, output) = thing Assertions.assertThat(eval(variable, classesDirectory)).isEqualTo(output) From 8bb12748d8ad46200c3f08087b721c83f0a24835 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Thu, 19 Oct 2023 08:09:01 +0200 Subject: [PATCH 045/114] Fix after merge --- .../commonTest/kotlin/arrow/core/TupleTest.kt | 81 ------------------- 1 file changed, 81 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt index b1d4c6e7346..8a625392dca 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt @@ -161,87 +161,6 @@ class TupleTest : StringSpec({ Tuple9(a, b, c, d, e, f, g, h, i).compareTo(Tuple9(a, b, c, d, e, f, g, h, i + 1)) shouldBe -1 } } - - "toStringN" { - checkAll( - Arb.int(), - Arb.int(), - Arb.int(), - Arb.int(), - Arb.int(), - Arb.int(), - Arb.int(), - Arb.int(), - Arb.int(), - Arb.int() - ) { a, b, c, d, e, f, g, h, i, j -> - Tuple10(a, b, c, d, e, f, g, h, i, j).toString() shouldBe "($a, $b, $c, $d, $e, $f, $g, $h, $i, $j)" - } - } - - "plusN" { - checkAll( - Arb.list(Arb.int(), 4..4), - Arb.list(Arb.int(), 4..4), - Arb.list(Arb.int(), 4..4), - Arb.list(Arb.int(), 4..4), - Arb.list(Arb.int(), 4..4), - Arb.list(Arb.int(), 2..2), - ) { (a, b, c, d), (e, f, g, h), (i, j, k, l), (m, n, o, p), (q, r, s, t), (u, v) -> - Tuple9(a, b, c, d, e, f, g, h, i) + j shouldBe Tuple10(a, b, c, d, e, f, g, h, i, j) - Tuple10(a, b, c, d, e, f, g, h, i, j) + k shouldBe Tuple11(a, b, c, d, e, f, g, h, i, j, k) - Tuple11(a, b, c, d, e, f, g, h, i, j, k) + l shouldBe Tuple12(a, b, c, d, e, f, g, h, i, j, k, l) - Tuple12(a, b, c, d, e, f, g, h, i, j, k, l) + m shouldBe Tuple13(a, b, c, d, e, f, g, h, i, j, k, l, m) - Tuple13(a, b, c, d, e, f, g, h, i, j, k, l, m) + n shouldBe Tuple14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) - Tuple14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) + o shouldBe Tuple15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) - Tuple15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) + p shouldBe Tuple16(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - Tuple16(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + q shouldBe Tuple17(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) - Tuple17(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) + r shouldBe Tuple18(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) - Tuple18(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) + s shouldBe Tuple19(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) - Tuple19(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) + t shouldBe Tuple20(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) - Tuple20(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) + u shouldBe Tuple21(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) - Tuple21(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) + v shouldBe Tuple22(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) - } - } - - "compareToN(equals)" { - checkAll( - Arb.list(Arb.int(), 4..4), - Arb.list(Arb.int(), 4..4), - Arb.list(Arb.int(), 2..2), - ) { (a, b, c, d), (e, f, g, h), (i, j) -> - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d, e, f, g, h, i, j)) shouldBe 0 - } - } - - "compareToN(not equals)" { - checkAll( - Arb.list(Arb.intOpenEnded(), 4..4), - Arb.list(Arb.intOpenEnded(), 4..4), - Arb.list(Arb.intOpenEnded(), 2..2), - ) { (a, b, c, d), (e, f, g, h), (i, j) -> - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a + 1, b, c, d, e, f, g, h, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a - 1, b, c, d, e, f, g, h, i, j)) shouldBe 1 - } - } - - "compareToN(deep not equals)" { - checkAll( - Arb.list(Arb.intOpenEnded(), 4..4), - Arb.list(Arb.intOpenEnded(), 4..4), - Arb.list(Arb.intOpenEnded(), 2..2), - ) { (a, b, c, d), (e, f, g, h), (i, j) -> - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b + 1, c, d, e, f, g, h, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c + 1, d, e, f, g, h, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d + 1, e, f, g, h, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d, e + 1, f, g, h, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d, e, f + 1, g, h, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d, e, f, g + 1, h, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d, e, f, g, h + 1, i, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d, e, f, g, h, i + 1, j)) shouldBe -1 - Tuple10(a, b, c, d, e, f, g, h, i, j).compareTo(Tuple10(a, b, c, d, e, f, g, h, i, j + 1)) shouldBe -1 - } - } }) private fun Arb.Companion.intOpenEnded() = Arb.int(Int.MIN_VALUE + 1, Int.MAX_VALUE - 1) From 8f12894b24055d1607409927200e328c7c85406b Mon Sep 17 00:00:00 2001 From: Andreas Storesund Madsen Date: Tue, 24 Oct 2023 23:13:13 +0200 Subject: [PATCH 046/114] Refactor ParMapTest from Kotest Plugin to Kotlin-test runtime #3191 (#3221) Co-authored-by: Simon Vergauwen Co-authored-by: Alejandro Serrano --- arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts index 827dbd4077f..7564b54ed64 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts @@ -37,12 +37,6 @@ kotlin { } } - jvmTest { - dependencies { - runtimeOnly(libs.kotest.runnerJUnit5) - } - } - jvmMain { dependencies { implementation(libs.kotlin.stdlib) From e75d31efa9c8a96d947e2096bdc9e414fc41deb6 Mon Sep 17 00:00:00 2001 From: molikuner Date: Wed, 25 Oct 2023 06:56:41 +0000 Subject: [PATCH 047/114] Refactor: Use Kotlin-test runtime for arrow-fx-stm tests (#3224) Co-authored-by: Alejandro Serrano --- arrow-libs/fx/arrow-fx-stm/build.gradle.kts | 25 +- .../kotlin/arrow/fx/stm/KotestConfig.kt | 10 - .../commonTest/kotlin/arrow/fx/stm/STMTest.kt | 462 +++++++++--------- .../kotlin/arrow/fx/stm/TArrayTest.kt | 60 +-- .../kotlin/arrow/fx/stm/TMVarTest.kt | 270 +++++----- .../kotlin/arrow/fx/stm/TMapTest.kt | 91 ++-- .../kotlin/arrow/fx/stm/TQueueTest.kt | 229 +++++---- .../kotlin/arrow/fx/stm/TSemaphoreTest.kt | 159 +++--- 8 files changed, 679 insertions(+), 627 deletions(-) delete mode 100644 arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/KotestConfig.kt diff --git a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts index 31786faea44..d8448e947e5 100644 --- a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts @@ -5,7 +5,6 @@ plugins { alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) alias(libs.plugins.kotlinx.kover) - alias(libs.plugins.kotest.multiplatform) alias(libs.plugins.spotless) } @@ -22,7 +21,6 @@ kotlin { commonMain { dependencies { api(projects.arrowCore) - compileOnly(libs.kotlin.stdlibCommon) implementation(libs.coroutines.core) } } @@ -30,25 +28,10 @@ kotlin { commonTest { dependencies { implementation(projects.arrowFxCoroutines) - implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) - } - } - jvmTest { - dependencies { - runtimeOnly(libs.kotest.runnerJUnit5) - } - } - - jvmMain { - dependencies { - implementation(libs.kotlin.stdlib) - } - } - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) + implementation(libs.kotlin.test) + implementation(libs.coroutines.test) } } } @@ -61,3 +44,7 @@ kotlin { } } } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/KotestConfig.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/KotestConfig.kt deleted file mode 100644 index ed1e6d93002..00000000000 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/KotestConfig.kt +++ /dev/null @@ -1,10 +0,0 @@ -package arrow.fx.stm - -import io.kotest.core.config.AbstractProjectConfig -import io.kotest.property.PropertyTesting - -class KotestConfig : AbstractProjectConfig() { - override suspend fun beforeProject() { - PropertyTesting.defaultIterationCount = 250 - } -} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt index 38264295207..2623f4dace7 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/STMTest.kt @@ -4,7 +4,6 @@ import arrow.fx.coroutines.parMap import arrow.fx.coroutines.parZip import arrow.fx.stm.internal.BlockedIndefinitely import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.ints.shouldBeInRange import io.kotest.matchers.shouldBe @@ -15,257 +14,278 @@ import io.kotest.property.checkAll import kotlinx.coroutines.async import kotlinx.coroutines.delay import kotlinx.coroutines.joinAll +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withTimeoutOrNull +import kotlin.test.Ignore +import kotlin.test.Test import kotlin.time.Duration.Companion.microseconds import kotlin.time.Duration.Companion.milliseconds import kotlin.time.ExperimentalTime @ExperimentalTime -class STMTest : StringSpec({ - "no-effects" { - atomically { 10 } shouldBeExactly 10 - } - "reading from vars" { - checkAll(Arb.int()) { i: Int -> - val tv = TVar.new(i) - atomically { - tv.read() - } shouldBeExactly i - tv.unsafeRead() shouldBeExactly i - } +class STMTest { + + @Test fun noEffects() = runTest { + atomically { 10 } shouldBeExactly 10 + } + + @Test fun readingFromVars() = runTest { + checkAll(Arb.int()) { i: Int -> + val tv = TVar.new(i) + atomically { + tv.read() + } shouldBeExactly i + tv.unsafeRead() shouldBeExactly i } - "reading and writing" { - checkAll(Arb.int(), Arb.int()) { i: Int, j: Int -> - val tv = TVar.new(i) - atomically { tv.write(j) } - tv.unsafeRead() shouldBeExactly j - } + } + + @Test fun readingAndWriting() = runTest { + checkAll(Arb.int(), Arb.int()) { i: Int, j: Int -> + val tv = TVar.new(i) + atomically { tv.write(j) } + tv.unsafeRead() shouldBeExactly j } - "read after a write should have the updated value" { - checkAll(Arb.int(), Arb.int()) { i: Int, j: Int -> - val tv = TVar.new(i) - atomically { tv.write(j); tv.read() } shouldBeExactly j - tv.unsafeRead() shouldBeExactly j - } + } + + @Test fun readAfterAWriteShouldHaveTheUpdatedValue() = runTest { + checkAll(Arb.int(), Arb.int()) { i: Int, j: Int -> + val tv = TVar.new(i) + atomically { tv.write(j); tv.read() } shouldBeExactly j + tv.unsafeRead() shouldBeExactly j } - "reading multiple variables" { - checkAll(Arb.int(), Arb.int(), Arb.int()) { i: Int, j: Int, k: Int -> - val v1 = TVar.new(i) - val v2 = TVar.new(j) - val v3 = TVar.new(k) - atomically { v1.read() + v2.read() + v3.read() } shouldBeExactly i + j + k - v1.unsafeRead() shouldBeExactly i - v2.unsafeRead() shouldBeExactly j - v3.unsafeRead() shouldBeExactly k - } + } + + @Test fun readingMultipleVariables() = runTest { + checkAll(Arb.int(), Arb.int(), Arb.int()) { i: Int, j: Int, k: Int -> + val v1 = TVar.new(i) + val v2 = TVar.new(j) + val v3 = TVar.new(k) + atomically { v1.read() + v2.read() + v3.read() } shouldBeExactly i + j + k + v1.unsafeRead() shouldBeExactly i + v2.unsafeRead() shouldBeExactly j + v3.unsafeRead() shouldBeExactly k } - "reading and writing multiple variables" { - checkAll(Arb.int(), Arb.int(), Arb.int()) { i: Int, j: Int, k: Int -> - val v1 = TVar.new(i) - val v2 = TVar.new(j) - val v3 = TVar.new(k) - val sum = TVar.new(0) - atomically { - val s = v1.read() + v2.read() + v3.read() - sum.write(s) - } - v1.unsafeRead() shouldBeExactly i - v2.unsafeRead() shouldBeExactly j - v3.unsafeRead() shouldBeExactly k - sum.unsafeRead() shouldBeExactly i + j + k + } + + @Test fun readingAndWritingMultipleVariables() = runTest { + checkAll(Arb.int(), Arb.int(), Arb.int()) { i: Int, j: Int, k: Int -> + val v1 = TVar.new(i) + val v2 = TVar.new(j) + val v3 = TVar.new(k) + val sum = TVar.new(0) + atomically { + val s = v1.read() + v2.read() + v3.read() + sum.write(s) } + v1.unsafeRead() shouldBeExactly i + v2.unsafeRead() shouldBeExactly j + v3.unsafeRead() shouldBeExactly k + sum.unsafeRead() shouldBeExactly i + j + k } - "retry without prior reads throws an exception" { - shouldThrow { atomically { retry() } } - } - "retry should suspend forever if no read variable changes" { - withTimeoutOrNull(500.milliseconds) { - val tv = TVar.new(0) - atomically { - if (tv.read() == 0) retry() - else 200 - } - } shouldBe null - } - "a suspended transaction will resume if a variable changes" { + } + + @Test fun retryWithoutPriorReadsThrowsAnException() = runTest { + shouldThrow { atomically { retry() } } + } + + @Test fun retryShouldSuspendForeverIfNoReadVariableChanges() = runTest { + withTimeoutOrNull(500.milliseconds) { val tv = TVar.new(0) - val f = async { - delay(500.milliseconds) - atomically { tv.modify { it + 1 } } - } atomically { - when (val i = tv.read()) { - 0 -> retry() - else -> i - } - } shouldBeExactly 1 - f.join() - } - "a suspended transaction will resume if any variable changes" { - val v1 = TVar.new(0) - val v2 = TVar.new(0) - val v3 = TVar.new(0) - val f = async { - delay(500.milliseconds) - atomically { v1.modify { it + 1 } } - delay(500.milliseconds) - atomically { v2.modify { it + 1 } } - delay(500.milliseconds) - atomically { v3.modify { it + 1 } } + if (tv.read() == 0) retry() + else 200 } - atomically { - val i = v1.read() + v2.read() + v3.read() - check(i >= 3) - i - } shouldBeExactly 3 - f.join() - } - "retry + orElse: retry orElse t1 = t1" { - atomically { - stm { retry() } orElse { 10 } - } shouldBeExactly 10 + } shouldBe null + } + + @Test fun aSuspendedTransactionWillResumeIfAVariableChanges() = runTest { + val tv = TVar.new(0) + val f = async { + delay(500.milliseconds) + atomically { tv.modify { it + 1 } } } - "retry + orElse: t1 orElse retry = t1" { - atomically { - stm { 10 } orElse { retry() } - } shouldBeExactly 10 + atomically { + when (val i = tv.read()) { + 0 -> retry() + else -> i + } + } shouldBeExactly 1 + f.join() + } + + @Test fun aSuspendedTransactionWillResumeIfAnyVariableChanges() = runTest { + val v1 = TVar.new(0) + val v2 = TVar.new(0) + val v3 = TVar.new(0) + val f = async { + delay(500.milliseconds) + atomically { v1.modify { it + 1 } } + delay(500.milliseconds) + atomically { v2.modify { it + 1 } } + delay(500.milliseconds) + atomically { v3.modify { it + 1 } } } - "retry + orElse: associativity" { - checkAll(Arb.boolean(), Arb.boolean(), Arb.boolean()) { b1: Boolean, b2: Boolean, b3: Boolean -> - if ((b1 || b2 || b3).not()) { - shouldThrow { - atomically { - stm { stm { check(b1) } orElse { check(b2) } } orElse { check(b3) } - } - } shouldBe shouldThrow { - atomically { - stm { check(b1) } orElse { stm { check(b2) } orElse { check(b3) } } - } - } - } else { + atomically { + val i = v1.read() + v2.read() + v3.read() + check(i >= 3) + i + } shouldBeExactly 3 + f.join() + } + + @Test fun retryOrElseRetryOrElseT1T1() = runTest { + atomically { + stm { retry() } orElse { 10 } + } shouldBeExactly 10 + } + + @Test fun retryOrElseT1OrElseRetryT1() = runTest { + atomically { + stm { 10 } orElse { retry() } + } shouldBeExactly 10 + } + + @Test fun retryOrElseAssociativity() = runTest { + checkAll(Arb.boolean(), Arb.boolean(), Arb.boolean()) { b1: Boolean, b2: Boolean, b3: Boolean -> + if ((b1 || b2 || b3).not()) { + shouldThrow { atomically { stm { stm { check(b1) } orElse { check(b2) } } orElse { check(b3) } - } shouldBe atomically { + } + } shouldBe shouldThrow { + atomically { stm { check(b1) } orElse { stm { check(b2) } orElse { check(b3) } } } } + } else { + atomically { + stm { stm { check(b1) } orElse { check(b2) } } orElse { check(b3) } + } shouldBe atomically { + stm { check(b1) } orElse { stm { check(b2) } orElse { check(b3) } } + } } } - "suspended transactions are resumed for variables accessed in orElse" { - val tv = TVar.new(0) - val f = async { - delay(10.microseconds) - atomically { tv.modify { it + 1 } } + } + + @Test fun suspendedTransactionsAreResumedForVariablesAccessedInOrElse() = runTest { + val tv = TVar.new(0) + val f = async { + delay(10.microseconds) + atomically { tv.modify { it + 1 } } + } + atomically { + stm { + when (val i = tv.read()) { + 0 -> retry() + else -> i } + } orElse { retry() } + } shouldBeExactly 1 + f.join() + } + + @Test fun onASingleVariableConcurrentTransactionsShouldBeLinear() = runTest { + val tv = TVar.new(0) + val res = TQueue.new() + + (0..100).map { + async { atomically { - stm { - when (val i = tv.read()) { - 0 -> retry() - else -> i - } - } orElse { retry() } - } shouldBeExactly 1 - f.join() - } - "on a single variable concurrent transactions should be linear" { - val tv = TVar.new(0) - val res = TQueue.new() + val r = tv.read().also { tv.write(it + 1) } + res.write(r) + } + } + }.joinAll() - (0..100).map { - async { - atomically { - val r = tv.read().also { tv.write(it + 1) } - res.write(r) - } - } - }.joinAll() + atomically { res.flush() } shouldBe (0..100).toList() + } - atomically { res.flush() } shouldBe (0..100).toList() - } - "atomically rethrows exceptions" { - shouldThrow { atomically { throw IllegalArgumentException("Test") } } + @Test fun atomicallyRethrowsExceptions() = runTest { + shouldThrow { atomically { throw IllegalArgumentException("Test") } } + } + + @Test fun throwingAnExceptionsShouldVoidAllStateChanges() = runTest { + val tv = TVar.new(10) + shouldThrow { + atomically { tv.write(30); throw IllegalArgumentException("test") } } - "throwing an exceptions should void all state changes" { - val tv = TVar.new(10) - shouldThrow { - atomically { tv.write(30); throw IllegalArgumentException("test") } + tv.unsafeRead() shouldBeExactly 10 + } + + @Test fun catchShouldWorkAsExcepted() = runTest { + val tv = TVar.new(10) + val ex = IllegalArgumentException("test") + atomically { + catch({ + tv.write(30) + throw ex + }) { e -> + e shouldBe ex } - tv.unsafeRead() shouldBeExactly 10 } - "catch should work as excepted" { - val tv = TVar.new(10) - val ex = IllegalArgumentException("test") - atomically { - catch({ - tv.write(30) - throw ex - }) { e -> - e shouldBe ex + tv.unsafeRead() shouldBeExactly 10 + } + + @Test fun concurrentExample1() = runTest { + val acc1 = TVar.new(100) + val acc2 = TVar.new(200) + parZip( + { + // transfer acc1 to acc2 + val amount = 50 + atomically { + val acc1Balance = acc1.read() + check(acc1Balance - amount >= 0) + acc1.write(acc1Balance - amount) + acc2.modify { it + 50 } } - } - tv.unsafeRead() shouldBeExactly 10 - } - "concurrent example 1" { - val acc1 = TVar.new(100) - val acc2 = TVar.new(200) - parZip( - { - // transfer acc1 to acc2 - val amount = 50 - atomically { - val acc1Balance = acc1.read() - check(acc1Balance - amount >= 0) - acc1.write(acc1Balance - amount) - acc2.modify { it + 50 } - } - }, - { - atomically { acc1.modify { it - 60 } } - delay(20.milliseconds) - atomically { acc1.modify { it + 60 } } - }, - { _, _ -> Unit } - ) - acc1.unsafeRead() shouldBeExactly 50 - acc2.unsafeRead() shouldBeExactly 250 - } + }, + { + atomically { acc1.modify { it - 60 } } + delay(20.milliseconds) + atomically { acc1.modify { it + 60 } } + }, + { _, _ -> Unit } + ) + acc1.unsafeRead() shouldBeExactly 50 + acc2.unsafeRead() shouldBeExactly 250 + } - // TypeError: Cannot read property 'toString' of undefined - // at ObjectLiteral_0.test(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:3661) - // at .invokeMatcher(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:19216) - // at .should(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:19212) - // at .shouldBeInRange(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:3652) - // at STMTransaction.f(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:261217) - // at commit.doResume(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:270552) - // at commit.CoroutineImpl.resumeWith(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:118697) - // at CancellableContinuationImpl.DispatchedTask.run(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:174593) - // at WindowMessageQueue.MessageQueue.process(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:177985) - // at .(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:177940) - "concurrent example 2".config(enabled = false) { - val tq = TQueue.new() - parZip( - { - // producers - (0..4).parMap { - for (i in (it * 20 + 1)..(it * 20 + 20)) { - atomically { tq.write(i) } - } - } - }, - { - val collected = mutableSetOf() - for (i in 1..100) { - // consumer - atomically { - tq.read().also { it shouldBeInRange (1..100) } - }.also { collected.add(it) } - } - // verify that we got 100 unique numbers - collected.size shouldBeExactly 100 + // TypeError: Cannot read property 'toString' of undefined + // at ObjectLiteral_0.test(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:3661) + // at .invokeMatcher(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:19216) + // at .should(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:19212) + // at .shouldBeInRange(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:3652) + // at STMTransaction.f(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:261217) + // at commit.doResume(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:270552) + // at commit.CoroutineImpl.resumeWith(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:118697) + // at CancellableContinuationImpl.DispatchedTask.run(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:174593) + // at WindowMessageQueue.MessageQueue.process(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:177985) + // at .(/var/folders/x5/6r18d9w52c7czy6zh5m1spvw0000gn/T/_karma_webpack_624630/commons.js:177940) + @Test @Ignore fun concurrentExample2ConfigEnabledFalse() = runTest { + val tq = TQueue.new() + parZip( + { + // producers + (0..4).parMap { + for (i in (it * 20 + 1)..(it * 20 + 20)) { + atomically { tq.write(i) } } - ) { _, _ -> Unit } - // the above only finishes if the consumer reads at least 100 values, this here is just to make sure there are no leftovers - atomically { tq.flush() } shouldBe emptyList() - } - -}) + } + }, + { + val collected = mutableSetOf() + for (i in 1..100) { + // consumer + atomically { + tq.read().also { it shouldBeInRange (1..100) } + }.also { collected.add(it) } + } + // verify that we got 100 unique numbers + collected.size shouldBeExactly 100 + } + ) { _, _ -> Unit } + // the above only finishes if the consumer reads at least 100 values, this here is just to make sure there are no leftovers + atomically { tq.flush() } shouldBe emptyList() + } +} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TArrayTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TArrayTest.kt index c8bf40ebad2..3bb492174ff 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TArrayTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TArrayTest.kt @@ -1,35 +1,39 @@ package arrow.fx.stm -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.shouldBe +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class TArrayTest : StringSpec({ - "creating an array" { - val t1 = TArray.new(10) { it } - t1.size() shouldBeExactly 10 - atomically { t1.fold(0) { acc, v -> acc + v } } shouldBeExactly (0..9).sum() - atomically { (0..9).fold(true) { acc, v -> t1.get(v) == v && acc } } shouldBe true +class TArrayTest { - val t2 = atomically { newTArray(10) { it } } - t2.size() shouldBeExactly 10 - atomically { t2.fold(0) { acc, v -> acc + v } } shouldBeExactly (0..9).sum() - atomically { (0..9).fold(true) { acc, v -> t2.get(v) == v && acc } } shouldBe true - } - "get should get the correct value" { - val t2 = atomically { newTArray(20) { it } } - atomically { (0..19).fold(true) { acc, v -> t2.get(v) == v && acc } } shouldBe true - } - "write should write to the correct value" { - val t2 = atomically { newTArray(20) { it } } - atomically { t2.get(5) } shouldBeExactly 5 - atomically { t2[5] = 2 } - atomically { t2.get(5) } shouldBeExactly 2 - } - "transform should perform an operation on each element" { - val t2 = atomically { newTArray(20) { it } } - atomically { t2.transform { it * 2 } } - atomically { t2.fold(0) { acc, v -> acc + v } } shouldBeExactly (0..19).sum() * 2 - } + @Test fun creatingAnArray() = runTest { + val t1 = TArray.new(10) { it } + t1.size() shouldBeExactly 10 + atomically { t1.fold(0) { acc, v -> acc + v } } shouldBeExactly (0..9).sum() + atomically { (0..9).fold(true) { acc, v -> t1.get(v) == v && acc } } shouldBe true + + val t2 = atomically { newTArray(10) { it } } + t2.size() shouldBeExactly 10 + atomically { t2.fold(0) { acc, v -> acc + v } } shouldBeExactly (0..9).sum() + atomically { (0..9).fold(true) { acc, v -> t2.get(v) == v && acc } } shouldBe true + } + + @Test fun getShouldGetTheCorrectValue() = runTest { + val t2 = atomically { newTArray(20) { it } } + atomically { (0..19).fold(true) { acc, v -> t2.get(v) == v && acc } } shouldBe true + } + + @Test fun writeShouldWriteToTheCorrectValue() = runTest { + val t2 = atomically { newTArray(20) { it } } + atomically { t2.get(5) } shouldBeExactly 5 + atomically { t2[5] = 2 } + atomically { t2.get(5) } shouldBeExactly 2 + } + + @Test fun transformShouldPerformAnOperationOnEachElement() = runTest { + val t2 = atomically { newTArray(20) { it } } + atomically { t2.transform { it * 2 } } + atomically { t2.fold(0) { acc, v -> acc + v } } shouldBeExactly (0..19).sum() * 2 } -) +} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMVarTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMVarTest.kt index eac2389e97b..4e23fd65780 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMVarTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMVarTest.kt @@ -1,140 +1,158 @@ package arrow.fx.stm -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.orNull import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class TMVarTest : StringSpec({ - "empty creates an empty TMVar" { - val t1 = TMVar.empty() - atomically { t1.tryTake() } shouldBe null - val t2 = atomically { newEmptyTMVar() } - atomically { t2.tryTake() } shouldBe null - } - "new creates a filled TMVar" { - val t1 = TMVar.new(100) - atomically { t1.take() } shouldBe 100 - val t2 = atomically { newTMVar(10) } - atomically { t2.take() } shouldBe 10 - } - "take leaves the TMVar empty" { - val tm = TMVar.new(500) - atomically { tm.take() } shouldBeExactly 500 - atomically { tm.tryTake() } shouldBe null - } - "isEmpty = tryRead == null" { - checkAll(Arb.int().orNull()) { i -> - val tm = when (i) { - null -> TMVar.empty() - else -> TMVar.new(i) - } - atomically { tm.isEmpty() } shouldBe - atomically { tm.tryRead() == null } - atomically { tm.isEmpty() } shouldBe - (i == null) - } - } - "isEmpty = tryRead != null" { - checkAll(Arb.int().orNull()) { i -> - val tm = when (i) { - null -> TMVar.empty() - else -> TMVar.new(i) - } - atomically { tm.isNotEmpty() } shouldBe - atomically { tm.tryRead() != null } - atomically { tm.isNotEmpty() } shouldBe - (i != null) +class TMVarTest { + + @Test fun emptyCreatesAnEmptyTMVar() = runTest { + val t1 = TMVar.empty() + atomically { t1.tryTake() } shouldBe null + val t2 = atomically { newEmptyTMVar() } + atomically { t2.tryTake() } shouldBe null + } + + @Test fun newCreatesAFilledTMVar() = runTest { + val t1 = TMVar.new(100) + atomically { t1.take() } shouldBe 100 + val t2 = atomically { newTMVar(10) } + atomically { t2.take() } shouldBe 10 + } + + @Test fun takeLeavesTheTMVarEmpty() = runTest { + val tm = TMVar.new(500) + atomically { tm.take() } shouldBeExactly 500 + atomically { tm.tryTake() } shouldBe null + } + + @Test fun isEmptyIsTryReadEqualsNull() = runTest { + checkAll(Arb.int().orNull()) { i -> + val tm = when (i) { + null -> TMVar.empty() + else -> TMVar.new(i) } + atomically { tm.isEmpty() } shouldBe + atomically { tm.tryRead() == null } + atomically { tm.isEmpty() } shouldBe + (i == null) } - "take retries on empty" { - val tm = TMVar.empty() - atomically { - stm { tm.take().let { true } } orElse { false } - } shouldBe false - atomically { tm.tryTake() } shouldBe null - } - "tryTake behaves like take if there is a value" { - val tm = TMVar.new(100) - atomically { - tm.tryTake() - } shouldBe 100 - atomically { tm.tryTake() } shouldBe null - } - "tryTake returns null on empty" { - val tm = TMVar.empty() - atomically { tm.tryTake() } shouldBe null - } - "read retries on empty" { - val tm = TMVar.empty() - atomically { - stm { tm.read().let { true } } orElse { false } - } shouldBe false - atomically { tm.tryTake() } shouldBe null - } - "read returns the value if not empty and does not remove it" { - val tm = TMVar.new(10) - atomically { - tm.read() - } shouldBe 10 - atomically { tm.tryTake() } shouldBe 10 - } - "tryRead behaves like read if there is a value" { - val tm = TMVar.new(100) - atomically { tm.tryRead() } shouldBe - atomically { tm.read() } - atomically { tm.tryTake() } shouldBe 100 - } - "tryRead returns null if there is no value" { - val tm = TMVar.empty() - atomically { tm.tryRead() } shouldBe null - atomically { tm.tryTake() } shouldBe null - } - "put retries if there is already a value" { - val tm = TMVar.new(5) - atomically { - stm { tm.put(100).let { true } } orElse { false } - } shouldBe false - atomically { tm.tryTake() } shouldBe 5 - } - "put replaces the value if it was empty" { - val tm = TMVar.empty() - atomically { - tm.put(100) - tm.tryTake() - } shouldBe 100 - } - "tryPut behaves like put if there is no value" { - val tm = TMVar.empty() - atomically { - tm.tryPut(100) - tm.tryTake() - } shouldBe atomically { - tm.put(100) - tm.tryTake() + } + + @Test fun isEmptyIsTryReadUnequalsNull() = runTest { + checkAll(Arb.int().orNull()) { i -> + val tm = when (i) { + null -> TMVar.empty() + else -> TMVar.new(i) } - atomically { tm.tryPut(30) } shouldBe true - atomically { tm.tryTake() } shouldBe 30 - } - "tryPut returns false if there is already a value" { - val tm = TMVar.new(30) - atomically { tm.tryPut(20) } shouldBe false - atomically { tm.tryTake() } shouldBe 30 - } - "swap replaces the current value only if it is not null" { - val tm = TMVar.new(30) - atomically { tm.swap(25) } shouldBeExactly 30 - atomically { tm.take() } shouldBeExactly 25 - } - "swap should retry if there is no value" { - val tm = TMVar.empty() - atomically { - stm { tm.swap(10).let { true } } orElse { false } - } shouldBe false - atomically { tm.tryTake() } shouldBe null + atomically { tm.isNotEmpty() } shouldBe + atomically { tm.tryRead() != null } + atomically { tm.isNotEmpty() } shouldBe + (i != null) } } -) + + @Test fun takeRetriesOnEmpty() = runTest { + val tm = TMVar.empty() + atomically { + stm { tm.take().let { true } } orElse { false } + } shouldBe false + atomically { tm.tryTake() } shouldBe null + } + + @Test fun tryTakeBehavesLikeTakeIfThereIsAValue() = runTest { + val tm = TMVar.new(100) + atomically { + tm.tryTake() + } shouldBe 100 + atomically { tm.tryTake() } shouldBe null + } + + @Test fun tryTakeReturnsNullOnEmpty() = runTest { + val tm = TMVar.empty() + atomically { tm.tryTake() } shouldBe null + } + + @Test fun readRetriesOnEmpty() = runTest { + val tm = TMVar.empty() + atomically { + stm { tm.read().let { true } } orElse { false } + } shouldBe false + atomically { tm.tryTake() } shouldBe null + } + + @Test fun readReturnsTheValueIfNotEmptyAndDoesNotRemoveIt() = runTest { + val tm = TMVar.new(10) + atomically { + tm.read() + } shouldBe 10 + atomically { tm.tryTake() } shouldBe 10 + } + + @Test fun tryReadBehavesLikeReadIfThereIsAValue() = runTest { + val tm = TMVar.new(100) + atomically { tm.tryRead() } shouldBe + atomically { tm.read() } + atomically { tm.tryTake() } shouldBe 100 + } + + @Test fun tryReadReturnsNullIfThereIsNoValue() = runTest { + val tm = TMVar.empty() + atomically { tm.tryRead() } shouldBe null + atomically { tm.tryTake() } shouldBe null + } + + @Test fun putRetriesIfThereIsAlreadyAValue() = runTest { + val tm = TMVar.new(5) + atomically { + stm { tm.put(100).let { true } } orElse { false } + } shouldBe false + atomically { tm.tryTake() } shouldBe 5 + } + + @Test fun putReplacesTheValueIfItWasEmpty() = runTest { + val tm = TMVar.empty() + atomically { + tm.put(100) + tm.tryTake() + } shouldBe 100 + } + + @Test fun tryPutBehavesLikePutIfThereIsNoValue() = runTest { + val tm = TMVar.empty() + atomically { + tm.tryPut(100) + tm.tryTake() + } shouldBe atomically { + tm.put(100) + tm.tryTake() + } + atomically { tm.tryPut(30) } shouldBe true + atomically { tm.tryTake() } shouldBe 30 + } + + @Test fun tryPutReturnsFalseIfThereIsAlreadyAValue() = runTest { + val tm = TMVar.new(30) + atomically { tm.tryPut(20) } shouldBe false + atomically { tm.tryTake() } shouldBe 30 + } + + @Test fun swapReplacesTheCurrentValueOnlyIfItIsNotNull() = runTest { + val tm = TMVar.new(30) + atomically { tm.swap(25) } shouldBeExactly 30 + atomically { tm.take() } shouldBeExactly 25 + } + + @Test fun swapShouldRetryIfThereIsNoValue() = runTest { + val tm = TMVar.empty() + atomically { + stm { tm.swap(10).let { true } } orElse { false } + } shouldBe false + atomically { tm.tryTake() } shouldBe null + } +} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMapTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMapTest.kt index a88c750fe9a..e7ea5776ddc 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMapTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TMapTest.kt @@ -1,59 +1,64 @@ package arrow.fx.stm -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe 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.test.runTest +import kotlin.test.Test -class TMapTest : StringSpec({ - "insert values" { - checkAll(Arb.int(), Arb.int()) { k, v -> - val map = TMap.new() - atomically { map.insert(k, v) } - atomically { map.lookup(k) } shouldBe v - } +class TMapTest { + + @Test fun insertValues() = runTest { + checkAll(Arb.int(), Arb.int()) { k, v -> + val map = TMap.new() + atomically { map.insert(k, v) } + atomically { map.lookup(k) } shouldBe v } - "insert multiple values" { - checkAll(Arb.map(Arb.int(), Arb.int())) { pairs -> - val map = TMap.new() - atomically { - for ((k, v) in pairs) map.insert(k, v) - } - atomically { - for ((k, v) in pairs) map.lookup(k) shouldBe v - } + } + + @Test fun insertMultipleValues() = runTest { + checkAll(Arb.map(Arb.int(), Arb.int())) { pairs -> + val map = TMap.new() + atomically { + for ((k, v) in pairs) map.insert(k, v) } - } - "insert multiple colliding values" { - checkAll(Arb.map(Arb.int(), Arb.int())) { pairs -> - val map = TMap.new { 0 } // hash function that always returns 0 - atomically { - for ((k, v) in pairs) map.insert(k, v) - } - atomically { - for ((k, v) in pairs) map.lookup(k) shouldBe v - } + atomically { + for ((k, v) in pairs) map.lookup(k) shouldBe v } } - "insert and remove" { - checkAll(Arb.int(), Arb.int()) { k, v -> - val map = TMap.new() - atomically { map.insert(k, v) } - atomically { map.lookup(k) } shouldBe v - atomically { map.remove(k) } - atomically { map.lookup(k) } shouldBe null + } + + @Test fun insertMultipleCollidingValues() = runTest { + checkAll(Arb.map(Arb.int(), Arb.int())) { pairs -> + val map = TMap.new { 0 } // hash function that always returns 0 + atomically { + for ((k, v) in pairs) map.insert(k, v) } - } - "update" { - checkAll(Arb.int(), Arb.int(), Arb.int()) { k, v, g -> - val map = TMap.new() - atomically { map.insert(k, v) } - atomically { map.lookup(k) } shouldBe v - atomically { map.update(k) { v + g } } - atomically { map.lookup(k) } shouldBe v + g + atomically { + for ((k, v) in pairs) map.lookup(k) shouldBe v } } } -) + + @Test fun insertAndRemove() = runTest { + checkAll(Arb.int(), Arb.int()) { k, v -> + val map = TMap.new() + atomically { map.insert(k, v) } + atomically { map.lookup(k) } shouldBe v + atomically { map.remove(k) } + atomically { map.lookup(k) } shouldBe null + } + } + + @Test fun update() = runTest { + checkAll(Arb.int(), Arb.int(), Arb.int()) { k, v, g -> + val map = TMap.new() + atomically { map.insert(k, v) } + atomically { map.lookup(k) } shouldBe v + atomically { map.update(k) { v + g } } + atomically { map.lookup(k) } shouldBe v + g + } + } +} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TQueueTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TQueueTest.kt index d55545e0329..8444f6e8518 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TQueueTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TQueueTest.kt @@ -1,124 +1,139 @@ package arrow.fx.stm -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest import kotlin.random.Random +import kotlin.test.Test -class TQueueTest : StringSpec({ - "writing to a queue adds an element" { - val tq = TQueue.new() - atomically { tq.write(10) } - atomically { tq.flush() } shouldBe listOf(10) - } - "reading from a queue should retry if the queue is empty" { - val tq = TQueue.new() - atomically { - stm { tq.read().let { true } } orElse { false } - } shouldBe false - } - "reading from a queue should remove that value" { - val tq = TQueue.new() - atomically { tq.write(10); tq.write(20) } - atomically { tq.read() } shouldBe 10 - atomically { tq.flush() } shouldBe listOf(20) - } - "tryRead behaves like read if there are values to read" { - val tq = TQueue.new() - atomically { tq.write(10) } - atomically { tq.tryRead() } shouldBe 10 - atomically { tq.flush() } shouldBe emptyList() - } - "tryRead returns null if the queue is empty" { - val tq = TQueue.new() - atomically { tq.tryRead() } shouldBe null - } - "flush empties the entire queue and returns it" { - val tq = TQueue.new() - atomically { tq.write(20); tq.write(30); tq.write(40) } - atomically { tq.flush() } shouldBe listOf(20, 30, 40) - atomically { tq.flush() } shouldBe emptyList() - } - "reading/flushing should work after mixed reads/writes" { - val tq = TQueue.new() - atomically { tq.write(20); tq.write(30); tq.peek(); tq.write(40) } - atomically { tq.read() } shouldBe 20 - atomically { tq.flush() } shouldBe listOf(30, 40) +class TQueueTest { - atomically { tq.write(20); tq.write(30); tq.peek(); tq.write(40) } - atomically { tq.flush() } shouldBe listOf(20, 30, 40) - atomically { tq.flush() } shouldBe emptyList() - } - "peek should leave the queue unchanged" { - val tq = TQueue.new() - atomically { tq.write(20); tq.write(30); tq.write(40) } - atomically { tq.peek() } shouldBeExactly 20 - atomically { tq.flush() } shouldBe listOf(20, 30, 40) - } - "peek should retry if the queue is empty" { + @Test fun writingToAQueueAddsAnElement() = runTest { + val tq = TQueue.new() + atomically { tq.write(10) } + atomically { tq.flush() } shouldBe listOf(10) + } + + @Test fun readingFromAQueueShouldRetryIfTheQueueIsEmpty() = runTest { + val tq = TQueue.new() + atomically { + stm { tq.read().let { true } } orElse { false } + } shouldBe false + } + + @Test fun readingFromAQueueShouldRemoveThatValue() = runTest { + val tq = TQueue.new() + atomically { tq.write(10); tq.write(20) } + atomically { tq.read() } shouldBe 10 + atomically { tq.flush() } shouldBe listOf(20) + } + + @Test fun tryReadBehavesLikeReadIfThereAreValuesToRead() = runTest { + val tq = TQueue.new() + atomically { tq.write(10) } + atomically { tq.tryRead() } shouldBe 10 + atomically { tq.flush() } shouldBe emptyList() + } + + @Test fun tryReadReturnsNullIfTheQueueIsEmpty() = runTest { + val tq = TQueue.new() + atomically { tq.tryRead() } shouldBe null + } + + @Test fun flushEmptiesTheEntireQueueAndReturnsIt() = runTest { + val tq = TQueue.new() + atomically { tq.write(20); tq.write(30); tq.write(40) } + atomically { tq.flush() } shouldBe listOf(20, 30, 40) + atomically { tq.flush() } shouldBe emptyList() + } + + @Test fun readingFlushingShouldWorkAfterMixedReadsWrites() = runTest { + val tq = TQueue.new() + atomically { tq.write(20); tq.write(30); tq.peek(); tq.write(40) } + atomically { tq.read() } shouldBe 20 + atomically { tq.flush() } shouldBe listOf(30, 40) + + atomically { tq.write(20); tq.write(30); tq.peek(); tq.write(40) } + atomically { tq.flush() } shouldBe listOf(20, 30, 40) + atomically { tq.flush() } shouldBe emptyList() + } + + @Test fun peekShouldLeaveTheQueueUnchanged() = runTest { + val tq = TQueue.new() + atomically { tq.write(20); tq.write(30); tq.write(40) } + atomically { tq.peek() } shouldBeExactly 20 + atomically { tq.flush() } shouldBe listOf(20, 30, 40) + } + + @Test fun peekShouldRetryIfTheQueueIsEmpty() = runTest { + val tq = TQueue.new() + atomically { + stm { tq.peek().let { true } } orElse { false } + } shouldBe false + } + + @Test fun tryPeekShouldBehaveLikePeekIfThereAreElements() = runTest { + val tq = TQueue.new() + atomically { tq.write(20); tq.write(30); tq.write(40) } + atomically { tq.peek() } shouldBeExactly + atomically { tq.tryPeek()!! } + atomically { tq.flush() } shouldBe listOf(20, 30, 40) + } + + @Test fun tryPeekShouldReturnNullIfTheQueueIsEmpty() = runTest { + val tq = TQueue.new() + atomically { tq.tryPeek() } shouldBe null + } + + @Test fun isEmptyAndIsNotEmptyShouldWorkCorrectly() = runTest { + val tq = TQueue.new() + atomically { tq.isEmpty() } shouldBe true + atomically { tq.isNotEmpty() } shouldBe false + atomically { tq.write(20) } + atomically { tq.isEmpty() } shouldBe false + atomically { tq.isNotEmpty() } shouldBe true + atomically { tq.peek(); tq.write(30) } + atomically { tq.isEmpty() } shouldBe false + atomically { tq.isNotEmpty() } shouldBe true + } + + @Test fun sizeShouldReturnTheCorrectAmount() = runTest { + checkAll(Arb.int(0..50)) { i -> val tq = TQueue.new() atomically { - stm { tq.peek().let { true } } orElse { false } - } shouldBe false - } - "tryPeek should behave like peek if there are elements" { - val tq = TQueue.new() - atomically { tq.write(20); tq.write(30); tq.write(40) } - atomically { tq.peek() } shouldBeExactly - atomically { tq.tryPeek()!! } - atomically { tq.flush() } shouldBe listOf(20, 30, 40) - } - "tryPeek should return null if the queue is empty" { - val tq = TQueue.new() - atomically { tq.tryPeek() } shouldBe null - } - "isEmpty and isNotEmpty should work correctly" { - val tq = TQueue.new() - atomically { tq.isEmpty() } shouldBe true - atomically { tq.isNotEmpty() } shouldBe false - atomically { tq.write(20) } - atomically { tq.isEmpty() } shouldBe false - atomically { tq.isNotEmpty() } shouldBe true - atomically { tq.peek(); tq.write(30) } - atomically { tq.isEmpty() } shouldBe false - atomically { tq.isNotEmpty() } shouldBe true - } - "size should return the correct amount" { - checkAll(Arb.int(0..50)) { i -> - val tq = TQueue.new() - atomically { - for (j in 0..i) { - // read to swap read and write lists randomly - if (Random.nextFloat() > 0.9) tq.tryPeek() - tq.write(j) - } + for (j in 0..i) { + // read to swap read and write lists randomly + if (Random.nextFloat() > 0.9) tq.tryPeek() + tq.write(j) } - atomically { tq.size() } shouldBeExactly i + 1 } + atomically { tq.size() } shouldBeExactly i + 1 } - "writeFront should work correctly" { - val tq = TQueue.new() - atomically { tq.writeFront(203) } - atomically { tq.peek() } shouldBeExactly 203 - atomically { tq.writeFront(50) } - atomically { tq.peek() } shouldBeExactly 50 - atomically { tq.flush() } shouldBe listOf(50, 203) - } - "removeAll should work" { - val tq = TQueue.new() - atomically { tq.removeAll { true } } - atomically { tq.flush() } shouldBe emptyList() + } - atomically { - for (i in 0..100) { - tq.write(i) - } - tq.removeAll { it.rem(2) == 0 } - tq.flush() - } shouldBe (0..100).filter { it.rem(2) == 0 } - } + @Test fun writeFrontShouldWorkCorrectly() = runTest { + val tq = TQueue.new() + atomically { tq.writeFront(203) } + atomically { tq.peek() } shouldBeExactly 203 + atomically { tq.writeFront(50) } + atomically { tq.peek() } shouldBeExactly 50 + atomically { tq.flush() } shouldBe listOf(50, 203) + } + + @Test fun removeAllShouldWork() = runTest { + val tq = TQueue.new() + atomically { tq.removeAll { true } } + atomically { tq.flush() } shouldBe emptyList() + + atomically { + for (i in 0..100) { + tq.write(i) + } + tq.removeAll { it.rem(2) == 0 } + tq.flush() + } shouldBe (0..100).filter { it.rem(2) == 0 } } -) +} diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TSemaphoreTest.kt b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TSemaphoreTest.kt index f0ace0450da..60ebee46b08 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TSemaphoreTest.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonTest/kotlin/arrow/fx/stm/TSemaphoreTest.kt @@ -1,80 +1,93 @@ package arrow.fx.stm import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.shouldBe +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class TSemaphoreTest : StringSpec({ - "creating a semaphore with a negative number of permits fails" { - shouldThrow { TSemaphore.new(-1) } - shouldThrow { atomically { newTSem(-1) } } - } - "available reads the correct amount" { - val ts = TSemaphore.new(10) - atomically { ts.available() } shouldBeExactly 10 - } - "acquire removes one permit" { - val ts = TSemaphore.new(8) - atomically { ts.acquire(); ts.available() } shouldBeExactly 7 - } - "acquire retries if no permits are available" { - val ts = TSemaphore.new(0) - atomically { - stm { ts.acquire().let { true } } orElse { false } - } shouldBe false - } - "acquire(n) should take n permits" { - val ts = TSemaphore.new(10) - atomically { - ts.acquire(5); ts.available() - } shouldBeExactly 5 - } - "acquire(n) should retry if not enough permits are available" { - val ts = TSemaphore.new(10) - atomically { - stm { ts.acquire(100).let { true } } orElse { false } - } shouldBe false - } - "tryAcquire should behave like acquire if enough permits are available" { - val ts = TSemaphore.new(11) - val ts2 = TSemaphore.new(11) - atomically { ts.tryAcquire() } shouldBe - atomically { ts2.acquire().let { true } } - atomically { ts.available() } shouldBeExactly - atomically { ts2.available() } - } - "tryAcquire should not retry if not enough permits are available" { - val ts = TSemaphore.new(0) - atomically { - ts.tryAcquire() - } shouldBe false - } - "tryAcquire(n) should behave like acquire(n) if enough permits are available" { - val ts = TSemaphore.new(11) - val ts2 = TSemaphore.new(11) - atomically { ts.tryAcquire(4) } shouldBe - atomically { ts2.acquire(4).let { true } } - atomically { ts.available() } shouldBeExactly - atomically { ts2.available() } - } - "tryAcquire(n) should not retry if not enough permits are available" { - val ts = TSemaphore.new(3) - atomically { - ts.tryAcquire(10) - } shouldBe false - } - "release should add one permit" { - val ts = TSemaphore.new(0) - atomically { ts.release(); ts.available() } shouldBeExactly 1 - } - "release(n) should throw if given a negative number" { - val ts = TSemaphore.new(1) - shouldThrow { atomically { ts.release(-1) } } - } - "release(n) should add n permits" { - val ts = TSemaphore.new(3) - atomically { ts.release(6); ts.available() } shouldBe 9 - } +class TSemaphoreTest { + + @Test fun creatingASemaphoreWithANegativeNumberOfPermitsFails() = runTest { + shouldThrow { TSemaphore.new(-1) } + shouldThrow { atomically { newTSem(-1) } } + } + + @Test fun availableReadsTheCorrectAmount() = runTest { + val ts = TSemaphore.new(10) + atomically { ts.available() } shouldBeExactly 10 + } + + @Test fun acquireRemovesOnePermit() = runTest { + val ts = TSemaphore.new(8) + atomically { ts.acquire(); ts.available() } shouldBeExactly 7 + } + + @Test fun acquireRetriesIfNoPermitsAreAvailable() = runTest { + val ts = TSemaphore.new(0) + atomically { + stm { ts.acquire().let { true } } orElse { false } + } shouldBe false + } + + @Test fun acquireNShouldTakeNPermits() = runTest { + val ts = TSemaphore.new(10) + atomically { + ts.acquire(5); ts.available() + } shouldBeExactly 5 + } + + @Test fun acquireNShouldRetryIfNotEnoughPermitsAreAvailable() = runTest { + val ts = TSemaphore.new(10) + atomically { + stm { ts.acquire(100).let { true } } orElse { false } + } shouldBe false + } + + @Test fun tryAcquireShouldBehaveLikeAcquireIfEnoughPermitsAreAvailable() = runTest { + val ts = TSemaphore.new(11) + val ts2 = TSemaphore.new(11) + atomically { ts.tryAcquire() } shouldBe + atomically { ts2.acquire().let { true } } + atomically { ts.available() } shouldBeExactly + atomically { ts2.available() } + } + + @Test fun tryAcquireShouldNotRetryIfNotEnoughPermitsAreAvailable() = runTest { + val ts = TSemaphore.new(0) + atomically { + ts.tryAcquire() + } shouldBe false + } + + @Test fun tryAcquireNShouldBehaveLikeAcquireNIfEnoughPermitsAreAvailable() = runTest { + val ts = TSemaphore.new(11) + val ts2 = TSemaphore.new(11) + atomically { ts.tryAcquire(4) } shouldBe + atomically { ts2.acquire(4).let { true } } + atomically { ts.available() } shouldBeExactly + atomically { ts2.available() } + } + + @Test fun tryAcquireNShouldNotRetryIfNotEnoughPermitsAreAvailable() = runTest { + val ts = TSemaphore.new(3) + atomically { + ts.tryAcquire(10) + } shouldBe false + } + + @Test fun releaseShouldAddOnePermit() = runTest { + val ts = TSemaphore.new(0) + atomically { ts.release(); ts.available() } shouldBeExactly 1 + } + + @Test fun releaseNShouldThrowIfGivenANegativeNumber() = runTest { + val ts = TSemaphore.new(1) + shouldThrow { atomically { ts.release(-1) } } + } + + @Test fun releaseNShouldAddNPermits() = runTest { + val ts = TSemaphore.new(3) + atomically { ts.release(6); ts.available() } shouldBe 9 } -) +} From 6a4422528284bfce6a76832ec565428202f0238e Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 25 Oct 2023 09:16:29 +0200 Subject: [PATCH 048/114] Update all Gradle files to mention kotlin.test --- .../core/arrow-annotations/build.gradle.kts | 10 ------ arrow-libs/core/arrow-atomic/build.gradle.kts | 20 ++++------- .../core/arrow-core-retrofit/build.gradle.kts | 7 +++- .../arrow-core-serialization/build.gradle.kts | 9 +++-- arrow-libs/core/arrow-core/build.gradle.kts | 28 ++++++--------- .../core/arrow-functions/build.gradle.kts | 28 ++++++--------- .../fx/arrow-fx-coroutines/build.gradle.kts | 20 ++++------- arrow-libs/fx/arrow-fx-stm/build.gradle.kts | 4 +-- .../arrow-optics-ksp-plugin/build.gradle.kts | 10 +++--- .../kotlin/arrow/optics/plugin/CopyTest.kt | 2 +- .../kotlin/arrow/optics/plugin/DSLTests.kt | 2 +- .../kotlin/arrow/optics/plugin/IsoTests.kt | 2 +- .../kotlin/arrow/optics/plugin/LensTests.kt | 2 +- .../arrow/optics/plugin/OptionalTests.kt | 2 +- .../kotlin/arrow/optics/plugin/PrismTests.kt | 2 +- .../arrow-optics-reflect/build.gradle.kts | 10 +++--- .../kotlin/arrow/optics/ReflectionTest.kt | 15 ++++---- .../optics/arrow-optics/build.gradle.kts | 35 +++++-------------- .../arrow-resilience/build.gradle.kts | 9 +++-- 19 files changed, 88 insertions(+), 129 deletions(-) diff --git a/arrow-libs/core/arrow-annotations/build.gradle.kts b/arrow-libs/core/arrow-annotations/build.gradle.kts index 4b2e4fd5171..cbcaa791e5f 100644 --- a/arrow-libs/core/arrow-annotations/build.gradle.kts +++ b/arrow-libs/core/arrow-annotations/build.gradle.kts @@ -18,20 +18,10 @@ apply(from = property("ANIMALSNIFFER_MPP")) kotlin { sourceSets { commonMain { - dependencies { - implementation(libs.kotlin.stdlibCommon) - } - } - jvmMain { dependencies { implementation(libs.kotlin.stdlib) } } - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) - } - } } jvm { diff --git a/arrow-libs/core/arrow-atomic/build.gradle.kts b/arrow-libs/core/arrow-atomic/build.gradle.kts index 4e2275757b3..f9e32f25a5d 100644 --- a/arrow-libs/core/arrow-atomic/build.gradle.kts +++ b/arrow-libs/core/arrow-atomic/build.gradle.kts @@ -22,7 +22,7 @@ kotlin { sourceSets { commonMain { dependencies { - api(libs.kotlin.stdlibCommon) + api(libs.kotlin.stdlib) } } @@ -30,21 +30,9 @@ kotlin { dependencies { implementation(projects.arrowFxCoroutines) implementation(libs.kotlin.test) + implementation(libs.coroutines.test) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) - implementation(libs.coroutines.test) - } - } - - jvmMain { - dependencies { - implementation(libs.kotlin.stdlib) - } - } - - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) } } } @@ -63,3 +51,7 @@ tasks.withType().configureEach { freeCompilerArgs = freeCompilerArgs + "-Xexpect-actual-classes" } } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/core/arrow-core-retrofit/build.gradle.kts b/arrow-libs/core/arrow-core-retrofit/build.gradle.kts index 92b0fa63f7c..82f1ef25e9e 100644 --- a/arrow-libs/core/arrow-core-retrofit/build.gradle.kts +++ b/arrow-libs/core/arrow-core-retrofit/build.gradle.kts @@ -4,7 +4,6 @@ plugins { id(libs.plugins.kotlin.jvm.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) - alias(libs.plugins.kotlinx.serialization) // Needed for testing only alias(libs.plugins.kotlinx.kover) alias(libs.plugins.spotless) @@ -24,6 +23,8 @@ dependencies { compileOnly(libs.squareup.retrofit) testImplementation(projects.arrowCore) + testImplementation(libs.kotlin.test) + testImplementation(libs.coroutines.test) testImplementation(libs.kotest.frameworkEngine) testImplementation(libs.kotest.assertionsCore) testImplementation(libs.kotest.property) @@ -41,3 +42,7 @@ tasks.jar { attributes["Automatic-Module-Name"] = "arrow.core.retrofit" } } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/core/arrow-core-serialization/build.gradle.kts b/arrow-libs/core/arrow-core-serialization/build.gradle.kts index e635f691b12..58d852c31d0 100644 --- a/arrow-libs/core/arrow-core-serialization/build.gradle.kts +++ b/arrow-libs/core/arrow-core-serialization/build.gradle.kts @@ -4,7 +4,6 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) - alias(libs.plugins.kotest.multiplatform) id(libs.plugins.kotlinx.serialization.get().pluginId) } @@ -16,7 +15,7 @@ kotlin { commonMain { dependencies { api(projects.arrowCore) - api(libs.kotlin.stdlibCommon) + api(libs.kotlin.stdlib) api(libs.kotlinx.serializationCore) } } @@ -24,6 +23,8 @@ kotlin { commonTest { dependencies { implementation(libs.kotlinx.serializationJson) + implementation(libs.kotlin.test) + implementation(libs.coroutines.test) implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) @@ -45,3 +46,7 @@ kotlin { } } } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index 3bec46f02a5..cb1e5ded6fd 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -25,7 +25,7 @@ kotlin { dependencies { api(projects.arrowAtomic) api(projects.arrowAnnotations) - api(libs.kotlin.stdlibCommon) + api(libs.kotlin.stdlib) } } @@ -33,29 +33,19 @@ kotlin { dependencies { implementation(projects.arrowFxCoroutines) implementation(projects.arrowFunctions) - implementation(libs.kotest.frameworkEngine) - implementation(libs.kotest.assertionsCore) - implementation(libs.kotest.property) - } + implementation(libs.kotlin.test) + implementation(libs.coroutines.test) + implementation(libs.kotest.frameworkEngine) + implementation(libs.kotest.assertionsCore) + implementation(libs.kotest.property) } + } jvmTest { dependencies { runtimeOnly(libs.kotest.runnerJUnit5) } } - - jvmMain { - dependencies { - implementation(libs.kotlin.stdlib) - } - } - - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) - } - } } jvm { @@ -71,3 +61,7 @@ kotlin { tasks.named("compileTestKotlinJvm") { kotlinOptions.freeCompilerArgs += "-Xcontext-receivers" } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/core/arrow-functions/build.gradle.kts b/arrow-libs/core/arrow-functions/build.gradle.kts index acb0d490905..5437121c9ba 100644 --- a/arrow-libs/core/arrow-functions/build.gradle.kts +++ b/arrow-libs/core/arrow-functions/build.gradle.kts @@ -26,35 +26,25 @@ kotlin { dependencies { api(projects.arrowAtomic) api(projects.arrowAnnotations) - api(libs.kotlin.stdlibCommon) + api(libs.kotlin.stdlib) } } commonTest { dependencies { implementation(projects.arrowFxCoroutines) - implementation(libs.kotest.frameworkEngine) - implementation(libs.kotest.assertionsCore) - implementation(libs.kotest.property) - } + implementation(libs.kotlin.test) + implementation(libs.coroutines.test) + implementation(libs.kotest.frameworkEngine) + implementation(libs.kotest.assertionsCore) + implementation(libs.kotest.property) } + } jvmTest { dependencies { runtimeOnly(libs.kotest.runnerJUnit5) } } - - jvmMain { - dependencies { - implementation(libs.kotlin.stdlib) - } - } - - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) - } - } } jvm { @@ -65,3 +55,7 @@ kotlin { } } } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts index 7564b54ed64..dd17fa7f888 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts @@ -22,7 +22,7 @@ kotlin { dependencies { api(projects.arrowCore) api(libs.coroutines.core) - implementation(libs.kotlin.stdlibCommon) + implementation(libs.kotlin.stdlib) } } @@ -30,22 +30,10 @@ kotlin { dependencies { implementation(projects.arrowCore) implementation(libs.kotlin.test) + implementation(libs.coroutines.test) implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) - implementation(libs.coroutines.test) - } - } - - jvmMain { - dependencies { - implementation(libs.kotlin.stdlib) - } - } - - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) } } } @@ -58,3 +46,7 @@ kotlin { } } } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts index d8448e947e5..22f7eff35a7 100644 --- a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts @@ -28,10 +28,10 @@ kotlin { commonTest { dependencies { implementation(projects.arrowFxCoroutines) - implementation(libs.kotest.assertionsCore) - implementation(libs.kotest.property) implementation(libs.kotlin.test) implementation(libs.coroutines.test) + implementation(libs.kotest.assertionsCore) + implementation(libs.kotest.property) } } } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts b/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts index be7c960620a..cff4ecbb9e3 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts @@ -24,8 +24,7 @@ dependencies { implementation(libs.ksp) testImplementation(libs.kotlin.stdlib) - testImplementation(libs.junitJupiter) - testImplementation(libs.junitJupiterEngine) + testImplementation(libs.kotlin.test) testImplementation(libs.assertj) testImplementation(libs.classgraph) testImplementation(libs.kotlinCompileTesting) { @@ -45,8 +44,7 @@ dependencies { testRuntimeOnly(projects.arrowOptics) } -tasks { - withType().configureEach { - maxParallelForks = 1 - } +tasks.withType { + maxParallelForks = 1 + useJUnitPlatform() } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt index b9cf3ef208d..76084dd7ff9 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/CopyTest.kt @@ -1,6 +1,6 @@ package arrow.optics.plugin -import org.junit.jupiter.api.Test +import kotlin.test.Test // from https://kotlinlang.slack.com/archives/C5UPMM0A0/p1688822411819599 // and https://github.com/overfullstack/my-lab/blob/master/arrow/src/test/kotlin/ga/overfullstack/optics/OpticsLab.kt diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt index 24798faaaa0..84cde1249e1 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt @@ -1,6 +1,6 @@ package arrow.optics.plugin -import org.junit.jupiter.api.Test +import kotlin.test.Test class DSLTests { diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt index 793ce9167a5..0abf877cc4a 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt @@ -1,7 +1,7 @@ package arrow.optics.plugin import arrow.optics.plugin.internals.noCompanion -import org.junit.jupiter.api.Test +import kotlin.test.Test class IsoTests { diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt index 4eb45199c16..5b4fd2fb9ba 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt @@ -1,6 +1,6 @@ package arrow.optics.plugin -import org.junit.jupiter.api.Test +import kotlin.test.Test class LensTests { diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt index 8244cf122a0..5aa64d19b23 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt @@ -1,6 +1,6 @@ package arrow.optics.plugin -import org.junit.jupiter.api.Test +import kotlin.test.Test class OptionalTests { diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/PrismTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/PrismTests.kt index 084865f0045..1b5dcec76d6 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/PrismTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/PrismTests.kt @@ -1,6 +1,6 @@ package arrow.optics.plugin -import org.junit.jupiter.api.Test +import kotlin.test.Test class PrismTests { diff --git a/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts b/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts index 13e73874df1..202c9d680e7 100644 --- a/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts @@ -23,13 +23,11 @@ dependencies { implementation(libs.kotlin.stdlib) testImplementation(libs.kotlin.stdlib) - testImplementation(libs.junitJupiterEngine) + testImplementation(libs.kotlin.test) + testImplementation(libs.coroutines.test) testImplementation(libs.kotlin.reflect) - - testImplementation(libs.kotest.frameworkEngine) testImplementation(libs.kotest.assertionsCore) testImplementation(libs.kotest.property) - testRuntimeOnly(libs.kotest.runnerJUnit5) } tasks.jar { @@ -37,3 +35,7 @@ tasks.jar { attributes["Automatic-Module-Name"] = "arrow.optics.reflect" } } + +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt b/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt index 6aa38211fda..2fa27e1de8a 100644 --- a/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt +++ b/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt @@ -1,11 +1,12 @@ package arrow.optics -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test data class Person(val name: String, val friends: List) @@ -13,15 +14,15 @@ sealed interface Cutlery object Fork : Cutlery object Spoon : Cutlery -object ReflectionTest : StringSpec({ - "lenses for field, get" { +class ReflectionTest { + @Test fun lensesForFieldGet() = runTest { checkAll(Arb.string(), Arb.list(Arb.string())) { nm, fs -> val p = Person(nm, fs.toMutableList()) Person::name.lens.get(p) shouldBe nm } } - "lenses for field, set" { + @Test fun lensesForFieldSet() = runTest { checkAll(Arb.string(), Arb.list(Arb.string())) { nm, fs -> val p = Person(nm, fs.toMutableList()) val m = Person::name.lens.modify(p) { it.capitalize() } @@ -29,7 +30,7 @@ object ReflectionTest : StringSpec({ } } - "traversal for list, set" { + @Test fun traversalForListSet() = runTest { checkAll(Arb.string(), Arb.list(Arb.string())) { nm, fs -> val p = Person(nm, fs) val m = Person::friends.every.modify(p) { it.capitalize() } @@ -37,11 +38,11 @@ object ReflectionTest : StringSpec({ } } - "instances" { + @Test fun instances() = runTest { val things = listOf(Fork, Spoon, Fork) val forks = Every.list() compose instance() val spoons = Every.list() compose instance() forks.size(things) shouldBe 2 spoons.size(things) shouldBe 1 } -}) +} diff --git a/arrow-libs/optics/arrow-optics/build.gradle.kts b/arrow-libs/optics/arrow-optics/build.gradle.kts index 55e7b9b05f3..e7a2843075a 100644 --- a/arrow-libs/optics/arrow-optics/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics/build.gradle.kts @@ -22,38 +22,34 @@ kotlin { commonMain { dependencies { api(projects.arrowCore) - api(libs.kotlin.stdlibCommon) + api(libs.kotlin.stdlib) } } commonTest { dependencies { + implementation(libs.kotlin.test) + implementation(libs.coroutines.test) implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } } + jvmTest { dependencies { implementation(libs.kotlin.stdlib) implementation(libs.kotest.frameworkEngine) - implementation(libs.junitJupiterEngine) - implementation(libs.kotlin.reflect) - + implementation(libs.junitJupiterEngine) + implementation(libs.kotlin.reflect) } } jvmMain { dependencies { - implementation(libs.kotlin.stdlib) api(libs.kotlin.reflect) } } - jsMain { - dependencies { - implementation(libs.kotlin.stdlibJS) - } - } } jvm { @@ -65,19 +61,6 @@ kotlin { } } -//fun DependencyHandlerScope.kspTest(dependencyNotation: Any): Unit { -// val exclude = setOf("commonTest", "nativeTest") -// add("kspMetadata", dependencyNotation) -// kotlin.sourceSets -// .filter { it.name !in exclude && it.name.contains("Test") } -// .forEach { -// val task = "ksp${it.name.capitalize()}" -// configurations.findByName(task)?.let { -// add(task, dependencyNotation) -// } -// } -//} - -//dependencies { -// kspTest(projects.arrowOpticsKspPlugin) -//} +tasks.withType { + useJUnitPlatform() +} diff --git a/arrow-libs/resilience/arrow-resilience/build.gradle.kts b/arrow-libs/resilience/arrow-resilience/build.gradle.kts index ba9d3ca78a8..4517c8504a9 100644 --- a/arrow-libs/resilience/arrow-resilience/build.gradle.kts +++ b/arrow-libs/resilience/arrow-resilience/build.gradle.kts @@ -19,16 +19,15 @@ kotlin { commonMain { dependencies { api(projects.arrowCore) - compileOnly(libs.kotlin.stdlibCommon) + compileOnly(libs.kotlin.stdlib) implementation(libs.coroutines.core) - implementation("org.jetbrains.kotlin:kotlin-stdlib") } } commonTest { dependencies { implementation(projects.arrowFxCoroutines) + implementation(libs.kotlin.test) implementation(libs.coroutines.test) - implementation(kotlin("test")) } } } @@ -41,3 +40,7 @@ kotlin { } } } + +tasks.withType { + useJUnitPlatform() +} From 335bd90a045414cb3c68bedc14cc4a321ff38393 Mon Sep 17 00:00:00 2001 From: Andreas Storesund Madsen Date: Thu, 26 Oct 2023 14:23:09 +0200 Subject: [PATCH 049/114] Refactor ParZip2Test from Kotest Plugin to Kotlin-test runtime #3192 (#3222) Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/fx/coroutines/ParZip2Test.kt | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt index 2f090154ed1..33b2b0f31e9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt @@ -1,6 +1,6 @@ package arrow.fx.coroutines.parZip -import arrow.atomic.Atomic +import arrow.atomic.AtomicInt import arrow.atomic.update import arrow.atomic.value import arrow.core.Either @@ -10,7 +10,6 @@ import arrow.fx.coroutines.guaranteeCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -25,93 +24,94 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ParZip2Test : StringSpec({ - "parZip 2 runs in parallel" { - checkAll(Arb.int(), Arb.int()) { a, b -> - val r = Atomic("") - val modifyGate = CompletableDeferred() +class ParZip2Test { + @Test fun parZip2RunsInParallel() = runTest { + checkAll(Arb.int(), Arb.int()) { a, b -> + val r = AtomicInt(0) + val modifyGate = CompletableDeferred() - parZip( - { - modifyGate.await() - r.update { i -> "$i$a" } - }, - { - r.value = "$b" - modifyGate.complete(0) - } - ) { _a, _b -> - Pair(_a, _b) + parZip( + { + modifyGate.await() + r.update { i -> i + a } + }, + { + r.value = b + modifyGate.complete(0) } - - r.value shouldBe "$b$a" + ) { _a, _b -> + Pair(_a, _b) } + + r.value shouldBe b + a } + } - "Cancelling parZip 2 cancels all participants" { - checkAll(Arb.int(), Arb.int()) { a, b -> - val s = Channel() - val pa = CompletableDeferred>() - val pb = CompletableDeferred>() + @Test fun cancellingParZip2CancelsAllParticipants() = runTest { + checkAll(Arb.int(), Arb.int()) { a, b -> + val s = Channel() + val pa = CompletableDeferred>() + val pb = CompletableDeferred>() - val loserA: suspend CoroutineScope.() -> Int = - { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } - val loserB: suspend CoroutineScope.() -> Int = - { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } + val loserA: suspend CoroutineScope.() -> Int = + { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } + val loserB: suspend CoroutineScope.() -> Int = + { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } - val f = async { parZip(loserA, loserB) { _a, _b -> Pair(_a, _b) } } + val f = async { parZip(loserA, loserB) { _a, _b -> Pair(_a, _b) } } - s.send(Unit) // Suspend until all racers started - s.send(Unit) - f.cancel() + s.send(Unit) // Suspend until all racers started + s.send(Unit) + f.cancel() - pa.await().let { (res, exit) -> - res shouldBe a - exit.shouldBeTypeOf() - } - pb.await().let { (res, exit) -> - res shouldBe b - exit.shouldBeTypeOf() - } + pa.await().let { (res, exit) -> + res shouldBe a + exit.shouldBeTypeOf() + } + pb.await().let { (res, exit) -> + res shouldBe b + exit.shouldBeTypeOf() } } + } - "parZip 2 cancels losers if a failure occurs in one of the tasks" { - checkAll(Arb.throwable(), Arb.boolean()) { e, leftWinner -> - val s = Channel() - val pa = CompletableDeferred() - - val winner: suspend CoroutineScope.() -> Unit = { s.send(Unit); throw e } - val loserA: suspend CoroutineScope.() -> Int = - { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(ex) } } + @Test fun parZip2CancelsLosersIfAFailtureOccursInOneOfTheTasts() = runTest { + checkAll(Arb.throwable(), Arb.boolean()) { e, leftWinner -> + val s = Channel() + val pa = CompletableDeferred() - val r = Either.catch { - if (leftWinner) parZip(winner, loserA) { _, _ -> Unit } - else parZip(loserA, winner) { _, _ -> Unit } - } + val winner: suspend CoroutineScope.() -> Unit = { s.send(Unit); throw e } + val loserA: suspend CoroutineScope.() -> Int = + { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(ex) } } - pa.await().shouldBeTypeOf() - r should leftException(e) + val r = Either.catch { + if (leftWinner) parZip(winner, loserA) { _, _ -> Unit } + else parZip(loserA, winner) { _, _ -> Unit } } + + pa.await().shouldBeTypeOf() + r should leftException(e) } + } - "parZip CancellationException on right can cancel rest" { - checkAll(Arb.string()) { msg -> - val exit = CompletableDeferred() - val start = CompletableDeferred() - try { - parZip({ - awaitExitCase(start, exit) - }, { - start.await() - throw CancellationException(msg) - }) { _, _ -> } - } catch (e: CancellationException) { - e.message shouldBe msg - } - exit.await().shouldBeTypeOf() + @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + checkAll(Arb.string()) { msg -> + val exit = CompletableDeferred() + val start = CompletableDeferred() + try { + parZip({ + awaitExitCase(start, exit) + }, { + start.await() + throw CancellationException(msg) + }) { _, _ -> } + } catch (e: CancellationException) { + e.message shouldBe msg } + exit.await().shouldBeTypeOf() } } -) +} From edd0dd50fce7fb143a7a3de1bf47926066f7ae57 Mon Sep 17 00:00:00 2001 From: Andreas Storesund Madsen Date: Thu, 26 Oct 2023 14:23:35 +0200 Subject: [PATCH 050/114] Refactor ParZip3Test from Kotest Plugin to Kotlin-test runtime #3193 (#3223) Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/fx/coroutines/ParZip3Test.kt | 194 +++++++++--------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt index bf1bc1c3e5e..1e2d05ff4c0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt @@ -9,7 +9,6 @@ import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -23,112 +22,113 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope - -class ParZip3Test : StringSpec({ - "parZip 3 runs in parallel" { - checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> - val r = Atomic("") - val modifyGate1 = CompletableDeferred() - val modifyGate2 = CompletableDeferred() - - parZip( - { - modifyGate2.await() - r.update { i -> "$i$a" } - }, - { - modifyGate1.await() - r.update { i -> "$i$b" } - modifyGate2.complete(Unit) - }, - { - r.value ="$c" - modifyGate1.complete(Unit) - } - ) { _a, _b, _c -> - Triple(_a, _b, _c) +import kotlinx.coroutines.test.runTest +import kotlin.test.Test + +class ParZip3Test { + @Test fun parZip3RunsInParallel() = runTest { + checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> + val r = Atomic("") + val modifyGate1 = CompletableDeferred() + val modifyGate2 = CompletableDeferred() + + parZip( + { + modifyGate2.await() + r.update { i -> "$i$a" } + }, + { + modifyGate1.await() + r.update { i -> "$i$b" } + modifyGate2.complete(Unit) + }, + { + r.value ="$c" + modifyGate1.complete(Unit) } - - r.value shouldBe "$c$b$a" + ) { _a, _b, _c -> + Triple(_a, _b, _c) } - } - "Cancelling parZip 3 cancels all participants" { - val s = Channel() - val pa = CompletableDeferred() - val pb = CompletableDeferred() - val pc = CompletableDeferred() - - val loserA: suspend CoroutineScope.() -> Int = - { awaitExitCase(s, pa) } - val loserB: suspend CoroutineScope.() -> Int = - { awaitExitCase(s, pb) } - val loserC: suspend CoroutineScope.() -> Int = - { awaitExitCase(s, pc) } - - val f = async { parZip(loserA, loserB, loserC) { _a, _b, _c -> Triple(_a, _b, _c) } } - - s.send(Unit) // Suspend until all racers started - s.send(Unit) - s.send(Unit) - f.cancel() - - pa.await().shouldBeTypeOf() - pb.await().shouldBeTypeOf() - pc.await().shouldBeTypeOf() + r.value shouldBe "$c$b$a" } + } - "parZip 3 cancels losers if a failure occurs in one of the tasks" { - checkAll( - Arb.throwable(), - Arb.element(listOf(1, 2, 3)), - ) { e, winningTask -> - val s = Channel() - val pa = CompletableDeferred() - val pb = CompletableDeferred() - - val winner: suspend CoroutineScope.() -> Int = { s.send(Unit); s.send(Unit); throw e } - val loserA: suspend CoroutineScope.() -> Int = - { awaitExitCase(s, pa) } - val loserB: suspend CoroutineScope.() -> Int = - { awaitExitCase(s, pb) } - - val r = Either.catch { - when (winningTask) { - 1 -> parZip(winner, loserA, loserB) { _, _, _ -> } - 2 -> parZip(loserA, winner, loserB) { _, _, _ -> } - else -> parZip(loserA, loserB, winner) { _, _, _ -> } - } - } + @Test fun cancellingParZip3CancelsAllParticipants() = runTest { + val s = Channel() + val pa = CompletableDeferred() + val pb = CompletableDeferred() + val pc = CompletableDeferred() + + val loserA: suspend CoroutineScope.() -> Int = + { awaitExitCase(s, pa) } + val loserB: suspend CoroutineScope.() -> Int = + { awaitExitCase(s, pb) } + val loserC: suspend CoroutineScope.() -> Int = + { awaitExitCase(s, pc) } + + val f = async { parZip(loserA, loserB, loserC) { _a, _b, _c -> Triple(_a, _b, _c) } } + + s.send(Unit) // Suspend until all racers started + s.send(Unit) + s.send(Unit) + f.cancel() + + pa.await().shouldBeTypeOf() + pb.await().shouldBeTypeOf() + pc.await().shouldBeTypeOf() + } - pa.await().shouldBeTypeOf() - pb.await().shouldBeTypeOf() - r should leftException(e) + @Test fun parZip3CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + checkAll( + Arb.throwable(), + Arb.element(listOf(1, 2, 3)), + ) { e, winningTask -> + val s = Channel() + val pa = CompletableDeferred() + val pb = CompletableDeferred() + + val winner: suspend CoroutineScope.() -> Int = { s.send(Unit); s.send(Unit); throw e } + val loserA: suspend CoroutineScope.() -> Int = + { awaitExitCase(s, pa) } + val loserB: suspend CoroutineScope.() -> Int = + { awaitExitCase(s, pb) } + + val r = Either.catch { + when (winningTask) { + 1 -> parZip(winner, loserA, loserB) { _, _, _ -> } + 2 -> parZip(loserA, winner, loserB) { _, _, _ -> } + else -> parZip(loserA, loserB, winner) { _, _, _ -> } + } } + + pa.await().shouldBeTypeOf() + pb.await().shouldBeTypeOf() + r should leftException(e) } + } - "parZip CancellationException on right can cancel rest" { - checkAll(Arb.string(), Arb.int(1..3)) { msg, cancel -> - val s = Channel() - val pa = CompletableDeferred() - val pb = CompletableDeferred() - - val winner: suspend CoroutineScope.() -> Int = { repeat(2) { s.send(Unit) }; throw CancellationException(msg) } - val loserA: suspend CoroutineScope.() -> Int = { awaitExitCase(s, pa) } - val loserB: suspend CoroutineScope.() -> Int = { awaitExitCase(s, pb) } - - try { - when (cancel) { - 1 -> parZip(winner, loserA, loserB) { _, _, _ -> } - 2 -> parZip(loserA, winner, loserB) { _, _, _ -> } - else -> parZip(loserA, loserB, winner) { _, _, _ -> } - } - } catch (e: CancellationException) { - e.message shouldBe msg + @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + checkAll(Arb.string(), Arb.int(1..3)) { msg, cancel -> + val s = Channel() + val pa = CompletableDeferred() + val pb = CompletableDeferred() + + val winner: suspend CoroutineScope.() -> Int = { repeat(2) { s.send(Unit) }; throw CancellationException(msg) } + val loserA: suspend CoroutineScope.() -> Int = { awaitExitCase(s, pa) } + val loserB: suspend CoroutineScope.() -> Int = { awaitExitCase(s, pb) } + + try { + when (cancel) { + 1 -> parZip(winner, loserA, loserB) { _, _, _ -> } + 2 -> parZip(loserA, winner, loserB) { _, _, _ -> } + else -> parZip(loserA, loserB, winner) { _, _, _ -> } } - pa.await().shouldBeTypeOf() - pb.await().shouldBeTypeOf() + } catch (e: CancellationException) { + e.message shouldBe msg } + pa.await().shouldBeTypeOf() + pb.await().shouldBeTypeOf() } } -) +} From f384c5de65e2e86a669fb118b728cc425b1ddbd1 Mon Sep 17 00:00:00 2001 From: Jonathan Lagneaux Date: Thu, 26 Oct 2023 14:24:24 +0200 Subject: [PATCH 051/114] Refactor GuaranteeCaseTest to use kotlin test (#3226) Closes #3190 --- .../arrow/fx/coroutines/GuaranteeCaseTest.kt | 83 ++++++++++--------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt index 2f636a7b381..1795c98fc0f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/GuaranteeCaseTest.kt @@ -1,7 +1,6 @@ package arrow.fx.coroutines import arrow.core.Either -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb @@ -10,55 +9,59 @@ import io.kotest.property.checkAll import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class GuaranteeCaseTest : StringSpec({ +class GuaranteeCaseTest { - "release for success was invoked" { - checkAll(Arb.int()) { i -> - val p = CompletableDeferred() - - val res = guaranteeCase( - fa = { i }, - finalizer = { ex -> require(p.complete(ex)) } - ) - - p.await() shouldBe ExitCase.Completed - res shouldBe i - } - } + @Test + fun releaseForSuccessWasInvoked() = runTest { + checkAll(Arb.int()) { i -> + val p = CompletableDeferred() - "release for error was invoked" { - checkAll(Arb.throwable()) { e -> - val p = CompletableDeferred() - val attempted = Either.catch { - guaranteeCase( - fa = { throw e }, - finalizer = { ex -> require(p.complete(ex)) } - ) - } + val res = guaranteeCase( + fa = { i }, + finalizer = { ex -> require(p.complete(ex)) } + ) - p.await() shouldBe ExitCase.Failure(e) - attempted shouldBe Either.Left(e) - } + p.await() shouldBe ExitCase.Completed + res shouldBe i } + } - "release for never was invoked" { + @Test + fun releaseForErrorWasInvoked() = runTest { + checkAll(Arb.throwable()) { e -> val p = CompletableDeferred() - val start = CompletableDeferred() - - val fiber = async { - guaranteeCase( - fa = { - start.complete(Unit) - awaitCancellation() - }, + val attempted = Either.catch { + guaranteeCase( + fa = { throw e }, finalizer = { ex -> require(p.complete(ex)) } ) } - start.await() - fiber.cancel() - p.await().shouldBeInstanceOf() + p.await() shouldBe ExitCase.Failure(e) + attempted shouldBe Either.Left(e) } } -) + + @Test + fun releaseForNeverWasInvoked() = runTest { + val p = CompletableDeferred() + val start = CompletableDeferred() + + val fiber = async { + guaranteeCase( + fa = { + start.complete(Unit) + awaitCancellation() + }, + finalizer = { ex -> require(p.complete(ex)) } + ) + } + + start.await() + fiber.cancel() + p.await().shouldBeInstanceOf() + } +} From 67f9c0f1a89e7440111bdbb76e1e4d6e8e349441 Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Thu, 26 Oct 2023 14:24:42 +0200 Subject: [PATCH 052/114] refactor: migrate NotEmptySetTest to kotlin-test (#3230) Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/core/NonEmptySetTest.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptySetTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptySetTest.kt index f90df187bec..9c50b8779fb 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptySetTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptySetTest.kt @@ -2,7 +2,6 @@ package arrow.core import arrow.core.test.nonEmptySet import io.kotest.assertions.withClue -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.booleans.shouldBeTrue import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe @@ -10,36 +9,38 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.next import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class NonEmptySetTest : StringSpec({ +class NonEmptySetTest { - "iterable.toNonEmptySetOrNull should round trip" { + @Test fun iterableToNonEmptySetOrNullShouldRoundTrip() = runTest { checkAll(Arb.nonEmptySet(Arb.int())) { nonEmptySet -> nonEmptySet.toNonEmptySetOrNull().shouldNotBeNull() shouldBe nonEmptySet } } - "iterable.toNonEmptySetOrNone should round trip" { + @Test fun iterableToNonEmptySetOrNoneShouldRoundTrip() = runTest { checkAll(Arb.nonEmptySet(Arb.int())) { nonEmptySet -> nonEmptySet.toNonEmptySetOrNone() shouldBe nonEmptySet.some() } } - "emptyList.toNonEmptySetOrNull should be null" { + @Test fun emptyListToNonEmptySetOrNullShouldBeNull() = runTest { listOf().toNonEmptySetOrNull() shouldBe null } - "emptyList.toNonEmptySetOrNone should be none" { + @Test fun emptyListToNonEmptySetOrNoneShouldBeNone() = runTest { listOf().toNonEmptySetOrNone() shouldBe none() } - "adding an element already present doesn't change the set" { + @Test fun addingAnElementAlreadyPresentDoesNotChangeTheSet() = runTest { val element = Arb.int().next() val initialSet: NonEmptySet = nonEmptySetOf(element) + Arb.nonEmptySet(Arb.int()).next() initialSet.plus(element) shouldBe initialSet } - "NonEmptySet equals Set" { + @Test fun nonEmptySetEqualsSet() = runTest { checkAll( Arb.nonEmptySet(Arb.int()) ) { nes -> @@ -51,7 +52,7 @@ class NonEmptySetTest : StringSpec({ } } - "NonEmptySet equals NonEmptySet" { + @Test fun nonEmptySetEqualsNonEmptySet() = runTest { checkAll( Arb.nonEmptySet(Arb.int()) ) { nes -> @@ -62,5 +63,5 @@ class NonEmptySetTest : StringSpec({ } } } -}) +} From 72aabc2375c425849adb79d88bb444f156424f19 Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Thu, 26 Oct 2023 14:25:04 +0200 Subject: [PATCH 053/114] refactor: migrate EagerEffectSpec to kotlin-test (#3233) Co-authored-by: Alejandro Serrano --- .../arrow/core/raise/EagerEffectSpec.kt | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt index 1ab81b4c351..80e5881c9d3 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt @@ -18,11 +18,13 @@ import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlin.test.Test import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.test.runTest @Suppress("UNREACHABLE_CODE", "UNUSED_EXPRESSION") -class EagerEffectSpec : StringSpec({ - "try/catch - can recover from raise" { +class EagerEffectSpec { + @Test fun tryCatchCanRecoverFromRaise() = runTest { checkAll(Arb.int(), Arb.string()) { i, s -> eagerEffect { try { @@ -34,7 +36,7 @@ class EagerEffectSpec : StringSpec({ } } - "try/catch - finally works" { + @Test fun tryCatchFinallyWorks() = runTest { checkAll(Arb.string(), Arb.int()) { s, i -> val promise = CompletableDeferred() eagerEffect { @@ -49,7 +51,7 @@ class EagerEffectSpec : StringSpec({ } } - "try/catch - First raise is ignored and second is returned" { + @Test fun tryCatchFirstRaiseIsIgnoredAndSecondIsReturned() = runTest { checkAll(Arb.int(), Arb.string(), Arb.string()) { i, s, s2 -> eagerEffect { try { @@ -62,7 +64,7 @@ class EagerEffectSpec : StringSpec({ } } - "recover - catch" { + @Test fun recoverCatch() = runTest { checkAll(Arb.int(), Arb.long()) { i, l -> eagerEffect { eagerEffect { @@ -75,7 +77,7 @@ class EagerEffectSpec : StringSpec({ } } - "recover - no catch" { + @Test fun recoverNoCatch() = runTest { checkAll(Arb.int(), Arb.long()) { i, l -> eagerEffect { eagerEffect { @@ -88,7 +90,7 @@ class EagerEffectSpec : StringSpec({ } } - "recover - raise from catch" { + @Test fun recoverRaiseFromCatch() = runTest { checkAll(Arb.long(), Arb.string()) { l, error -> eagerEffect { eagerEffect { @@ -101,18 +103,18 @@ class EagerEffectSpec : StringSpec({ } } - "success" { + @Test fun success() = runTest { eagerEffect { 1 } .fold({ unreachable() }, ::identity) shouldBe 1 } - "short-circuit" { + @Test fun shortCircuit() = runTest { eagerEffect { raise("hello") }.fold(::identity) { unreachable() } shouldBe "hello" } - "Rethrows exceptions" { + @Test fun rethrowsExceptions() = runTest { val e = RuntimeException("test") Either.catch { eagerEffect { throw e } @@ -120,7 +122,7 @@ class EagerEffectSpec : StringSpec({ } shouldBe Either.Left(e) } - "ensure null in eager either computation" { + @Test fun ensureNullInEagerEitherComputation() = runTest { checkAll(Arb.boolean(), Arb.int(), Arb.string()) { predicate, success, raise -> either { ensure(predicate) { raise } @@ -129,7 +131,7 @@ class EagerEffectSpec : StringSpec({ } } - "ensureNotNull in eager either computation" { + @Test fun ensureNotNullInEagerEitherComputation() = runTest { fun square(i: Int): Int = i * i checkAll(Arb.int().orNull(), Arb.string()) { i: Int?, raise: String -> @@ -142,7 +144,7 @@ class EagerEffectSpec : StringSpec({ } } - "recover - happy path" { + @Test fun recoverHappyPath() = runTest { checkAll(Arb.string()) { str -> eagerEffect { str @@ -151,7 +153,7 @@ class EagerEffectSpec : StringSpec({ } } - "recover - error path and recover" { + @Test fun recoverErrorPathAndRecover() = runTest { checkAll(Arb.int(), Arb.string()) { int, fallback -> eagerEffect { raise(int) @@ -161,7 +163,7 @@ class EagerEffectSpec : StringSpec({ } } - "recover - error path and re-raise" { + @Test fun recoverErrorPathAndReRaise() = runTest { checkAll(Arb.int(), Arb.string()) { int, fallback -> eagerEffect { raise(int) @@ -171,7 +173,7 @@ class EagerEffectSpec : StringSpec({ } } - "recover - error path and throw" { + @Test fun recoverErrorPathAndThrow() = runTest { checkAll(Arb.int(), Arb.string()) { int, msg -> shouldThrow { eagerEffect { @@ -183,7 +185,7 @@ class EagerEffectSpec : StringSpec({ } } - "catch - happy path" { + @Test fun catchHappyPath() = runTest { checkAll(Arb.string()) { str -> eagerEffect { str @@ -192,7 +194,7 @@ class EagerEffectSpec : StringSpec({ } } - "catch - error path and recover" { + @Test fun catchErrorPathAndRecover() = runTest { checkAll(Arb.string(), Arb.string()) { msg, fallback -> eagerEffect { throw RuntimeException(msg) @@ -201,7 +203,7 @@ class EagerEffectSpec : StringSpec({ } } - "catch - error path and re-raise" { + @Test fun catchErrorPathAndReRaise() = runTest { checkAll(Arb.string(), Arb.int()) { msg, fallback -> eagerEffect { throw RuntimeException(msg) @@ -210,7 +212,7 @@ class EagerEffectSpec : StringSpec({ } } - "catch - error path and throw" { + @Test fun catchErrorPathAndThrow() = runTest { checkAll(Arb.string(), Arb.string()) { msg, msg2 -> shouldThrow { eagerEffect { @@ -221,21 +223,21 @@ class EagerEffectSpec : StringSpec({ } } - "catch - reified exception and recover" { + @Test fun catchReifiedExceptionAndRecover() = runTest { eagerEffect { throw ArithmeticException() }.catch { _: ArithmeticException -> 1 } .fold({ unreachable() }, ::identity) shouldBe 1 } - "catch - reified exception and raise" { + @Test fun catchReifiedExceptionAndRaise() = runTest { eagerEffect { throw ArithmeticException("Boom!") }.catch { e: ArithmeticException -> raise(e.message.shouldNotBeNull()) } .fold(::identity) { unreachable() } shouldBe "Boom!" } - "catch - reified exception and no match" { + @Test fun catchReifiedExceptionAndNoMatch() = runTest { shouldThrow { eagerEffect { throw RuntimeException("Boom!") @@ -244,7 +246,7 @@ class EagerEffectSpec : StringSpec({ }.message shouldBe "Boom!" } - "shift leaked results in RaiseLeakException" { + @Test fun shiftLeakedResultsInRaiseLeakException() = runTest { eagerEffect { suspend { raise("failure") } }.fold( @@ -254,7 +256,7 @@ class EagerEffectSpec : StringSpec({ { unreachable() }) { f -> f() } } - "shift leaked results in RaiseLeakException with exception" { + @Test fun shiftLeakedResultsInRaiseLeakExceptionWithException() = runTest { shouldThrow { val leak = CompletableDeferred Unit>() eagerEffect { @@ -270,7 +272,7 @@ class EagerEffectSpec : StringSpec({ }.message shouldStartWith "raise or bind was called outside of its DSL scope" } - "shift leaked results in RaiseLeakException after raise" { + @Test fun shiftLeakedResultsInRaiseLeakExceptionAfterRaise() = runTest { shouldThrow { val leak = CompletableDeferred Unit>() eagerEffect { @@ -285,7 +287,7 @@ class EagerEffectSpec : StringSpec({ }.message shouldStartWith "raise or bind was called outside of its DSL scope" } - "mapError - raise and transform error" { + @Test fun mapErrorRaiseAndTransformError() = runTest { checkAll(Arb.long(), Arb.string()) { l, s -> (eagerEffect { raise(l) @@ -296,10 +298,10 @@ class EagerEffectSpec : StringSpec({ } } - "mapError - success" { + @Test fun mapErrorSuccess() = runTest { checkAll(Arb.int()) { i -> (eagerEffect { i } mapError { unreachable() }) .get() shouldBe i } } -}) +} From 12b3ebf270caae33529504d62c03eefcaf669586 Mon Sep 17 00:00:00 2001 From: Alphonse Bendt <370821+abendt@users.noreply.github.com> Date: Thu, 26 Oct 2023 14:25:29 +0200 Subject: [PATCH 054/114] Refactor NullableSpec from Kotest Plugin to Kotlin-test runtime (#3236) https://github.com/arrow-kt/arrow/issues/3153 Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/core/raise/NullableSpec.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt index 2a667f06df3..f967a1a95cb 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt @@ -2,17 +2,17 @@ package arrow.core.raise import arrow.core.Either import arrow.core.Some -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.orNull import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -@Suppress("UNREACHABLE_CODE") -class NullableSpec : StringSpec({ - "ensure null in nullable computation" { +class NullableSpec { + @Test fun ensureNullInNullableComputation() = runTest { checkAll(Arb.boolean(), Arb.int()) { predicate, i -> nullable { ensure(predicate) @@ -21,7 +21,7 @@ class NullableSpec : StringSpec({ } } - "ensureNotNull in nullable computation" { + @Test fun ensureNotNullInNullableComputation() = runTest { fun square(i: Int): Int = i * i checkAll(Arb.int().orNull()) { i: Int? -> nullable { @@ -31,7 +31,7 @@ class NullableSpec : StringSpec({ } } - "short circuit null" { + @Test fun shortCircuitNull() = runTest { nullable { val number: Int = "s".length (number.takeIf { it > 1 }?.toString()).bind() @@ -39,7 +39,7 @@ class NullableSpec : StringSpec({ } shouldBe null } - "ensureNotNull short circuit" { + @Test fun ensureNotNullShortCircuit() = runTest { nullable { val number: Int = "s".length ensureNotNull(number.takeIf { it > 1 }) @@ -47,13 +47,13 @@ class NullableSpec : StringSpec({ } shouldBe null } - "simple case" { + @Test fun simpleCase() = runTest { nullable { "s".length.bind() } shouldBe 1 } - "multiple types" { + @Test fun multipleTypes() = runTest { nullable { val number = "s".length val string = number.toString().bind() @@ -61,7 +61,7 @@ class NullableSpec : StringSpec({ } shouldBe "1" } - "binding option in nullable" { + @Test fun bindingOptionInNullable() = runTest { nullable { val number = Some("s".length) val string = number.map(Int::toString).bind() @@ -69,7 +69,7 @@ class NullableSpec : StringSpec({ } shouldBe "1" } - "binding either in nullable" { + @Test fun bindingEitherInNullable() = runTest { nullable { val number = Either.Right("s".length) val string = number.map(Int::toString).bind() @@ -77,7 +77,7 @@ class NullableSpec : StringSpec({ } shouldBe "1" } - "binding either in nullable, ignore errors" { + @Test fun bindingEitherInNullableIgnoreErrors() = runTest { nullable { val number = Either.Right("s".length) as Either val string = ignoreErrors { number.map(Int::toString).bind() } @@ -85,7 +85,7 @@ class NullableSpec : StringSpec({ } shouldBe "1" } - "short circuit option" { + @Test fun shortCircuitOption() = runTest { nullable { val number = Some("s".length) number.filter { it > 1 }.map(Int::toString).bind() @@ -93,7 +93,7 @@ class NullableSpec : StringSpec({ } shouldBe null } - "when expression" { + @Test fun whenExpression() = runTest { nullable { val number = "s".length.bind() val string = when (number) { @@ -104,7 +104,7 @@ class NullableSpec : StringSpec({ } shouldBe "1" } - "if expression" { + @Test fun ifExpression() = runTest { nullable { val number = "s".length.bind() val string = if (number == 1) { @@ -116,7 +116,7 @@ class NullableSpec : StringSpec({ } shouldBe "1" } - "if expression short circuit" { + @Test fun ifExpressionShortCircuit() = runTest { nullable { val number = "s".length.bind() val string = if (number != 1) { @@ -128,18 +128,18 @@ class NullableSpec : StringSpec({ } shouldBe null } - "Either can be bind" { + @Test fun eitherOfNothingAndSomethingCanBeBound() = runTest { nullable { val either: Either = Either.Right(4) either.bind() + 3 } shouldBe 7 } - "Recover works as expected" { + @Test fun recoverWorksAsExpected() = runTest { nullable { val one: Int = recover({ null.bind() }) { 1 } val two = 2.bind() one + two } shouldBe 3 } -}) +} From 402c280d58b97af5e412c189d59ca58f83c861a0 Mon Sep 17 00:00:00 2001 From: Jonathan Lagneaux Date: Thu, 26 Oct 2023 14:25:41 +0200 Subject: [PATCH 055/114] Refactor BracketCaseTest to use kotlin test (#3237) Closes #3186 Co-authored-by: Alejandro Serrano --- .../arrow/fx/coroutines/BracketCaseTest.kt | 609 +++++++++--------- 1 file changed, 315 insertions(+), 294 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt index 5892715e859..62cd84c51bb 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/BracketCaseTest.kt @@ -1,7 +1,6 @@ package arrow.fx.coroutines import arrow.core.Either -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf @@ -12,358 +11,380 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.test.runTest +import kotlin.test.Test import kotlin.time.ExperimentalTime @ExperimentalTime -class BracketCaseTest : StringSpec({ - "Immediate acquire bracketCase finishes successfully" { - checkAll(Arb.int(), Arb.int()) { a, b -> - var once = true - bracketCase( - acquire = { a }, - use = { aa -> Pair(aa, b) }, - release = { _, _ -> - require(once) - once = false - } - ) shouldBe Pair(a, b) - } +class BracketCaseTest { + @Test + fun immediateAcquireBracketCaseFinishesSuccessfully() = runTest { + checkAll(Arb.int(), Arb.int()) { a, b -> + var once = true + bracketCase( + acquire = { a }, + use = { aa -> Pair(aa, b) }, + release = { _, _ -> + require(once) + once = false + } + ) shouldBe Pair(a, b) } + } - "Suspended acquire bracketCase finishes successfully" { - checkAll(Arb.int(), Arb.int()) { a, b -> - var once = true - bracketCase( - acquire = { a.suspend() }, - use = { aa -> Pair(aa, b) }, - release = { _, _ -> - require(once) - once = false - } - ) shouldBe Pair(a, b) - } + @Test + fun suspendedAcquireBracketCaseFinishedSuccessfully() = runTest { + checkAll(Arb.int(), Arb.int()) { a, b -> + var once = true + bracketCase( + acquire = { a.suspend() }, + use = { aa -> Pair(aa, b) }, + release = { _, _ -> + require(once) + once = false + } + ) shouldBe Pair(a, b) } + } - "Immediate error in acquire stays the same error" { - checkAll(Arb.throwable()) { e -> - Either.catch { - bracketCase( - acquire = { throw e }, - use = { 5 }, - release = { _, _ -> Unit } - ) - } should leftException(e) - } + @Test + fun immediateErrorInAcquireStaysTheSameError() = runTest { + checkAll(Arb.throwable()) { e -> + Either.catch { + bracketCase( + acquire = { throw e }, + use = { 5 }, + release = { _, _ -> Unit } + ) + } should leftException(e) } + } - "Suspend error in acquire stays the same error" { - checkAll(Arb.throwable()) { e -> - Either.catch { - bracketCase( - acquire = { e.suspend() }, - use = { 5 }, - release = { _, _ -> Unit } - ) - } should leftException(e) - } + @Test + fun suspendErrorInAcquireStaysTheSameError() = runTest { + checkAll(Arb.throwable()) { e -> + Either.catch { + bracketCase( + acquire = { e.suspend() }, + use = { 5 }, + release = { _, _ -> Unit } + ) + } should leftException(e) } + } - "Immediate use bracketCase finishes successfully" { - checkAll(Arb.int(), Arb.int()) { a, b -> - var once = true - bracketCase( - acquire = { a }, - use = { aa -> Pair(aa, b).suspend() }, - release = { _, _ -> - require(once) - once = false - } - ) shouldBe Pair(a, b) - } + @Test + fun immediateUseBracketCaseFinishedSuccessfully() = runTest { + checkAll(Arb.int(), Arb.int()) { a, b -> + var once = true + bracketCase( + acquire = { a }, + use = { aa -> Pair(aa, b).suspend() }, + release = { _, _ -> + require(once) + once = false + } + ) shouldBe Pair(a, b) } + } - "Suspended use bracketCase finishes successfully" { - checkAll(Arb.int(), Arb.int()) { a, b -> - var once = true - bracketCase( - acquire = { a }, - use = { aa -> Pair(aa, b).suspend() }, - release = { _, _ -> - require(once) - once = false + @Test + fun suspendedUseBracketCaseFinishesSuccessfully() = runTest { + checkAll(Arb.int(), Arb.int()) { a, b -> + var once = true + bracketCase( + acquire = { a }, + use = { aa -> Pair(aa, b).suspend() }, + release = { _, _ -> + require(once) + once = false + } + ) shouldBe Pair(a, b) + } + } + + @Test + fun bracketCaseMustRunReleaseTaskOnUseImmediateError() = runTest { + checkAll(Arb.int(), Arb.throwable()) { i, e -> + val promise = CompletableDeferred() + + Either.catch { + bracketCase( + acquire = { i }, + use = { throw e }, + release = { _, ex -> + require(promise.complete(ex)) { "Release should only be called once, called again with $ex" } } - ) shouldBe Pair(a, b) + ) } - } - "bracketCase must run release task on use immediate error" { - checkAll(Arb.int(), Arb.throwable()) { i, e -> - val promise = CompletableDeferred() - - Either.catch { - bracketCase( - acquire = { i }, - use = { throw e }, - release = { _, ex -> - require(promise.complete(ex)) { "Release should only be called once, called again with $ex" } - } - ) - } + promise.await() shouldBe ExitCase.Failure(e) + } + } - promise.await() shouldBe ExitCase.Failure(e) + @Test + fun bracketCaseMustRunReleaseTaskOnUseSuspendedError() = runTest { + checkAll(Arb.int(), Arb.throwable()) { x, e -> + val promise = CompletableDeferred>() + + Either.catch { + bracketCase( + acquire = { x }, + use = { e.suspend() }, + release = { xx, ex -> + require(promise.complete(Pair(xx, ex))) { "Release should only be called once, called again with $ex" } + } + ) } + + promise.await() shouldBe Pair(x, ExitCase.Failure(e)) } + } - "bracketCase must run release task on use suspended error" { - checkAll(Arb.int(), Arb.throwable()) { x, e -> - val promise = CompletableDeferred>() - - Either.catch { - bracketCase( - acquire = { x }, - use = { e.suspend() }, - release = { xx, ex -> - require(promise.complete(Pair(xx, ex))) { "Release should only be called once, called again with $ex" } - } - ) - } + @Test + fun bracketCaseMustAlwaysRunImmediateRelease() = runTest { + checkAll(Arb.int()) { x -> + val promise = CompletableDeferred>() - promise.await() shouldBe Pair(x, ExitCase.Failure(e)) + Either.catch { + bracketCase( + acquire = { x }, + use = { it }, + release = { xx, ex -> + require(promise.complete(Pair(xx, ex))) { "Release should only be called once, called again with $ex" } + } + ) } + + promise.await() shouldBe Pair(x, ExitCase.Completed) } + } - "bracketCase must always run immediate release" { - checkAll(Arb.int()) { x -> - val promise = CompletableDeferred>() - - Either.catch { - bracketCase( - acquire = { x }, - use = { it }, - release = { xx, ex -> - require(promise.complete(Pair(xx, ex))) { "Release should only be called once, called again with $ex" } - } - ) - } + @Test + fun bracketCaseMustAlwaysRunSuspendedRelease() = runTest { + checkAll(Arb.int()) { x -> + val promise = CompletableDeferred>() - promise.await() shouldBe Pair(x, ExitCase.Completed) + Either.catch { + bracketCase( + acquire = { x }, + use = { it }, + release = { xx, ex -> + require(promise.complete(Pair(xx, ex))) { "Release should only be called once, called again with $ex" } + .suspend() + } + ) } + + promise.await() shouldBe Pair(x, ExitCase.Completed) } + } - "bracketCase must always run suspended release" { - checkAll(Arb.int()) { x -> - val promise = CompletableDeferred>() - - Either.catch { - bracketCase( - acquire = { x }, - use = { it }, - release = { xx, ex -> - require(promise.complete(Pair(xx, ex))) { "Release should only be called once, called again with $ex" } - .suspend() - } - ) - } + @Test + fun bracketCaseMustAlwaysRunImmediateReleaseError() = runTest { + checkAll(Arb.int(), Arb.throwable()) { n, e -> + Either.catch { + bracketCase( + acquire = { n }, + use = { it }, + release = { _, _ -> throw e } + ) + } should leftException(e) + } + } - promise.await() shouldBe Pair(x, ExitCase.Completed) - } + @Test + fun bracketCaseMustAlwaysRunSuspendedReleaseError() = runTest { + checkAll(Arb.int(), Arb.throwable()) { n, e -> + Either.catch { + bracketCase( + acquire = { n }, + use = { it }, + release = { _, _ -> e.suspend() } + ) + } should leftException(e) } + } - "bracketCase must always run immediate release error" { - checkAll(Arb.int(), Arb.throwable()) { n, e -> - Either.catch { - bracketCase( - acquire = { n }, - use = { it }, - release = { _, _ -> throw e } - ) - } should leftException(e) - } + operator fun Throwable.plus(other: Throwable): Throwable = + apply { addSuppressed(other) } + + @Test + fun bracketCaseMustComposeImmediateUseAndImmediateReleaseError() = runTest { + checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + Either.catch { + bracketCase( + acquire = { n }, + use = { throw e }, + release = { _, _ -> throw e2 } + ) + } shouldBe Either.Left(e + e2) } + } - "bracketCase must always run suspended release error" { - checkAll(Arb.int(), Arb.throwable()) { n, e -> - Either.catch { - bracketCase( - acquire = { n }, - use = { it }, - release = { _, _ -> e.suspend() } - ) - } should leftException(e) - } + @Test + fun bracketCaseMustComposeSuspendUseAndImmediateReleaseError() = runTest { + checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + Either.catch { + bracketCase( + acquire = { n }, + use = { e.suspend() }, + release = { _, _ -> throw e2 } + ) + } shouldBe Either.Left(e + e2) } - - operator fun Throwable.plus(other: Throwable): Throwable = - apply { addSuppressed(other) } - - "bracketCase must compose immediate use & immediate release error" { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> - Either.catch { - bracketCase( - acquire = { n }, - use = { throw e }, - release = { _, _ -> throw e2 } - ) - } shouldBe Either.Left(e + e2) - } + } + + @Test + fun bracketCaseMustComposeImmediateUseAndSuspendReleaseError() = runTest { + checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + Either.catch { + bracketCase( + acquire = { n }, + use = { throw e }, + release = { _, _ -> e2.suspend() } + ) + } shouldBe Either.Left(e + e2) } + } - "bracketCase must compose suspend use & immediate release error" { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> - Either.catch { - bracketCase( - acquire = { n }, - use = { e.suspend() }, - release = { _, _ -> throw e2 } - ) - } shouldBe Either.Left(e + e2) - } + @Test + fun bracketCaseMustComposeSuspendUseAndSuspendReleaseError() = runTest { + checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> + Either.catch { + bracketCase( + acquire = { n }, + use = { e.suspend() }, + release = { _, _ -> e2.suspend() } + ) + } shouldBe Either.Left(e + e2) } + } - "bracketCase must compose immediate use & suspend release error" { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> - Either.catch { - bracketCase( - acquire = { n }, - use = { throw e }, - release = { _, _ -> e2.suspend() } - ) - } shouldBe Either.Left(e + e2) - } + @Test + fun cancelOnBracketCaseReleaseWithImmediateAcquire() = runTest { + val start = CompletableDeferred() + val exit = CompletableDeferred() + + val f = async { + bracketCase( + acquire = { }, + use = { + // Signal that fiber is running + start.complete(Unit) + awaitCancellation() + }, + release = { _, exitCase -> + require(exit.complete(exitCase)) { "Release should only be called once, called again with $exitCase" } + } + ) } - "bracketCase must compose suspend use & suspend release error" { - checkAll(Arb.int(), Arb.throwable(), Arb.throwable()) { n, e, e2 -> - Either.catch { - bracketCase( - acquire = { n }, - use = { e.suspend() }, - release = { _, _ -> e2.suspend() } - ) - } shouldBe Either.Left(e + e2) - } + // Wait until the fiber is started before cancelling + start.await() + f.cancel() + exit.await().shouldBeInstanceOf() + } + + @Test + fun cancelOnBracketCaseReleasesWithSuspendingAcquire() = runTest { + val start = CompletableDeferred() + val exit = CompletableDeferred() + + val f = async { + bracketCase( + acquire = { Unit.suspend() }, + use = { + // Signal that fiber is running + start.complete(Unit) + awaitCancellation() + }, + release = { _, exitCase -> + require(exit.complete(exitCase)) { "Release should only be called once, called again with $exitCase" } + } + ) } - "cancel on bracketCase releases with immediate acquire" { - val start = CompletableDeferred() - val exit = CompletableDeferred() + // Wait until the fiber is started before cancelling + start.await() + f.cancel() + exit.await().shouldBeInstanceOf() + } - val f = async { - bracketCase( - acquire = { Unit }, - use = { - // Signal that fiber is running - start.complete(Unit) - awaitCancellation() - }, - release = { _, exitCase -> - require(exit.complete(exitCase)) { "Release should only be called once, called again with $exitCase" } - } - ) - } + @Test + fun cancelOnBracketCaseDoesNotInvokeAfterFinishing() = runTest { + val start = CompletableDeferred() + val exit = CompletableDeferred() + + val f = async { + bracketCase( + acquire = { Unit }, + use = { Unit.suspend() }, + release = { _, exitCase -> + require(exit.complete(exitCase)) { "Release should only be called once, called again with $exitCase" } + } + ) - // Wait until the fiber is started before cancelling - start.await() - f.cancel() - exit.await().shouldBeInstanceOf() + // Signal that fiber can be cancelled running + start.complete(Unit) + awaitCancellation() } - "cancel on bracketCase releases with suspending acquire" { - val start = CompletableDeferred() - val exit = CompletableDeferred() + // Wait until the fiber is started before cancelling + start.await() + f.cancel() + exit.await() shouldBe ExitCase.Completed + } + + @Test + fun acquireOnBracketCaseIsNotCancellable() = runTest { + checkAll(Arb.int(), Arb.int()) { x, y -> + val mVar = Channel(1).apply { send(x) } + val latch = CompletableDeferred() + val p = CompletableDeferred() - val f = async { + val fiber = async { bracketCase( - acquire = { Unit.suspend() }, - use = { - // Signal that fiber is running - start.complete(Unit) - awaitCancellation() + acquire = { + latch.complete(Unit) + // This should be uncancellable, and suspends until capacity 1 is received + mVar.send(y) }, - release = { _, exitCase -> - require(exit.complete(exitCase)) { "Release should only be called once, called again with $exitCase" } - } + use = { awaitCancellation() }, + release = { _, exitCase -> require(p.complete(exitCase)) } ) } - // Wait until the fiber is started before cancelling - start.await() - f.cancel() - exit.await().shouldBeInstanceOf() + // Wait until acquire started + latch.await() + async { fiber.cancel() } + + mVar.receive() shouldBe x + mVar.receive() shouldBe y + p.await().shouldBeInstanceOf() } + } - "cancel on bracketCase doesn't invoke after finishing" { - val start = CompletableDeferred() - val exit = CompletableDeferred() + @Test + fun releaseOnBracketCaseIsNotCancellable() = runTest { + checkAll(Arb.int(), Arb.int()) { x, y -> + val mVar = Channel(1).apply { send(x) } + val latch = CompletableDeferred() - val f = async { + val fiber = async { bracketCase( - acquire = { Unit }, - use = { Unit.suspend() }, - release = { _, exitCase -> - require(exit.complete(exitCase)) { "Release should only be called once, called again with $exitCase" } - } + acquire = { latch.complete(Unit) }, + use = { awaitCancellation() }, + release = { _, _ -> mVar.send(y) } ) - - // Signal that fiber can be cancelled running - start.complete(Unit) - awaitCancellation() - } - - // Wait until the fiber is started before cancelling - start.await() - f.cancel() - exit.await() shouldBe ExitCase.Completed - } - - "acquire on bracketCase is not cancellable" { - checkAll(Arb.int(), Arb.int()) { x, y -> - val mVar = Channel(1).apply { send(x) } - val latch = CompletableDeferred() - val p = CompletableDeferred() - - val fiber = async { - bracketCase( - acquire = { - latch.complete(Unit) - // This should be uncancellable, and suspends until capacity 1 is received - mVar.send(y) - }, - use = { awaitCancellation() }, - release = { _, exitCase -> require(p.complete(exitCase)) } - ) - } - - // Wait until acquire started - latch.await() - async { fiber.cancel() } - - mVar.receive() shouldBe x - mVar.receive() shouldBe y - p.await().shouldBeInstanceOf() } - } - "release on bracketCase is not cancellable" { - checkAll(Arb.int(), Arb.int()) { x, y -> - val mVar = Channel(1).apply { send(x) } - val latch = CompletableDeferred() - - val fiber = async { - bracketCase( - acquire = { latch.complete(Unit) }, - use = { awaitCancellation() }, - release = { _, _ -> mVar.send(y) } - ) - } - - latch.await() - async { fiber.cancel() } + latch.await() + async { fiber.cancel() } - mVar.receive() shouldBe x - // If release was cancelled this hangs since the buffer is empty - mVar.receive() shouldBe y - } + mVar.receive() shouldBe x + // If release was cancelled this hangs since the buffer is empty + mVar.receive() shouldBe y } } -) +} From 1fd3cbf91c589a26d23a704a2b07dc61e736052d Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Sat, 28 Oct 2023 09:08:40 +0200 Subject: [PATCH 056/114] Move arrow-functions tests to kotlin.test (#3243) --- .../core/arrow-functions/build.gradle.kts | 10 - .../kotlin/arrow/core/AndThenTests.kt | 27 +- .../kotlin/arrow/core/FunctionSyntaxTest.kt | 294 +++++++++--------- .../kotlin/arrow/core/KotestConfig.kt | 12 - .../kotlin/arrow/core/MemoizationTest.kt | 33 +- 5 files changed, 178 insertions(+), 198 deletions(-) delete mode 100644 arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt diff --git a/arrow-libs/core/arrow-functions/build.gradle.kts b/arrow-libs/core/arrow-functions/build.gradle.kts index 5437121c9ba..3a20ee1e556 100644 --- a/arrow-libs/core/arrow-functions/build.gradle.kts +++ b/arrow-libs/core/arrow-functions/build.gradle.kts @@ -1,13 +1,10 @@ @file:Suppress("DSL_SCOPE_VIOLATION") -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) alias(libs.plugins.kotlinx.kover) - alias(libs.plugins.kotest.multiplatform) alias(libs.plugins.spotless) } @@ -34,17 +31,10 @@ kotlin { implementation(projects.arrowFxCoroutines) implementation(libs.kotlin.test) implementation(libs.coroutines.test) - implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } } - - jvmTest { - dependencies { - runtimeOnly(libs.kotest.runnerJUnit5) - } - } } jvm { diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/AndThenTests.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/AndThenTests.kt index 492d12c4aa2..d2c23ef2426 100644 --- a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/AndThenTests.kt +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/AndThenTests.kt @@ -2,7 +2,6 @@ package arrow.core import io.kotest.common.Platform import io.kotest.common.platform -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.matchers.shouldBe import io.kotest.property.arbitrary.arbitrary @@ -10,18 +9,20 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.next import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class AndThenTests : StringSpec({ - val count = when (platform) { +class AndThenTests { + private val count = when (platform) { Platform.JVM -> 200_000 else -> 1000 } - fun Arb.Companion.functionAToB(arb: Arb): Arb<(A) -> B> = arbitrary { random -> + private fun Arb.Companion.functionAToB(arb: Arb): Arb<(A) -> B> = arbitrary { random -> { _: A -> arb.next(random) }.memoize() } - "AndThen0 - compose a chain of functions with andThen should be same with AndThen" { + @Test fun andThen0ComposeChainWithAndThen() = runTest { checkAll(Arb.int(), Arb.list(Arb.functionAToB(Arb.int()))) { i, fs -> val result = fs.fold({ i }) { acc, f -> { f(acc()) } @@ -35,7 +36,7 @@ class AndThenTests : StringSpec({ } } - "AndThen0 - andThen is stack safe" { + @Test fun andThen0AndThenStackSafe() = runTest { val result = (0 until count).fold({ 0 }) { acc, _ -> acc.andThen { it + 1 } }.invoke() @@ -43,7 +44,7 @@ class AndThenTests : StringSpec({ result shouldBe count } - "AndThen1 - compose a chain of functions with andThen should be same with AndThen" { + @Test fun andThen1ComposeChainWithAndThen() = runTest { checkAll(Arb.int(), Arb.list(Arb.functionAToB(Arb.int()))) { i, fs -> val result = fs.fold({ x: Int -> x }) { acc, f -> { x: Int -> f(acc(x)) } @@ -57,7 +58,7 @@ class AndThenTests : StringSpec({ } } - "AndThen1 - compose a chain of function with compose should be same with AndThen" { + @Test fun andThen1ComposeChainWithCompose() = runTest { checkAll(Arb.int(), Arb.list(Arb.functionAToB(Arb.int()))) { i, fs -> val result = fs.fold({ x: Int -> x }) { acc, f -> { x: Int -> acc(f(x)) } @@ -71,7 +72,7 @@ class AndThenTests : StringSpec({ } } - "AndThen1 - andThen is stack safe" { + @Test fun andThen1AndThenStackSafe() = runTest { val result = (0 until count).fold({ x: Int -> x }) { acc, _ -> acc.andThen { it + 1 } }.invoke(0) @@ -79,7 +80,7 @@ class AndThenTests : StringSpec({ result shouldBe count } - "AndThen1 - compose is stack safe" { + @Test fun andThen1ComposeStackSafe() = runTest { val result = (0 until count).fold({ x: Int -> x }) { acc, _ -> acc.compose { it + 1 } }.invoke(0) @@ -87,7 +88,7 @@ class AndThenTests : StringSpec({ result shouldBe count } - "AndThen2 - compose a chain of functions with andThen should be same with AndThen" { + @Test fun andThen2ComposeChainWithAndThen() = runTest { checkAll(Arb.int(), Arb.int(), Arb.list(Arb.functionAToB(Arb.int()))) { i, j, fs -> val result = fs.fold({ x: Int, y: Int -> x + y }) { acc, f -> { x: Int, y: Int -> f(acc(x, y)) } @@ -101,11 +102,11 @@ class AndThenTests : StringSpec({ } } - "AndThen2 - andThen is stack safe" { + @Test fun andThen2AndThenStackSafe() = runTest { val result = (0 until count).fold({ x: Int, y: Int -> x + y }) { acc, _ -> acc.andThen { it + 1 } }.invoke(0, 0) result shouldBe count } -}) +} diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt index 204cb0f7863..6ceca3327bc 100644 --- a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt @@ -1,158 +1,158 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class FunctionSyntaxTest : StringSpec({ +class FunctionSyntaxTest { val sum = { i1: Int, i2: Int -> i1 + i2 } val add5 = { i: Int -> i + 5 } val multiplyBy2 = { i: Int -> i * 2 } - "it should compose function correctly (andThen)" { - val potato = "potato" - val ninja = "ninja" - val get = { potato } - val map = { word: String -> ninja + word } - (get andThen map)() - (ninja + potato) shouldBe (get andThen map)() + @Test fun andThenComposesCorrectly() = runTest { + val potato = "potato" + val ninja = "ninja" + val get = { potato } + val map = { word: String -> ninja + word } + (get andThen map)() + (ninja + potato) shouldBe (get andThen map)() + } + + @Test fun andThen1() = runTest { + val add5andMultiplyBy2 = add5 andThen multiplyBy2 + add5andMultiplyBy2(2) shouldBe 14 + } + + @Test fun andThen2() = runTest { + val sumAndMultiplyBy2 = sum andThen multiplyBy2 + sumAndMultiplyBy2(5, 2) shouldBe 14 + } + + @Test fun compose() = runTest { + val multiplyBy2andAdd5 = add5 compose multiplyBy2 + multiplyBy2andAdd5(2) shouldBe 9 + } + + @Test fun currying() = runTest { + val sum2ints = { x: Int, y: Int -> x + y } + val curried = sum2ints.curried() + curried(2)(4) shouldBe 6 + val addFive = curried(5) + addFive(7) shouldBe 12 + } + + @Test fun uncurrying() = runTest { + val sum2ints: (Int, Int) -> Int = { x, y -> x + y } + val curried: (Int) -> (Int) -> Int = sum2ints.curried() + curried(2)(4) shouldBe 6 + // same type as sum2ints, + curried.uncurried()(2, 4) shouldBe 6 + sum2ints(2, 4) shouldBe 6 + } + + @Test fun curryingEffect() = runTest { + val sum2ints: suspend (Int, Int) -> Int = { x: Int, y: Int -> x + y } + val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() + curried(2)(4) shouldBe 6 + val addFive: suspend (Int) -> Int = curried(5) + addFive(7) shouldBe 12 + } + + @Test fun uncurryingEffect() = runTest { + val sum2ints: suspend (Int, Int) -> Int = { x, y -> x + y } + val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() + curried(2)(4) shouldBe 6 + // same type as sum2ints, + curried.uncurried()(2, 4) shouldBe 6 + sum2ints(2, 4) shouldBe 6 + } + + @Test fun memoize() = runTest { + var counterA = 0 + var counterB = 0 + + val a = { _: Int -> counterA++ } + val b = { _: Int -> counterB++ }.memoize() + + repeat(5) { a(1) } + repeat(5) { b(1) } + + counterA shouldBe 5 + counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once + } + + @Test fun memoizeEmpty() = runTest { + var counterA = 0 + var counterB = 0 + + val a = { counterA++ } + val b = { counterB++ }.memoize() + + repeat(5) { a() } + repeat(5) { b() } + + counterA shouldBe 5 + counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once + } + + @Test fun partially() = runTest { + val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10 = sum5ints.partially5(10) + val sum3intsTo15 = sum4intsTo10.partially4(5) + val sum2intsTo17 = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + + val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + + val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + @Test fun suspendPartially() = runTest { + val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10 = sum5ints.partially5(10) + val sum3intsTo15 = sum4intsTo10.partially4(5) + val sum2intsTo17 = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + + val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + + val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + @Test fun partials() = runTest { + val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10: (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) + val sum3intsTo15: (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) + val sum2intsTo17: (Int, Int) -> Int = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + val helloX: (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + @Test fun suspendPartials() = runTest { + val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } + val sum4intsTo10: suspend (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) + val sum3intsTo15: suspend (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) + val sum2intsTo17: suspend (Int, Int) -> Int = sum3intsTo15.partially3(2) + sum2intsTo17(1, 2) shouldBe 20 + val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } + val helloX: suspend (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") + helloX("Arrow") shouldBe "Hello, Arrow!" + } + + @Test fun bind() = runTest { + var i = 0 + fun inc(a: Int) { + i += a } - "testAndThen" { - val add5andMultiplyBy2 = add5 andThen multiplyBy2 - add5andMultiplyBy2(2) shouldBe 14 - } - - "testAndThen2" { - val sumAndMultiplyBy2 = sum andThen multiplyBy2 - sumAndMultiplyBy2(5, 2) shouldBe 14 - } - - "testCompose" { - val multiplyBy2andAdd5 = add5 compose multiplyBy2 - multiplyBy2andAdd5(2) shouldBe 9 - } - - "testCurrying" { - val sum2ints = { x: Int, y: Int -> x + y } - val curried = sum2ints.curried() - curried(2)(4) shouldBe 6 - val addFive = curried(5) - addFive(7) shouldBe 12 - } - - "testUncurrying" { - val sum2ints: (Int, Int) -> Int = { x, y -> x + y } - val curried: (Int) -> (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - // same type as sum2ints, - curried.uncurried()(2, 4) shouldBe 6 - sum2ints(2, 4) shouldBe 6 - } - - "testCurryingEffect" { - val sum2ints: suspend (Int, Int) -> Int = { x: Int, y: Int -> x + y } - val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - val addFive: suspend (Int) -> Int = curried(5) - addFive(7) shouldBe 12 - } - - "testUncurryingEffect" { - val sum2ints: suspend (Int, Int) -> Int = { x, y -> x + y } - val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - // same type as sum2ints, - curried.uncurried()(2, 4) shouldBe 6 - sum2ints(2, 4) shouldBe 6 - } - - "memoize" { - var counterA = 0 - var counterB = 0 - - val a = { _: Int -> counterA++ } - val b = { _: Int -> counterB++ }.memoize() - - repeat(5) { a(1) } - repeat(5) { b(1) } - - counterA shouldBe 5 - counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once - } - - "memoizeEmpty" { - var counterA = 0 - var counterB = 0 - - val a = { counterA++ } - val b = { counterB++ }.memoize() - - repeat(5) { a() } - repeat(5) { b() } - - counterA shouldBe 5 - counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once - } - - "partially" { - val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10 = sum5ints.partially5(10) - val sum3intsTo15 = sum4intsTo10.partially4(5) - val sum2intsTo17 = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - - val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - - val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "suspend partially" { - val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10 = sum5ints.partially5(10) - val sum3intsTo15 = sum4intsTo10.partially4(5) - val sum2intsTo17 = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - - val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - - val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "partials" { - val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10: (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) - val sum3intsTo15: (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) - val sum2intsTo17: (Int, Int) -> Int = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - val helloX: (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "suspend partials" { - val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10: suspend (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) - val sum3intsTo15: suspend (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) - val sum2intsTo17: suspend (Int, Int) -> Int = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - val helloX: suspend (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "bind" { - var i = 0 - fun inc(a: Int) { - i += a - } - - val binded = ::inc.partially1(5) - i shouldBe 0 - binded() - i shouldBe 5 - } - -}) + val binded = ::inc.partially1(5) + i shouldBe 0 + binded() + i shouldBe 5 + } +} diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt deleted file mode 100644 index ce7f493fad2..00000000000 --- a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/KotestConfig.kt +++ /dev/null @@ -1,12 +0,0 @@ -package arrow.core - -import io.kotest.core.config.AbstractProjectConfig -import io.kotest.property.PropertyTesting -import kotlin.time.Duration -import kotlin.time.Duration.Companion.seconds - -class KotestConfig : AbstractProjectConfig() { - override suspend fun beforeProject() { - PropertyTesting.defaultIterationCount = 250 - } -} diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt index 24478adfc21..2c99471e987 100644 --- a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt @@ -1,14 +1,15 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import io.kotest.property.checkAll import io.kotest.matchers.shouldBe import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlin.random.Random +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class MemoizationTest : StringSpec({ - "Memoize races" { +class MemoizationTest { + @Test fun memoizeRaces() = runTest { checkAll { fun sum(): Int = Random.nextInt(Int.MAX_VALUE) @@ -24,7 +25,7 @@ class MemoizationTest : StringSpec({ } } - "Memoize P0 only first execution runs" { + @Test fun memoize0OnlyFirst() = runTest { var runs = 0 fun sum(): Int { runs++ @@ -38,7 +39,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 1 } - "Memoize P0 nullable" { + @Test fun memoize0Nullable() = runTest { var runs = 0 fun sum(): Int? { runs++ @@ -52,7 +53,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 1 } - "Memoize P1 only first execution runs" { + @Test fun memoize1OnlyFirst() = runTest { var runs = 0 fun sum(n: Int): Int { runs++ @@ -70,7 +71,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 3 } - "Memoize P1 nullable" { + @Test fun memoize1Nullable() = runTest { var runs = 0 fun sum(n: Int): Int? { runs++ @@ -84,7 +85,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 1 } - "Memoize P2 only first execution runs" { + @Test fun memoize2OnlyFirst() = runTest { var runs = 0 fun sum(n1: Int, n2: Int): Int { runs++ @@ -103,7 +104,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 3 } - "Memoize P2 nullable" { + @Test fun memoize2Nullable() = runTest { var runs = 0 fun sum(n: Int, m: Int): Int? { runs++ @@ -117,7 +118,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 1 } - "Memoize P3 only first execution runs" { + @Test fun memoize3OnlyFirst() = runTest { var runs = 0 fun sum(n1: Int, n2: Int, n3: Int): Int { runs++ @@ -136,7 +137,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 3 } - "Memoize P3 nullable" { + @Test fun memoize3Nullable() = runTest { var runs = 0 fun sum(a: Int, b: Int, c: Int): Int? { runs++ @@ -150,7 +151,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 1 } - "Memoize P4 only first execution runs" { + @Test fun memoize4OnlyFirst() = runTest { var runs = 0 fun sum(n1: Int, n2: Int, n3: Int, n4: Int): Int { runs++ @@ -169,7 +170,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 3 } - "Memoize P4 nullable" { + @Test fun memoize4Nullable() = runTest { var runs = 0 fun sum(a: Int, b: Int, c: Int, d: Int): Int? { runs++ @@ -183,7 +184,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 1 } - "Memoize P5 only first execution runs" { + @Test fun memoize5OnlyFirst() = runTest { var runs = 0 fun sum(n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Int { runs++ @@ -202,7 +203,7 @@ class MemoizationTest : StringSpec({ runs shouldBe 3 } - "Memoize P5 nullable" { + @Test fun memoize5Nullable() = runTest { var runs = 0 fun sum(a: Int, b: Int, c: Int, d: Int, e: Int): Int? { runs++ @@ -215,6 +216,6 @@ class MemoizationTest : StringSpec({ memoized(1, 2, 3, 4, 5) shouldBe null runs shouldBe 1 } -}) +} private fun consecSumResult(n: Int): Int = (n * (n + 1)) / 2 From a6f1e7377c4a20055968657f493fc0cae0222e79 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Sun, 29 Oct 2023 07:38:28 +0100 Subject: [PATCH 057/114] Inline `AtomicBoolean` (#3240) * Inline AtomicBoolean * Update API files --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../core/arrow-atomic/api/arrow-atomic.api | 33 ++++++++++++------- .../kotlin/arrow/atomic/AtomicBoolean.kt | 20 +++++++---- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/arrow-libs/core/arrow-atomic/api/arrow-atomic.api b/arrow-libs/core/arrow-atomic/api/arrow-atomic.api index a077cc554d2..3e8e5de6c25 100644 --- a/arrow-libs/core/arrow-atomic/api/arrow-atomic.api +++ b/arrow-libs/core/arrow-atomic/api/arrow-atomic.api @@ -1,19 +1,28 @@ public final class arrow/atomic/AtomicBoolean { - public fun (Z)V - public final fun compareAndSet (ZZ)Z - public final fun get ()Z - public final fun getAndSet (Z)Z - public final fun getValue ()Z - public final fun set (Z)V - public final fun setValue (Z)V + public static final synthetic fun box-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Larrow/atomic/AtomicBoolean; + public static final fun compareAndSet-impl (Ljava/util/concurrent/atomic/AtomicInteger;ZZ)Z + public static fun constructor-impl (Z)Ljava/util/concurrent/atomic/AtomicInteger; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Ljava/util/concurrent/atomic/AtomicInteger;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/concurrent/atomic/AtomicInteger;Ljava/util/concurrent/atomic/AtomicInteger;)Z + public static final fun get-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Z + public static final fun getAndSet-impl (Ljava/util/concurrent/atomic/AtomicInteger;Z)Z + public static final fun getValue-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Z + public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/concurrent/atomic/AtomicInteger;)I + public static final fun set-impl (Ljava/util/concurrent/atomic/AtomicInteger;Z)V + public static final fun setValue-impl (Ljava/util/concurrent/atomic/AtomicInteger;Z)V + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/concurrent/atomic/AtomicInteger; } public final class arrow/atomic/AtomicBooleanKt { - public static final fun getAndUpdate (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Z - public static final fun loop (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; - public static final fun tryUpdate (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Z - public static final fun update (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)V - public static final fun updateAndGet (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Z + public static final fun getAndUpdate-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Z + public static final fun loop-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; + public static final fun tryUpdate-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Z + public static final fun update-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)V + public static final fun updateAndGet-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Z } public final class arrow/atomic/AtomicIntKt { diff --git a/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt index 93e0446b946..cecd7b6f5b0 100644 --- a/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt +++ b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt @@ -1,10 +1,13 @@ package arrow.atomic -public class AtomicBoolean(value: Boolean) { - private val inner = AtomicInt(value.toInt()) +import kotlin.jvm.JvmInline + +@JvmInline +public value class AtomicBoolean private constructor(private val inner: AtomicInt) { + public constructor(value: Boolean): this(AtomicInt(value.toInt())) public var value: Boolean - get() = inner.value != 0 + get() = inner.value.toBoolean() set(value) { inner.value = value.toInt() } @@ -18,12 +21,15 @@ public class AtomicBoolean(value: Boolean) { } public fun getAndSet(value: Boolean): Boolean = - inner.getAndSet(value.toInt()) == 1 - - private fun Boolean.toInt(): Int = - if (this) 1 else 0 + inner.getAndSet(value.toInt()).toBoolean() } +private inline fun Boolean.toInt(): Int = + if (this) 1 else 0 + +private inline fun Int.toBoolean(): Boolean = + this != 0 + /** * Infinite loop that reads this atomic variable and performs the specified [action] on its value. From 1b68bfcc354a4737be3e8b5e2fff7561250e97a2 Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Sun, 29 Oct 2023 07:39:13 +0100 Subject: [PATCH 058/114] refactor: migrate MappersSpec to kotlin-test (#3248) --- .../kotlin/arrow/core/raise/MappersSpec.kt | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt index 0da9d2304aa..32c62a557fe 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/MappersSpec.kt @@ -6,8 +6,6 @@ import arrow.core.merge import arrow.core.none import arrow.core.test.either import arrow.core.toOption -import arrow.core.raise.toOption -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.constant @@ -17,75 +15,77 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import kotlin.Result.Companion.failure import kotlin.Result.Companion.success +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class MappersSpec : StringSpec({ - "effect - toEither" { +class MappersSpec { + @Test fun effectToEither() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> effect { a.bind() }.toEither() shouldBe a } } - "eagerEffect - toEither" { + @Test fun eagerEffectToEither() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> eagerEffect { a.bind() }.toEither() shouldBe a } } - "effect - toIor" { + @Test fun effectToIor() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> effect { a.bind() }.toIor() shouldBe a.fold({ Ior.Left(it) }, { Ior.Right(it) }) } } - "eagerEffect - toIor" { + @Test fun eagerEffectToIor() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> eagerEffect { a.bind() }.toIor() shouldBe a.fold({ Ior.Left(it) }, { Ior.Right(it) }) } } - "effect - getOrNull" { + @Test fun effectGetOrNull() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> effect { a.bind() }.getOrNull() shouldBe a.getOrNull() } } - "eagerEffect - getOrNull" { + @Test fun eagerEffectGetOrNull() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> eagerEffect { a.bind() }.getOrNull() shouldBe a.getOrNull() } } - "effect - toOption { none() }" { + @Test fun effectToOptionNone() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> effect { a.bind() }.toOption { none() } shouldBe a.getOrNull().toOption() } } - "eagerEffect - toOption { none() }" { + @Test fun eagerEffectToOptionNone() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> eagerEffect { a.bind() }.toOption { none() } shouldBe a.getOrNull().toOption() } } - "effect - toOption" { + @Test fun effectToOption() = runTest { checkAll(Arb.either(Arb.constant(None), Arb.string())) { a -> effect { a.bind() }.toOption() shouldBe a.getOrNull().toOption() } } - "eagerEffect - toOption" { + @Test fun eagerEffectToOption() = runTest { checkAll(Arb.either(Arb.constant(None), Arb.string())) { a -> eagerEffect { a.bind() }.toOption() shouldBe a.getOrNull().toOption() } } - "effect - toResult { }" { + @Test fun effectToResultWithBlock() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> effect { a.bind() }.toResult { success(it) } shouldBe a.fold({ success(it) }, { success(it) }) } } - "eagerEffect - toResult { }" { + @Test fun eagerEffectToResultWithBlock() = runTest { checkAll(Arb.either(Arb.int(), Arb.string())) { a -> eagerEffect { a.bind() }.toResult { success(it) } shouldBe a.fold({ success(it) }, { success(it) }) } @@ -93,47 +93,47 @@ class MappersSpec : StringSpec({ val boom = RuntimeException("Boom!") - "effect - toResult { } - exception" { + @Test fun effectToResultWithBlockException() = runTest { effect { throw boom }.toResult { success(it) } shouldBe failure(boom) } - "eagerEffect - toResult { } - exception" { + @Test fun eagerEffectToResultWithBlockException() = runTest { checkAll(Arb.string()) { a -> eagerEffect { throw boom }.toResult { success(it) } shouldBe failure(boom) } } - "effect - toResult()" { + @Test fun effectToResult() = runTest { checkAll(Arb.either(Arb.string().map { RuntimeException(it) }, Arb.string())) { a -> effect { a.bind() }.toResult() shouldBe a.fold({ failure(it) }, { success(it) }) } } - "eagerEffect - toResult()" { + @Test fun eagerEffectToResult() = runTest { checkAll(Arb.either(Arb.string().map { RuntimeException(it) }, Arb.string())) { a -> eagerEffect { a.bind() }.toResult() shouldBe a.fold({ failure(it) }, { success(it) }) } } - "effect - toResult() - exception" { + @Test fun effectToResultException() = runTest { effect { throw boom }.toResult() shouldBe failure(boom) } - "eagerEffect - toResult() - exception" { + @Test fun eagerEffectToResultException() = runTest { checkAll(Arb.string()) { a -> eagerEffect { throw boom }.toResult() shouldBe failure(boom) } } - "effect - merge" { + @Test fun effectMerge() = runTest { checkAll(Arb.either(Arb.string(), Arb.string())) { a -> effect { a.bind() }.merge() shouldBe a.merge() } } - "eagerEffect - merge" { + @Test fun eagerEffectMerge() = runTest { checkAll(Arb.either(Arb.string(), Arb.string())) { a -> eagerEffect { a.bind() }.merge() shouldBe a.merge() } } -}) +} From 2fa4f4101c923b5aec5b397e119aa822ac39afd5 Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Sat, 28 Oct 2023 23:40:22 -0700 Subject: [PATCH 059/114] Refactor ResourceTestJvm from Kotest Plugin to Kotlin-test runtime (#3244) Closes #3213 --- .../arrow/fx/coroutines/ResourceTestJvm.kt | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt index 4fa664d4ea5..d54f894bc5d 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ResourceTestJvm.kt @@ -1,15 +1,16 @@ package arrow.fx.coroutines import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import java.util.concurrent.atomic.AtomicBoolean import java.lang.AutoCloseable import java.io.Closeable import io.kotest.property.Arb import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ResourceTestJvm : StringSpec({ +class ResourceTestJvm { class AutoCloseableTest : AutoCloseable { val didClose = AtomicBoolean(false) @@ -20,8 +21,8 @@ class ResourceTestJvm : StringSpec({ val didClose = AtomicBoolean(false) override fun close() = didClose.set(true) } - - "AutoCloseable closes" { + + @Test fun autoCloseableCloses() = runTest { val t = AutoCloseableTest() resourceScope { autoCloseable { t } @@ -29,23 +30,23 @@ class ResourceTestJvm : StringSpec({ t.didClose.get() shouldBe true } - - "AutoCloseable closes on error" { + + @Test fun autoCloseableClosesOnError() = runTest { checkAll(Arb.throwable()) { throwable -> val t = AutoCloseableTest() - + shouldThrow { resourceScope { autoCloseable { t } throw throwable } } shouldBe throwable - + t.didClose.get() shouldBe true } } - - "Closeable closes" { + + @Test fun closeableCloses() = runTest { val t = CloseableTest() resourceScope { @@ -54,8 +55,8 @@ class ResourceTestJvm : StringSpec({ t.didClose.get() shouldBe true } - - "Closeable closes on error" { + + @Test fun closeableClosesOnError() = runTest { checkAll(Arb.throwable()) { throwable -> val t = CloseableTest() @@ -69,4 +70,4 @@ class ResourceTestJvm : StringSpec({ t.didClose.get() shouldBe true } } -}) +} From 99b1bf0cd6b756419b781c15c05b86d764c1e2ce Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Sun, 29 Oct 2023 07:42:03 +0100 Subject: [PATCH 060/114] refactor: migrate FlowJvmTest to Kotlin-test (#3228) --- .../kotlin/arrow/fx/coroutines/FlowJvmTest.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt index c4c05febe8a..1ca0f21b4d9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt @@ -1,22 +1,23 @@ package arrow.fx.coroutines -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlin.test.Test import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toSet import kotlin.time.ExperimentalTime import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.test.runTest @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) @ExperimentalTime -class FlowJvmTest : StringSpec({ - "parMap - single thread - identity" { +class FlowJvmTest { + @Test fun parMapSingleThreadIdentity() = runTest { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> @@ -25,8 +26,8 @@ class FlowJvmTest : StringSpec({ } } } - - "parMap - flowOn" { + + @Test fun parMapflowOn() = runTest { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> @@ -38,7 +39,7 @@ class FlowJvmTest : StringSpec({ } } - "parMapUnordered - single thread - identity" { + @Test fun parMapUnorderedSingleThreadIdentity() = runTest { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> @@ -48,7 +49,7 @@ class FlowJvmTest : StringSpec({ } } - "parMapUnordered - flowOn" { + @Test fun parMapUnorderedFlowOn() = runTest { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> @@ -59,4 +60,4 @@ class FlowJvmTest : StringSpec({ } } } -}) +} From fdf6e99a17994ab4bf9a99bedbcef368ce24077c Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Sat, 28 Oct 2023 23:42:52 -0700 Subject: [PATCH 061/114] Refactor ParZip9JvmTest from Kotest Plugin to Kotlin-test runtime (#3245) Closes #3211 --- .../kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt index ad229af6e16..fdd3a74b23a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt @@ -3,7 +3,6 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.Tuple9 import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -13,14 +12,16 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test import java.util.concurrent.Executors -class ParZip9JvmTest : StringSpec({ +class ParZip9JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - "parZip 9 returns to original context" { + @Test fun parZip9ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } @@ -57,7 +58,7 @@ class ParZip9JvmTest : StringSpec({ } - "parZip 9 returns to original context on failure" { + @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } @@ -192,7 +193,7 @@ class ParZip9JvmTest : StringSpec({ } } - "parZip 9 finishes on single thread" { + @Test fun parZip9FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { parZip( @@ -215,4 +216,4 @@ class ParZip9JvmTest : StringSpec({ } } } -}) +} From 6b794a973b885989ec12fb61d556d7f95cfd35d2 Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Sat, 28 Oct 2023 23:43:24 -0700 Subject: [PATCH 062/114] Refactor ParZip8JvmTest from Kotest Plugin to Kotlin-test runtime (#3246) Closes #3210 --- .../kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt index b76f03c74ae..52b2febd22f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt @@ -3,7 +3,6 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.Tuple8 import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -14,13 +13,15 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test -class ParZip8JvmTest : StringSpec({ +class ParZip8JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - "parZip 8 returns to original context" { + @Test fun parZip8ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } @@ -47,7 +48,7 @@ class ParZip8JvmTest : StringSpec({ } - "parZip 8 returns to original context on failure" { + @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } @@ -159,7 +160,7 @@ class ParZip8JvmTest : StringSpec({ } } - "parZip 8 finishes on single thread" { + @Test fun parZip8FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") @@ -182,4 +183,4 @@ class ParZip8JvmTest : StringSpec({ } } } -}) +} From bd5baa2de6165951a30543ff8f24ac116b3e97b8 Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Tue, 31 Oct 2023 08:32:35 +0100 Subject: [PATCH 063/114] refactor: migrate NumberInstancesTest to kotlin-test (#3232) --- .../core/extensions/NumberInstancesTest.kt | 20 ++++++++----- .../commonTest/kotlin/arrow/core/test/Laws.kt | 28 +++++++++++-------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt index ad826f6f1ad..59709b7e86a 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt @@ -2,15 +2,15 @@ package arrow.core.extensions import arrow.core.test.laws.MonoidLaws import arrow.core.test.laws.SemiringLaws -import arrow.core.test.testLaws -import io.kotest.core.spec.style.StringSpec +import arrow.core.test.testLawsCommon import io.kotest.property.Arb import io.kotest.property.arbitrary.byte import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.short +import kotlin.test.Test -class NumberInstancesTest : StringSpec({ +class NumberInstancesTest { fun testAllLaws( name: String, @@ -21,13 +21,19 @@ class NumberInstancesTest : StringSpec({ GEN: Arb, eq: (F, F) -> Boolean = { a, b -> a == b } ) { - testLaws(SemiringLaws(name, zero, combine, one, combineMultiplicate, GEN, eq)) - testLaws(MonoidLaws(name, zero, combine, GEN, eq)) + testLawsCommon(SemiringLaws(name, zero, combine, one, combineMultiplicate, GEN, eq)) + testLawsCommon(MonoidLaws(name, zero, combine, GEN, eq)) } + @Test fun testByteLaws() = testAllLaws("Byte", 0, { x, y -> (x + y).toByte() }, 1, { x, y -> (x * y).toByte() }, Arb.byte()) + + @Test fun testShortLaws() = testAllLaws("Short", 0, { x, y -> (x + y).toShort() }, 1, { x, y -> (x * y).toShort() }, Arb.short()) + + @Test fun testIntLaws() = testAllLaws("Int", 0, Int::plus, 1, Int::times, Arb.int()) - testAllLaws("Long", 0, Long::plus, 1, Long::times, Arb.long()) -}) + @Test fun testLongLaws() = + testAllLaws("Long", 0, Long::plus, 1, Long::times, Arb.long()) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt index b2383454f66..c5221757595 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt @@ -1,17 +1,17 @@ package arrow.core.test import io.kotest.assertions.fail +import io.kotest.assertions.withClue import io.kotest.core.names.TestName import io.kotest.core.spec.style.StringSpec -import io.kotest.core.spec.style.scopes.StringSpecScope import io.kotest.core.spec.style.scopes.addTest -import io.kotest.core.test.TestContext +import kotlinx.coroutines.test.runTest interface LawSet { val laws: List } -data class Law(val name: String, val test: suspend TestContext.() -> Unit) +data class Law(val name: String, val test: suspend () -> Unit) fun A.equalUnderTheLaw(b: A, f: (A, A) -> Boolean = { x, y -> x == y }): Boolean = if (f(this, b)) true else fail("Found $this but expected: $b") @@ -23,15 +23,21 @@ fun StringSpec.testLaws(vararg laws: List): Unit = laws .distinctBy { law: Law -> law.name } .forEach { law: Law -> addTest(TestName(null, law.name, false), false, null) { - law.test(StringSpecScope(this.coroutineContext, testCase)) + runTest { law.test() } } } -fun StringSpec.testLaws(prefix: String, vararg laws: List): Unit = laws - .flatMap { list: List -> list.asIterable() } - .distinctBy { law: Law -> law.name } - .forEach { law: Law -> - addTest(TestName(prefix, law.name, false), false, null) { - law.test(StringSpecScope(this.coroutineContext, testCase)) +fun testLawsCommon(lawSet: LawSet) = withClue("In $lawSet") { + testLawsCommon(lawSet.laws) +} + +fun testLawsCommon(vararg laws: List) = runTest { + laws + .flatMap(List::asIterable) + .distinctBy(Law::name) + .forEach { law: Law -> + withClue("Testing ${law.name}") { + law.test() + } } - } +} From 9b6ce55a33b28f23a93119fe0962caf596196ff3 Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Tue, 31 Oct 2023 08:33:47 +0100 Subject: [PATCH 064/114] refactor: OptionTest to kotlin-test runtime (#3229) --- .../kotlin/arrow/core/OptionTest.kt | 87 ++++++++++--------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt index d709ba1eaf1..267f2574854 100755 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt @@ -3,8 +3,7 @@ package arrow.core import arrow.core.raise.option import arrow.core.test.laws.MonoidLaws import arrow.core.test.option -import arrow.core.test.testLaws -import io.kotest.core.spec.style.StringSpec +import arrow.core.test.testLawsCommon import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.property.Arb @@ -14,17 +13,19 @@ import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class OptionTest : StringSpec({ +class OptionTest { val some: Option = Some("kotlin") val none: Option = None - testLaws( + @Test fun testMonoidLaws() = testLawsCommon( MonoidLaws("Option", None, { x, y -> x.combine(y, Int::plus) }, Arb.option(Arb.int())) ) - "ensure null in option computation" { + @Test fun ensureNullInOptionComputation() = runTest { checkAll(Arb.boolean(), Arb.int()) { predicate, i -> option { ensure(predicate) @@ -33,7 +34,7 @@ class OptionTest : StringSpec({ } } - "ensureNotNull in option computation" { + @Test fun ensureNotNullInOptionComputation() = runTest { fun square(i: Int): Int = i * i checkAll(Arb.int().orNull()) { i: Int? -> option { @@ -43,7 +44,7 @@ class OptionTest : StringSpec({ } } - "short circuit null" { + @Test fun shortCircuitNull() = runTest { option { val number: Int = "s".length ensureNotNull(number.takeIf { it > 1 }) @@ -51,7 +52,7 @@ class OptionTest : StringSpec({ } shouldBe None } - "tap applies effects returning the original value" { + @Test fun tapAppliesEffectsReturningTheOriginalValue() = runTest { checkAll(Arb.option(Arb.long())) { option -> var effect = 0 val res = option.onSome { effect += 1 } @@ -64,7 +65,7 @@ class OptionTest : StringSpec({ } } - "tapNone applies effects returning the original value" { + @Test fun tapNoneAppliesEffectsReturningTheOriginalValue() = runTest { checkAll(Arb.option(Arb.long())) { option -> var effect = 0 val res = option.onNone { effect += 1 } @@ -77,7 +78,7 @@ class OptionTest : StringSpec({ } } - "fromNullable should work for both null and non-null values of nullable types" { + @Test fun fromNullableShouldWorkForBothNullAndNonNullValuesOfNullableTypes() = runTest { checkAll(Arb.int().orNull()) { a: Int? -> // This seems to be generating only non-null values, so it is complemented by the next test val o: Option = Option.fromNullable(a) @@ -85,49 +86,49 @@ class OptionTest : StringSpec({ } } - "fromNullable should return none for null values of nullable types" { + @Test fun fromNullableShouldReturnNoneForNullValuesOfNullableTypes() = runTest { val a: Int? = null Option.fromNullable(a) shouldBe None } - "getOrElse" { + @Test fun getOrElse() = runTest { some.getOrElse { "java" } shouldBe "kotlin" none.getOrElse { "java" } shouldBe "java" } - "getOrNull" { + @Test fun getOrNull() = runTest { some.getOrNull() shouldNotBe null none.getOrNull() shouldBe null } - "map" { + @Test fun map() = runTest { some.map(String::uppercase) shouldBe Some("KOTLIN") none.map(String::uppercase) shouldBe None } - "fold" { + @Test fun fold() = runTest { some.fold({ 0 }) { it.length } shouldBe 6 none.fold({ 0 }) { it.length } shouldBe 0 } - "flatMap" { + @Test fun flatMap() = runTest { some.flatMap { Some(it.uppercase()) } shouldBe Some("KOTLIN") none.flatMap { Some(it.uppercase()) } shouldBe None } - "filter" { + @Test fun filter() = runTest { some.filter { it == "java" } shouldBe None none.filter { it == "java" } shouldBe None some.filter { it.startsWith('k') } shouldBe Some("kotlin") } - "filterNot" { + @Test fun filterNot() = runTest { some.filterNot { it == "java" } shouldBe Some("kotlin") none.filterNot { it == "java" } shouldBe None some.filterNot { it.startsWith('k') } shouldBe None } - "filterIsInstance" { + @Test fun filterIsInstance() = runTest { val someAny: Option = some someAny.filterIsInstance() shouldBe Some("kotlin") someAny.filterIsInstance() shouldBe None @@ -141,12 +142,12 @@ class OptionTest : StringSpec({ noneAny.filterIsInstance() shouldBe None } - "toList" { + @Test fun toList() = runTest { some.toList() shouldBe listOf("kotlin") none.toList() shouldBe listOf() } - "Iterable.firstOrNone" { + @Test fun iterableFirstOrNone() = runTest { val iterable = iterableOf(1, 2, 3, 4, 5, 6) iterable.firstOrNone() shouldBe Some(1) iterable.firstOrNone { it > 2 } shouldBe Some(3) @@ -162,7 +163,7 @@ class OptionTest : StringSpec({ nullableIterable2.firstOrNone { it == null } shouldBe Some(null) } - "Collection.firstOrNone" { + @Test fun collectionFirstOrNone() = runTest { val list = listOf(1, 2, 3, 4, 5, 6) list.firstOrNone() shouldBe Some(1) @@ -173,7 +174,7 @@ class OptionTest : StringSpec({ nullableList.firstOrNone() shouldBe Some(null) } - "Iterable.singleOrNone" { + @Test fun iterableSingleOrNone() = runTest { val iterable = iterableOf(1, 2, 3, 4, 5, 6) iterable.singleOrNone() shouldBe None iterable.singleOrNone { it > 2 } shouldBe None @@ -192,7 +193,7 @@ class OptionTest : StringSpec({ nullableSingleIterable3.singleOrNone { it == null } shouldBe None } - "Collection.singleOrNone" { + @Test fun collectionSingleOrNone() = runTest { val list = listOf(1, 2, 3, 4, 5, 6) list.singleOrNone() shouldBe None @@ -203,7 +204,7 @@ class OptionTest : StringSpec({ nullableSingleList.singleOrNone() shouldBe Some(null) } - "Iterable.lastOrNone" { + @Test fun iterableLastOrNone() = runTest { val iterable = iterableOf(1, 2, 3, 4, 5, 6) iterable.lastOrNone() shouldBe Some(6) iterable.lastOrNone { it < 4 } shouldBe Some(3) @@ -219,7 +220,7 @@ class OptionTest : StringSpec({ nullableIterable2.lastOrNone { it == null } shouldBe Some(null) } - "Collection.lastOrNone" { + @Test fun collectionLastOrNone() = runTest { val list = listOf(1, 2, 3, 4, 5, 6) list.lastOrNone() shouldBe Some(6) @@ -230,7 +231,7 @@ class OptionTest : StringSpec({ nullableList.lastOrNone() shouldBe Some(null) } - "Iterable.elementAtOrNone" { + @Test fun iterableElementAtOrNone() = runTest { val iterable = iterableOf(1, 2, 3, 4, 5, 6) iterable.elementAtOrNone(index = 3 - 1) shouldBe Some(3) iterable.elementAtOrNone(index = -1) shouldBe None @@ -240,7 +241,7 @@ class OptionTest : StringSpec({ nullableIterable.elementAtOrNone(index = 3 - 1) shouldBe Some(null) } - "Collection.elementAtOrNone" { + @Test fun collectionElementAtOrNone() = runTest { val list = listOf(1, 2, 3, 4, 5, 6) list.elementAtOrNone(index = 3 - 1) shouldBe Some(3) list.elementAtOrNone(index = -1) shouldBe None @@ -250,77 +251,77 @@ class OptionTest : StringSpec({ nullableList.elementAtOrNone(index = 3 - 1) shouldBe Some(null) } - "toLeftOption" { + @Test fun toLeftOption() = runTest { 1.leftIor().leftOrNull() shouldBe 1 2.rightIor().leftOrNull() shouldBe null (1 to 2).bothIor().leftOrNull() shouldBe 1 } - "Option>.toMap()" { + @Test fun optionPairToMap() = runTest { val some: Option> = Some("key" to "value") val none: Option> = None some.toMap() shouldBe mapOf("key" to "value") none.toMap() shouldBe emptyMap() } - "catch should return Some(result) when f does not throw" { + @Test fun catchShouldReturnSomeResultWhenFDoesNotThrow() = runTest { val recover: (Throwable) -> Option = { _ -> None} Option.catch(recover) { 1 } shouldBe Some(1) } - "catch with default recover should return Some(result) when f does not throw" { + @Test fun catchWithDefaultRecoverShouldReturnSomeResultWhenFDoesNotThrow() = runTest { Option.catch { 1 } shouldBe Some(1) } - "catch should return Some(recoverValue) when f throws" { + @Test fun catchShouldReturnSomeRecoverValueWhenFThrows() = runTest { val exception = Exception("Boom!") val recoverValue = 10 val recover: (Throwable) -> Option = { _ -> Some(recoverValue) } Option.catch(recover) { throw exception } shouldBe Some(recoverValue) } - "catch should return None when f throws" { + @Test fun catchShouldReturnNoneWhenFThrows() = runTest { val exception = Exception("Boom!") Option.catch { throw exception } shouldBe None } - "invoke operator should return Some" { + @Test fun invokeOperatorShouldReturnSome() = runTest { checkAll(Arb.int()) { a: Int -> Option(a) shouldBe Some(a) } } - "isNone should return true if None and false if Some" { + @Test fun isNoneShouldReturnTrueIfNoneAndFalseIfSome() = runTest { none.isNone() shouldBe true none.isSome() shouldBe false } - "isSome should return true if Some and false if None" { + @Test fun isSomeShouldReturnTrueIfSomeAndFalseIfNone() = runTest { some.isSome() shouldBe true some.isNone() shouldBe false } - "isSome with predicate" { + @Test fun isSomeWithPredicate() = runTest { some.isSome { it.startsWith('k') } shouldBe true some.isSome { it.startsWith('j') } shouldBe false none.isSome { it.startsWith('k') } shouldBe false } - "flatten" { + @Test fun flatten() = runTest { checkAll(Arb.int()) { a: Int -> Some(Some(a)).flatten() shouldBe Some(a) Some(None).flatten() shouldBe None } } - "widen" { + @Test fun widen() = runTest { checkAll(Arb.string()) { a: String -> val widen: Option = Option(a).widen() widen.map { it.length } shouldBe Some(a.length) } } - "compareTo with Some values" { + @Test fun compareToWithSomeValues() = runTest { checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> val opA = Option(a) val opB = Option(b) @@ -333,7 +334,7 @@ class OptionTest : StringSpec({ } } - "compareTo with None values" { + @Test fun compareToWithNoneValues() = runTest { val opA = Option(1) val opB = None (opA > opB) shouldBe true @@ -350,7 +351,7 @@ class OptionTest : StringSpec({ (none == some) shouldBe false (none != some) shouldBe true } -}) +} // Utils From 1c9087d852e29d951ec6fd57fe9729faa10eadbb Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 2 Nov 2023 10:33:57 +0100 Subject: [PATCH 065/114] Revert "Inline `AtomicBoolean` (#3240)" (#3279) This reverts commit a6f1e7377c4a20055968657f493fc0cae0222e79. --- .../core/arrow-atomic/api/arrow-atomic.api | 33 +++++++------------ .../kotlin/arrow/atomic/AtomicBoolean.kt | 20 ++++------- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/arrow-libs/core/arrow-atomic/api/arrow-atomic.api b/arrow-libs/core/arrow-atomic/api/arrow-atomic.api index 3e8e5de6c25..a077cc554d2 100644 --- a/arrow-libs/core/arrow-atomic/api/arrow-atomic.api +++ b/arrow-libs/core/arrow-atomic/api/arrow-atomic.api @@ -1,28 +1,19 @@ public final class arrow/atomic/AtomicBoolean { - public static final synthetic fun box-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Larrow/atomic/AtomicBoolean; - public static final fun compareAndSet-impl (Ljava/util/concurrent/atomic/AtomicInteger;ZZ)Z - public static fun constructor-impl (Z)Ljava/util/concurrent/atomic/AtomicInteger; - public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Ljava/util/concurrent/atomic/AtomicInteger;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Ljava/util/concurrent/atomic/AtomicInteger;Ljava/util/concurrent/atomic/AtomicInteger;)Z - public static final fun get-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Z - public static final fun getAndSet-impl (Ljava/util/concurrent/atomic/AtomicInteger;Z)Z - public static final fun getValue-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Z - public fun hashCode ()I - public static fun hashCode-impl (Ljava/util/concurrent/atomic/AtomicInteger;)I - public static final fun set-impl (Ljava/util/concurrent/atomic/AtomicInteger;Z)V - public static final fun setValue-impl (Ljava/util/concurrent/atomic/AtomicInteger;Z)V - public fun toString ()Ljava/lang/String; - public static fun toString-impl (Ljava/util/concurrent/atomic/AtomicInteger;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Ljava/util/concurrent/atomic/AtomicInteger; + public fun (Z)V + public final fun compareAndSet (ZZ)Z + public final fun get ()Z + public final fun getAndSet (Z)Z + public final fun getValue ()Z + public final fun set (Z)V + public final fun setValue (Z)V } public final class arrow/atomic/AtomicBooleanKt { - public static final fun getAndUpdate-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Z - public static final fun loop-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; - public static final fun tryUpdate-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Z - public static final fun update-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)V - public static final fun updateAndGet-NCWaHEY (Ljava/util/concurrent/atomic/AtomicInteger;Lkotlin/jvm/functions/Function1;)Z + public static final fun getAndUpdate (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Z + public static final fun loop (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Ljava/lang/Void; + public static final fun tryUpdate (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Z + public static final fun update (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)V + public static final fun updateAndGet (Larrow/atomic/AtomicBoolean;Lkotlin/jvm/functions/Function1;)Z } public final class arrow/atomic/AtomicIntKt { diff --git a/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt index cecd7b6f5b0..93e0446b946 100644 --- a/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt +++ b/arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt @@ -1,13 +1,10 @@ package arrow.atomic -import kotlin.jvm.JvmInline - -@JvmInline -public value class AtomicBoolean private constructor(private val inner: AtomicInt) { - public constructor(value: Boolean): this(AtomicInt(value.toInt())) +public class AtomicBoolean(value: Boolean) { + private val inner = AtomicInt(value.toInt()) public var value: Boolean - get() = inner.value.toBoolean() + get() = inner.value != 0 set(value) { inner.value = value.toInt() } @@ -21,14 +18,11 @@ public value class AtomicBoolean private constructor(private val inner: AtomicIn } public fun getAndSet(value: Boolean): Boolean = - inner.getAndSet(value.toInt()).toBoolean() -} + inner.getAndSet(value.toInt()) == 1 -private inline fun Boolean.toInt(): Int = - if (this) 1 else 0 - -private inline fun Int.toBoolean(): Boolean = - this != 0 + private fun Boolean.toInt(): Int = + if (this) 1 else 0 +} /** From 1050868e507c24e0665e066091ecfa22e0011465 Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:42:05 -0700 Subject: [PATCH 066/114] Refactor ParZip6JvmTest from Kotest Plugin to Kotlin-test runtime (#3255) Closes #3208 --- .../kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt index 9dfb64a2f67..40fc8124137 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt @@ -3,7 +3,6 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.Tuple6 import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -14,13 +13,15 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test -class ParZip6JvmTest : StringSpec({ +class ParZip6JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - "parZip 6 returns to original context" { + @Test fun parZip6ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } @@ -45,7 +46,7 @@ class ParZip6JvmTest : StringSpec({ } } - "parZip 6 returns to original context on failure" { + @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } @@ -123,7 +124,7 @@ class ParZip6JvmTest : StringSpec({ } } - "parZip 6 finishes on single thread" { + @Test fun parZip6FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") @@ -136,4 +137,4 @@ class ParZip6JvmTest : StringSpec({ } } } -}) +} From 85c200009e9afb9fad0f3ff0ee7b7082c47b70de Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:42:20 -0700 Subject: [PATCH 067/114] Refactor ParZip5JvmTest from Kotest Plugin to Kotlin-test runtime (#3256) Closes #3207 --- .../kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt index 34596e56a88..98ede0dcf03 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt @@ -3,7 +3,6 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.Tuple5 import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -14,13 +13,15 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test -class ParZip5JvmTest : StringSpec({ +class ParZip5JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - "parZip 5 returns to original context" { + @Test fun parZip5ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } @@ -40,10 +41,9 @@ class ParZip5JvmTest : StringSpec({ threadName() shouldStartWith "single" } } - } - "parZip 5 returns to original context on failure" { + @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } @@ -107,7 +107,7 @@ class ParZip5JvmTest : StringSpec({ } } - "parZip 5 finishes on single thread" { + @Test fun parZip5FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") @@ -127,4 +127,3 @@ class ParZip5JvmTest : StringSpec({ } } } -) From 6bcb161605355ae7be52791cf05e4a3d185997bd Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:42:40 -0700 Subject: [PATCH 068/114] Refactor ParZip3JvmTest from Kotest Plugin to Kotlin-test runtime (#3258) Closes #3205 --- .../kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt index 3306da6f5c1..b29ea698f8e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt @@ -2,7 +2,6 @@ package arrow.fx.coroutines import arrow.core.Either import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -12,10 +11,12 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test -class ParZip3JvmTest : StringSpec({ - "parZip 3 returns to original context" { +class ParZip3JvmTest { + @Test fun parZip3ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } @@ -35,7 +36,7 @@ class ParZip3JvmTest : StringSpec({ } } - "parZip 3 returns to original context on failure" { + @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } @@ -75,7 +76,7 @@ class ParZip3JvmTest : StringSpec({ } } - "parZip 3 finishes on single thread" { + @Test fun parZip3FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") @@ -90,4 +91,4 @@ class ParZip3JvmTest : StringSpec({ } } } -}) +} From 4ff47224401de722a410803af7f126b186ee5996 Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:42:53 -0700 Subject: [PATCH 069/114] Refactor ParZip2JvmTest from Kotest Plugin to Kotlin-test runtime (#3259) Closes #3204 --- .../kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt index 6302f9f782d..f79c1567376 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt @@ -2,7 +2,6 @@ package arrow.fx.coroutines import arrow.core.Either import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -12,11 +11,13 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.coroutines.CoroutineContext +import kotlin.test.Test -class ParZip2JvmTest : StringSpec({ - "parZip 2 returns to original context" { +class ParZip2JvmTest { + @Test fun parZip2ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip2" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } @@ -35,7 +36,7 @@ class ParZip2JvmTest : StringSpec({ } } - "parZip 2 returns to original context on failure" { + @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip2" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } @@ -56,7 +57,7 @@ class ParZip2JvmTest : StringSpec({ } } - "parZip 2 finishes on single thread" { + @Test fun parZip2FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") @@ -68,7 +69,6 @@ class ParZip2JvmTest : StringSpec({ } } } -) suspend fun parallelCtx( nThreads: Int, From 092838f7eed12bcf9033acb664d1f6c0b05c317a Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:43:07 -0700 Subject: [PATCH 070/114] Refactor ParMapJvmTest from Kotest Plugin to Kotlin-test runtime (#3260) Closes #3203 --- .../arrow/fx/coroutines/ParMapJvmTest.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt index fc99c51ef13..c40ea02e221 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt @@ -1,14 +1,15 @@ package arrow.fx.coroutines import io.kotest.assertions.fail -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ParMapJvmTest : StringSpec({ - "parMap runs on provided context" { // 100 is same default length as Arb.list +class ParMapJvmTest { + @Test fun parMapRunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMap(single()) { Thread.currentThread().name } @@ -17,7 +18,7 @@ class ParMapJvmTest : StringSpec({ } } - "parMap(concurrency = 3) runs on provided context" { + @Test fun parMapConcurrency3RunsOnProvidedContext() = runTest { checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMap(single(), concurrency = 3) { @@ -28,7 +29,7 @@ class ParMapJvmTest : StringSpec({ } } - "parMapOrAccumulate(combine = emptyError) runs on provided context" { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateCombineEmptyErrorRunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate(single(), combine = emptyError) { Thread.currentThread().name } @@ -40,7 +41,7 @@ class ParMapJvmTest : StringSpec({ } } - "parMapOrAccumulate(combine = emptyError, concurrency = 3) runs on provided context" { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateCombineEmptyErrorConcurrency3RunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate( @@ -56,7 +57,7 @@ class ParMapJvmTest : StringSpec({ } } - "parMapOrAccumulate runs on provided context" { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateRunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate(single()) { @@ -70,7 +71,7 @@ class ParMapJvmTest : StringSpec({ } } - "parMapOrAccumulate(concurrency = 3) runs on provided context" { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateConcurrency3RunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { @@ -84,7 +85,7 @@ class ParMapJvmTest : StringSpec({ ) } } -}) +} private val emptyError: (Nothing, Nothing) -> Nothing = { _, _ -> throw AssertionError("Should not be called") } From b8595b09c6e2c137a88bacbfe1a8bc5b8308392f Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:45:21 -0700 Subject: [PATCH 071/114] Refactor ParZip4JvmTest from Kotest Plugin to Kotlin-test runtime (#3257) Closes #3206 --- .../kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt index 2ad241a338e..92fb66836fa 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt @@ -3,7 +3,6 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.Tuple4 import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -13,10 +12,12 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test -class ParZip4JvmTest : StringSpec({ - "parZip 4 returns to original context" { +class ParZip4JvmTest { + @Test fun parZip4ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } @@ -41,7 +42,7 @@ class ParZip4JvmTest : StringSpec({ } } - "parZip 4 returns to original context on failure" { + @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } @@ -92,7 +93,7 @@ class ParZip4JvmTest : StringSpec({ } } - "parZip 4 finishes on single thread" { + @Test fun parZip4FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") @@ -109,4 +110,3 @@ class ParZip4JvmTest : StringSpec({ } } } -) From 1b8ec543a42fb65fcf8ca8bdc7a780e2baab315e Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Thu, 2 Nov 2023 10:45:56 +0100 Subject: [PATCH 072/114] refactor: migrate RaiseAccumulateSpec to kotlin-test (#3250) --- .../kotlin/arrow/core/raise/RaiseAccumulateSpec.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt index 64584c77789..c8f68853a72 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt @@ -3,11 +3,12 @@ package arrow.core.raise import arrow.core.NonEmptyList import arrow.core.left import arrow.core.nonEmptyListOf -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class RaiseAccumulateSpec : StringSpec({ - "RaiseAccumulate takes precedence over extension function" { +class RaiseAccumulateSpec { + @Test fun raiseAccumulateTakesPrecedenceOverExtensionFunction() = runTest { either, Int> { zipOrAccumulate( { ensure(false) { "false" } }, @@ -15,4 +16,4 @@ class RaiseAccumulateSpec : StringSpec({ ) { _, _ -> 1 } } shouldBe nonEmptyListOf("false", "1: IsFalse", "2: IsFalse").left() } -}) +} From 74a92229c7853c2c2a9603aae29d090c82f535c2 Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:46:22 -0700 Subject: [PATCH 073/114] Refactor ParZip7JvmTest from Kotest Plugin to Kotlin-test runtime (#3247) Closes #3209 Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt index 502519e47e4..1af73d38194 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt @@ -3,7 +3,6 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.Tuple7 import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.mpp.NamedThreadFactory @@ -14,13 +13,15 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test -class ParZip7JvmTest : StringSpec({ +class ParZip7JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - "parZip 7 returns to original context" { + @Test fun parZip7ReturnsToOriginalContext() = runTest { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } @@ -46,7 +47,7 @@ class ParZip7JvmTest : StringSpec({ } } - "parZip 7 returns to original context on failure" { + @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTest { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } @@ -141,7 +142,7 @@ class ParZip7JvmTest : StringSpec({ } } - "parZip 7 finishes on single thread" { + @Test fun parZip7FinishesOnSingleThread() = runTest { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") @@ -164,4 +165,3 @@ class ParZip7JvmTest : StringSpec({ } } } -) From 40fcd76cad29eea60b7f644131780394fc16b09d Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Thu, 2 Nov 2023 20:44:25 +0530 Subject: [PATCH 074/114] Update ComparisonKtTest.kt (#3274) Co-authored-by: Simon Vergauwen --- .../kotlin/arrow/core/ComparisonKtTest.kt | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt index 4f40b9b0d06..1be9f189a4c 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt @@ -1,7 +1,6 @@ package arrow.core import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.checkAll import io.kotest.matchers.shouldBe @@ -12,6 +11,8 @@ import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.short import io.kotest.property.arbitrary.string +import kotlinx.coroutines.test.runTest +import kotlin.test.Test data class Person(val age: Int, val name: String) : Comparable { companion object { @@ -29,8 +30,8 @@ data class Person(val age: Int, val name: String) : Comparable { fun Arb.Companion.person(): Arb = Arb.bind(Arb.int(), Arb.string(), ::Person) -class ComparisonKtTest : StringSpec({ - "Arberic - sort2" { +class ComparisonKtTest { + @Test fun arbericSort2() = runTest { checkAll(Arb.person(), Arb.person()) { a, b -> val (first, second) = sort(a, b) val (aa, bb) = listOf(a, b).sorted() @@ -42,7 +43,7 @@ class ComparisonKtTest : StringSpec({ } } - "Arberic - sort3" { + @Test fun arbericSort3() = runTest { checkAll(Arb.person(), Arb.person(), Arb.person()) { a, b, c -> val (first, second, third) = sort(a, b, c) val (aa, bb, cc) = listOf(a, b, c).sorted() @@ -55,7 +56,7 @@ class ComparisonKtTest : StringSpec({ } } - "Arberic - sortAll" { + @Test fun arbericSortAll() = runTest { checkAll(Arb.person(), Arb.list(Arb.person(), 0..50)) { a, lst -> val aas = lst.toTypedArray() val res = sort(a, *aas) @@ -65,7 +66,7 @@ class ComparisonKtTest : StringSpec({ } } - "Arberic - comparator - sort2" { + @Test fun arbericComparatorSort2() = runTest { checkAll(Arb.person(), Arb.person()) { a, b -> val (first, second) = sort(a, b, Person.comparator) val (aa, bb) = listOf(a, b).sorted() @@ -77,7 +78,7 @@ class ComparisonKtTest : StringSpec({ } } - "Arberic - comparator - sort3" { + @Test fun arbericComparatorSort3() = runTest { checkAll(Arb.person(), Arb.person(), Arb.person()) { a, b, c -> val (first, second, third) = sort(a, b, c, Person.comparator) val (aa, bb, cc) = listOf(a, b, c).sorted() @@ -90,7 +91,7 @@ class ComparisonKtTest : StringSpec({ } } - "Byte - sort2" { + @Test fun byteSort2() = runTest { checkAll(Arb.byte(), Arb.byte()) { a, b -> val (first, second) = sort(a, b) val (aa, bb) = listOf(a, b).sorted() @@ -102,7 +103,7 @@ class ComparisonKtTest : StringSpec({ } } - "Byte - sort3" { + @Test fun byteSort3() = runTest { checkAll(Arb.byte(), Arb.byte(), Arb.byte()) { a, b, c -> val (first, second, third) = sort(a, b, c) val (aa, bb, cc) = listOf(a, b, c).sorted() @@ -115,7 +116,7 @@ class ComparisonKtTest : StringSpec({ } } - "Byte - sortAll" { + @Test fun byteSortAll() = runTest { checkAll(Arb.byte(), Arb.byte(), Arb.byte(), Arb.byte()) { a, b, c, d -> val res = sort(a, b, c, d) val expected = listOf(a, b, c, d).sorted() @@ -124,7 +125,7 @@ class ComparisonKtTest : StringSpec({ } } - "Short - sort2" { + @Test fun shortSort2() = runTest { checkAll(Arb.short(), Arb.short()) { a, b -> val (first, second) = sort(a, b) val (aa, bb) = listOf(a, b).sorted() @@ -136,7 +137,7 @@ class ComparisonKtTest : StringSpec({ } } - "Short - sort3" { + @Test fun shortSort3() = runTest { checkAll(Arb.short(), Arb.short(), Arb.short()) { a, b, c -> val (first, second, third) = sort(a, b, c) val (aa, bb, cc) = listOf(a, b, c).sorted() @@ -149,7 +150,7 @@ class ComparisonKtTest : StringSpec({ } } - "Short - sortAll" { + @Test fun shortSortAll() = runTest { checkAll(Arb.short(), Arb.short(), Arb.short(), Arb.short()) { a, b, c, d -> val res = sort(a, b, c, d) val expected = listOf(a, b, c, d).sorted() @@ -157,8 +158,8 @@ class ComparisonKtTest : StringSpec({ res shouldBe expected } } - - "Int - sort2" { + + @Test fun intSort2() = runTest { checkAll(Arb.int(), Arb.int()) { a, b -> val (first, second) = sort(a, b) val (aa, bb) = listOf(a, b).sorted() @@ -168,7 +169,7 @@ class ComparisonKtTest : StringSpec({ } } - "Int - sort3" { + @Test fun intSort3() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> val (first, second, third) = sort(a, b, c) val (aa, bb, cc) = listOf(a, b, c).sorted() @@ -181,7 +182,7 @@ class ComparisonKtTest : StringSpec({ } } - "Int - sortAll" { + @Test fun intSortAll() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d -> val res = sort(a, b, c, d) val expected = listOf(a, b, c, d).sorted() @@ -190,7 +191,7 @@ class ComparisonKtTest : StringSpec({ } } - "Long - sort2" { + @Test fun longSort2() = runTest { checkAll(Arb.long(), Arb.long()) { a, b -> val (first, second) = sort(a, b) val (aa, bb) = listOf(a, b).sorted() @@ -202,7 +203,7 @@ class ComparisonKtTest : StringSpec({ } } - "Long - sort3" { + @Test fun longSort3() = runTest { checkAll(Arb.long(), Arb.long(), Arb.long()) { a, b, c -> val (first, second, third) = sort(a, b, c) val (aa, bb, cc) = listOf(a, b, c).sorted() @@ -215,7 +216,7 @@ class ComparisonKtTest : StringSpec({ } } - "Long - sortAll" { + @Test fun longSortAll() = runTest { checkAll(Arb.long(), Arb.long(), Arb.long(), Arb.long()) { a, b, c, d -> val res = sort(a, b, c, d) val expected = listOf(a, b, c, d).sorted() @@ -223,4 +224,4 @@ class ComparisonKtTest : StringSpec({ res shouldBe expected } } -}) +} From 4e0846eb33a3ce95a184b99fae6bc850a3d0f618 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Thu, 2 Nov 2023 21:48:56 +0530 Subject: [PATCH 075/114] Update OptionSpec.kt (#3271) Co-authored-by: Simon Vergauwen --- .../kotlin/arrow/core/raise/OptionSpec.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt index 7490e643be3..3cd9d552dee 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt @@ -4,17 +4,18 @@ import arrow.core.None import arrow.core.Some import arrow.core.some import arrow.core.toOption -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.orNull import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class OptionSpec : StringSpec({ +class OptionSpec { - "ensure" { + @Test fun ensure() = runTest { checkAll(Arb.boolean(), Arb.int()) { b, i -> option { ensure(b) @@ -23,7 +24,7 @@ class OptionSpec : StringSpec({ } } - "ensureNotNull in option computation" { + @Test fun ensureNotNullInOptionComputation() = runTest { fun square(i: Int): Int = i * i checkAll(Arb.int().orNull()) { i: Int? -> option { @@ -33,7 +34,7 @@ class OptionSpec : StringSpec({ } } - "short circuit option" { + @Test fun shortCircuitOption() = runTest { @Suppress("UNREACHABLE_CODE") option { ensureNotNull(null) @@ -41,11 +42,11 @@ class OptionSpec : StringSpec({ } shouldBe None } - "Recover works as expected" { + @Test fun RecoverWorksAsExpected() = runTest { option { val one: Int = recover({ None.bind() }) { 1 } val two = Some(2).bind() one + two } shouldBe Some(3) } -}) +} From 6117dc4d5ef3bda1fbe9577869771c4c5719ba68 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sat, 4 Nov 2023 15:40:13 +0530 Subject: [PATCH 076/114] Update TraceJvmSpec.kt (#3276) * Update TraceJvmSpec.kt * Update TraceJvmSpec.kt --------- Co-authored-by: Simon Vergauwen --- .../jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt index caaf88af7ff..94d3d50c740 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/arrow/core/raise/TraceJvmSpec.kt @@ -1,11 +1,12 @@ package arrow.core.raise -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe - +import kotlin.test.Test +import kotlinx.coroutines.test.runTest + @OptIn(ExperimentalTraceApi::class) -class TraceJvmSpec : StringSpec({ - "Can trace a typed error" { +class TraceJvmSpec { + @Test fun canTraceATypedError() = runTest { either { traced({ raise(RuntimeException("")) }) { traced, raised -> // Remove first 2 lines: @@ -21,4 +22,4 @@ class TraceJvmSpec : StringSpec({ } } } -}) +} From 162686d61c7e16b2327886e2335e386a860bc211 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sat, 4 Nov 2023 15:41:46 +0530 Subject: [PATCH 077/114] Update ParZip9Test.kt (#3265) * Update ParZip9Test.kt * Update ParZip9Test.kt --- .../kotlin/arrow/fx/coroutines/ParZip9Test.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt index ad9a470af40..8be40bbd564 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt @@ -9,7 +9,6 @@ import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -23,9 +22,13 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class ParZip9Test : StringSpec({ - "parZip 9 runs in parallel" { +class ParZip9Test { + + @Test + fun parZip9RunsInParallel() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h, i -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -88,8 +91,9 @@ class ParZip9Test : StringSpec({ r.get() shouldBe "$i$h$g$f$e$d$c$b$a" } } - - "Cancelling parZip 9 cancels all participants" { + + @Test + fun CancellingParZip9CancelsAllParticipants() = runTest { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -130,8 +134,9 @@ class ParZip9Test : StringSpec({ ph.await().shouldBeTypeOf() pi.await().shouldBeTypeOf() } - - "parZip 9 cancels losers if a failure occurs in one of the tasks" { + + @Test + fun parZip9CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9)) @@ -181,8 +186,9 @@ class ParZip9Test : StringSpec({ r should leftException(e) } } - - "parZip CancellationException on right can cancel rest" { + + @Test + fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { checkAll(Arb.string(), Arb.int(1..9)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() @@ -230,4 +236,3 @@ class ParZip9Test : StringSpec({ } } } -) From b73aa229c0e7af983547a3251ae0e51e22d3f40b Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sat, 4 Nov 2023 15:42:10 +0530 Subject: [PATCH 078/114] Update ParZip8Test.kt (#3266) --- .../kotlin/arrow/fx/coroutines/ParZip8Test.kt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt index cf83052a036..b92c6677542 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt @@ -10,7 +10,6 @@ import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -24,9 +23,12 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class ParZip8Test : StringSpec({ - "parZip 8 runs in parallel" { +class ParZip8Test { + @Test + fun parZip8RunsInParallel() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -83,8 +85,9 @@ class ParZip8Test : StringSpec({ r.value shouldBe "$h$g$f$e$d$c$b$a" } } - - "Cancelling parZip 8 cancels all participants" { + + @Test + fun CancellingParZip8CancelsAllParticipants() = runTest { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -122,8 +125,9 @@ class ParZip8Test : StringSpec({ pg.await().shouldBeTypeOf() ph.await().shouldBeTypeOf() } - - "parZip 8 cancels losers if a failure occurs in one of the tasks" { + + @Test + fun parZip8CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6, 7, 8)) @@ -169,8 +173,9 @@ class ParZip8Test : StringSpec({ r should leftException(e) } } - - "parZip CancellationException on right can cancel rest" { + + @Test + fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { checkAll(Arb.string(), Arb.int(1..8)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() @@ -214,4 +219,3 @@ class ParZip8Test : StringSpec({ } } } -) From d38c768f14736c99a83ecacb1c4e9c10f5afaaf1 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sat, 4 Nov 2023 15:42:31 +0530 Subject: [PATCH 079/114] Update ParZip7Test.kt (#3267) --- .../kotlin/arrow/fx/coroutines/ParZip7Test.kt | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt index 90e15fa4d0b..3c4be417dd5 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt @@ -10,7 +10,6 @@ import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -24,9 +23,12 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ParZip7Test : StringSpec({ - "parZip 7 runs in parallel" { +class ParZip7Test { + @Test + fun parZip7RunsInParallel() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -77,8 +79,9 @@ class ParZip7Test : StringSpec({ r.value shouldBe "$g$f$e$d$c$b$a" } } - - "Cancelling parZip 7 cancels all participants" { + + @Test + fun CancellingParZip7CancelsAllParticipants() = runTest { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -113,8 +116,9 @@ class ParZip7Test : StringSpec({ pf.await().shouldBeTypeOf() pg.await().shouldBeTypeOf() } - - "parZip 7 cancels losers if a failure occurs in one of the tasks" { + + @Test + fun parZip7CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6, 7)) @@ -157,8 +161,9 @@ class ParZip7Test : StringSpec({ r should leftException(e) } } - - "parZip CancellationException on right can cancel rest" { + + @Test + fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { checkAll(Arb.string(), Arb.int(1..7)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() @@ -197,5 +202,4 @@ class ParZip7Test : StringSpec({ pf.await().shouldBeTypeOf() } } - } -) +} From f72e042be4ebe0605b206da91bc9cba2f3da3aa4 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sat, 4 Nov 2023 15:42:54 +0530 Subject: [PATCH 080/114] Update ParZip6Test.kt (#3268) --- .../kotlin/arrow/fx/coroutines/ParZip6Test.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt index 0be161a5ae0..77eebeed8a9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt @@ -10,7 +10,6 @@ import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -24,9 +23,12 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ParZip6Test : StringSpec({ - "parZip 6 runs in parallel" { +class ParZip6Test { + @Test + fun parZip6RunsInParallel() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -72,7 +74,8 @@ class ParZip6Test : StringSpec({ } } - "Cancelling parZip 6 cancels all participants" { + @Test + fun CancellingParZip6CancelsAllParticipants() = runTest { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -104,8 +107,9 @@ class ParZip6Test : StringSpec({ pe.await().shouldBeTypeOf() pf.await().shouldBeTypeOf() } - - "parZip 6 cancels losers if a failure occurs in one of the tasks" { + + @Test + fun parZip6CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6)) @@ -143,8 +147,9 @@ class ParZip6Test : StringSpec({ r should leftException(e) } } - - "parZip CancellationException on right can cancel rest" { + + @Test + fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { checkAll(Arb.string(), Arb.int(1..6)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() @@ -180,4 +185,3 @@ class ParZip6Test : StringSpec({ } } } -) From 6aad57d51bee507b9235b2bab03aa332ff445728 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sat, 4 Nov 2023 15:43:22 +0530 Subject: [PATCH 081/114] Update ParZip5Test.kt (#3269) --- .../kotlin/arrow/fx/coroutines/ParZip5Test.kt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt index 29e73ef9fac..8af58f145c2 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt @@ -10,7 +10,6 @@ import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -24,9 +23,12 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ParZip5Test : StringSpec({ - "parZip 5 runs in parallel" { +class ParZip5Test { + @Test + fun parZip5RunsInParallel() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -65,8 +67,9 @@ class ParZip5Test : StringSpec({ r.value shouldBe "$e$d$c$b$a" } } - - "Cancelling parZip 5 cancels all participants" { + + @Test + fun CancellingParZip5CancelsAllParticipants() = runTest { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -101,8 +104,9 @@ class ParZip5Test : StringSpec({ pd.await().shouldBeTypeOf() pe.await().shouldBeTypeOf() } - - "parZip 5 cancels losers if a failure occurs in one of the tasks" { + + @Test + fun parZip5CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5)), @@ -136,8 +140,9 @@ class ParZip5Test : StringSpec({ r should leftException(e) } } - - "parZip CancellationException on right can cancel rest" { + + @Test + fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { checkAll(Arb.string(), Arb.int(1..5)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() @@ -169,4 +174,3 @@ class ParZip5Test : StringSpec({ } } } -) From 19d1a2923187f134ddb59822642cf3043d966293 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sat, 4 Nov 2023 15:43:57 +0530 Subject: [PATCH 082/114] Update ParZip4Test.kt (#3270) --- .../kotlin/arrow/fx/coroutines/ParZip4Test.kt | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt index 24c956fe65f..f3bd76a59e5 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt @@ -10,7 +10,6 @@ import arrow.fx.coroutines.awaitExitCase import arrow.fx.coroutines.leftException import arrow.fx.coroutines.parZip import arrow.fx.coroutines.throwable -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -24,9 +23,12 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope - -class ParZip4Test : StringSpec({ - "parZip 4 runs in parallel" { +import kotlinx.coroutines.test.runTest +import kotlin.test.Test + +class ParZip4Test { + @Test + fun parZip4RunsInParallel() = runTest { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -59,8 +61,9 @@ class ParZip4Test : StringSpec({ r.value shouldBe "$d$c$b$a" } } - - "Cancelling parZip 4 cancels all participants" { + + @Test + fun CancellingParZip4CancelsAllParticipants() = runTest { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -82,8 +85,9 @@ class ParZip4Test : StringSpec({ pc.await().shouldBeTypeOf() pd.await().shouldBeTypeOf() } - - "parZip 4 cancels losers if a failure occurs in one of the tasks" { + + @Test + fun parZip4CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4)), @@ -113,8 +117,9 @@ class ParZip4Test : StringSpec({ r should leftException(e) } } - - "parZip CancellationException on right can cancel rest" { + + @Test + fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { checkAll(Arb.string(), Arb.int(1..4)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() @@ -142,4 +147,3 @@ class ParZip4Test : StringSpec({ } } } -) From d31a84bcb954256c956fdd7ef268923961e7aed1 Mon Sep 17 00:00:00 2001 From: Jonathan Lagneaux Date: Tue, 7 Nov 2023 13:35:33 +0100 Subject: [PATCH 083/114] Refactor CountDownLatchSpec and CyclicBarrierSpec to use kotlin test (#3227) * Refactor CountDownLatchSpec to use kotlin test Closes #3187 * Refactor CyclicBarrierSpec to use kotlin test Closes #3188 --------- Co-authored-by: Alejandro Serrano --- .../arrow/fx/coroutines/CountDownLatchSpec.kt | 40 +++++++++++-------- .../arrow/fx/coroutines/CyclicBarrierSpec.kt | 40 ++++++++++++------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt index b39b93397c8..1aceb561cf1 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt @@ -1,7 +1,6 @@ package arrow.fx.coroutines import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.nulls.shouldBeNull import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -13,25 +12,30 @@ import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.joinAll import kotlinx.coroutines.launch +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withTimeoutOrNull +import kotlin.test.Test -class CountDownLatchSpec : StringSpec({ - "should raise an exception when constructed with a negative or zero capacity" { +class CountDownLatchSpec { + @Test + fun shouldRaiseAnExceptionWhenConstructedWithNegativeOrZeroCapacity() = runTest { checkAll(Arb.long(Long.MIN_VALUE, 0)) { i -> shouldThrow { CountDownLatch(i) }.message shouldBe "CountDownLatch must be constructed with positive non-zero initial count, but was $i" } } - - "release and then await should complete" { + + @Test + fun releaseAndThenAwaitShouldComplete() = runTest { checkAll(Arb.long(1, 100)) { count -> val latch = CountDownLatch(count) repeat(count.toInt()) { latch.countDown() } latch.await() shouldBe Unit } } - - "await and then release should complete" { + + @Test + fun awaitAndThenReleaseShouldComplete() = runTest { checkAll(Arb.long(1, 100)) { count -> val latch = CountDownLatch(count) val job = launch { latch.await() } @@ -39,8 +43,9 @@ class CountDownLatchSpec : StringSpec({ job.join() shouldBe Unit } } - - "await with > 1 latch unreleased should block" { + + @Test + fun awaitWithMoreThanOneLatchUnreleasedShouldBlock() = runTest { checkAll(Arb.long(1, 100)) { count -> val latch = CountDownLatch(count) repeat(count.toInt() - 1) { latch.countDown() } @@ -48,8 +53,9 @@ class CountDownLatchSpec : StringSpec({ latch.count() shouldBe 1 } } - - "multiple awaits should all complete" { + + @Test + fun multipleAwaitsShouldAllComplete() = runTest { checkAll(Arb.long(1, 100)) { count -> val latch = CountDownLatch(count) val jobs = (0 until count).map { launch { latch.await() } } @@ -57,14 +63,16 @@ class CountDownLatchSpec : StringSpec({ jobs.joinAll() } } - - "should release when latches == 0" { + + @Test + fun shouldReleaseWhenLatchesEqualsZero() = runTest { val latch = CountDownLatch(1) latch.countDown() latch.countDown() } - - "await is cancelable" { + + @Test + fun awaitIsCancelable() = runTest { val latch = CountDownLatch(1) val exit = CompletableDeferred() val job = launch(start = CoroutineStart.UNDISPATCHED) { @@ -74,4 +82,4 @@ class CountDownLatchSpec : StringSpec({ exit.isCompleted shouldBe true exit.await().shouldBeTypeOf() } -}) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt index d92530df839..2daf01e9b3f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt @@ -2,7 +2,6 @@ package arrow.fx.coroutines import arrow.core.Either import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf import io.kotest.property.Arb @@ -13,30 +12,36 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.launch +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class CyclicBarrierSpec : StringSpec({ - "should raise an exception when constructed with a negative or zero capacity" { +class CyclicBarrierSpec { + @Test + fun shouldRaiseAnExceptionWhenConstructedWithNegativeOrZeroCapacity() = runTest { checkAll(Arb.int(Int.MIN_VALUE, 0)) { i -> shouldThrow { CyclicBarrier(i) }.message shouldBe "Cyclic barrier must be constructed with positive non-zero capacity $i but was $i > 0" } } - "barrier of capacity 1 is a no op" { + @Test + fun barrierOfCapacity1IsANoOp() = runTest { checkAll(Arb.constant(Unit)) { val barrier = CyclicBarrier(1) barrier.await() } } - "awaiting all in parallel resumes all coroutines" { + @Test + fun awaitingAllInParallelResumesAllCoroutines() = runTest { checkAll(Arb.int(1, 100)) { i -> val barrier = CyclicBarrier(i) (0 until i).parMap { barrier.await() } } } - "should reset once full" { + @Test + fun shouldResetOnceFull() = runTest { checkAll(Arb.constant(Unit)) { val barrier = CyclicBarrier(2) parZip({ barrier.await() }, { barrier.await() }) { _, _ -> } @@ -44,7 +49,8 @@ class CyclicBarrierSpec : StringSpec({ } } - "executes runnable once full" { + @Test + fun executesRunnableOnceFull() = runTest { var barrierRunnableInvoked = false val barrier = CyclicBarrier(2) { barrierRunnableInvoked = true } parZip({ barrier.await() }, { barrier.await() }) { _, _ -> } @@ -52,7 +58,8 @@ class CyclicBarrierSpec : StringSpec({ barrierRunnableInvoked shouldBe true } - "await is cancelable" { + @Test + fun awaitIsCancelable() = runTest { checkAll(Arb.int(2, Int.MAX_VALUE)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -68,14 +75,16 @@ class CyclicBarrierSpec : StringSpec({ } } - "should clean up upon cancellation of await" { + @Test + fun shouldCleanUpUponCancellationOfAwait() = runTest { checkAll(Arb.constant(Unit)) { val barrier = CyclicBarrier(2) launch(start = CoroutineStart.UNDISPATCHED) { barrier.await() }.cancelAndJoin() } } - "reset cancels all awaiting" { + @Test + fun resetCancelsAllAwaiting() = runTest { checkAll(Arb.int(2, 100)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -92,7 +101,8 @@ class CyclicBarrierSpec : StringSpec({ } } - "should clean up upon reset" { + @Test + fun shouldCleanUpUponReset() = runTest { checkAll(Arb.int(2, 100)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -107,7 +117,8 @@ class CyclicBarrierSpec : StringSpec({ } } - "race fiber cancel and barrier full" { + @Test + fun raceFiberCancelAndBarrierFull() = runTest { checkAll(Arb.constant(Unit)) { val barrier = CyclicBarrier(2) val job = launch(start = CoroutineStart.UNDISPATCHED) { barrier.await() } @@ -120,7 +131,8 @@ class CyclicBarrierSpec : StringSpec({ } } - "reset" { + @Test + fun reset() = runTest { checkAll(Arb.int(2..10)) { n -> val barrier = CyclicBarrier(n) @@ -140,4 +152,4 @@ class CyclicBarrierSpec : StringSpec({ } } } -}) +} From 89163f985d7765d8a24bfb049c5a6cbce41ff8a3 Mon Sep 17 00:00:00 2001 From: "HyunWoo Lee (Nunu Lee)" <54518925+l2hyunwoo@users.noreply.github.com> Date: Thu, 9 Nov 2023 02:11:06 +0900 Subject: [PATCH 084/114] Refactor NonEmptyListTest to kotlin-test (#3231) * Add kotlin test dependency * Refactor NonEmptyList Test to use kotlin test --------- Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/core/NonEmptyListTest.kt | 634 ++++++++++-------- 1 file changed, 336 insertions(+), 298 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index 6ff83ec9b02..5daf09ca177 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -1,11 +1,8 @@ package arrow.core -import arrow.core.test.laws.SemigroupLaws import arrow.core.test.nonEmptyList import arrow.core.test.stackSafeIteration -import arrow.core.test.testLaws import io.kotest.assertions.withClue -import io.kotest.core.spec.style.StringSpec import io.kotest.inspectors.shouldForAll import io.kotest.matchers.booleans.shouldBeTrue import io.kotest.matchers.nulls.shouldBeNull @@ -14,350 +11,391 @@ import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.* import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest import kotlin.math.max import kotlin.math.min - -class NonEmptyListTest : StringSpec({ - - testLaws(SemigroupLaws("NonEmptyList", NonEmptyList::plus, Arb.nonEmptyList(Arb.int()))) - - "iterable.toNonEmptyListOrNull should round trip" { - checkAll(Arb.nonEmptyList(Arb.int())) { nonEmptyList -> - nonEmptyList.all.toNonEmptyListOrNull().shouldNotBeNull() shouldBe nonEmptyList - } +import kotlin.test.Test + +class NonEmptyListTest { + + @Test + fun nonEmptyList() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { nel1, nel2, nel3 -> + (nel1 + nel2) + nel3 shouldBe nel1 + (nel2 + nel3) } + } - "iterable.toNonEmptyListOrNull should return null for an empty iterable" { - listOf().toNonEmptyListOrNull().shouldBeNull() + @Test + fun iterableToNonEmptyListOrNullShouldRoundTrip() = runTest { + checkAll(Arb.nonEmptyList(Arb.int())) { nonEmptyList -> + nonEmptyList.all.toNonEmptyListOrNull().shouldNotBeNull() shouldBe nonEmptyList } + } - "iterable.toNonEmptyListOrNull should work correctly when the iterable starts with or contains null" { - checkAll(Arb.nonEmptyList(Arb.int().orNull())) { nonEmptyList -> - nonEmptyList.all.toNonEmptyListOrNull().shouldNotBeNull() shouldBe nonEmptyList - } + @Test + fun iterableToNonEmptyListOrNoneShouldRoundTrip() = runTest { + checkAll(Arb.nonEmptyList(Arb.int())) { nonEmptyList -> + nonEmptyList.all.toNonEmptyListOrNone() shouldBe nonEmptyList.some() } + } - "iterable.toNonEmptyListOrNone should round trip" { - checkAll(Arb.nonEmptyList(Arb.int())) { nonEmptyList -> - nonEmptyList.all.toNonEmptyListOrNone() shouldBe nonEmptyList.some() - } + @Test + fun iterableToNonEmptyListOrNullShouldReturnNullForAnEmptyIterable() = runTest { + listOf().toNonEmptyListOrNull().shouldBeNull() + } + + @Test + fun iterableToNonEmptyListOrNullShouldWorkCorrectlyWhenTheIterableStartsWithOrContainsNull() = runTest { + checkAll(Arb.nonEmptyList(Arb.int().orNull())) { nonEmptyList -> + nonEmptyList.all.toNonEmptyListOrNull().shouldNotBeNull() shouldBe nonEmptyList } + } - "can align lists with different lengths" { - checkAll(Arb.nonEmptyList(Arb.boolean()), Arb.nonEmptyList(Arb.boolean())) { a, b -> - val result = a.align(b) + @Test + fun canAlignListsWithDifferentLengths() = runTest { + checkAll(Arb.nonEmptyList(Arb.boolean()), Arb.nonEmptyList(Arb.boolean())) { a, b -> + val result = a.align(b) - result.size shouldBe max(a.size, b.size) - result.take(min(a.size, b.size)).shouldForAll { - it.isBoth() shouldBe true - } - result.drop(min(a.size, b.size)).shouldForAll { - if (a.size < b.size) { - it.isRight() shouldBe true - } else { - it.isLeft() shouldBe true - } - } + result.size shouldBe max(a.size, b.size) + result.take(min(a.size, b.size)).shouldForAll { + it.isBoth() shouldBe true } - } - - "mapOrAccumulate is stack-safe, and runs in original order" { - val acc = mutableListOf() - val res = (0..stackSafeIteration()) - .toNonEmptyListOrNull()!! - .mapOrAccumulate(String::plus) { - acc.add(it) - it + result.drop(min(a.size, b.size)).shouldForAll { + if (a.size < b.size) { + it.isRight() shouldBe true + } else { + it.isLeft() shouldBe true } - res shouldBe Either.Right(acc) - res shouldBe Either.Right((0..stackSafeIteration()).toList()) + } } + } + + @Test + fun mapOrAccumulateIsStackSafeAndRunsInOriginalOrder() = runTest { + val acc = mutableListOf() + val res = (0..stackSafeIteration()) + .toNonEmptyListOrNull()!! + .mapOrAccumulate(String::plus) { + acc.add(it) + it + } + res shouldBe Either.Right(acc) + res shouldBe Either.Right((0..stackSafeIteration()).toList()) + } + + @Test + fun mapOrAccumulateAccumulatesErrors() = runTest { + checkAll(Arb.nonEmptyList(Arb.int())) { nel -> + val res = nel.mapOrAccumulate { i -> + if (i % 2 == 0) i else raise(i) + } - "mapOrAccumulate accumulates errors" { - checkAll(Arb.nonEmptyList(Arb.int())) { nel -> - val res = nel.mapOrAccumulate { i -> - if (i % 2 == 0) i else raise(i) - } - - val expected = nel.filterNot { it % 2 == 0 } - .toNonEmptyListOrNull()?.left() ?: nel.filter { it % 2 == 0 }.right() + val expected = nel.filterNot { it % 2 == 0 } + .toNonEmptyListOrNull()?.left() ?: nel.filter { it % 2 == 0 }.right() - res shouldBe expected - } + res shouldBe expected } + } - "mapOrAccumulate accumulates errors with combine function" { - checkAll(Arb.nonEmptyList(Arb.negativeInt())) { nel -> - val res = nel.mapOrAccumulate(String::plus) { i -> - if (i > 0) i else raise("Negative") - } - - res shouldBe nel.map { "Negative" }.joinToString("").left() + @Test + fun mapOrAccumulateAccumulatesErrorsWithCombineFunction() = runTest { + checkAll(Arb.nonEmptyList(Arb.negativeInt())) { nel -> + val res = nel.mapOrAccumulate(String::plus) { i -> + if (i > 0) i else raise("Negative") } + + res shouldBe nel.map { "Negative" }.joinToString("").left() } + } - "padZip" { - checkAll(Arb.nonEmptyList(Arb.int()), Arb.nonEmptyList(Arb.int())) { a, b -> - val result = a.padZip(b) - val left = a + List(max(0, b.size - a.size)) { null } - val right = b + List(max(0, a.size - b.size)) { null } + @Test + fun padZip() = runTest { + checkAll(Arb.nonEmptyList(Arb.int()), Arb.nonEmptyList(Arb.int())) { a, b -> + val result = a.padZip(b) + val left = a + List(max(0, b.size - a.size)) { null } + val right = b + List(max(0, a.size - b.size)) { null } - result shouldBe left.zip(right) - } + result shouldBe left.zip(right) } + } - "padZip with transformation" { - checkAll(Arb.nonEmptyList(Arb.int()), Arb.nonEmptyList(Arb.int())) { a, b -> - val result = a.padZip(b, { it * 2 }, { it * 3 }, { x, y -> x + y }) + @Test + fun padZipWithTransformation() = runTest { + checkAll(Arb.nonEmptyList(Arb.int()), Arb.nonEmptyList(Arb.int())) { a, b -> + val result = a.padZip(b, { it * 2 }, { it * 3 }, { x, y -> x + y }) - val minSize = min(a.size, b.size) - result.size shouldBe max(a.size, b.size) - result.take(minSize) shouldBe a.take(minSize).zip(b.take(minSize)) { x, y -> x + y } + val minSize = min(a.size, b.size) + result.size shouldBe max(a.size, b.size) + result.take(minSize) shouldBe a.take(minSize).zip(b.take(minSize)) { x, y -> x + y } - if (a.size > b.size) - result.drop(minSize) shouldBe a.drop(minSize).map { it * 2 } - else - result.drop(minSize) shouldBe b.drop(minSize).map { it * 3 } - } + if (a.size > b.size) + result.drop(minSize) shouldBe a.drop(minSize).map { it * 2 } + else + result.drop(minSize) shouldBe b.drop(minSize).map { it * 3 } } + } - "unzip is the inverse of zip" { - checkAll(Arb.nonEmptyList(Arb.int())) { nel -> - val zipped = nel.zip(nel) - val left = zipped.map { it.first } - val right = zipped.map { it.second } + @Test + fun unzipIsTheInverseOfZip() = runTest { + checkAll(Arb.nonEmptyList(Arb.int())) { nel -> + val zipped = nel.zip(nel) + val left = zipped.map { it.first } + val right = zipped.map { it.second } - left shouldBe nel - right shouldBe nel - } + left shouldBe nel + right shouldBe nel } + } - "unzip with split function" { - checkAll(Arb.nonEmptyList(Arb.pair(Arb.int(), Arb.int()))) { nel -> - val unzipped = nel.unzip(::identity) + @Test + fun unzipWithSplitFunction() = runTest { + checkAll(Arb.nonEmptyList(Arb.pair(Arb.int(), Arb.int()))) { nel -> + val unzipped = nel.unzip(::identity) - unzipped.first shouldBe nel.map { it.first } - unzipped.second shouldBe nel.map { it.second } - } + unzipped.first shouldBe nel.map { it.first } + unzipped.second shouldBe nel.map { it.second } } - - "zip2" { - checkAll(Arb.nonEmptyList(Arb.int()), Arb.nonEmptyList(Arb.int())) { a, b -> - val result = a.zip(b) - val expected = a.all.zip(b.all).toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip2() = runTest { + checkAll(Arb.nonEmptyList(Arb.int()), Arb.nonEmptyList(Arb.int())) { a, b -> + val result = a.zip(b) + val expected = a.all.zip(b.all).toNonEmptyListOrNull() + result shouldBe expected } - - "zip3" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c -> - val result = a.zip(b, c, ::Triple) - val expected = a.all.zip(b.all, c.all, ::Triple).toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip3() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { a, b, c -> + val result = a.zip(b, c, ::Triple) + val expected = a.all.zip(b.all, c.all, ::Triple).toNonEmptyListOrNull() + result shouldBe expected } - - "zip4" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c, d -> - val result = a.zip(b, c, d, ::Tuple4) - val expected = a.all.zip(b.all, c.all, d.all, ::Tuple4).toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip4() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { a, b, c, d -> + val result = a.zip(b, c, d, ::Tuple4) + val expected = a.all.zip(b.all, c.all, d.all, ::Tuple4).toNonEmptyListOrNull() + result shouldBe expected } - - "zip5" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c, d, e -> - val result = a.zip(b, c, d, e, ::Tuple5) - val expected = a.all.zip(b.all, c.all, d.all, e.all, ::Tuple5).toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip5() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { a, b, c, d, e -> + val result = a.zip(b, c, d, e, ::Tuple5) + val expected = a.all.zip(b.all, c.all, d.all, e.all, ::Tuple5).toNonEmptyListOrNull() + result shouldBe expected } - - "zip6" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c, d, e, f -> - val result = a.zip(b, c, d, e, f, ::Tuple6) - val expected = - a.all.zip(b.all, c.all, d.all, e.all, f.all, ::Tuple6).toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip6() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { a, b, c, d, e, f -> + val result = a.zip(b, c, d, e, f, ::Tuple6) + val expected = + a.all.zip(b.all, c.all, d.all, e.all, f.all, ::Tuple6).toNonEmptyListOrNull() + result shouldBe expected } - - "zip7" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c, d, e, f, g -> - val result = a.zip(b, c, d, e, f, g, ::Tuple7) - val expected = - a.all.zip(b.all, c.all, d.all, e.all, f.all, g.all, ::Tuple7).toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip7() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { a, b, c, d, e, f, g -> + val result = a.zip(b, c, d, e, f, g, ::Tuple7) + val expected = + a.all.zip(b.all, c.all, d.all, e.all, f.all, g.all, ::Tuple7).toNonEmptyListOrNull() + result shouldBe expected } - - "zip8" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c, d, e, f, g, h -> - val result = a.zip(b, c, d, e, f, g, h, ::Tuple8) - val expected = a.all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, ::Tuple8) - .toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip8() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { a, b, c, d, e, f, g, h -> + val result = a.zip(b, c, d, e, f, g, h, ::Tuple8) + val expected = a.all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, ::Tuple8) + .toNonEmptyListOrNull() + result shouldBe expected } - - "zip9" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()), - Arb.nonEmptyList(Arb.int()) - ) { a, b, c, d, e, f, g, h, i -> - val result = a.zip(b, c, d, e, f, g, h, i, ::Tuple9) - val expected = a.all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, i.all, ::Tuple9) - .toNonEmptyListOrNull() - result shouldBe expected - } + } + + @Test + fun zip9() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()), + Arb.nonEmptyList(Arb.int()) + ) { a, b, c, d, e, f, g, h, i -> + val result = a.zip(b, c, d, e, f, g, h, i, ::Tuple9) + val expected = a.all.zip(b.all, c.all, d.all, e.all, f.all, g.all, h.all, i.all, ::Tuple9) + .toNonEmptyListOrNull() + result shouldBe expected } - - "max element" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - val result = a.max() - val expected = a.maxOrNull() - result shouldBe expected - } + } + + @Test + fun maxElement() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + val result = a.max() + val expected = a.maxOrNull() + result shouldBe expected } - - "maxBy element" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - val result = a.maxBy(::identity) - val expected = a.maxByOrNull(::identity) - result shouldBe expected - } + } + + @Test + fun maxByElement() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + val result = a.maxBy(::identity) + val expected = a.maxByOrNull(::identity) + result shouldBe expected } - - "min element" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - val result = a.min() - val expected = a.minOrNull() - result shouldBe expected - } + } + + @Test + fun minElement() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + val result = a.min() + val expected = a.minOrNull() + result shouldBe expected } - - "minBy element" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - val result = a.minBy(::identity) - val expected = a.minByOrNull(::identity) - result shouldBe expected - } + } + + @Test + fun minByElement() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + val result = a.minBy(::identity) + val expected = a.minByOrNull(::identity) + result shouldBe expected } - - "NonEmptyList equals List" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - withClue("$a should be equal to ${a.all}") { - // `shouldBe` doesn't use the `equals` methods on `Iterable` - (a == a.all).shouldBeTrue() - } + } + + @Test + fun nonEmptyListEqualsList() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + withClue("$a should be equal to ${a.all}") { + // `shouldBe` doesn't use the `equals` methods on `Iterable` + (a == a.all).shouldBeTrue() } } - - "lastOrNull" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - val result = a.lastOrNull() - val expected = a.last() - result shouldBe expected - } + } + + @Test + fun lastOrNull() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + val result = a.lastOrNull() + val expected = a.last() + result shouldBe expected } - - "extract" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - val result = a.extract() - val expected = a.head - result shouldBe expected - } + } + + @Test + fun extract() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + val result = a.extract() + val expected = a.head + result shouldBe expected } - - "plus" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.int() - ) { a, b -> - val result = a + b - val expected = a.all + b - result shouldBe expected - } + } + + @Test + fun plus() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.int() + ) { a, b -> + val result = a + b + val expected = a.all + b + result shouldBe expected } - - "coflatMap should retain the same length as the original list" { - checkAll( - Arb.nonEmptyList(Arb.int()) - ) { a -> - val result = a.coflatMap { it.all } - val expected = a.all - result.size shouldBe expected.size - } + } + + @Test + fun coflatMapKeepsLength() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()) + ) { a -> + val result = a.coflatMap { it.all } + val expected = a.all + result.size shouldBe expected.size } - - "foldLeft should sum up correctly for addition" { - checkAll( - Arb.nonEmptyList(Arb.int()), - Arb.int() - ) { list, initial -> - val result = list.foldLeft(initial) { acc, i -> acc + i } - val expected = initial + list.all.sum() - result shouldBe expected - } + } + + @Test + fun foldLeftAddition() = runTest { + checkAll( + Arb.nonEmptyList(Arb.int()), + Arb.int() + ) { list, initial -> + val result = list.foldLeft(initial) { acc, i -> acc + i } + val expected = initial + list.all.sum() + result shouldBe expected } -}) + } +} From bcc46f3f7b9a21d94ea80ddc4080b2bc8b00dfd3 Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Wed, 8 Nov 2023 18:11:58 +0100 Subject: [PATCH 085/114] refactor: migrate EffectSpec to kotlin-test (#3234) --- .../kotlin/arrow/core/raise/EffectSpec.kt | 135 +++++++++--------- 1 file changed, 67 insertions(+), 68 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt index 9ddf60fb44d..1db7c93608a 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt @@ -12,7 +12,6 @@ import arrow.core.test.nonEmptySet import arrow.core.toNonEmptyListOrNull import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldStartWith @@ -32,13 +31,15 @@ import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED import kotlin.coroutines.intrinsics.intercepted import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn import kotlin.coroutines.startCoroutine +import kotlin.test.Test import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext @Suppress("UNREACHABLE_CODE") -class EffectSpec : StringSpec({ - "try/catch - can recover from raise" { +class EffectSpec { + @Test fun tryCatchCanRecoverFromRaise() = runTest { checkAll(Arb.int().suspend(), Arb.string().suspend()) { i, s -> effect { try { @@ -50,7 +51,7 @@ class EffectSpec : StringSpec({ } } - "try/catch - finally works" { + @Test fun tryCatchFinallyWorks() = runTest { checkAll(Arb.string().suspend(), Arb.int().suspend()) { s, i -> val promise = CompletableDeferred() effect { @@ -64,7 +65,7 @@ class EffectSpec : StringSpec({ } } - "try/catch - First raise is ignored and second is returned" { + @Test fun tryCatchFirstRaiseIsIgnoredAndSecondIsReturned() = runTest { checkAll(Arb.int().suspend(), Arb.string().suspend(), Arb.string().suspend()) { i, s, s2 -> effect { try { @@ -78,7 +79,7 @@ class EffectSpec : StringSpec({ } } - "recover - raise" { + @Test fun recoverRaise() = runTest { checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> effect { effect { @@ -91,7 +92,7 @@ class EffectSpec : StringSpec({ } } - "recover - raise and transform error" { + @Test fun recoverRaiseAndTransformError() = runTest { checkAll( Arb.long().suspend(), Arb.string().suspend() @@ -107,7 +108,7 @@ class EffectSpec : StringSpec({ } } - "recover - success" { + @Test fun recoverSuccess() = runTest { checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> effect { effect { i() } getOrElse { unreachable() } @@ -115,7 +116,7 @@ class EffectSpec : StringSpec({ } } - "recover + catch - raise and recover" { + @Test fun recoverCatchRaiseAndRecover() = runTest { checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> effect { effect { @@ -128,7 +129,7 @@ class EffectSpec : StringSpec({ } } - "recover + catch - raise and transform error" { + @Test fun recoverCatchRaiseAndTransformError() = runTest { checkAll(Arb.long().suspend(), Arb.string().suspend()) { l, s -> effect { effect { @@ -143,7 +144,7 @@ class EffectSpec : StringSpec({ val boom = RuntimeException("boom") - "recover + catch - throw and recover" { + @Test fun recoverCatchThrowAndRecover() = runTest { checkAll(Arb.int().suspend()) { i -> effect { effect { @@ -156,7 +157,7 @@ class EffectSpec : StringSpec({ } } - "recover + catch - throw and transform error" { + @Test fun recoverCatchThrowAndTransformError() = runTest { checkAll(Arb.string().suspend()) { s -> effect { effect { @@ -169,7 +170,7 @@ class EffectSpec : StringSpec({ } } - "recover + catch - raise and throw" { + @Test fun recoverCatchRaiseAndThrow() = runTest { checkAll(Arb.long().suspend(), Arb.string().suspend()) { l, s -> effect { effect { @@ -183,7 +184,7 @@ class EffectSpec : StringSpec({ } } - "recover + catch - throw and throw" { + @Test fun recoverCatchThrowAndThrow() = runTest { val boom2 = ArithmeticException("boom2") effect { effect { @@ -195,7 +196,7 @@ class EffectSpec : StringSpec({ }.fold(::identity, { unreachable() }) { unreachable() } shouldBe boom2 } - "recover + catch - success" { + @Test fun recoverCatchSuccess() = runTest { checkAll(Arb.int().suspend(), Arb.long().suspend()) { i, l -> effect { effect { i() } @@ -204,7 +205,7 @@ class EffectSpec : StringSpec({ } } - "catch - throw and throw" { + @Test fun catchThrowAndThrow() = runTest { val boom2 = ArithmeticException("boom2") effect { effect { @@ -216,7 +217,7 @@ class EffectSpec : StringSpec({ }.fold(::identity, { unreachable() }) { unreachable() } shouldBe boom2 } - "catch - throw and transform error" { + @Test fun catchThrowAndTransformError() = runTest { checkAll(Arb.string().suspend()) { s -> effect { effect { @@ -229,7 +230,7 @@ class EffectSpec : StringSpec({ } } - "catch - throw and recover" { + @Test fun catchThrowAndRecover() = runTest { checkAll(Arb.int().suspend()) { i -> effect { effect { @@ -242,7 +243,7 @@ class EffectSpec : StringSpec({ } } - "eagerEffect can be consumed within an Effect computation" { + @Test fun eagerEffectCanBeConsumedWithinAnEffectComputation() = runTest { checkAll(Arb.int(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = eagerEffect { a } @@ -255,7 +256,7 @@ class EffectSpec : StringSpec({ } } - "eagerEffect raise short-circuits effect computation" { + @Test fun eagerEffectRaiseShortCircuitsEffectComputation() = runTest { checkAll(Arb.string(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = eagerEffect { raise(a) } @@ -268,7 +269,7 @@ class EffectSpec : StringSpec({ } } - "eagerEffect can be consumed within an Effect computation with bind" { + @Test fun eagerEffectCanBeConsumedWithinAnEffectComputationWithBind() = runTest { checkAll(Arb.int(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = eagerEffect { a } @@ -281,7 +282,7 @@ class EffectSpec : StringSpec({ } } - "eagerEffect raise short-circuits effect computation with bind" { + @Test fun eagerEffectRaiseShortCircuitsEffectComputationWithBind() = runTest { checkAll(Arb.string(), Arb.int().suspend()) { a, b -> val eager: EagerEffect = eagerEffect { raise(a) } @@ -294,14 +295,14 @@ class EffectSpec : StringSpec({ } } - "success" { + @Test fun success() = runTest { checkAll(Arb.int().suspend()) { i -> effect { i() } .getOrElse { unreachable() } shouldBe i() } } - "short-circuit" { + @Test fun shortCircuit() = runTest { checkAll(Arb.string().suspend()) { msg -> effect { raise(msg()) @@ -309,7 +310,7 @@ class EffectSpec : StringSpec({ } } - "Rethrows exceptions" { + @Test fun rethrowsExceptions() = runTest { checkAll(Arb.string().suspend()) { msg -> shouldThrow { effect { @@ -319,7 +320,7 @@ class EffectSpec : StringSpec({ } } - "Can short-circuit from nested blocks" { + @Test fun canShortCircuitFromNestedBlocks() = runTest { checkAll(Arb.string().suspend()) { msg -> effect { effect { raise(msg()) }.getOrElse { unreachable() } @@ -329,7 +330,7 @@ class EffectSpec : StringSpec({ } } - "Can short-circuit immediately after suspending from nested blocks" { + @Test fun canShortCircuitImmediatelyAfterSuspendingFromNestedBlocks() = runTest { checkAll(Arb.string().suspend()) { msg -> effect { effect { @@ -341,7 +342,7 @@ class EffectSpec : StringSpec({ } } - "ensure null in either computation" { + @Test fun ensureNullInEitherComputation() = runTest { checkAll( Arb.boolean().suspend(), Arb.int().suspend(), @@ -354,7 +355,7 @@ class EffectSpec : StringSpec({ } } - "ensureNotNull in either computation" { + @Test fun ensureNotNullInEitherComputation() = runTest { fun square(i: Int): Int = i * i checkAll(Arb.int().orNull().suspend(), Arb.string().suspend()) { i, raise -> @@ -369,7 +370,7 @@ class EffectSpec : StringSpec({ } } - "#2760 - dispatching in nested Effect blocks does not make the nested Continuation to hang" { + @Test fun issue2760DispatchingInNestedEffectBlocksDoesNotMakeTheNestedContinuationToHang() = runTest { checkAll(Arb.string()) { msg -> fun failure(): Effect = effect { withContext(Dispatchers.Default) {} @@ -386,7 +387,7 @@ class EffectSpec : StringSpec({ } } - "#2779 - handleErrorWith does not make nested Continuations hang" { + @Test fun issue2779HandleErrorWithDoesNotMakeNestedContinuationsHang() = runTest { checkAll(Arb.string()) { error -> val failed: Effect = effect { withContext(Dispatchers.Default) {} @@ -402,7 +403,7 @@ class EffectSpec : StringSpec({ } } - "#2779 - bind nested in fold does not make nested Continuations hang" { + @Test fun issue2779BindNestedInFoldDoesNotMakeNestedContinuationsHang() = runTest { checkAll(Arb.string()) { error -> val failed: Effect = effect { withContext(Dispatchers.Default) {} @@ -422,7 +423,7 @@ class EffectSpec : StringSpec({ } } - "Can handle thrown exceptions" { + @Test fun canHandleThrownExceptions() = runTest { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> effect { throw RuntimeException(msg()) @@ -434,7 +435,7 @@ class EffectSpec : StringSpec({ } } - "Can raise from thrown exceptions" { + @Test fun canRaiseFromThrownExceptions() = runTest { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> effect { effect { @@ -448,7 +449,7 @@ class EffectSpec : StringSpec({ } } - "Can throw from thrown exceptions" { + @Test fun canThrowFromThrownExceptions() = runTest { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> shouldThrow { effect { @@ -462,7 +463,7 @@ class EffectSpec : StringSpec({ } } - "recover - happy path" { + @Test fun recoverHappyPath() = runTest { checkAll(Arb.string().suspend()) { str -> effect { str() @@ -471,7 +472,7 @@ class EffectSpec : StringSpec({ } } - "recover - error path and recover" { + @Test fun recoverErrorPathAndRecover() = runTest { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> effect { raise(int()) @@ -481,7 +482,7 @@ class EffectSpec : StringSpec({ } } - "recover - error path and re-raise" { + @Test fun recoverErrorPathAndReRaise() = runTest { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, fallback -> effect { raise(int()) @@ -491,7 +492,7 @@ class EffectSpec : StringSpec({ } } - "recover - error path and throw" { + @Test fun recoverErrorPathAndThrow() = runTest { checkAll(Arb.int().suspend(), Arb.string().suspend()) { int, msg -> shouldThrow { effect { @@ -503,7 +504,7 @@ class EffectSpec : StringSpec({ } } - "catch - happy path" { + @Test fun catchHappyPath() = runTest { checkAll(Arb.string().suspend()) { str -> effect { str() @@ -512,7 +513,7 @@ class EffectSpec : StringSpec({ } } - "catch - error path and recover" { + @Test fun catchErrorPathAndRecover() = runTest { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> effect { throw RuntimeException(msg()) @@ -521,7 +522,7 @@ class EffectSpec : StringSpec({ } } - "catch - error path and re-raise" { + @Test fun catchErrorPathAndReRaise() = runTest { checkAll(Arb.string().suspend(), Arb.int().suspend()) { msg, fallback -> effect { throw RuntimeException(msg()) @@ -530,7 +531,7 @@ class EffectSpec : StringSpec({ } } - "catch - error path and throw" { + @Test fun catchErrorPathAndThrow() = runTest { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, msg2 -> effect { throw RuntimeException(msg()) @@ -541,7 +542,7 @@ class EffectSpec : StringSpec({ } } - "catch - reified error path and recover " { + @Test fun catchReifiedErrorPathAndRecover() = runTest { checkAll(Arb.string().suspend(), Arb.string().suspend()) { msg, fallback -> effect { throw ArithmeticException(msg()) @@ -552,7 +553,7 @@ class EffectSpec : StringSpec({ } } - "catch - reified error path and raise " { + @Test fun catchReifiedErrorPathAndRaise() = runTest { checkAll(Arb.string().suspend(), Arb.int().suspend()) { msg, error -> effect { throw ArithmeticException(msg()) @@ -563,7 +564,7 @@ class EffectSpec : StringSpec({ } } - "catch - reified error path and no match " { + @Test fun catchReifiedErrorPathAndNoMatch() = runTest { checkAll(Arb.string().suspend(), Arb.int().suspend()) { msg, error -> effect { throw RuntimeException(msg()) @@ -578,7 +579,7 @@ class EffectSpec : StringSpec({ } } - "catch - success" { + @Test fun catchSuccess() = runTest { checkAll(Arb.string().suspend()) { msg -> effect { msg() @@ -587,7 +588,7 @@ class EffectSpec : StringSpec({ } } - "catch - exception" { + @Test fun catchException() = runTest { checkAll(Arb.string().suspend()) { msg -> effect { throw RuntimeException(msg()) @@ -599,7 +600,7 @@ class EffectSpec : StringSpec({ } } - "accumulate, returns every error" { + @Test fun accumulateReturnsEveryError() = runTest { checkAll(Arb.list(Arb.int(), range = 2..100)) { errors -> either, List> { mapOrAccumulate(errors) { raise(it) } @@ -607,7 +608,7 @@ class EffectSpec : StringSpec({ } } - "accumulate, returns no error" { + @Test fun accumulateReturnsNoError() = runTest { checkAll(Arb.list(Arb.int())) { elements -> either, List> { mapOrAccumulate(elements) { it } @@ -615,7 +616,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptyList - mapOrAccumulate, returns every error" { + @Test fun nonEmptyListMapOrAccumulateReturnsEveryError() = runTest { checkAll(Arb.nonEmptyList(Arb.int(), range = 2..100)) { errors -> either, NonEmptyList> { mapOrAccumulate(errors) { raise(it) } @@ -623,7 +624,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptyList - mapOrAccumulate, returns no error" { + @Test fun nonEmptyListMapOrAccumulateReturnsNoError() = runTest { checkAll(Arb.nonEmptyList(Arb.int())) { elements -> either, NonEmptyList> { mapOrAccumulate(elements) { it } @@ -631,7 +632,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptySet - mapOrAccumulate, returns every error" { + @Test fun nonEmptySetMapOrAccumulateReturnsEveryError() = runTest { checkAll(Arb.nonEmptySet(Arb.int(), range = 2..100)) { errors -> either, NonEmptySet> { mapOrAccumulate(errors) { raise(it) } @@ -639,7 +640,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptySet - mapOrAccumulate, returns no error" { + @Test fun nonEmptySetMapOrAccumulateReturnsNoError() = runTest { checkAll(Arb.nonEmptySet(Arb.int())) { elements -> either, NonEmptySet> { mapOrAccumulate(elements) { it } @@ -647,7 +648,7 @@ class EffectSpec : StringSpec({ } } - "bindAll fails on first error" { + @Test fun bindAllFailsOnFirstError() = runTest { checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()))) { eithers -> val expected = eithers.firstOrNull { it.isLeft() } ?: eithers.mapNotNull { it.getOrNull() }.right() either { @@ -656,9 +657,7 @@ class EffectSpec : StringSpec({ } } - fun Either.leftOrNull(): E? = fold(::identity) { null } - - "accumulate - bindAll" { + @Test fun accumulateBindAll() = runTest { checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()))) { eithers -> val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.right() @@ -672,7 +671,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptyList - bindAll fails on first error" { + @Test fun nonEmptyListBindAllFailsOnFirstError() = runTest { checkAll(Arb.nonEmptyList(Arb.either(Arb.int(), Arb.int()))) { eithers -> val expected = eithers.firstOrNull { it.isLeft() } ?: eithers.mapNotNull { it.getOrNull() }.right() either { @@ -681,7 +680,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptyList - bindAll accumulate errors" { + @Test fun nonEmptyListBindAllAccumulateErrors() = runTest { checkAll(Arb.nonEmptyList(Arb.either(Arb.int(), Arb.int()))) { eithers -> val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.right() @@ -695,7 +694,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptySet - bindAll fails on first error" { + @Test fun nonEmptySetBindAllFailsOnFirstError() = runTest { checkAll(Arb.nonEmptySet(Arb.either(Arb.int(), Arb.int()))) { eithers -> val expected = eithers.firstOrNull { it.isLeft() } ?: eithers.mapNotNull { it.getOrNull() }.toSet().right() either { @@ -704,7 +703,7 @@ class EffectSpec : StringSpec({ } } - "NonEmptySet - bindAll accumulate errors" { + @Test fun nonEmptySetBindAllAccumulateErrors() = runTest { checkAll(Arb.nonEmptySet(Arb.either(Arb.int(), Arb.int()))) { eithers -> val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.toSet().right() @@ -718,7 +717,7 @@ class EffectSpec : StringSpec({ } } - "shift leaked results in RaiseLeakException" { + @Test fun shiftLeakedResultsInRaiseLeakException() = runTest { effect { suspend { raise("failure") } }.fold( @@ -728,7 +727,7 @@ class EffectSpec : StringSpec({ { unreachable() }) { f -> f() } } - "shift leaked results in RaiseLeakException with exception" { + @Test fun shiftLeakedResultsInRaiseLeakExceptionWithException() = runTest { shouldThrow { val leak = CompletableDeferred Unit>() effect { @@ -744,7 +743,7 @@ class EffectSpec : StringSpec({ }.message shouldStartWith "raise or bind was called outside of its DSL scope" } - "shift leaked results in RaiseLeakException after raise" { + @Test fun shiftLeakedResultsInRaiseLeakExceptionAfterRaise() = runTest { shouldThrow { val leak = CompletableDeferred Unit>() effect { @@ -759,7 +758,7 @@ class EffectSpec : StringSpec({ }.message shouldStartWith "raise or bind was called outside of its DSL scope" } - "mapError - raise and transform error" { + @Test fun mapErrorRaiseAndTransformError() = runTest { checkAll( Arb.long().suspend(), Arb.string().suspend() @@ -773,13 +772,13 @@ class EffectSpec : StringSpec({ } } - "mapError - success" { + @Test fun mapErrorSuccess() = runTest { checkAll(Arb.int().suspend()) { i -> (effect { i() } mapError { unreachable() }) .get() shouldBe i() } } -}) +} private data class Failure(val msg: String) From e35d935d53747f5c668f01e99fefdb480bd19146 Mon Sep 17 00:00:00 2001 From: Jonathan Lagneaux Date: Wed, 8 Nov 2023 18:12:20 +0100 Subject: [PATCH 086/114] Refactor FlowTest to use kotlin test (#3238) Closes #3189 Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/fx/coroutines/FlowTest.kt | 503 +++++++++--------- 1 file changed, 254 insertions(+), 249 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt index 5854b0c8da3..0bead6212fb 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt @@ -1,7 +1,6 @@ package arrow.fx.coroutines import io.kotest.assertions.fail -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf import io.kotest.property.Arb @@ -9,7 +8,6 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.positiveInt import io.kotest.property.checkAll -import kotlin.time.ExperimentalTime import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview @@ -28,300 +26,307 @@ import kotlinx.coroutines.test.advanceTimeBy import kotlinx.coroutines.test.currentTime import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withTimeoutOrNull +import kotlin.test.Test +import kotlin.time.ExperimentalTime @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) @ExperimentalTime -class FlowTest : StringSpec({ +class FlowTest { - "parMap - concurrency = 1 - identity" { - checkAll(Arb.flow(Arb.int())) { flow -> - flow.parMap(1) { it } - .toList() shouldBe flow.toList() - } + @Test + fun parMapConcurrentEqualOneMinusIdentity() = runTest { + checkAll(Arb.flow(Arb.int())) { flow -> + flow.parMap(1) { it } + .toList() shouldBe flow.toList() } + } - "parMap - runs in parallel" { - checkAll(Arb.int(), Arb.int(1..2)) { i, n -> - val latch = CompletableDeferred() - flowOf(1, 2).parMap { index -> - if (index == n) latch.await() - else { - latch.complete(i) - null - } - }.toList().filterNotNull() shouldBe listOf(i) - } + @Test + fun parMapRunsInParallel() = runTest { + checkAll(Arb.int(), Arb.int(1..2)) { i, n -> + val latch = CompletableDeferred() + flowOf(1, 2).parMap { index -> + if (index == n) latch.await() + else { + latch.complete(i) + null + } + }.toList().filterNotNull() shouldBe listOf(i) + } + } + + @Test + fun parMapTriggersCancelSignal() = runTest { + val latch = CompletableDeferred() + val exit = CompletableDeferred() + + val job = launch { + flowOf(1).parMap { _ -> + guaranteeCase({ + latch.complete(Unit) + awaitCancellation() + }, { ex -> exit.complete(ex) }) + }.collect() } + latch.await() + job.cancelAndJoin() + job.isCancelled shouldBe true + exit.await().shouldBeTypeOf() + } - "parMap - triggers cancel signal" { - val latch = CompletableDeferred() - val exit = CompletableDeferred() + @Test + fun parMapExceptionInParMapCancelsAllRunningTasks() = runTest { + checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> + val latch = CompletableDeferred() + val exit = CompletableDeferred>() - val job = launch { - flowOf(1).parMap { _ -> + assertThrowable { + flowOf(1, 2).parMap { index -> + if (index == n) { guaranteeCase({ latch.complete(Unit) awaitCancellation() - }, { ex -> exit.complete(ex) }) - }.collect() - } - latch.await() - job.cancelAndJoin() - job.isCancelled shouldBe true - exit.await().shouldBeTypeOf() - } + }, { ex -> exit.complete(Pair(i, ex)) }) + } else { + latch.await() + throw e + } + }.collect() + fail("Cannot reach here. $e should be thrown.") + } shouldBe e - "parMap - exception in parMap cancels all running tasks" { - checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> - val latch = CompletableDeferred() - val exit = CompletableDeferred>() - - assertThrowable { - flowOf(1, 2).parMap { index -> - if (index == n) { - guaranteeCase({ - latch.complete(Unit) - awaitCancellation() - }, { ex -> exit.complete(Pair(i, ex)) }) - } else { - latch.await() - throw e - } - }.collect() - fail("Cannot reach here. $e should be thrown.") - } shouldBe e - - val (ii, ex) = exit.await() - ii shouldBe i - ex.shouldBeTypeOf() - } + val (ii, ex) = exit.await() + ii shouldBe i + ex.shouldBeTypeOf() } + } - "parMap - Cancelling parMap cancels all running jobs" { - checkAll(Arb.int(), Arb.int()) { i, i2 -> - val latch = CompletableDeferred() - val exitA = CompletableDeferred>() - val exitB = CompletableDeferred>() + @Test + fun parMapCancellingParMapCancelsAllRunningJobs() = runTest { + checkAll(Arb.int(), Arb.int()) { i, i2 -> + val latch = CompletableDeferred() + val exitA = CompletableDeferred>() + val exitB = CompletableDeferred>() - val job = launch { - flowOf(1, 2).parMap { index -> - guaranteeCase({ - if (index == 2) latch.complete(Unit) - awaitCancellation() - }, { ex -> - if (index == 1) exitA.complete(Pair(i, ex)) - else exitB.complete(Pair(i2, ex)) - }) - }.collect() - } + val job = launch { + flowOf(1, 2).parMap { index -> + guaranteeCase({ + if (index == 2) latch.complete(Unit) + awaitCancellation() + }, { ex -> + if (index == 1) exitA.complete(Pair(i, ex)) + else exitB.complete(Pair(i2, ex)) + }) + }.collect() + } - latch.await() - job.cancel() + latch.await() + job.cancel() - val (ii, ex) = exitA.await() - ii shouldBe i - ex.shouldBeTypeOf() + val (ii, ex) = exitA.await() + ii shouldBe i + ex.shouldBeTypeOf() - val (ii2, ex2) = exitB.await() - ii2 shouldBe i2 - ex2.shouldBeTypeOf() - } + val (ii2, ex2) = exitB.await() + ii2 shouldBe i2 + ex2.shouldBeTypeOf() } + } - "parMapUnordered - concurrency = 1 - identity" { - checkAll(Arb.flow(Arb.int())) { flow -> - flow.parMapUnordered(concurrency = 1) { it } - .toSet() shouldBe flow.toSet() - } + @Test + fun parMapUnorderedConcurrentEqualOneMinusIdentity() = runTest { + checkAll(Arb.flow(Arb.int())) { flow -> + flow.parMapUnordered(concurrency = 1) { it } + .toSet() shouldBe flow.toSet() } + } - "parMapUnordered - runs in parallel" { - checkAll(Arb.int(), Arb.int(1..2)) { i, n -> - val latch = CompletableDeferred() - flowOf(1, 2).parMapUnordered { index -> - if (index == n) latch.await() - else { - latch.complete(i) - null - } - }.toSet().filterNotNull() shouldBe setOf(i) - } + @Test + fun parMapUnorderedRunsInParallel() = runTest { + checkAll(Arb.int(), Arb.int(1..2)) { i, n -> + val latch = CompletableDeferred() + flowOf(1, 2).parMapUnordered { index -> + if (index == n) latch.await() + else { + latch.complete(i) + null + } + }.toSet().filterNotNull() shouldBe setOf(i) } + } - "parMapUnordered - triggers cancel signal" { - val latch = CompletableDeferred() - val exit = CompletableDeferred() + @Test + fun parMapUnorderedTriggersCancelSignal() = runTest { + val latch = CompletableDeferred() + val exit = CompletableDeferred() - val job = launch { - flowOf(1).parMapUnordered { - guaranteeCase({ - latch.complete(Unit) - awaitCancellation() - }, { ex -> exit.complete(ex) }) - }.collect() - } - latch.await() - job.cancelAndJoin() - - job.isCancelled shouldBe true - exit.await().shouldBeTypeOf() + val job = launch { + flowOf(1).parMapUnordered { _ -> + guaranteeCase({ + latch.complete(Unit) + awaitCancellation() + }, { ex -> exit.complete(ex) }) + }.collect() } + latch.await() + job.cancelAndJoin() - "parMapUnordered - exception in parMap cancels all running tasks" { - checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> - val latch = CompletableDeferred() - val exit = CompletableDeferred>() - - assertThrowable { - flowOf(1, 2).parMapUnordered { index -> - if (index == n) { - guaranteeCase({ - latch.complete(Unit) - awaitCancellation() - }, { ex -> exit.complete(Pair(i, ex)) }) - } else { - latch.await() - throw e - } - }.collect() - fail("Cannot reach here. $e should be thrown.") - } shouldBe e - - val (ii, ex) = exit.await() - ii shouldBe i - ex.shouldBeTypeOf() - } - } + job.isCancelled shouldBe true + exit.await().shouldBeTypeOf() + } - "parMapUnordered - Cancelling parMap cancels all running jobs" { - checkAll(Arb.int(), Arb.int()) { i, i2 -> - val latch = CompletableDeferred() - val exitA = CompletableDeferred>() - val exitB = CompletableDeferred>() + @Test + fun parMapUnorderedExceptionInParMapCancelsAllRunningTasks() = runTest { + checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> + val latch = CompletableDeferred() + val exit = CompletableDeferred>() - val job = launch { - flowOf(1, 2).parMapUnordered { index -> + assertThrowable { + flowOf(1, 2).parMapUnordered { index -> + if (index == n) { guaranteeCase({ - if (index == 2) latch.complete(Unit) + latch.complete(Unit) awaitCancellation() - }, { ex -> - if (index == 1) exitA.complete(Pair(i, ex)) - else exitB.complete(Pair(i2, ex)) - }) - }.collect() - } + }, { ex -> exit.complete(Pair(i, ex)) }) + } else { + latch.await() + throw e + } + }.collect() + fail("Cannot reach here. $e should be thrown.") + } shouldBe e - latch.await() - job.cancel() + val (ii, ex) = exit.await() + ii shouldBe i + ex.shouldBeTypeOf() + } + } - val (ii, ex) = exitA.await() - ii shouldBe i - ex.shouldBeTypeOf() + @Test + fun parMapUnorderedCancellingParMapCancelsAllRunningJobs() = runTest { + checkAll(Arb.int(), Arb.int()) { i, i2 -> + val latch = CompletableDeferred() + val exitA = CompletableDeferred>() + val exitB = CompletableDeferred>() - val (ii2, ex2) = exitB.await() - ii2 shouldBe i2 - ex2.shouldBeTypeOf() + val job = launch { + flowOf(1, 2).parMapUnordered { index -> + guaranteeCase({ + if (index == 2) latch.complete(Unit) + awaitCancellation() + }, { ex -> + if (index == 1) exitA.complete(Pair(i, ex)) + else exitB.complete(Pair(i2, ex)) + }) + }.collect() } + + latch.await() + job.cancel() + + val (ii, ex) = exitA.await() + ii shouldBe i + ex.shouldBeTypeOf() + + val (ii2, ex2) = exitB.await() + ii2 shouldBe i2 + ex2.shouldBeTypeOf() } + } - "fixedDelay" { - runTest { - checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> - val emissionDuration = waitPeriod / 10L - var state: Long? = null - - val rate = flow { emit(delay(waitPeriod)) }.repeat() - .map { - val now = state ?: currentTime - val nextNow = currentTime - val lapsed = nextNow - now - state = nextNow - delay(emissionDuration) - lapsed - } - .take(n) - .toList() - - rate.first() shouldBe 0 // First element is immediately - rate.drop(1).forEach { act -> - act shouldBe (waitPeriod + emissionDuration) // Remaining elements all take delay + emission duration - } + @Test + fun fixedDelay() = runTest { + checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> + val emissionDuration = waitPeriod / 10L + var state: Long? = null + + val rate = flow { emit(delay(waitPeriod)) }.repeat() + .map { + val now = state ?: currentTime + val nextNow = currentTime + val lapsed = nextNow - now + state = nextNow + delay(emissionDuration) + lapsed } + .take(n) + .toList() + + rate.first() shouldBe 0 // First element is immediately + rate.drop(1).forEach { act -> + act shouldBe (waitPeriod + emissionDuration) // Remaining elements all take delay + emission duration } } - - "fixedRate" { - runTest { - checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> - val emissionDuration = waitPeriod / 10 - var state: Long? = null - - val rate = fixedRate(waitPeriod) { currentTime } - .map { - val now = state ?: currentTime - val nextNow = currentTime - val lapsed = nextNow - now - state = nextNow - delay(emissionDuration) - lapsed - } - .take(n) - .toList() - - rate.first() shouldBe 0 // First element is immediately - rate.drop(1).forEach { act -> - // Remaining elements all take total of waitPeriod, emissionDuration is correctly taken into account. - act shouldBe waitPeriod - } + } + + @Test + fun fixedRate() = runTest { + checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> + val emissionDuration = waitPeriod / 10 + var state: Long? = null + + val rate = fixedRate(waitPeriod) { currentTime } + .map { + val now = state ?: currentTime + val nextNow = currentTime + val lapsed = nextNow - now + state = nextNow + delay(emissionDuration) + lapsed } + .take(n) + .toList() + + rate.first() shouldBe 0 // First element is immediately + rate.drop(1).forEach { act -> + // Remaining elements all take total of waitPeriod, emissionDuration is correctly taken into account. + act shouldBe waitPeriod } } - - "fixedRate(dampen = true)" { - runTest { - val buffer = mutableListOf() - withTimeoutOrNull(4500) { - fixedRate(1000, true) { currentTime } - .mapIndexed { index, _ -> - if (index == 0) delay(3000) else Unit - advanceTimeBy(1) - }.collect(buffer::add) - } - buffer.size shouldBe 2 + + + @Test + fun fixedRateWithDampenTrue() = runTest { + val buffer = mutableListOf() + withTimeoutOrNull(4500) { + fixedRate(1000, true) { currentTime } + .mapIndexed { index, _ -> + if (index == 0) delay(3000) else Unit + advanceTimeBy(1) + }.collect(buffer::add) } + buffer.size shouldBe 2 } - - "fixedRate(dampen = false)" { - runTest { - val buffer = mutableListOf() - withTimeoutOrNull(4500) { - fixedRate(1000, false) { currentTime } - .mapIndexed { index, _ -> - if (index == 0) delay(3000) else Unit - advanceTimeBy(1) - }.collect(buffer::add) - } - buffer.size shouldBe 4 + + @Test + fun fixedRateWithDampenFalse() = runTest { + val buffer = mutableListOf() + withTimeoutOrNull(4500) { + fixedRate(1000, false) { currentTime } + .mapIndexed { index, _ -> + if (index == 0) delay(3000) else Unit + advanceTimeBy(1) + }.collect(buffer::add) } + buffer.size shouldBe 4 } - - "mapIndexed" { - runTest { - val flow = flowOf(1, 2, 3) - .mapIndexed { index, value -> IndexedValue(index, value) } - - flow.toList() shouldBe listOf( - IndexedValue(0, 1), - IndexedValue(1, 2), - IndexedValue(2, 3) - ) - - flow.toList() shouldBe listOf( - IndexedValue(0, 1), - IndexedValue(1, 2), - IndexedValue(2, 3) - ) - } + + @Test + fun mapIndexed() = runTest { + val flow = flowOf(1, 2, 3) + .mapIndexed { index, value -> IndexedValue(index, value) } + + flow.toList() shouldBe listOf( + IndexedValue(0, 1), + IndexedValue(1, 2), + IndexedValue(2, 3) + ) + + flow.toList() shouldBe listOf( + IndexedValue(0, 1), + IndexedValue(1, 2), + IndexedValue(2, 3) + ) } } -) +} From aa3402b5a2aad7004f0069bd0d99f0d5a473ab3e Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Wed, 8 Nov 2023 18:12:44 +0100 Subject: [PATCH 087/114] refactor: migrate IorSpec to kotlin-test (#3249) Co-authored-by: Simon Vergauwen --- .../kotlin/arrow/core/raise/IorSpec.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt index 007135ee848..d9e2554a0a4 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt @@ -4,21 +4,22 @@ import arrow.core.Either import arrow.core.Ior import arrow.core.test.nonEmptyList import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll +import kotlin.test.Test import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.test.runTest @Suppress( "UNREACHABLE_CODE", "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION", "UNUSED_VARIABLE" ) -class IorSpec : StringSpec({ - "Accumulates" { +class IorSpec { + @Test fun accumulates() = runTest { ior(String::plus) { val one = Ior.Both("Hello", 1).bind() val two = Ior.Both(", World!", 2).bind() @@ -26,7 +27,7 @@ class IorSpec : StringSpec({ } shouldBe Ior.Both("Hello, World!", 3) } - "Accumulates and short-circuits with Left" { + @Test fun accumulatesAndShortCircuitsWithLeft() = runTest { ior(String::plus) { val one = Ior.Both("Hello", 1).bind() val two: Int = Ior.Left(", World!").bind() @@ -34,7 +35,7 @@ class IorSpec : StringSpec({ } shouldBe Ior.Left("Hello, World!") } - "Accumulates with Either" { + @Test fun accumulatesWithEither() = runTest { ior(String::plus) { val one = Ior.Both("Hello", 1).bind() val two: Int = Either.Left(", World!").bind() @@ -42,7 +43,7 @@ class IorSpec : StringSpec({ } shouldBe Ior.Left("Hello, World!") } - "Concurrent - arrow.ior bind" { + @Test fun concurrentArrowIorBind() = runTest { checkAll(Arb.nonEmptyList(Arb.int())) { xs -> ior(List::plus) { xs.mapIndexed { index, s -> async { Ior.Both(listOf(s), index).bind() } }.awaitAll() @@ -51,7 +52,7 @@ class IorSpec : StringSpec({ } } - "Accumulates eagerly" { + @Test fun accumulatesEagerly() = runTest { ior(String::plus) { val one = Ior.Both("Hello", 1).bind() val two = Ior.Both(", World!", 2).bind() @@ -59,7 +60,7 @@ class IorSpec : StringSpec({ } shouldBe Ior.Both("Hello, World!", 3) } - "Accumulates with Either eagerly" { + @Test fun accumulatesWithEitherEagerly() = runTest { ior(String::plus) { val one = Ior.Both("Hello", 1).bind() val two: Int = Either.Left(", World!").bind() @@ -67,7 +68,7 @@ class IorSpec : StringSpec({ } shouldBe Ior.Left("Hello, World!") } - "Ior rethrows exception" { + @Test fun iorRethrowsException() = runTest { val boom = RuntimeException("Boom!") shouldThrow { ior(String::plus) { @@ -76,7 +77,7 @@ class IorSpec : StringSpec({ }.message shouldBe "Boom!" } - "Recover works as expected" { + @Test fun recoverWorksAsExpected() = runTest { ior(String::plus) { val one = recover({ Ior.Left("Hello").bind() }) { 1 } val two = Ior.Right(2).bind() @@ -84,4 +85,4 @@ class IorSpec : StringSpec({ one + two + three } shouldBe Ior.Both(", World", 6) } -}) +} From 0cceefdf0c8c3868680ae2c71864bd90c4fab22c Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Wed, 8 Nov 2023 18:13:03 +0100 Subject: [PATCH 088/114] refactor: migrate ResultSpec to kotlin-test (#3251) Co-authored-by: Simon Vergauwen --- .../kotlin/arrow/core/raise/ResultSpec.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/ResultSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/ResultSpec.kt index db631c2700b..126f6c4b77b 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/ResultSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/ResultSpec.kt @@ -1,31 +1,31 @@ package arrow.core.raise -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -@Suppress("UNREACHABLE_CODE") -class ResultSpec : StringSpec({ +class ResultSpec { val boom = RuntimeException("Boom!") - "Result - exception" { + @Test fun resultException() = runTest { result { throw boom } shouldBe Result.failure(boom) } - "Result - success" { + @Test fun resultSuccess() = runTest { result { 1 } shouldBe Result.success(1) } - "Result - raise" { + @Test fun resultRaise() = runTest { result { raise(boom) } shouldBe Result.failure(boom) } - "Recover works as expected" { + @Test fun recoverWorksAsExpected() = runTest { result { val one: Int = recover({ Result.failure(boom).bind() }) { 1 } val two = Result.success(2).bind() one + two } shouldBe Result.success(3) } -}) +} From 9cdb86acf66dd84269346dad9169a59354fda5ca Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Wed, 8 Nov 2023 18:13:24 +0100 Subject: [PATCH 089/114] refactor: migrate StructuredConcurrencySpec to kotlin-test (#3252) --- .../core/raise/StructuredConcurrencySpec.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/StructuredConcurrencySpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/StructuredConcurrencySpec.kt index 5ce8a987981..8a616c73c12 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/StructuredConcurrencySpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/StructuredConcurrencySpec.kt @@ -5,7 +5,6 @@ import arrow.fx.coroutines.ExitCase import arrow.fx.coroutines.guaranteeCase import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldBeIn import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe @@ -15,6 +14,7 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlin.test.Test import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope @@ -27,11 +27,12 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withTimeout @Suppress("DeferredResultUnused") -class StructuredConcurrencySpec : StringSpec({ - "async - suspendCancellableCoroutine.invokeOnCancellation is called with Raised Continuation" { +class StructuredConcurrencySpec { + @Test fun asyncSuspendCancellableCoroutineInvokeOnCancellationIsCalledWithRaisedContinuation() = runTest { val started = CompletableDeferred() val cancelled = CompletableDeferred() @@ -58,13 +59,13 @@ class StructuredConcurrencySpec : StringSpec({ } } - "Computation blocks run on parent context" { + @Test fun computationBlocksRunOnParentContext() = runTest { val parentCtx = currentCoroutineContext() effect { currentCoroutineContext() shouldBe parentCtx } .fold({ fail("Should never be here") }, ::identity) } - "Concurrent raise - async await" { + @Test fun concurrentRaiseAsyncAwait() = runTest { checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { @@ -77,7 +78,7 @@ class StructuredConcurrencySpec : StringSpec({ } } - "Concurrent raise - async await exit results" { + @Test fun concurrentRaiseAsyncAwaitExitResults() = runTest { checkAll(Arb.int()) { a -> val scopeExit = CompletableDeferred() val fbExit = CompletableDeferred() @@ -121,7 +122,7 @@ class StructuredConcurrencySpec : StringSpec({ } } - "Concurrent raise - async" { + @Test fun concurrentRaiseAsync() = runTest { checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { @@ -135,7 +136,7 @@ class StructuredConcurrencySpec : StringSpec({ } } - "Concurrent raise - async exit results" { + @Test fun concurrentRaiseAsyncExitResults() = runTest { checkAll(Arb.int(), Arb.string()) { a, str -> val exitScope = CompletableDeferred() val startLatches = (0..10).map { CompletableDeferred() } @@ -171,7 +172,7 @@ class StructuredConcurrencySpec : StringSpec({ } } - "Concurrent raise - launch" { + @Test fun concurrentRaiseLaunch() = runTest { checkAll(Arb.int(), Arb.int()) { a, b -> effect { coroutineScope { @@ -184,7 +185,7 @@ class StructuredConcurrencySpec : StringSpec({ } } - "Concurrent raise - launch exit results" { + @Test fun concurrentRaiseLaunchExitResults() = runTest { checkAll(Arb.int(), Arb.string()) { a, str -> val scopeExit = CompletableDeferred() val startLatches = (0..10).map { CompletableDeferred() } @@ -222,7 +223,7 @@ class StructuredConcurrencySpec : StringSpec({ // `raise` escapes `cont` block, and gets rethrown inside `coroutineScope`. // Effectively awaiting/executing DSL code, outside of the DSL... - "async funky scenario #1 - Extract `raise` from `effect` through `async`" { + @Test fun asyncFunkyScenario1ExtractRaiseFromEffectThroughAsync() = runTest { checkAll(Arb.int(), Arb.int()) { a, b -> shouldThrow { coroutineScope { @@ -237,4 +238,4 @@ class StructuredConcurrencySpec : StringSpec({ }.message shouldStartWith "raise or bind was called outside of its DSL scope" } } -}) +} From 045572ec7ff7aeef91b0488e39f68e716e4b642d Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Wed, 8 Nov 2023 18:13:44 +0100 Subject: [PATCH 090/114] refactor: migrate TraceSpec to kotlin-test (#3253) --- .../commonTest/kotlin/arrow/core/raise/TraceSpec.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/TraceSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/TraceSpec.kt index 7a488a1f2f7..6a07de04bcd 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/TraceSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/TraceSpec.kt @@ -2,17 +2,18 @@ package arrow.core.raise import arrow.core.right import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlin.test.Test import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.test.runTest @OptIn(ExperimentalTraceApi::class) -class TraceSpec : StringSpec({ - "trace is empty when no errors" { +class TraceSpec { + @Test fun traceIsEmptyWhenNoErrors() = runTest { checkAll(Arb.int()) { i -> either { traced({ i }) { _,_ -> unreachable() } @@ -20,7 +21,7 @@ class TraceSpec : StringSpec({ } } - "trace is empty with exception" { + @Test fun traceIsEmptyWithException() = runTest { checkAll(Arb.string()) { msg -> val error = RuntimeException(msg) shouldThrow { @@ -31,7 +32,7 @@ class TraceSpec : StringSpec({ } } - "nested tracing - identity" { + @Test fun nestedTracingIdentity() = runTest { val inner = CompletableDeferred() ior(String::plus) { traced({ @@ -43,4 +44,4 @@ class TraceSpec : StringSpec({ } } } -}) +} From 9e679efe4de3f4bf5ccbcaca06da6d3134e129ca Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Wed, 8 Nov 2023 18:14:04 +0100 Subject: [PATCH 091/114] refactor: migrate GeneratorsTest to kotlin-test (#3254) --- .../kotlin/arrow/core/test/GeneratorsTest.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt index e23a4bb51be..4a6681befbe 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/GeneratorsTest.kt @@ -1,6 +1,5 @@ package arrow.core.test -import io.kotest.core.spec.style.FreeSpec import io.kotest.inspectors.forAll import io.kotest.inspectors.forAtLeastOne import io.kotest.matchers.ints.shouldBeGreaterThan @@ -15,9 +14,11 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.next import io.kotest.property.arbitrary.orNull import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class GeneratorsTest : FreeSpec({ - "functionAToB: should return same result when invoked multiple times" { +class GeneratorsTest { + @Test fun functionAToBShouldReturnSameResultWhenInvokedMultipleTimes() = runTest { checkAll( Arb.int(), Arb.functionAToB(Arb.int()) @@ -26,7 +27,7 @@ class GeneratorsTest : FreeSpec({ } } - "functionAToB: should return some different values" { + @Test fun functionAToBShouldReturnSomeDifferentValues() = runTest { val a = Arb.int().next(fixedRandom) val a2 = Arb.int().next(fixedRandom) @@ -37,7 +38,7 @@ class GeneratorsTest : FreeSpec({ }.shouldNotBeNull() } - "functionABCToD: should return same result when invoked multiple times" { + @Test fun functionABCToDShouldReturnSameResultWhenInvokedMultipleTimes() = runTest { checkAll( Arb.int(), Arb.int(), @@ -48,7 +49,7 @@ class GeneratorsTest : FreeSpec({ } } - "functionABCToD: should return some different values" { + @Test fun functionABCToDShouldReturnSomeDifferentValues() = runTest { val a = Arb.int().next(fixedRandom) val a2 = Arb.int().next(fixedRandom) val b = Arb.int().next(fixedRandom) @@ -61,7 +62,7 @@ class GeneratorsTest : FreeSpec({ }.shouldNotBeNull() } - "Arb.map2: at least one sample should share no keys" { + @Test fun arbMap2AtLeastOneSampleShouldShareNoKeys() = runTest { val result = givenSamples( Arb.map2( Arb.int(), @@ -73,7 +74,7 @@ class GeneratorsTest : FreeSpec({ result.forAtLeastOne { it.shouldBeZero() } } - "Arb.map2: at least one sample should share some keys" { + @Test fun arbMap2AtLeastOneSampleShouldShareSomeKeys() = runTest { val result = givenSamples( Arb.map2( Arb.int(), @@ -85,7 +86,7 @@ class GeneratorsTest : FreeSpec({ result.forAtLeastOne { it.shouldBeGreaterThan(0) } } - "Arb.map2: no null values if the arb does not produce nullables" { + @Test fun arbMap2NoNullValuesIfTheArbDoesNotProduceNullables() = runTest { givenSamples(Arb.map2(Arb.int(), Arb.boolean(), Arb.boolean())) .forAll { sample -> sample.value.first.values.forAll { it.shouldNotBeNull() } @@ -93,27 +94,27 @@ class GeneratorsTest : FreeSpec({ } } - "Arb.map2: can contain null values if the arb produces nullables" { + @Test fun arbMap2CanContainNullValuesIfTheArbProducesNullables() = runTest { givenSamples(Arb.map2(Arb.int(), Arb.boolean().orNull(), Arb.boolean().orNull())) .forAtLeastOne { sample -> sample.value.first.values.forAtLeastOne { it.shouldBeNull() } } .forAtLeastOne { sample -> sample.value.second.values.forAtLeastOne { it.shouldBeNull() } } } - "Arb.map3: at least one sample should share no keys" { + @Test fun arbMap3AtLeastOneSampleShouldShareNoKeys() = runTest { val result = givenSamples(Arb.map3(Arb.int(), Arb.boolean(), Arb.boolean(), Arb.boolean())) .map { it.value.first.keys.intersect(it.value.second.keys).size }.toList() result.forAtLeastOne { it.shouldBeZero() } } - "Arb.map3: at least one sample should share some keys" { + @Test fun ArbMap3AtLeastOneSampleShouldShareSomeKeys() = runTest { val result = givenSamples(Arb.map3(Arb.int(), Arb.boolean(), Arb.boolean(), Arb.boolean())) .map { it.value.first.keys.intersect(it.value.second.keys).size }.toList() result.forAtLeastOne { it.shouldBeGreaterThan(0) } } - "Arb.map3: no null values if the arb does not produce nullables" { + @Test fun arbMap3NoNullValuesIfTheArbDoesNotProduceNullables() = runTest { givenSamples(Arb.map3(Arb.int(), Arb.boolean(), Arb.boolean(), Arb.boolean())) .forAll { sample -> sample.value.first.values.forAll { it.shouldNotBeNull() } @@ -122,13 +123,13 @@ class GeneratorsTest : FreeSpec({ } } - "Arb.map3: can contain null values if the arb produces nullables" { + @Test fun arbMap3CanContainNullValuesIfTheArbProducesNullables() = runTest { givenSamples(Arb.map3(Arb.int(), Arb.boolean().orNull(), Arb.boolean().orNull(), Arb.boolean().orNull())) .forAtLeastOne { sample -> sample.value.first.values.forAtLeastOne { it.shouldBeNull() } } .forAtLeastOne { sample -> sample.value.second.values.forAtLeastOne { it.shouldBeNull() } } .forAtLeastOne { sample -> sample.value.third.values.forAtLeastOne { it.shouldBeNull() } } } -}) +} private fun givenSamples(arb: Arb, count: Int = 250) = arb.generate(fixedRandom).take(count).toList() From ec6ff880136b0bcc077a9cdec3b84fb3d12bd799 Mon Sep 17 00:00:00 2001 From: Chris Black <2538545+chrsblck@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:14:24 -0800 Subject: [PATCH 092/114] Refactor RaceNJvmTest from Kotest Plugin to Kotlin-test runtime (#3261) Closes #3212 Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/fx/coroutines/RaceNJvmTest.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt index 0cf099c7abe..6b2e553114e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt @@ -2,17 +2,18 @@ package arrow.fx.coroutines import arrow.core.Either import arrow.core.identity -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.test.Test -class RaceNJvmTest : StringSpec({ - "race2 returns to original context" { +class RaceNJvmTest { + @Test fun race2ReturnsToOriginalContext() = runTest { val racerName = "race2" checkAll(Arb.int(1..2)) { choose -> resourceScope { @@ -31,8 +32,8 @@ class RaceNJvmTest : StringSpec({ } } } - - "race2 returns to original context on failure" { + + @Test fun race2ReturnsToOriginalContextOnFailure() = runTest { val racerName = "race2" checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> @@ -54,14 +55,14 @@ class RaceNJvmTest : StringSpec({ } } - "first racer out of 2 always wins on a single thread" { + @Test fun firstRacerOutOf2AlwaysWinsOnASingleThread() = runTest { resourceScope { val ctx = singleThreadContext("single") raceN(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) }.swap().getOrNull() shouldStartWith "single" } - "race3 returns to original context" { + @Test fun race3ReturnsToOriginalContext() = runTest { val racerName = "race3" checkAll(Arb.int(1..3)) { choose -> @@ -90,7 +91,7 @@ class RaceNJvmTest : StringSpec({ } } - "race3 returns to original context on failure" { + @Test fun race3ReturnsToOriginalContextOnFailure() = runTest { val racerName = "race3" checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> @@ -120,4 +121,3 @@ class RaceNJvmTest : StringSpec({ } } } -) From 99a8e49c0f610ccd11e93575672cba330e160173 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Wed, 8 Nov 2023 22:14:40 +0500 Subject: [PATCH 093/114] Update ArrowResponseEAdapterTest.kt (#3264) * Update ArrowResponseEAdapterTest.kt * Update ArrowResponseEAdapterTest.kt --------- Co-authored-by: Simon Vergauwen Co-authored-by: Alejandro Serrano --- .../either/ArrowResponseEAdapterTest.kt | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt index cc43ff7d359..4d3d2c4ca16 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt @@ -5,20 +5,24 @@ import arrow.core.right import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock import arrow.retrofit.adapter.retrofit.SuspendApiTestClient -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.SocketPolicy import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class ArrowResponseEAdapterTest : StringSpec({ +class ArrowResponseEAdapterTest { lateinit var server: MockWebServer lateinit var service: SuspendApiTestClient - beforeAny { + @BeforeTest + fun initialize() { server = MockWebServer() server.start() service = Retrofit.Builder() @@ -29,9 +33,13 @@ class ArrowResponseEAdapterTest : StringSpec({ .create(SuspendApiTestClient::class.java) } - afterAny { server.shutdown() } - - "should return ResponseMock for 200 with valid JSON" { + @AfterTest + fun shutdown() { + server.shutdown() + } + + @Test + fun shouldReturnResponseMockFor200WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val responseE = service.getResponseE() @@ -42,7 +50,8 @@ class ArrowResponseEAdapterTest : StringSpec({ } } - "should return Unit when service method returns Unit and null body received" { + @Test + fun shouldReturnUnitWhenServiceMethodReturnsUnitAndNullBodyReceived() = runTest { server.enqueue(MockResponse().setResponseCode(204)) val responseE = service.postSomethingResponseE("Sample string") @@ -52,8 +61,9 @@ class ArrowResponseEAdapterTest : StringSpec({ body shouldBe Unit.right() } } - - "should return Unit when service method returns Unit and JSON body received" { + + @Test + fun shouldReturnUnitWhenServiceMethodReturnsUnitAndJsonBodyReceived() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val responseE = service.postSomethingResponseE("Sample string") @@ -64,7 +74,8 @@ class ArrowResponseEAdapterTest : StringSpec({ } } - "should return ErrorMock for 400 with valid JSON" { + @Test + fun shouldReturnErrorMockFor400WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"errorCode":42}""").setResponseCode(400)) val responseE = service.getResponseE() @@ -74,28 +85,31 @@ class ArrowResponseEAdapterTest : StringSpec({ body shouldBe ErrorMock(42).left() } } - - "should throw for 200 with invalid JSON" { + + @Test + fun shouldThrowFor200WithInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""")) val responseE = runCatching { service.getResponseE() } responseE.isFailure shouldBe true } - - "should throw for 400 and invalid JSON" { + + @Test + fun shouldThrowFor400AndInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""").setResponseCode(400)) val responseE = runCatching { service.getResponseE() } responseE.isFailure shouldBe true } - - "should throw when server disconnects" { + + @Test + fun shouldThrowWhenServerDisconnects() = runTest { server.enqueue(MockResponse().apply { socketPolicy = SocketPolicy.DISCONNECT_AFTER_REQUEST }) val responseE = runCatching { service.getResponseE() } responseE.isFailure shouldBe true } -}) +} From 33adc3cb382dc01324ad177d74eeb4c4bf8d965b Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Wed, 8 Nov 2023 22:15:11 +0500 Subject: [PATCH 094/114] Update CollectionsSyntaxTests.kt (#3273) * Update CollectionsSyntaxTests.kt * Update CollectionsSyntaxTests.kt --------- Co-authored-by: Simon Vergauwen Co-authored-by: Alejandro Serrano --- .../kotlin/arrow/core/CollectionsSyntaxTests.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CollectionsSyntaxTests.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CollectionsSyntaxTests.kt index 27a6975fc6b..3ce6f5bd96b 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CollectionsSyntaxTests.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CollectionsSyntaxTests.kt @@ -16,21 +16,22 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class CollectionsSyntaxTests : StringSpec({ - "tail" { +class CollectionsSyntaxTests { + @Test fun tail() = runTest { listOf(1, 2, 3).tail() shouldBe listOf(2, 3) } - "prependTo" { + @Test fun prependTo() = runTest { 1 prependTo listOf(2, 3) shouldBe listOf(1, 2, 3) } - "destructured" { + @Test fun destructured() = runTest { val (head, tail) = listOf(1, 2, 3).let { it.first() to it.tail() } head shouldBe 1 tail shouldBe listOf(2, 3) } -}) +} From cc9bd474b5435e4a7f5308f26c893ced72d6f651 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Wed, 8 Nov 2023 22:15:32 +0500 Subject: [PATCH 095/114] Update NonFatalJvmTest.kt (#3277) --- .../src/jvmTest/java/arrow/core/NonFatalJvmTest.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt index a819be52fc9..cf6c7b9dee4 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt @@ -1,10 +1,11 @@ package arrow.core import io.kotest.assertions.throwables.shouldThrowAny -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class NonFatalJvmTest : StringSpec({ +class NonFatalJvmTest { val fatals: List = listOf( InterruptedException(), @@ -15,16 +16,17 @@ class NonFatalJvmTest : StringSpec({ }, ) - "Test fatals using #invoke()" { + @Test fun testFatalsUsingInvoke() = runTest { fatals.forEach { NonFatal(it) shouldBe false } } - "Test fatals using Throwable#nonFatalOrThrow" { + + @Test fun testFatalsUsingThrowableNonFatalOrThrow() = runTest { fatals.forEach { shouldThrowAny { it.nonFatalOrThrow() } } } -}) +} From 4ba933eed8a4d56785681b3254c7d83dce26de17 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Wed, 8 Nov 2023 22:15:53 +0500 Subject: [PATCH 096/114] Update ArrowEitherCallAdapterTest.kt (#3278) * Update ArrowEitherCallAdapterTest.kt * Update ArrowEitherCallAdapterTest.kt --- .../either/ArrowEitherCallAdapterTest.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt index b6f8f902f18..247a390a735 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt @@ -5,20 +5,21 @@ import arrow.core.right import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock import arrow.retrofit.adapter.retrofit.SuspendApiTestClient -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.SocketPolicy import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class ArrowEitherCallAdapterTest : StringSpec({ +class ArrowEitherCallAdapterTest { lateinit var server: MockWebServer lateinit var service: SuspendApiTestClient - beforeAny { + @Test fun beforeAny = runTime { server = MockWebServer() server.start() service = Retrofit.Builder() @@ -29,9 +30,9 @@ class ArrowEitherCallAdapterTest : StringSpec({ .create(SuspendApiTestClient::class.java) } - afterAny { server.shutdown() } + @Test fun afterAny = runTime { server.shutdown() } - "should return ResponseMock for 200 with valid JSON" { + @Test fun shouldReturnResponseMockFor200WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val body = service.getEither() @@ -39,7 +40,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe ResponseMock("Arrow rocks").right() } - "should return Unit when service method returns Unit and null body received" { + @Test fun shouldReturnUnitWhenServiceMethodReturnsUnitAndNullBodyReceived() = runTest { server.enqueue(MockResponse().setResponseCode(204)) val body = service.postSomething("Sample string") @@ -47,7 +48,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe Unit.right() } - "should return Unit when service method returns Unit and JSON body received" { + @Test fun shouldReturnUnitWhenServiceMethodReturnsUnitAndJsonBodyReceived() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val body = service.postSomething("Sample string") @@ -55,7 +56,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe Unit.right() } - "should return ErrorMock for 400 with valid JSON" { + @Test fun shouldReturnErrorMockFor400WithvalidJson() = runTest { server.enqueue(MockResponse().setBody("""{"errorCode":666}""").setResponseCode(400)) val body = service.getEither() @@ -63,7 +64,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe ErrorMock(666).left() } - "should throw for 200 with invalid JSON" { + @Test fun shouldThrowFor200WithInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""")) val body = runCatching { service.getEither() } @@ -71,7 +72,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body.isFailure shouldBe true } - "should throw for 400 and invalid JSON" { + @Test fun shouldThrowFor400AndInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""").setResponseCode(400)) val body = runCatching { service.getEither() } @@ -79,11 +80,11 @@ class ArrowEitherCallAdapterTest : StringSpec({ body.isFailure shouldBe true } - "should throw when server disconnects" { + @Test fun shouldThrowWhenServerDisconnects() = runTest { server.enqueue(MockResponse().apply { socketPolicy = SocketPolicy.DISCONNECT_AFTER_REQUEST }) val body = runCatching { service.getEither() } body.isFailure shouldBe true } -}) +} From a359b791350f300bb7c6f97cc7d6c0cf00abb412 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Wed, 8 Nov 2023 18:16:28 +0100 Subject: [PATCH 097/114] Move tests from `serialization` and `functions` completely to `kotlin.test` (#3289) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../arrow-core-serialization/build.gradle.kts | 10 +- .../arrow/core/serialization/BackAgainTest.kt | 35 +-- arrow-libs/core/arrow-core/build.gradle.kts | 1 - .../commonMain/kotlin/arrow/core/Either.kt | 8 +- .../kotlin/arrow/core/FunctionSyntaxTest.kt | 158 ----------- .../kotlin/arrow/core/MemoizationTest.kt | 251 ------------------ .../kotlin/arrow/core/test/Generators.kt | 17 +- .../kotlin/examples/example-either-01.kt | 8 +- .../kotlin/arrow/core/CurryingTest.kt | 201 +++++++++----- build.gradle.kts | 1 + 10 files changed, 166 insertions(+), 524 deletions(-) delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt rename arrow-libs/core/{arrow-core => arrow-functions}/src/commonTest/kotlin/arrow/core/CurryingTest.kt (86%) diff --git a/arrow-libs/core/arrow-core-serialization/build.gradle.kts b/arrow-libs/core/arrow-core-serialization/build.gradle.kts index 58d852c31d0..53ff992767d 100644 --- a/arrow-libs/core/arrow-core-serialization/build.gradle.kts +++ b/arrow-libs/core/arrow-core-serialization/build.gradle.kts @@ -4,7 +4,8 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) - alias(libs.plugins.kotest.multiplatform) + alias(libs.plugins.kotlinx.kover) + alias(libs.plugins.spotless) id(libs.plugins.kotlinx.serialization.get().pluginId) } @@ -25,17 +26,10 @@ kotlin { implementation(libs.kotlinx.serializationJson) implementation(libs.kotlin.test) implementation(libs.coroutines.test) - implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } } - - jvmTest { - dependencies { - runtimeOnly(libs.kotest.runnerJUnit5) - } - } } jvm { diff --git a/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt b/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt index c8fe782a083..f76c7c0c804 100644 --- a/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt +++ b/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt @@ -13,17 +13,18 @@ import arrow.core.Ior import arrow.core.NonEmptyList import arrow.core.NonEmptySet import arrow.core.Option -import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.checkAll +import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.map +import io.kotest.property.arbitrary.string +import kotlin.test.Test +import kotlinx.coroutines.test.runTest import kotlinx.serialization.UseSerializers import kotlinx.serialization.json.Json import kotlinx.serialization.json.encodeToJsonElement import kotlinx.serialization.json.decodeFromJsonElement -import io.kotest.matchers.shouldBe -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.map -import io.kotest.property.arbitrary.string import kotlinx.serialization.Serializable /* @@ -46,24 +47,28 @@ data class NonEmptyListInside(val thing: NonEmptyList) @Serializable data class NonEmptySetInside(val thing: NonEmptySet) -inline fun StringSpec.backAgain(generator: Arb) { - "there and back again, ${T::class.simpleName}" { +inline fun backAgain(generator: Arb) = + runTest { checkAll(generator) { e -> val result = Json.encodeToJsonElement(e) val back = Json.decodeFromJsonElement(result) back shouldBe e } } -} /** * Checks that the result of serializing a value into JSON, * and then deserializing it, gives back the original. */ -class BackAgainTest : StringSpec({ - backAgain(Arb.either(Arb.string(), Arb.int()).map(::EitherInside)) - backAgain(Arb.ior(Arb.string(), Arb.int()).map(::IorInside)) - backAgain(Arb.option(Arb.string()).map(::OptionInside)) - backAgain(Arb.nonEmptyList(Arb.int()).map(::NonEmptyListInside)) - backAgain(Arb.nonEmptySet(Arb.int()).map(::NonEmptySetInside)) -}) +class BackAgainTest { + @Test fun backAgainEither() = + backAgain(Arb.either(Arb.string(), Arb.int()).map(::EitherInside)) + @Test fun backAgainIor() = + backAgain(Arb.ior(Arb.string(), Arb.int()).map(::IorInside)) + @Test fun backAgainOption() = + backAgain(Arb.option(Arb.string()).map(::OptionInside)) + @Test fun backAgainNonEmptyList() = + backAgain(Arb.nonEmptyList(Arb.int()).map(::NonEmptyListInside)) + @Test fun backAgainNonEmptySet() = + backAgain(Arb.nonEmptySet(Arb.int()).map(::NonEmptySetInside)) +} diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index cb1e5ded6fd..afcf7ecbe22 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -32,7 +32,6 @@ kotlin { commonTest { dependencies { implementation(projects.arrowFxCoroutines) - implementation(projects.arrowFunctions) implementation(libs.kotlin.test) implementation(libs.coroutines.test) implementation(libs.kotest.frameworkEngine) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index f195fbb99a8..85590c561d7 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -32,13 +32,15 @@ public typealias EitherNel = Either, A> * all becomes even more unwieldy when we try to compose exception-throwing procedures. * * ```kotlin - * import arrow.core.andThen - * * //sampleStart * val throwsSomeStuff: (Int) -> Double = {x -> x.toDouble()} * val throwsOtherThings: (Double) -> String = {x -> x.toString()} * val moreThrowing: (String) -> List = {x -> listOf(x)} - * val magic = throwsSomeStuff.andThen(throwsOtherThings).andThen(moreThrowing) + * val magic: (Int) -> List = { x -> + * val y = throwsSomeStuff(x) + * val z = throwsOtherThings(y) + * moreThrowing(z) + * } * //sampleEnd * fun main() { * println ("magic = $magic") diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt deleted file mode 100644 index 204cb0f7863..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt +++ /dev/null @@ -1,158 +0,0 @@ -package arrow.core - -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe - -class FunctionSyntaxTest : StringSpec({ - - val sum = { i1: Int, i2: Int -> i1 + i2 } - val add5 = { i: Int -> i + 5 } - val multiplyBy2 = { i: Int -> i * 2 } - - "it should compose function correctly (andThen)" { - val potato = "potato" - val ninja = "ninja" - val get = { potato } - val map = { word: String -> ninja + word } - (get andThen map)() - (ninja + potato) shouldBe (get andThen map)() - } - - "testAndThen" { - val add5andMultiplyBy2 = add5 andThen multiplyBy2 - add5andMultiplyBy2(2) shouldBe 14 - } - - "testAndThen2" { - val sumAndMultiplyBy2 = sum andThen multiplyBy2 - sumAndMultiplyBy2(5, 2) shouldBe 14 - } - - "testCompose" { - val multiplyBy2andAdd5 = add5 compose multiplyBy2 - multiplyBy2andAdd5(2) shouldBe 9 - } - - "testCurrying" { - val sum2ints = { x: Int, y: Int -> x + y } - val curried = sum2ints.curried() - curried(2)(4) shouldBe 6 - val addFive = curried(5) - addFive(7) shouldBe 12 - } - - "testUncurrying" { - val sum2ints: (Int, Int) -> Int = { x, y -> x + y } - val curried: (Int) -> (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - // same type as sum2ints, - curried.uncurried()(2, 4) shouldBe 6 - sum2ints(2, 4) shouldBe 6 - } - - "testCurryingEffect" { - val sum2ints: suspend (Int, Int) -> Int = { x: Int, y: Int -> x + y } - val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - val addFive: suspend (Int) -> Int = curried(5) - addFive(7) shouldBe 12 - } - - "testUncurryingEffect" { - val sum2ints: suspend (Int, Int) -> Int = { x, y -> x + y } - val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - // same type as sum2ints, - curried.uncurried()(2, 4) shouldBe 6 - sum2ints(2, 4) shouldBe 6 - } - - "memoize" { - var counterA = 0 - var counterB = 0 - - val a = { _: Int -> counterA++ } - val b = { _: Int -> counterB++ }.memoize() - - repeat(5) { a(1) } - repeat(5) { b(1) } - - counterA shouldBe 5 - counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once - } - - "memoizeEmpty" { - var counterA = 0 - var counterB = 0 - - val a = { counterA++ } - val b = { counterB++ }.memoize() - - repeat(5) { a() } - repeat(5) { b() } - - counterA shouldBe 5 - counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once - } - - "partially" { - val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10 = sum5ints.partially5(10) - val sum3intsTo15 = sum4intsTo10.partially4(5) - val sum2intsTo17 = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - - val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - - val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "suspend partially" { - val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10 = sum5ints.partially5(10) - val sum3intsTo15 = sum4intsTo10.partially4(5) - val sum2intsTo17 = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - - val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - - val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "partials" { - val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10: (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) - val sum3intsTo15: (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) - val sum2intsTo17: (Int, Int) -> Int = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - val helloX: (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "suspend partials" { - val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10: suspend (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) - val sum3intsTo15: suspend (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) - val sum2intsTo17: suspend (Int, Int) -> Int = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - val helloX: suspend (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "bind" { - var i = 0 - fun inc(a: Int) { - i += a - } - - val binded = ::inc.partially1(5) - i shouldBe 0 - binded() - i shouldBe 5 - } - -}) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt deleted file mode 100644 index b3a5c484bdb..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt +++ /dev/null @@ -1,251 +0,0 @@ -package arrow.core - -import io.kotest.core.spec.style.StringSpec -import io.kotest.property.checkAll -import io.kotest.matchers.shouldBe -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import kotlin.random.Random - -class MemoizationTest : StringSpec({ - "Memoize races" { - checkAll { - fun sum(): Int = - Random.nextInt(Int.MAX_VALUE) - - val memoized = ::sum.memoize() - - val (first, second) = listOf( - async { memoized() }, - async { memoized() } - ).awaitAll() - - first shouldBe second - } - } - - "Memoize P0 only first execution runs" { - var runs = 0 - fun sum(): Int { - runs++ - return 1 - } - - val memoized = ::sum.memoize() - - memoized() shouldBe 1 - memoized() shouldBe 1 - runs shouldBe 1 - } - - "Memoize P0 nullable" { - var runs = 0 - fun sum(): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized() shouldBe null - memoized() shouldBe null - runs shouldBe 1 - } - - "Memoize P1 only first execution runs" { - var runs = 0 - fun sum(n: Int): Int { - runs++ - return n + 1 - } - - val memoized = ::sum.memoize() - - memoized(1) shouldBe 2 - memoized(1) shouldBe 2 - runs shouldBe 1 - memoized(2) shouldBe 3 - runs shouldBe 2 - memoized(3) shouldBe 4 - runs shouldBe 3 - } - - "Memoize P1 nullable" { - var runs = 0 - fun sum(n: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1) shouldBe null - memoized(1) shouldBe null - runs shouldBe 1 - } - - "Memoize P2 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int): Int { - runs++ - return n1 + n2 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(2) + 1 - - memoized(1, 2) shouldBe result - memoized(1, 2) shouldBe result - runs shouldBe 1 - memoized(2, 1) shouldBe result - runs shouldBe 2 - memoized(3, 2) shouldBe 6 - runs shouldBe 3 - } - - "Memoize P2 nullable" { - var runs = 0 - fun sum(n: Int, m: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2) shouldBe null - memoized(1, 2) shouldBe null - runs shouldBe 1 - } - - "Memoize P3 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int, n3: Int): Int { - runs++ - return n1 + n2 + n3 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(3) + 1 - - memoized(1, 2, 3) shouldBe result - memoized(1, 2, 3) shouldBe result - runs shouldBe 1 - memoized(2, 3, 1) shouldBe result - runs shouldBe 2 - memoized(3, 1, 2) shouldBe result - runs shouldBe 3 - } - - "Memoize P3 nullable" { - var runs = 0 - fun sum(a: Int, b: Int, c: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2, 3) shouldBe null - memoized(1, 2, 3) shouldBe null - runs shouldBe 1 - } - - "Memoize P4 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int, n3: Int, n4: Int): Int { - runs++ - return n1 + n2 + n3 + n4 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(4) + 1 - - memoized(1, 2, 3, 4) shouldBe result - memoized(1, 2, 3, 4) shouldBe result - runs shouldBe 1 - memoized(2, 3, 4, 1) shouldBe result - runs shouldBe 2 - memoized(3, 4, 1, 2) shouldBe result - runs shouldBe 3 - } - - "Memoize P4 nullable" { - var runs = 0 - fun sum(a: Int, b: Int, c: Int, d: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2, 3, 4) shouldBe null - memoized(1, 2, 3, 4) shouldBe null - runs shouldBe 1 - } - - "Memoize P5 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Int { - runs++ - return n1 + n2 + n3 + n4 + n5 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(5) + 1 - - memoized(1, 2, 3, 4, 5) shouldBe result - memoized(1, 2, 3, 4, 5) shouldBe result - runs shouldBe 1 - memoized(2, 3, 4, 5, 1) shouldBe result - runs shouldBe 2 - memoized(3, 4, 5, 1, 2) shouldBe result - runs shouldBe 3 - } - - "Memoize P5 nullable" { - var runs = 0 - fun sum(a: Int, b: Int, c: Int, d: Int, e: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2, 3, 4, 5) shouldBe null - memoized(1, 2, 3, 4, 5) shouldBe null - runs shouldBe 1 - } - - "Recursive memoization" { - var runs = 0 - val memoizedDeepRecursiveFibonacci: DeepRecursiveFunction = - MemoizedDeepRecursiveFunction { n -> - when (n) { - 0 -> 0.also { runs++ } - 1 -> 1 - else -> callRecursive(n - 1) + callRecursive(n - 2) - } - } - val result = memoizedDeepRecursiveFibonacci(5) - result shouldBe 5 - runs shouldBe 1 - } - - "Recursive memoization, run twice should be memoized" { - var runs = 0 - val memoizedDeepRecursiveFibonacci: DeepRecursiveFunction = - MemoizedDeepRecursiveFunction { n -> - when (n) { - 0 -> 0.also { runs++ } - 1 -> 1 - else -> callRecursive(n - 1) + callRecursive(n - 2) - } - } - val result1 = memoizedDeepRecursiveFibonacci(5) - val result2 = memoizedDeepRecursiveFibonacci(5) - result1 shouldBe result2 - runs shouldBe 1 - } -}) - -private fun consecSumResult(n: Int): Int = (n * (n + 1)) / 2 diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index 8aaea6cd455..d0d0166edad 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -1,15 +1,6 @@ package arrow.core.test -import arrow.core.Either -import arrow.core.Ior -import arrow.core.NonEmptyList -import arrow.core.NonEmptySet -import arrow.core.Option -import arrow.core.left -import arrow.core.memoize -import arrow.core.right -import arrow.core.toNonEmptySetOrNull -import arrow.core.toOption +import arrow.core.* import io.kotest.property.Arb import io.kotest.property.arbitrary.arbitrary import io.kotest.property.arbitrary.bind @@ -47,11 +38,13 @@ fun Arb.Companion.sequence(arb: Arb, range: IntRange = 0 .. 100): Arb Arb.Companion.functionAToB(arb: Arb): Arb<(A) -> B> = arbitrary { random -> - { _: A -> arb.next(random) }.memoize() + val memoized = MemoizedDeepRecursiveFunction { _ -> arb.next(random) } + fun (x: A): B = memoized(x) } fun Arb.Companion.functionABCToD(arb: Arb): Arb<(A, B, C) -> D> = arbitrary { random -> - { _: A, _:B, _:C -> arb.next(random)}.memoize() + val memoized = MemoizedDeepRecursiveFunction, D> { _ -> arb.next(random) } + fun (x: A, y: B, z: C): D = memoized(Triple(x, y, z)) } fun Arb.Companion.throwable(): Arb = diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt index 313a4846eda..2239f19f668 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt @@ -1,12 +1,14 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither01 -import arrow.core.andThen - val throwsSomeStuff: (Int) -> Double = {x -> x.toDouble()} val throwsOtherThings: (Double) -> String = {x -> x.toString()} val moreThrowing: (String) -> List = {x -> listOf(x)} -val magic = throwsSomeStuff.andThen(throwsOtherThings).andThen(moreThrowing) +val magic: (Int) -> List = { x -> + val y = throwsSomeStuff(x) + val z = throwsOtherThings(y) + moreThrowing(z) +} fun main() { println ("magic = $magic") } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/CurryingTest.kt similarity index 86% rename from arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt rename to arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/CurryingTest.kt index cec444b9c23..28886cab4bc 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/CurryingTest.kt @@ -1,162 +1,184 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class CurryingTest : StringSpec({ +class CurryingTest { fun arb(): Arb = Arb.string(1) //region curried - "A 2-arity curried function returns the same result as the function before being curried" { + @Test + fun curry2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add = { p1: String, p2: String -> p1 + p2 } add.curried()(a1)(a2) shouldBe add(a1, a2) } } - "A 3-arity curried function returns the same result as the function before being curried" { + @Test + fun curry3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add = { p1: String, p2: String, p3: String -> p1 + p2 + p3 } add.curried()(a1)(a2)(a3) shouldBe add(a1, a2, a3) } } - "A 4-arity curried function returns the same result as the function before being curried" { + @Test + fun curry4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add = { p1: String, p2: String, p3: String, p4: String -> p1 + p2 + p3 + p4 } add.curried()(a1)(a2)(a3)(a4) shouldBe add(a1, a2, a3, a4) } } - "A 5-arity curried function returns the same result as the function before being curried" { + @Test + fun curry5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String -> p1 + p2 + p3 + p4 + p5 } add.curried()(a1)(a2)(a3)(a4)(a5) shouldBe add(a1, a2, a3, a4, a5) } } - "A 6-arity curried function returns the same result as the function before being curried" { + @Test + fun curry6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String -> p1 + p2 + p3 + p4 + p5 + p6 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6) shouldBe add(a1, a2, a3, a4, a5, a6) } } - "A 7-arity curried function returns the same result as the function before being curried" { + @Test + fun curry7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7) shouldBe add(a1, a2, a3, a4, a5, a6, a7) } } - "An 8-arity curried function returns the same result as the function before being curried" { + @Test + fun curry8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8) } } - "A 9-arity curried function returns the same result as the function before being curried" { + @Test + fun curry9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9) } } - "A 10-arity curried function returns the same result as the function before being curried" { + @Test + fun curry10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) } } - "An 11-arity curried function returns the same result as the function before being curried" { + @Test + fun curry11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) } } - "A 12-arity curried function returns the same result as the function before being curried" { + @Test + fun curry12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) } } - /* Waiting for Kotest 5.6.0 to be released + /* - "A 13-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> + @Test + fun curry13() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) } } - "A 14-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14 -> + @Test + fun curry14() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) } } - "A 15-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 -> + @Test + fun curry15() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) } } - "A 16-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16 -> + @Test + fun curry16() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) } } - "A 17-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17 -> + @Test + fun curry17() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) } } - "A 18-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18 -> + @Test + fun curry18() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) } } - "A 19-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19 -> + @Test + fun curry19() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) } } - "A 20-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 -> + @Test + fun curry20() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String, p20: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) } } - "A 21-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21 -> + @Test + fun curry21() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String, p20: String, p21: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20 + p21 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20)(a21) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21) } } - "A 22-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22 -> + @Test + fun curry22() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String, p20: String, p21: String, p22: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20 + p21 + p22 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20)(a21)(a22) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22) } @@ -168,7 +190,8 @@ class CurryingTest : StringSpec({ // region uncurried - "A 2-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add = { p1: String, p2: String -> p1 + p2 } val curriedAdd = add.curried() @@ -176,7 +199,8 @@ class CurryingTest : StringSpec({ } } - "A 3-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add = { p1: String, p2: String, p3: String -> p1 + p2 + p3 } val curriedAdd = add.curried() @@ -184,7 +208,8 @@ class CurryingTest : StringSpec({ } } - "A 4-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add = { p1: String, p2: String, p3: String, p4: String -> p1 + p2 + p3 + p4 } val curriedAdd = add.curried() @@ -192,7 +217,8 @@ class CurryingTest : StringSpec({ } } - "A 5-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String -> p1 + p2 + p3 + p4 + p5 } val curriedAdd = add.curried() @@ -200,7 +226,8 @@ class CurryingTest : StringSpec({ } } - "A 6-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String -> p1 + p2 + p3 + p4 + p5 + p6 } val curriedAdd = add.curried() @@ -208,7 +235,8 @@ class CurryingTest : StringSpec({ } } - "A 7-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } val curriedAdd = add.curried() @@ -216,7 +244,8 @@ class CurryingTest : StringSpec({ } } - "A 8-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } val curriedAdd = add.curried() @@ -224,7 +253,8 @@ class CurryingTest : StringSpec({ } } - "A 9-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } val curriedAdd = add.curried() @@ -232,7 +262,8 @@ class CurryingTest : StringSpec({ } } - "A 10-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } val curriedAdd = add.curried() @@ -240,7 +271,8 @@ class CurryingTest : StringSpec({ } } - "A 11-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } val curriedAdd = add.curried() @@ -248,7 +280,8 @@ class CurryingTest : StringSpec({ } } - "A 12-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String-> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } val curriedAdd = add.curried() @@ -256,7 +289,7 @@ class CurryingTest : StringSpec({ } } - /* Waiting for Kotest 5.6.0 to be released + /* "A 13-arity curried function returns the same result as the function after being uncurried" { checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> @@ -344,84 +377,95 @@ class CurryingTest : StringSpec({ // region curried effect - "A 2-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add: suspend (String, String) -> String = { p1, p2 -> p1 + p2 } add.curried()(a1)(a2) shouldBe add(a1, a2) } } - "A 3-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add: suspend (String, String, String) -> String = { p1, p2, p3 -> p1 + p2 + p3 } add.curried()(a1)(a2)(a3) shouldBe add(a1, a2, a3) } } - "A 4-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add: suspend (String, String, String, String) -> String = { p1, p2, p3, p4 -> p1 + p2 + p3 + p4 } add.curried()(a1)(a2)(a3)(a4) shouldBe add(a1, a2, a3, a4) } } -// - "A 5-arity curried effect returns the same result as the effect before being curried" { + + @Test + fun curryEffect5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add: suspend (String, String, String, String, String) -> String = { p1, p2, p3, p4, p5 -> p1 + p2 + p3 + p4 + p5 } add.curried()(a1)(a2)(a3)(a4)(a5) shouldBe add(a1, a2, a3, a4, a5) } } - "A 6-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add: suspend (String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6 -> p1 + p2 + p3 + p4 + p5 + p6 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6) shouldBe add(a1, a2, a3, a4, a5, a6) } } - "A 7-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add: suspend (String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7) shouldBe add(a1, a2, a3, a4, a5, a6, a7) } } - "An 8-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add: suspend (String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8) } } - "A 9-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add: suspend (String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9) } } - "A 10-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add: suspend (String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) } } - "An 11-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) } } - "A 12-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) } } - /* Waiting for Kotest 5.6.0 to be released + /* "A 13-arity curried effect returns the same result as the effect before being curried" { checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> @@ -499,7 +543,8 @@ class CurryingTest : StringSpec({ // region uncurried effect - "A 2-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add: suspend (String, String) -> String = { p1, p2 -> p1 + p2 } val curriedAdd = add.curried() @@ -507,7 +552,8 @@ class CurryingTest : StringSpec({ } } - "A 3-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add: suspend (String, String, String) -> String = { p1, p2, p3 -> p1 + p2 + p3 } val curriedAdd = add.curried() @@ -515,15 +561,17 @@ class CurryingTest : StringSpec({ } } - "A 4-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add: suspend (String, String, String, String) -> String = { p1, p2, p3, p4 -> p1 + p2 + p3 + p4 } val curriedAdd = add.curried() curriedAdd(a1)(a2)(a3)(a4) shouldBe curriedAdd.uncurried()(a1, a2, a3, a4) } } -// - "A 5-arity curried effect returns the same result as the effect after being uncurried" { + + @Test + fun curryUncurryEffect5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add: suspend (String, String, String, String, String) -> String = { p1, p2, p3, p4, p5 -> p1 + p2 + p3 + p4 + p5 } val curriedAdd = add.curried() @@ -531,7 +579,8 @@ class CurryingTest : StringSpec({ } } - "A 6-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add: suspend (String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6 -> p1 + p2 + p3 + p4 + p5 + p6 } val curriedAdd = add.curried() @@ -539,7 +588,8 @@ class CurryingTest : StringSpec({ } } - "A 7-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add: suspend (String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } val curriedAdd = add.curried() @@ -547,7 +597,8 @@ class CurryingTest : StringSpec({ } } - "An 8-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add: suspend (String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } val curriedAdd = add.curried() @@ -555,7 +606,8 @@ class CurryingTest : StringSpec({ } } - "A 9-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add: suspend (String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } val curriedAdd = add.curried() @@ -563,7 +615,8 @@ class CurryingTest : StringSpec({ } } - "A 10-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add: suspend (String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } val curriedAdd = add.curried() @@ -571,7 +624,8 @@ class CurryingTest : StringSpec({ } } - "An 11-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } val curriedAdd = add.curried() @@ -579,7 +633,8 @@ class CurryingTest : StringSpec({ } } - "A 12-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } val curriedAdd = add.curried() @@ -587,7 +642,7 @@ class CurryingTest : StringSpec({ } } - /* Waiting for Kotest 5.6.0 to be released + /* "A 13-arity curried effect returns the same result as the effect after being uncurried" { checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> @@ -672,4 +727,4 @@ class CurryingTest : StringSpec({ */ // endregion -}) +} diff --git a/build.gradle.kts b/build.gradle.kts index cc6ea0d8f1c..072f06ed65f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -68,6 +68,7 @@ dependencies { kover(projects.arrowCore) kover(projects.arrowCoreRetrofit) kover(projects.arrowCoreSerialization) + kover(projects.arrowFunctions) kover(projects.arrowFxCoroutines) kover(projects.arrowFxStm) kover(projects.arrowOptics) From f137b22f5eb4356c553dd1319da8a5193a0484f4 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 8 Nov 2023 20:22:02 +0100 Subject: [PATCH 098/114] Fix problems with tests --- .../either/ArrowEitherCallAdapterTest.kt | 10 ++++++--- .../either/ArrowResponseEAdapterTest.kt | 12 +++++----- .../java/arrow/core/NonFatalJvmTest.kt | 4 ++-- .../arrow/fx/coroutines/CyclicBarrierSpec.kt | 6 ++--- .../kotlin/arrow/fx/coroutines/FlowTest.kt | 4 ++-- .../kotlin/arrow/fx/coroutines/Generators.kt | 6 ++--- .../kotlin/arrow/optics/ReflectionTest.kt | 22 +++++++++++-------- .../kotlin/arrow/resilience/CircuitBreaker.kt | 7 ------ .../arrow/resilience/CircuitBreakerTest.kt | 21 ++++++++---------- .../kotlin/arrow/resilience/FlowTest.kt | 2 -- .../kotlin/arrow/resilience/SagaSpec.kt | 1 - .../kotlin/arrow/resilience/ScheduleTest.kt | 8 ------- .../examples/example-circuitbreaker-01.kt | 2 -- .../examples/example-circuitbreaker-02.kt | 2 -- 14 files changed, 45 insertions(+), 62 deletions(-) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt index 247a390a735..1c481385ab6 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt @@ -6,20 +6,22 @@ import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock import arrow.retrofit.adapter.retrofit.SuspendApiTestClient import io.kotest.matchers.shouldBe +import kotlinx.coroutines.test.runTest import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.SocketPolicy import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import kotlin.test.AfterTest +import kotlin.test.BeforeTest import kotlin.test.Test -import kotlinx.coroutines.test.runTest class ArrowEitherCallAdapterTest { lateinit var server: MockWebServer lateinit var service: SuspendApiTestClient - @Test fun beforeAny = runTime { + @BeforeTest fun initialize() { server = MockWebServer() server.start() service = Retrofit.Builder() @@ -30,7 +32,9 @@ class ArrowEitherCallAdapterTest { .create(SuspendApiTestClient::class.java) } - @Test fun afterAny = runTime { server.shutdown() } + @AfterTest fun shutdown() { + server.shutdown() + } @Test fun shouldReturnResponseMockFor200WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt index 4d3d2c4ca16..43b4a184cfa 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt @@ -6,6 +6,7 @@ import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock import arrow.retrofit.adapter.retrofit.SuspendApiTestClient import io.kotest.matchers.shouldBe +import kotlinx.coroutines.test.runTest import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.SocketPolicy @@ -14,7 +15,6 @@ import retrofit2.converter.gson.GsonConverterFactory import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test -import kotlinx.coroutines.test.runTest class ArrowResponseEAdapterTest { @@ -37,7 +37,7 @@ class ArrowResponseEAdapterTest { fun shutdown() { server.shutdown() } - + @Test fun shouldReturnResponseMockFor200WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) @@ -61,7 +61,7 @@ class ArrowResponseEAdapterTest { body shouldBe Unit.right() } } - + @Test fun shouldReturnUnitWhenServiceMethodReturnsUnitAndJsonBodyReceived() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) @@ -85,7 +85,7 @@ class ArrowResponseEAdapterTest { body shouldBe ErrorMock(42).left() } } - + @Test fun shouldThrowFor200WithInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""")) @@ -94,7 +94,7 @@ class ArrowResponseEAdapterTest { responseE.isFailure shouldBe true } - + @Test fun shouldThrowFor400AndInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""").setResponseCode(400)) @@ -103,7 +103,7 @@ class ArrowResponseEAdapterTest { responseE.isFailure shouldBe true } - + @Test fun shouldThrowWhenServerDisconnects() = runTest { server.enqueue(MockResponse().apply { socketPolicy = SocketPolicy.DISCONNECT_AFTER_REQUEST }) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt index cf6c7b9dee4..c519c15f24d 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/NonFatalJvmTest.kt @@ -2,8 +2,8 @@ package arrow.core import io.kotest.assertions.throwables.shouldThrowAny import io.kotest.matchers.shouldBe -import kotlin.test.Test import kotlinx.coroutines.test.runTest +import kotlin.test.Test class NonFatalJvmTest { val fatals: List = @@ -21,7 +21,7 @@ class NonFatalJvmTest { NonFatal(it) shouldBe false } } - + @Test fun testFatalsUsingThrowableNonFatalOrThrow() = runTest { fatals.forEach { shouldThrowAny { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt index 2daf01e9b3f..42202887750 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt @@ -34,7 +34,7 @@ class CyclicBarrierSpec { @Test fun awaitingAllInParallelResumesAllCoroutines() = runTest { - checkAll(Arb.int(1, 100)) { i -> + checkAll(Arb.int(1, 20)) { i -> val barrier = CyclicBarrier(i) (0 until i).parMap { barrier.await() } } @@ -85,7 +85,7 @@ class CyclicBarrierSpec { @Test fun resetCancelsAllAwaiting() = runTest { - checkAll(Arb.int(2, 100)) { i -> + checkAll(Arb.int(2, 20)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -103,7 +103,7 @@ class CyclicBarrierSpec { @Test fun shouldCleanUpUponReset() = runTest { - checkAll(Arb.int(2, 100)) { i -> + checkAll(Arb.int(2, 20)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt index 0bead6212fb..e79d057391d 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt @@ -236,7 +236,7 @@ class FlowTest { @Test fun fixedDelay() = runTest { - checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> + checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..20)) { waitPeriod, n -> val emissionDuration = waitPeriod / 10L var state: Long? = null @@ -261,7 +261,7 @@ class FlowTest { @Test fun fixedRate() = runTest { - checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..100)) { waitPeriod, n -> + checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..20)) { waitPeriod, n -> val emissionDuration = waitPeriod / 10 var state: Long? = null diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt index 3484779ea02..a164322d573 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt @@ -27,10 +27,10 @@ import kotlin.coroutines.intrinsics.intercepted import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn import kotlin.coroutines.startCoroutine -fun Arb.Companion.flow(arbA: Arb): Arb> = +fun Arb.Companion.flow(arbA: Arb, range: IntRange = 1 .. 20): Arb> = Arb.choose( - 10 to Arb.list(arbA).map { it.asFlow() }, - 10 to Arb.list(arbA).map { channelFlow { it.forEach { send(it) } }.buffer(Channel.RENDEZVOUS) }, + 10 to Arb.list(arbA, range).map { it.asFlow() }, + 10 to Arb.list(arbA, range).map { channelFlow { it.forEach { send(it) } }.buffer(Channel.RENDEZVOUS) }, 1 to Arb.constant(emptyFlow()), ) diff --git a/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt b/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt index 2fa27e1de8a..78deb285ca4 100644 --- a/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt +++ b/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt @@ -2,6 +2,8 @@ package arrow.optics import io.kotest.matchers.shouldBe import io.kotest.property.Arb +import io.kotest.property.arbitrary.Codepoint +import io.kotest.property.arbitrary.ascii import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.string import io.kotest.property.checkAll @@ -11,30 +13,32 @@ import kotlin.test.Test data class Person(val name: String, val friends: List) sealed interface Cutlery -object Fork : Cutlery -object Spoon : Cutlery +data object Fork : Cutlery +data object Spoon : Cutlery class ReflectionTest { + private val asciiString: Arb = Arb.string(codepoints = Codepoint.ascii()) + @Test fun lensesForFieldGet() = runTest { - checkAll(Arb.string(), Arb.list(Arb.string())) { nm, fs -> + checkAll(asciiString, Arb.list(asciiString, 1..20)) { nm, fs -> val p = Person(nm, fs.toMutableList()) Person::name.lens.get(p) shouldBe nm } } @Test fun lensesForFieldSet() = runTest { - checkAll(Arb.string(), Arb.list(Arb.string())) { nm, fs -> + checkAll(asciiString, Arb.list(asciiString, 1..20)) { nm, fs -> val p = Person(nm, fs.toMutableList()) - val m = Person::name.lens.modify(p) { it.capitalize() } - m shouldBe Person(nm.capitalize(), fs) + val m = Person::name.lens.modify(p) { it.lowercase() } + m shouldBe Person(nm.lowercase(), fs) } } @Test fun traversalForListSet() = runTest { - checkAll(Arb.string(), Arb.list(Arb.string())) { nm, fs -> + checkAll(asciiString, Arb.list(asciiString, 1..20)) { nm, fs -> val p = Person(nm, fs) - val m = Person::friends.every.modify(p) { it.capitalize() } - m shouldBe Person(nm, fs.map { it.capitalize() }) + val m = Person::friends.every.modify(p) { it.lowercase() } + m shouldBe Person(nm, fs.map { it.lowercase() }) } } diff --git a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt index c1950a7befd..51a89feac7e 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt @@ -1,5 +1,3 @@ -@file:OptIn(ExperimentalTime::class) - package arrow.resilience import arrow.atomic.Atomic @@ -14,7 +12,6 @@ import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.withContext import kotlin.time.Duration import kotlin.time.Duration.Companion.nanoseconds -import kotlin.time.ExperimentalTime import kotlin.time.TimeMark import kotlin.time.TimeSource @@ -50,9 +47,7 @@ import kotlin.time.TimeSource * import arrow.resilience.CircuitBreaker * import kotlinx.coroutines.delay * import kotlin.time.Duration.Companion.seconds - * import kotlin.time.ExperimentalTime * - * @ExperimentalTime * suspend fun main(): Unit { * //sampleStart * val circuitBreaker = CircuitBreaker( @@ -92,9 +87,7 @@ import kotlin.time.TimeSource * import arrow.resilience.retry * import kotlinx.coroutines.delay * import kotlin.time.Duration.Companion.seconds - * import kotlin.time.ExperimentalTime * - * @ExperimentalTime * suspend fun main(): Unit { * suspend fun apiCall(): Unit { * println("apiCall . . .") diff --git a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt index 4a2125b058a..bebebdd2ddd 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/CircuitBreakerTest.kt @@ -5,7 +5,6 @@ import arrow.resilience.CircuitBreaker.OpeningStrategy import arrow.resilience.CircuitBreaker.OpeningStrategy.SlidingWindow import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.async import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.runTest @@ -20,20 +19,18 @@ import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds -import kotlin.time.ExperimentalTime import kotlin.time.TestTimeSource -@OptIn(ExperimentalTime::class, ExperimentalCoroutinesApi::class) class CircuitBreakerTest { - val dummy = RuntimeException("dummy") - val maxFailures = 5 - val exponentialBackoffFactor = 2.0 - val resetTimeout = 500.milliseconds - val maxTimeout = 1000.milliseconds + private val dummy = RuntimeException("dummy") + private val maxFailures = 5 + private val exponentialBackoffFactor = 2.0 + private val resetTimeout = 500.milliseconds + private val maxTimeout = 1000.milliseconds @Test fun shouldWorkForSuccessfulAsyncTasks(): TestResult = runTest { - val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures),) + val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures)) var effect = 0 val iterations = stackSafeIteration() Schedule.recurs(iterations.toLong()).repeat { @@ -44,7 +41,7 @@ class CircuitBreakerTest { @Test fun shouldWorkForSuccessfulImmediateTasks(): TestResult = runTest { - val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures),) + val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures)) var effect = 0 val iterations = stackSafeIteration() Schedule.recurs(iterations.toLong()).repeat { @@ -55,7 +52,7 @@ class CircuitBreakerTest { @Test fun staysClosedAfterLessThanMaxFailures(): TestResult = runTest { - val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures),) + val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures)) val result = recurAndCollect>(4).repeat { Either.catch { cb.protectOrThrow { throw dummy } } @@ -67,7 +64,7 @@ class CircuitBreakerTest { @Test fun closedCircuitBreakerResetsFailureCountAfterSuccess(): TestResult = runTest { - val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures),) + val cb = CircuitBreaker(resetTimeout = resetTimeout, openingStrategy = OpeningStrategy.Count(maxFailures)) val result = recurAndCollect>(4).repeat { Either.catch { cb.protectOrThrow { throw dummy } } diff --git a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/FlowTest.kt b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/FlowTest.kt index 17882ad0825..86e8d99ba7a 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/FlowTest.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/FlowTest.kt @@ -15,10 +15,8 @@ import kotlin.test.assertFailsWith import kotlin.test.assertTrue import kotlin.test.fail import kotlin.time.Duration.Companion.milliseconds -import kotlin.time.ExperimentalTime @OptIn(ExperimentalCoroutinesApi::class) -@ExperimentalTime class FlowTest { @Test diff --git a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/SagaSpec.kt b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/SagaSpec.kt index 63b25e7c307..b6ae2ae121d 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/SagaSpec.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/SagaSpec.kt @@ -14,7 +14,6 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.fail -@OptIn(ExperimentalCoroutinesApi::class) @Suppress("unused") class SagaSpec { diff --git a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt index 4e6f09dbc7c..540bfdaf4d9 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonTest/kotlin/arrow/resilience/ScheduleTest.kt @@ -5,7 +5,6 @@ import arrow.atomic.updateAndGet import arrow.core.Either import arrow.resilience.Schedule.Decision.Continue import arrow.resilience.Schedule.Decision.Done -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withTimeout @@ -19,7 +18,6 @@ import kotlin.time.Duration import kotlin.time.Duration.Companion.ZERO import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds -import kotlin.time.ExperimentalTime internal data class SideEffect(var counter: Int = 0) { fun increment() { @@ -27,9 +25,6 @@ internal data class SideEffect(var counter: Int = 0) { } } -@OptIn(ExperimentalCoroutinesApi::class) -@ExperimentalTime -@Suppress("UNREACHABLE_CODE", "UNUSED_VARIABLE") class ScheduleTest { class MyException : Exception() @@ -287,19 +282,16 @@ fun Schedule.Decision.delay(): Duration? = when (this) { is Done -> null } -@ExperimentalTime private fun fibs(one: Duration): Sequence = generateSequence(Pair(one, one)) { (a, b) -> Pair(b, (a + b)) }.map { it.first } -@ExperimentalTime private fun exp(base: Duration): Sequence = generateSequence(Pair(base, 1.0)) { (_, n) -> Pair(base * 2.0.pow(n), n + 1) }.map { it.first } -@ExperimentalTime private fun linear(base: Duration): Sequence = generateSequence(Pair(base, 1.0)) { (_, n) -> Pair((base * n), (n + 1)) diff --git a/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-01.kt b/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-01.kt index 0f646f65684..68469f2fdfe 100644 --- a/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-01.kt +++ b/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-01.kt @@ -5,9 +5,7 @@ import arrow.core.Either import arrow.resilience.CircuitBreaker import kotlinx.coroutines.delay import kotlin.time.Duration.Companion.seconds -import kotlin.time.ExperimentalTime -@ExperimentalTime suspend fun main(): Unit { val circuitBreaker = CircuitBreaker( resetTimeout = 2.seconds, diff --git a/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-02.kt b/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-02.kt index 9aaace53da3..5611e480b01 100644 --- a/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-02.kt +++ b/arrow-libs/resilience/arrow-resilience/src/jvmTest/kotlin/examples/example-circuitbreaker-02.kt @@ -7,9 +7,7 @@ import arrow.resilience.Schedule import arrow.resilience.retry import kotlinx.coroutines.delay import kotlin.time.Duration.Companion.seconds -import kotlin.time.ExperimentalTime -@ExperimentalTime suspend fun main(): Unit { suspend fun apiCall(): Unit { println("apiCall . . .") From 0c39851c32cc1db6699bf20f8cf7b8c73392e12a Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Wed, 8 Nov 2023 20:35:10 +0100 Subject: [PATCH 099/114] Remove a bunch of warnings in `arrow-2` (#3282) Co-authored-by: serras Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- arrow-libs/core/arrow-atomic/build.gradle.kts | 6 +- .../core/arrow-core-retrofit/build.gradle.kts | 2 +- .../either/EitherCallAdapterFactory.kt | 2 +- .../arrow-core-serialization/build.gradle.kts | 2 +- arrow-libs/core/arrow-core/api/arrow-core.api | 2 +- arrow-libs/core/arrow-core/build.gradle.kts | 6 +- .../commonMain/kotlin/arrow/core/Either.kt | 1 + .../kotlin/arrow/core/NonEmptyList.kt | 5 +- .../commonMain/kotlin/arrow/core/NonFatal.kt | 2 +- .../commonMain/kotlin/arrow/core/Sequence.kt | 15 +- .../src/commonMain/kotlin/arrow/core/map.kt | 2 +- .../kotlin/arrow/core/nonFatalOrThrow.kt | 2 +- .../commonMain/kotlin/arrow/core/predef.kt | 2 + .../kotlin/arrow/core/raise/Effect.kt | 8 +- .../kotlin/arrow/core/raise/ErrorHandlers.kt | 14 +- .../kotlin/arrow/core/raise/Raise.kt | 8 +- .../examples/example-effect-error-01.kt | 6 +- .../examples/example-effect-error-04.kt | 4 +- .../examples/example-effect-error-05.kt | 2 +- .../jvmTest/kotlin/examples/example-map-02.kt | 2 +- .../kotlin/examples/example-nonfatal-01.kt | 2 +- .../examples/example-nonfatalorthrow-01.kt | 2 +- .../kotlin/examples/example-raise-04.kt | 4 +- .../kotlin/examples/example-raise-08.kt | 2 +- .../kotlin/examples/example-raise-dsl-05.kt | 2 +- .../kotlin/examples/example-raise-dsl-06.kt | 2 +- .../kotlin/examples/example-raise-dsl-09.kt | 2 +- .../kotlin/examples/example-raise-dsl-10.kt | 2 +- .../kotlin/examples/example-sequence-11.kt | 2 +- .../kotlin/examples/example-sequence-12.kt | 2 +- .../kotlin/examples/example-sequence-13.kt | 2 +- .../kotlin/examples/example-sequence-14.kt | 2 +- .../kotlin/examples/example-sequence-15.kt | 2 +- .../kotlin/examples/example-sequence-16.kt | 2 +- .../core/arrow-functions/build.gradle.kts | 2 +- .../kotlin/arrow/core/MemoizationTest.kt | 2 + .../fx/arrow-fx-coroutines/build.gradle.kts | 2 +- .../kotlin/arrow/fx/coroutines/Bracket.kt | 13 +- .../kotlin/arrow/fx/coroutines/ParZip.kt | 2 + .../arrow/fx/coroutines/ParZipOrAccumulate.kt | 128 ++++++++-------- .../arrow/fx/coroutines/CyclicBarrierSpec.kt | 2 +- .../arrow/fx/coroutines/ResourceExtensions.kt | 3 +- .../kotlin/examples/example-bracket-01.kt | 4 +- .../kotlin/examples/example-bracket-02.kt | 4 +- arrow-libs/fx/arrow-fx-stm/build.gradle.kts | 9 +- .../src/commonMain/kotlin/arrow/fx/stm/STM.kt | 4 +- .../commonMain/kotlin/arrow/fx/stm/TArray.kt | 1 + .../commonMain/kotlin/arrow/fx/stm/TVar.kt | 1 + .../kotlin/arrow/fx/stm/internal/Hamt.kt | 4 +- .../kotlin/arrow/fx/stm/internal/Impl.kt | 34 +++-- .../jvmTest/kotlin/examples/example-stm-06.kt | 2 +- .../jvmTest/kotlin/examples/example-stm-41.kt | 1 + .../kotlin/examples/example-tarray-04.kt | 1 + .../arrow-optics-ksp-plugin/build.gradle.kts | 2 +- .../arrow-optics-reflect/build.gradle.kts | 2 +- .../optics/arrow-optics/build.gradle.kts | 2 +- .../kotlin/arrow/optics/Optional.kt | 4 +- .../kotlin/arrow/optics/Traversal.kt | 138 +++++++++--------- .../commonMain/kotlin/arrow/optics/predef.kt | 2 +- .../kotlin/examples/example-optional-01.kt | 4 +- .../arrow-resilience/build.gradle.kts | 2 +- .../kotlin/arrow/resilience/Saga.kt | 1 + arrow-libs/stack/build.gradle.kts | 1 + 63 files changed, 269 insertions(+), 231 deletions(-) diff --git a/arrow-libs/core/arrow-atomic/build.gradle.kts b/arrow-libs/core/arrow-atomic/build.gradle.kts index f9e32f25a5d..70f921b0a88 100644 --- a/arrow-libs/core/arrow-atomic/build.gradle.kts +++ b/arrow-libs/core/arrow-atomic/build.gradle.kts @@ -47,11 +47,9 @@ kotlin { } tasks.withType().configureEach { - kotlinOptions { - freeCompilerArgs = freeCompilerArgs + "-Xexpect-actual-classes" - } + kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes" } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/core/arrow-core-retrofit/build.gradle.kts b/arrow-libs/core/arrow-core-retrofit/build.gradle.kts index 82f1ef25e9e..8a1af47a255 100644 --- a/arrow-libs/core/arrow-core-retrofit/build.gradle.kts +++ b/arrow-libs/core/arrow-core-retrofit/build.gradle.kts @@ -43,6 +43,6 @@ tasks.jar { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt b/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt index e6e7a910e13..b277e0ee2ad 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either/EitherCallAdapterFactory.kt @@ -110,7 +110,7 @@ public class EitherCallAdapterFactory : CallAdapter.Factory() { } } - private inline fun extractErrorAndReturnType(wrapperType: Type, returnType: ParameterizedType): Pair { + private fun extractErrorAndReturnType(wrapperType: Type, returnType: ParameterizedType): Pair { if (wrapperType !is ParameterizedType) { val name = parseTypeName(returnType) throw IllegalArgumentException( diff --git a/arrow-libs/core/arrow-core-serialization/build.gradle.kts b/arrow-libs/core/arrow-core-serialization/build.gradle.kts index 53ff992767d..6ba4450f34f 100644 --- a/arrow-libs/core/arrow-core-serialization/build.gradle.kts +++ b/arrow-libs/core/arrow-core-serialization/build.gradle.kts @@ -41,6 +41,6 @@ kotlin { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index c536327fe75..9f112df7e83 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -1011,7 +1011,7 @@ public final class arrow/core/raise/RaiseKt { public static final fun get (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun get (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun getOrElse (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static final fun getOrElse (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun getOrElse (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun getOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun getOrNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun ior (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index afcf7ecbe22..5cba44a0899 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -57,10 +57,14 @@ kotlin { } // enables context receivers for Jvm Tests +tasks.withType().configureEach { + kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes" +} + tasks.named("compileTestKotlinJvm") { kotlinOptions.freeCompilerArgs += "-Xcontext-receivers" } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 85590c561d7..305de144f9d 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -1332,6 +1332,7 @@ public inline infix fun Either.getOrElse(default: (A) -> B): B { * * */ +@Suppress("NOTHING_TO_INLINE") public inline fun Either.merge(): A = fold(::identity, ::identity) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index e1f8c963795..5eb622b7bac 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -179,7 +179,7 @@ public value class NonEmptyList @PublishedApi internal constructor( else -> head } - @Suppress("OVERRIDE_BY_INLINE") + @Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public override inline fun distinct(): NonEmptyList = NonEmptyList(all.distinct()) @@ -340,6 +340,7 @@ public fun nonEmptyListOf(head: A, vararg t: A): NonEmptyList = NonEmptyList(listOf(head) + t) @JvmName("nel") +@Suppress("NOTHING_TO_INLINE") public inline fun A.nel(): NonEmptyList = NonEmptyList(listOf(this)) @@ -355,9 +356,11 @@ public inline fun > NonEmptyList.minBy(selector: (A) -> public inline fun > NonEmptyList.maxBy(selector: (A) -> B): A = maxByOrNull(selector)!! +@Suppress("NOTHING_TO_INLINE") public inline fun > NonEmptyList.min(): T = minOrNull()!! +@Suppress("NOTHING_TO_INLINE") public inline fun > NonEmptyList.max(): T = maxOrNull()!! 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 index 05493d03e06..7740e42794f 100644 --- 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 @@ -24,7 +24,7 @@ import kotlin.coroutines.cancellation.CancellationException * else -> "Hello" * } * - * fun main(args: Array) { + * fun main() { * val nonFatal: Either = * //sampleStart * try { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt index e0ba84b2a10..16d501363ae 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt @@ -8,7 +8,6 @@ package arrow.core import arrow.core.Either.Left import arrow.core.Either.Right import arrow.core.raise.RaiseAccumulate -import arrow.core.raise.either import arrow.core.raise.fold import kotlin.experimental.ExperimentalTypeInference @@ -574,7 +573,7 @@ public fun Sequence.salign( * @return a tuple containing Sequence with [Either.Left] and another Sequence with its [Either.Right] values. */ public fun Sequence>.separateEither(): Pair, List> = - fold(listOf() to listOf()) { (lefts, rights), either -> + fold(listOf() to listOf()) { (lefts, rights), either -> when (either) { is Left -> lefts + either.value to rights is Right -> lefts to rights + either.value @@ -637,7 +636,7 @@ public fun Sequence.mapOrAccumulate( * import arrow.core.leftIor * import arrow.core.unalign * - * fun main(args: Array) { + * fun main() { * //sampleStart * val result = sequenceOf(("A" to 1).bothIor(), ("B" to 2).bothIor(), "C".leftIor()).unalign() * //sampleEnd @@ -662,7 +661,7 @@ public fun Sequence>.unalign(): Pair, Sequence> * import arrow.core.leftIor * import arrow.core.unalign * - * fun main(args: Array) { + * fun main() { * //sampleStart * val result = sequenceOf(1, 2, 3).unalign { it.leftIor() } * //sampleEnd @@ -680,7 +679,7 @@ public fun Sequence.unalign(fa: (C) -> Ior): Pair * ```kotlin * import arrow.core.unweave * - * fun main(args: Array) { + * fun main() { * //sampleStart * val result = sequenceOf(1,2,3).unweave { i -> sequenceOf("$i, ${i + 1}") } * //sampleEnd @@ -700,7 +699,7 @@ public fun Sequence.unweave(ffa: (A) -> Sequence): Sequence = * ```kotlin * import arrow.core.unzip * - * fun main(args: Array) { + * fun main() { * //sampleStart * val result = sequenceOf("A" to 1, "B" to 2).unzip() * //sampleEnd @@ -720,7 +719,7 @@ public fun Sequence>.unzip(): Pair, Sequence> = * ```kotlin * import arrow.core.unzip * - * fun main(args: Array) { + * fun main() { * //sampleStart * val result = * sequenceOf("A:1", "B:2", "C:3").unzip { e -> @@ -743,7 +742,7 @@ public fun Sequence.unzip(fc: (C) -> Pair): Pair, * ```kotlin * import arrow.core.widen * - * fun main(args: Array) { + * fun main() { * val original: Sequence = sequenceOf("Hello World") * val result: Sequence = original.widen() * } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt index d4ed66d3b32..4c2bb6977d3 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/map.kt @@ -35,7 +35,7 @@ public fun Map.zip(other: Map): Map> = * * fun test() { * mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) { - * key, a, b -> "$a ~ $b" + * _, a, b -> "$a ~ $b" * } shouldBe mapOf(1 to "A ~ 1", 2 to "B ~ 2") * } * ``` 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 index 5a3c58883a5..12efe514998 100644 --- 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 @@ -17,7 +17,7 @@ package arrow.core * else -> "Hello" * } * - * fun main(args: Array) { + * fun main() { * val nonFatal: Either = * //sampleStart * try { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt index c7171e1793e..e426016dffc 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/predef.kt @@ -1,5 +1,6 @@ package arrow.core +@Suppress("NOTHING_TO_INLINE") public inline fun identity(a: A): A = a /** @@ -14,6 +15,7 @@ internal object EmptyValue { inline fun unbox(value: Any?): A = if (value === this) null as A else value as A + @Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE") public inline fun combine(first: Any?, second: T, combine: (T, T) -> T): T = if (first === EmptyValue) second else combine(first as T, second) } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt index 761822b6196..232f8318627 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Effect.kt @@ -289,8 +289,8 @@ import kotlin.jvm.JvmName * ```kotlin * val default5: Effect = * foreign - * .catch { ex: RuntimeException -> -1 } - * .catch { ex: java.sql.SQLException -> -2 } + * .catch { _: RuntimeException -> -1 } + * .catch { _: java.sql.SQLException -> -2 } * ``` * * Finally, since `catch` also supports `suspend` we can safely call other `suspend` code and throw `Throwable` into the `suspend` system. @@ -456,7 +456,7 @@ import kotlin.jvm.JvmName * effect { * bracketCase( * acquire = { File("build.gradle.kts").bufferedReader() }, - * use = { reader: BufferedReader -> raise(error) }, + * use = { _: BufferedReader -> raise(error) }, * release = { reader, exitCase -> * reader.close() * exit.complete(exitCase) @@ -664,11 +664,13 @@ import kotlin.jvm.JvmName */ public typealias Effect = suspend Raise.() -> A +@Suppress("NOTHING_TO_INLINE") public inline fun effect(@BuilderInference noinline block: suspend Raise.() -> A): Effect = block /** The same behavior and API as [Effect] except without requiring _suspend_. */ public typealias EagerEffect = Raise.() -> A +@Suppress("NOTHING_TO_INLINE") public inline fun eagerEffect(@BuilderInference noinline block: Raise.() -> A): EagerEffect = block public suspend fun Effect.merge(): A = merge { invoke() } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/ErrorHandlers.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/ErrorHandlers.kt index dbca820ca22..fa49119e799 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/ErrorHandlers.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/ErrorHandlers.kt @@ -23,9 +23,9 @@ import kotlin.jvm.JvmName * * val error = effect { raise(Error) } // Raise(error) * - * val a = error.recover { error -> User } // Success(User) - * val b = error.recover { error -> raise("other-failure") } // Raise(other-failure) - * val c = error.recover { error -> throw RuntimeException("BOOM") } // Exception(BOOM) + * val a = error.recover { _ -> User } // Success(User) + * val b = error.recover { _ -> raise("other-failure") } // Raise(other-failure) + * val c = error.recover { _ -> throw RuntimeException("BOOM") } // Exception(BOOM) * ``` * */ @@ -93,7 +93,7 @@ public fun Effect.catch(): Effect> = catch({ Result.success(invoke()) }, Result.Companion::failure) } -public suspend inline infix fun Effect.getOrElse(recover: suspend (error: Error) -> A): A = +public suspend inline infix fun Effect.getOrElse(recover: (error: Error) -> A): A = recover({ invoke() }) { recover(it) } /** @@ -110,9 +110,9 @@ public suspend inline infix fun Effect.getOrElse(recover: s * * val error = effect { raise(Error) } // Raise(error) * - * val a = error.mapError { error -> "some-failure" } // Raise(some-failure) + * val a = error.mapError { _ -> "some-failure" } // Raise(some-failure) * val b = error.mapError(Any::toString) // Raise(Error) - * val c = error.mapError { error -> throw RuntimeException("BOOM") } // Exception(BOOM) + * val c = error.mapError { _ -> throw RuntimeException("BOOM") } // Exception(BOOM) * ``` * */ @@ -147,7 +147,7 @@ public inline infix fun EagerEffect.getOrElse(recover: (err * * val error = eagerEffect { raise(Error) } // Raise(error) * - * val a = error.mapError { error -> "some-failure" } // Raise(some-failure) + * val a = error.mapError { _ -> "some-failure" } // Raise(some-failure) * val b = error.mapError(Any::toString) // Raise(Error) * ``` * diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt index 0bbd1a4b586..3f3617f65ef 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt @@ -264,7 +264,7 @@ public interface Raise { * * either { * val x = one.bind() - * val y = recover({ left.bind() }) { failure : String -> 1 } + * val y = recover({ left.bind() }) { _ : String -> 1 } * x + y * } shouldBe Either.Right(2) * } @@ -325,7 +325,7 @@ public interface Raise { * recover({ raise("failed") }) { str -> str.length } shouldBe 6 * * either { - * recover({ raise("failed") }) { str -> raise(-1) } + * recover({ raise("failed") }) { _ -> raise(-1) } * } shouldBe Either.Left(-1) * } * ``` @@ -421,7 +421,7 @@ public inline fun recover( * --> * ```kotlin * fun test() { - * catch({ throw RuntimeException("BOOM") }) { t -> + * catch({ throw RuntimeException("BOOM") }) { _ -> * "fallback" * } shouldBe "fallback" * @@ -460,7 +460,7 @@ public inline fun catch(block: () -> A, catch: (throwable: Throwable) -> A): * --> * ```kotlin * fun test() { - * catch({ throw RuntimeException("BOOM") }) { t -> + * catch({ throw RuntimeException("BOOM") }) { _ -> * "fallback" * } shouldBe "fallback" * diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt index b6d7af378af..eb4cc8e5176 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-01.kt @@ -9,6 +9,6 @@ object Error val error = effect { raise(Error) } // Raise(error) -val a = error.recover { error -> User } // Success(User) -val b = error.recover { error -> raise("other-failure") } // Raise(other-failure) -val c = error.recover { error -> throw RuntimeException("BOOM") } // Exception(BOOM) +val a = error.recover { _ -> User } // Success(User) +val b = error.recover { _ -> raise("other-failure") } // Raise(other-failure) +val c = error.recover { _ -> throw RuntimeException("BOOM") } // Exception(BOOM) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-04.kt index 97ddc6117d2..72f5b3736e5 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-04.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-04.kt @@ -9,6 +9,6 @@ object Error val error = effect { raise(Error) } // Raise(error) -val a = error.mapError { error -> "some-failure" } // Raise(some-failure) +val a = error.mapError { _ -> "some-failure" } // Raise(some-failure) val b = error.mapError(Any::toString) // Raise(Error) -val c = error.mapError { error -> throw RuntimeException("BOOM") } // Exception(BOOM) +val c = error.mapError { _ -> throw RuntimeException("BOOM") } // Exception(BOOM) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-05.kt index d1fab1d6d94..73fd1a576cf 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-05.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-effect-error-05.kt @@ -9,5 +9,5 @@ object Error val error = eagerEffect { raise(Error) } // Raise(error) -val a = error.mapError { error -> "some-failure" } // Raise(some-failure) +val a = error.mapError { _ -> "some-failure" } // Raise(some-failure) val b = error.mapError(Any::toString) // Raise(Error) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt index c7c4ffdd2e6..c61c582f042 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-map-02.kt @@ -6,6 +6,6 @@ import io.kotest.matchers.shouldBe fun test() { mapOf(1 to "A", 2 to "B").zip(mapOf(1 to "1", 2 to "2", 3 to "3")) { - key, a, b -> "$a ~ $b" + _, a, b -> "$a ~ $b" } shouldBe mapOf(1 to "A ~ 1", 2 to "B ~ 2") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt index 32ebd78ac2e..df6f9a58f15 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatal-01.kt @@ -11,7 +11,7 @@ fun unsafeFunction(i: Int): String = else -> "Hello" } -fun main(args: Array) { +fun main() { val nonFatal: Either = //sampleStart try { diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt index 07bf2372556..56a31b281c2 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-nonfatalorthrow-01.kt @@ -11,7 +11,7 @@ fun unsafeFunction(i: Int): String = else -> "Hello" } -fun main(args: Array) { +fun main() { val nonFatal: Either = //sampleStart try { diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt index 6fa5fe86c21..fe60fd2b1ce 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-04.kt @@ -43,8 +43,8 @@ val default4: Effect = val default5: Effect = foreign - .catch { ex: RuntimeException -> -1 } - .catch { ex: java.sql.SQLException -> -2 } + .catch { _: RuntimeException -> -1 } + .catch { _: java.sql.SQLException -> -2 } suspend fun java.sql.SQLException.isForeignKeyViolation(): Boolean = true diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt index 7f52b2e77e1..73b82b9361f 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-08.kt @@ -18,7 +18,7 @@ suspend fun main() { effect { bracketCase( acquire = { File("build.gradle.kts").bufferedReader() }, - use = { reader: BufferedReader -> raise(error) }, + use = { _: BufferedReader -> raise(error) }, release = { reader, exitCase -> reader.close() exit.complete(exitCase) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt index 83d6ebd0359..6449d5b0c86 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-05.kt @@ -13,7 +13,7 @@ fun test() { either { val x = one.bind() - val y = recover({ left.bind() }) { failure : String -> 1 } + val y = recover({ left.bind() }) { _ : String -> 1 } x + y } shouldBe Either.Right(2) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt index 73ef8a21ede..da5185f1b0e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-06.kt @@ -10,6 +10,6 @@ fun test() { recover({ raise("failed") }) { str -> str.length } shouldBe 6 either { - recover({ raise("failed") }) { str -> raise(-1) } + recover({ raise("failed") }) { _ -> raise(-1) } } shouldBe Either.Left(-1) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt index cbf67703845..3e678e2fb3b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-09.kt @@ -7,7 +7,7 @@ import arrow.core.raise.catch import io.kotest.matchers.shouldBe fun test() { - catch({ throw RuntimeException("BOOM") }) { t -> + catch({ throw RuntimeException("BOOM") }) { _ -> "fallback" } shouldBe "fallback" diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt index 94834cbbb6d..923e84e7c2b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-10.kt @@ -7,7 +7,7 @@ import arrow.core.raise.catch import io.kotest.matchers.shouldBe fun test() { - catch({ throw RuntimeException("BOOM") }) { t -> + catch({ throw RuntimeException("BOOM") }) { _ -> "fallback" } shouldBe "fallback" diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt index 913edd869ce..c8a06580d4b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-11.kt @@ -5,7 +5,7 @@ import arrow.core.bothIor import arrow.core.leftIor import arrow.core.unalign -fun main(args: Array) { +fun main() { //sampleStart val result = sequenceOf(("A" to 1).bothIor(), ("B" to 2).bothIor(), "C".leftIor()).unalign() //sampleEnd diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt index c78a9a358d3..768b3e87ec1 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-12.kt @@ -4,7 +4,7 @@ package arrow.core.examples.exampleSequence12 import arrow.core.leftIor import arrow.core.unalign -fun main(args: Array) { +fun main() { //sampleStart val result = sequenceOf(1, 2, 3).unalign { it.leftIor() } //sampleEnd diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt index 2fe0df59e49..45cc0c7710b 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-13.kt @@ -3,7 +3,7 @@ package arrow.core.examples.exampleSequence13 import arrow.core.unweave -fun main(args: Array) { +fun main() { //sampleStart val result = sequenceOf(1,2,3).unweave { i -> sequenceOf("$i, ${i + 1}") } //sampleEnd diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt index a2a90952121..835b67cdb14 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-14.kt @@ -3,7 +3,7 @@ package arrow.core.examples.exampleSequence14 import arrow.core.unzip -fun main(args: Array) { +fun main() { //sampleStart val result = sequenceOf("A" to 1, "B" to 2).unzip() //sampleEnd diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt index b0b55bba261..e45890c3984 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-15.kt @@ -3,7 +3,7 @@ package arrow.core.examples.exampleSequence15 import arrow.core.unzip -fun main(args: Array) { +fun main() { //sampleStart val result = sequenceOf("A:1", "B:2", "C:3").unzip { e -> diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt index f85ad833147..8eed0fd16b7 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt @@ -3,7 +3,7 @@ package arrow.core.examples.exampleSequence16 import arrow.core.widen -fun main(args: Array) { +fun main() { val original: Sequence = sequenceOf("Hello World") val result: Sequence = original.widen() } diff --git a/arrow-libs/core/arrow-functions/build.gradle.kts b/arrow-libs/core/arrow-functions/build.gradle.kts index 3a20ee1e556..748b9680ca8 100644 --- a/arrow-libs/core/arrow-functions/build.gradle.kts +++ b/arrow-libs/core/arrow-functions/build.gradle.kts @@ -46,6 +46,6 @@ kotlin { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt index 2c99471e987..ffbd512fc05 100644 --- a/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/MemoizationTest.kt @@ -1,3 +1,5 @@ +@file:Suppress("UNUSED_PARAMETER") + package arrow.core import io.kotest.property.checkAll diff --git a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts index dd17fa7f888..884445b8ca9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts @@ -47,6 +47,6 @@ kotlin { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt index 3ad336a3b8a..983dc48e558 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt @@ -31,6 +31,7 @@ public sealed class ExitCase { * @see guarantee for registering a handler that is guaranteed to always run. * @see guaranteeCase for registering a handler that executes for any [ExitCase]. */ +@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") public suspend inline fun onCancel( fa: suspend () -> A, crossinline onCancel: suspend () -> Unit @@ -54,6 +55,7 @@ public suspend inline fun onCancel( * @param finalizer handler to run after [fa]. * @see guaranteeCase for registering a handler that tracks the [ExitCase] of [fa]. */ +@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") public suspend inline fun guarantee( fa: suspend () -> A, crossinline finalizer: suspend () -> Unit @@ -83,6 +85,7 @@ public suspend inline fun guarantee( * @param finalizer handler to run after [fa]. * @see guarantee for registering a handler that ignores the [ExitCase] of [fa]. */ +@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") public suspend inline fun guaranteeCase( fa: suspend () -> A, crossinline finalizer: suspend (ExitCase) -> Unit @@ -115,10 +118,10 @@ public suspend inline fun guaranteeCase( * ```kotlin * import arrow.fx.coroutines.* * - * class File(url: String) { + * class File(val url: String) { * fun open(): File = this * fun close(): Unit {} - * override fun toString(): String = "This file contains some interesting content!" + * override fun toString(): String = "This file contains some interesting content from $url!" * } * * suspend fun openFile(uri: String): File = File(uri).open() @@ -138,6 +141,7 @@ public suspend inline fun guaranteeCase( * ``` * */ +@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") public suspend inline fun bracket( crossinline acquire: suspend () -> A, use: suspend (A) -> B, @@ -191,13 +195,13 @@ public suspend inline fun bracket( * ```kotlin * import arrow.fx.coroutines.* * - * class File(url: String) { + * class File(val url: String) { * fun open(): File = this * fun close(): Unit {} * } * * suspend fun File.content(): String = - * "This file contains some interesting content!" + * "This file contains some interesting content from $url!" * suspend fun openFile(uri: String): File = File(uri).open() * suspend fun closeFile(file: File): Unit = file.close() * @@ -221,6 +225,7 @@ public suspend inline fun bracket( * ``` * */ +@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") public suspend inline fun bracketCase( crossinline acquire: suspend () -> A, use: suspend (A) -> B, diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt index aef614128b9..46a86a257bc 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt @@ -1,3 +1,5 @@ +@file:Suppress("UNCHECKED_CAST") + package arrow.fx.coroutines import kotlinx.coroutines.CoroutineScope diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZipOrAccumulate.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZipOrAccumulate.kt index 08e17606308..3a7ea2104b7 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZipOrAccumulate.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZipOrAccumulate.kt @@ -14,44 +14,44 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline combine: (E, E) -> E, crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, - crossinline f: suspend CoroutineScope.(A, B) -> C + crossinline transform: suspend CoroutineScope.(A, B) -> C ): C = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, crossinline combine: (E, E) -> E, crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, - crossinline f: suspend CoroutineScope.(A, B) -> C + crossinline transform: suspend CoroutineScope.(A, B) -> C ): C = parZip( context, { either { fa(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fb(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b -> - Either.zipOrAccumulate(a, b) { aa, bb -> f(aa, bb) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b) { aa, bb -> transform(aa, bb) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, - crossinline f: suspend CoroutineScope.(A, B) -> C + crossinline transform: suspend CoroutineScope.(A, B) -> C ): C = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, - crossinline f: suspend CoroutineScope.(A, B) -> C + crossinline transform: suspend CoroutineScope.(A, B) -> C ): C = parZip( context, { either { fa(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fb(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b -> - Either.zipOrAccumulate(a, b) { aa, bb -> f(aa, bb) }.bind() + Either.zipOrAccumulate(a, b) { aa, bb -> transform(aa, bb) }.bind() } //endregion @@ -61,9 +61,9 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, - crossinline f: suspend CoroutineScope.(A, B, C) -> D + crossinline transform: suspend CoroutineScope.(A, B, C) -> D ): D = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, @@ -71,7 +71,7 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, - crossinline f: suspend CoroutineScope.(A, B, C) -> D + crossinline transform: suspend CoroutineScope.(A, B, C) -> D ): D = parZip( context, @@ -79,23 +79,23 @@ public suspend inline fun Raise.parZipOrAccumulate( { either { fb(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fc(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c -> - Either.zipOrAccumulate(a, b, c) { aa, bb, cc -> f(aa, bb, cc) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b, c) { aa, bb, cc -> transform(aa, bb, cc) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, - crossinline f: suspend CoroutineScope.(A, B, C) -> D + crossinline transform: suspend CoroutineScope.(A, B, C) -> D ): D = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, crossinline fa: suspend ScopedRaiseAccumulate.() -> A, crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, - crossinline f: suspend CoroutineScope.(A, B, C) -> D + crossinline transform: suspend CoroutineScope.(A, B, C) -> D ): D = parZip( context, @@ -103,7 +103,7 @@ public suspend inline fun Raise>.parZipOrAccumul { either { fb(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fc(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c -> - Either.zipOrAccumulate(a, b, c) { aa, bb, cc -> f(aa, bb, cc) }.bind() + Either.zipOrAccumulate(a, b, c) { aa, bb, cc -> transform(aa, bb, cc) }.bind() } //endregion @@ -114,9 +114,9 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, - crossinline f: suspend CoroutineScope.(A, B, C, D) -> F + crossinline transform: suspend CoroutineScope.(A, B, C, D) -> F ): F = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, @@ -125,7 +125,7 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, - crossinline f: suspend CoroutineScope.(A, B, C, D) -> F + crossinline transform: suspend CoroutineScope.(A, B, C, D) -> F ): F = parZip( context, @@ -134,7 +134,7 @@ public suspend inline fun Raise.parZipOrAccumulate( { either { fc(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fd(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d -> - Either.zipOrAccumulate(a, b, c, d) { aa, bb, cc, dd -> f(aa, bb, cc, dd) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b, c, d) { aa, bb, cc, dd -> transform(aa, bb, cc, dd) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( @@ -142,9 +142,9 @@ public suspend inline fun Raise>.parZipOrAccu crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, - crossinline f: suspend CoroutineScope.(A, B, C, D) -> F + crossinline transform: suspend CoroutineScope.(A, B, C, D) -> F ): F = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, @@ -152,7 +152,7 @@ public suspend inline fun Raise>.parZipOrAccu crossinline fb: suspend ScopedRaiseAccumulate.() -> B, crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, - crossinline f: suspend CoroutineScope.(A, B, C, D) -> F + crossinline transform: suspend CoroutineScope.(A, B, C, D) -> F ): F = parZip( context, @@ -161,7 +161,7 @@ public suspend inline fun Raise>.parZipOrAccu { either { fc(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fd(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d -> - Either.zipOrAccumulate(a, b, c, d) { aa, bb, cc, dd -> f(aa, bb, cc, dd) }.bind() + Either.zipOrAccumulate(a, b, c, d) { aa, bb, cc, dd -> transform(aa, bb, cc, dd) }.bind() } //endregion @@ -173,9 +173,9 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, - crossinline f: suspend CoroutineScope.(A, B, C, D, F) -> G + crossinline transform: suspend CoroutineScope.(A, B, C, D, F) -> G ): G = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, @@ -185,7 +185,7 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, - crossinline f: suspend CoroutineScope.(A, B, C, D, F) -> G + crossinline transform: suspend CoroutineScope.(A, B, C, D, F) -> G ): G = parZip( context, @@ -195,7 +195,7 @@ public suspend inline fun Raise.parZipOrAccumulate( { either { fd(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { ff(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f -> - Either.zipOrAccumulate(a, b, c, d, f) { aa, bb, cc, dd, ff -> f(aa, bb, cc, dd, ff) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b, c, d, f) { aa, bb, cc, dd, ff -> transform(aa, bb, cc, dd, ff) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( @@ -204,9 +204,9 @@ public suspend inline fun Raise>.parZipOrA crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, - crossinline f: suspend CoroutineScope.(A, B, C, D, F) -> G + crossinline transform: suspend CoroutineScope.(A, B, C, D, F) -> G ): G = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, @@ -215,7 +215,7 @@ public suspend inline fun Raise>.parZipOrA crossinline fc: suspend ScopedRaiseAccumulate.() -> C, crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, - crossinline f: suspend CoroutineScope.(A, B, C, D, F) -> G + crossinline transform: suspend CoroutineScope.(A, B, C, D, F) -> G ): G = parZip( context, @@ -225,7 +225,7 @@ public suspend inline fun Raise>.parZipOrA { either { fd(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { ff(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f -> - Either.zipOrAccumulate(a, b, c, d, f) { aa, bb, cc, dd, ff -> f(aa, bb, cc, dd, ff) }.bind() + Either.zipOrAccumulate(a, b, c, d, f) { aa, bb, cc, dd, ff -> transform(aa, bb, cc, dd, ff) }.bind() } //endregion @@ -238,9 +238,9 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G) -> H + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G) -> H ): H = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, @@ -251,7 +251,7 @@ public suspend inline fun Raise.parZipOrAccumulate( crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G) -> H + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G) -> H ): H = parZip( context, @@ -262,7 +262,7 @@ public suspend inline fun Raise.parZipOrAccumulate( { either { ff(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fg(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f, g -> - Either.zipOrAccumulate(a, b, c, d, f, g) { aa, bb, cc, dd, ff, gg -> f(aa, bb, cc, dd, ff, gg) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b, c, d, f, g) { aa, bb, cc, dd, ff, gg -> transform(aa, bb, cc, dd, ff, gg) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( @@ -272,9 +272,9 @@ public suspend inline fun Raise>.parZip crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G) -> H + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G) -> H ): H = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, @@ -284,7 +284,7 @@ public suspend inline fun Raise>.parZip crossinline fd: suspend ScopedRaiseAccumulate.() -> D, crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G) -> H + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G) -> H ): H = parZip( context, @@ -295,7 +295,7 @@ public suspend inline fun Raise>.parZip { either { ff(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fg(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f, g -> - Either.zipOrAccumulate(a, b, c, d, f, g) { aa, bb, cc, dd, ff, gg -> f(aa, bb, cc, dd, ff, gg) }.bind() + Either.zipOrAccumulate(a, b, c, d, f, g) { aa, bb, cc, dd, ff, gg -> transform(aa, bb, cc, dd, ff, gg) }.bind() } //endregion @@ -309,9 +309,9 @@ public suspend inline fun Raise.parZipOrAccumulat crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I ): I = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, fh, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, fh, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, @@ -323,7 +323,7 @@ public suspend inline fun Raise.parZipOrAccumulat crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I ): I = parZip( context, @@ -335,7 +335,7 @@ public suspend inline fun Raise.parZipOrAccumulat { either { fg(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fh(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f, g, h -> - Either.zipOrAccumulate(a, b, c, d, f, g, h) { aa, bb, cc, dd, ff, gg, hh -> f(aa, bb, cc, dd, ff, gg, hh) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b, c, d, f, g, h) { aa, bb, cc, dd, ff, gg, hh -> transform(aa, bb, cc, dd, ff, gg, hh) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( @@ -346,9 +346,9 @@ public suspend inline fun Raise>.par crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I ): I = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, fh, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, fh, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, @@ -359,7 +359,7 @@ public suspend inline fun Raise>.par crossinline ff: suspend ScopedRaiseAccumulate.() -> F, crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H) -> I ): I = parZip( context, @@ -371,7 +371,7 @@ public suspend inline fun Raise>.par { either { fg(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fh(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f, g, h -> - Either.zipOrAccumulate(a, b, c, d, f, g, h) { aa, bb, cc, dd, ff, gg, hh -> f(aa, bb, cc, dd, ff, gg, hh) }.bind() + Either.zipOrAccumulate(a, b, c, d, f, g, h) { aa, bb, cc, dd, ff, gg, hh -> transform(aa, bb, cc, dd, ff, gg, hh) }.bind() } //endregion @@ -386,9 +386,9 @@ public suspend inline fun Raise.parZipOrAccumu crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J ): J = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, fh, fi, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, fh, fi, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, @@ -401,7 +401,7 @@ public suspend inline fun Raise.parZipOrAccumu crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J ): J = parZip( context, @@ -414,7 +414,7 @@ public suspend inline fun Raise.parZipOrAccumu { either { fh(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fi(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f, g, h, i -> - Either.zipOrAccumulate(a, b, c, d, f, g, h, i) { aa, bb, cc, dd, ff, gg, hh, ii -> f(aa, bb, cc, dd, ff, gg, hh, ii) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b, c, d, f, g, h, i) { aa, bb, cc, dd, ff, gg, hh, ii -> transform(aa, bb, cc, dd, ff, gg, hh, ii) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( @@ -426,9 +426,9 @@ public suspend inline fun Raise>. crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J ): J = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, fh, fi, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, fh, fi, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, @@ -440,7 +440,7 @@ public suspend inline fun Raise>. crossinline fg: suspend ScopedRaiseAccumulate.() -> G, crossinline fh: suspend ScopedRaiseAccumulate.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I) -> J ): J = parZip( context, @@ -453,7 +453,7 @@ public suspend inline fun Raise>. { either { fh(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fi(ScopedRaiseAccumulate(this, this@parZip)) } }, ) { a, b, c, d, f, g, h, i -> - Either.zipOrAccumulate(a, b, c, d, f, g, h, i) { aa, bb, cc, dd, ff, gg, hh, ii -> f(aa, bb, cc, dd, ff, gg, hh, ii) }.bind() + Either.zipOrAccumulate(a, b, c, d, f, g, h, i) { aa, bb, cc, dd, ff, gg, hh, ii -> transform(aa, bb, cc, dd, ff, gg, hh, ii) }.bind() } //endregion @@ -469,9 +469,9 @@ public suspend inline fun Raise.parZipOrAcc crossinline fh: suspend ScopedRaiseAccumulate.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, crossinline fj: suspend ScopedRaiseAccumulate.() -> J, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K ): K = - parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, fh, fi, fj, f) + parZipOrAccumulate(EmptyCoroutineContext, combine, fa, fb, fc, fd, ff, fg, fh, fi, fj, transform) public suspend inline fun Raise.parZipOrAccumulate( context: CoroutineContext, @@ -485,7 +485,7 @@ public suspend inline fun Raise.parZipOrAcc crossinline fh: suspend ScopedRaiseAccumulate.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, crossinline fj: suspend ScopedRaiseAccumulate.() -> J, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K ): K = parZip( context, @@ -499,7 +499,7 @@ public suspend inline fun Raise.parZipOrAcc { either { fi(ScopedRaiseAccumulate(this, this@parZip)) } }, { either { fj(ScopedRaiseAccumulate(this, this@parZip)) } } ) { a, b, c, d, f, g, h, i, j -> - Either.zipOrAccumulate(a, b, c, d, f, g, h, i, j) { aa, bb, cc, dd, ff, gg, hh, ii, jj -> f(aa, bb, cc, dd, ff, gg, hh, ii, jj) }.getOrElse { raise(it.reduce(combine)) } + Either.zipOrAccumulate(a, b, c, d, f, g, h, i, j) { aa, bb, cc, dd, ff, gg, hh, ii, jj -> transform(aa, bb, cc, dd, ff, gg, hh, ii, jj) }.getOrElse { raise(it.reduce(combine)) } } public suspend inline fun Raise>.parZipOrAccumulate( @@ -512,9 +512,9 @@ public suspend inline fun Raise.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, crossinline fj: suspend ScopedRaiseAccumulate.() -> J, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K ): K = - parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, fh, fi, fj, f) + parZipOrAccumulate(EmptyCoroutineContext, fa, fb, fc, fd, ff, fg, fh, fi, fj, transform) public suspend inline fun Raise>.parZipOrAccumulate( context: CoroutineContext, @@ -527,7 +527,7 @@ public suspend inline fun Raise.() -> H, crossinline fi: suspend ScopedRaiseAccumulate.() -> I, crossinline fj: suspend ScopedRaiseAccumulate.() -> J, - crossinline f: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K + crossinline transform: suspend CoroutineScope.(A, B, C, D, F, G, H, I, J) -> K ): K = parZip( context, @@ -541,6 +541,6 @@ public suspend inline fun Raise - Either.zipOrAccumulate(a, b, c, d, f, g, h, i, j) { aa, bb, cc, dd, ff, gg, hh, ii, jj -> f(aa, bb, cc, dd, ff, gg, hh, ii, jj) }.bind() + Either.zipOrAccumulate(a, b, c, d, f, g, h, i, j) { aa, bb, cc, dd, ff, gg, hh, ii, jj -> transform(aa, bb, cc, dd, ff, gg, hh, ii, jj) }.bind() } //endregion diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt index 42202887750..64cbc6769b1 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt @@ -140,7 +140,7 @@ class CyclicBarrierSpec { val jobs = (0 until n - 1).map { i -> launch(start = CoroutineStart.UNDISPATCHED) { - guaranteeCase(barrier::await, exits[i]::complete) + guaranteeCase({ barrier.await() }, exits[i]::complete) } } 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 index 887dc41a809..b36b6e8bf3e 100644 --- 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 @@ -4,6 +4,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExecutorCoroutineDispatcher +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.newFixedThreadPoolContext import kotlinx.coroutines.newSingleThreadContext @@ -151,7 +152,7 @@ public fun autoCloseable( * ``` * */ -@OptIn(DelicateCoroutinesApi::class) +@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class) @ResourceDSL public suspend fun ResourceScope.singleThreadContext(name: String): ExecutorCoroutineDispatcher = closeable { newSingleThreadContext(name) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt index ecec44ced00..5ccc4eeb503 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-01.kt @@ -3,10 +3,10 @@ package arrow.fx.coroutines.examples.exampleBracket01 import arrow.fx.coroutines.* -class File(url: String) { +class File(val url: String) { fun open(): File = this fun close(): Unit {} - override fun toString(): String = "This file contains some interesting content!" + override fun toString(): String = "This file contains some interesting content from $url!" } suspend fun openFile(uri: String): File = File(uri).open() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt index dfa4131c13e..d16d7ca953d 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/examples/example-bracket-02.kt @@ -3,13 +3,13 @@ package arrow.fx.coroutines.examples.exampleBracket02 import arrow.fx.coroutines.* -class File(url: String) { +class File(val url: String) { fun open(): File = this fun close(): Unit {} } suspend fun File.content(): String = - "This file contains some interesting content!" + "This file contains some interesting content from $url!" suspend fun openFile(uri: String): File = File(uri).open() suspend fun closeFile(file: File): Unit = file.close() diff --git a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts index 22f7eff35a7..a44b7d98dbf 100644 --- a/arrow-libs/fx/arrow-fx-stm/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-stm/build.gradle.kts @@ -1,5 +1,8 @@ @file:Suppress("DSL_SCOPE_VIOLATION") +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + + plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) @@ -45,6 +48,10 @@ kotlin { } } -tasks.withType { +tasks.withType().configureEach { + kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes" +} + +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt index 895be245622..95a93ae33c2 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt @@ -250,7 +250,7 @@ public interface STM { * suspend fun main() { * //sampleStart * val result = atomically { - * catch({ throw Throwable() }) { e -> "caught" } + * catch({ throw Throwable() }) { _ -> "caught" } * } * //sampleEnd * println("Result $result") @@ -1202,6 +1202,7 @@ public interface STM { * tarr.transform { it + 1 } * } * //sampleEnd + * println("Result $result") * } * ``` * @@ -1538,6 +1539,7 @@ public interface STM { * * Equal to [suspend] just with an [STM] receiver. */ +@Suppress("NOTHING_TO_INLINE") public inline fun stm(noinline f: STM.() -> A): STM.() -> A = f /** diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TArray.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TArray.kt index 0aa446ecd67..5cb8024f3bc 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TArray.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TArray.kt @@ -86,6 +86,7 @@ public fun STM.newTArray(xs: Iterable): TArray = * tarr.transform { it + 1 } * } * //sampleEnd + * println("Result $result") * } * ``` * diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt index f1ced7f5779..195c6b9f99e 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt @@ -166,6 +166,7 @@ public class TVar internal constructor(a: A) { * Internal unsafe (non-suspend) version of read. Used by various other internals and [unsafeRead] to * read the current value respecting its state. */ + @Suppress("UNCHECKED_CAST") internal fun readI(): A { while (true) { ref.value.let { a -> diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Hamt.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Hamt.kt index 7ee918fdc38..d045ed617f3 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Hamt.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Hamt.kt @@ -1,3 +1,5 @@ +@file:Suppress("UNCHECKED_CAST") + package arrow.fx.stm.internal import arrow.fx.stm.TVar @@ -22,7 +24,7 @@ public inline fun STM.lookupHamtWithHash(hmt: Hamt, hash: Int, test: (A) val branches = hamt.branches.read() when (val branch = branches[branchInd]) { null -> return null - is Branch.Leaf -> return@lookupHamtWithHash (branch.value as Array).find(test) + is Branch.Leaf -> return (branch.value as Array).find(test) is Branch.Branches -> { depth = depth.nextDepth() hamt = branch.sub diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt index dce1120b864..211d58b8041 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt @@ -1,3 +1,5 @@ +@file:Suppress("UNCHECKED_CAST") + package arrow.fx.stm.internal import arrow.atomic.Atomic @@ -11,17 +13,17 @@ import kotlin.coroutines.Continuation * A STMFrame keeps the reads and writes performed by a transaction. * It may have a parent which is only used for read lookups. */ -internal class STMFrame(val parent: STMFrame? = null) : STM { +internal class STMFrame(private val parent: STMFrame? = null) : STM { class Entry(var initialVal: Any?, var newVal: Any?) { - object NO_CHANGE - object NOT_PRESENT + object NoChange + object NotPresent fun isWrite(): Boolean = - newVal !== NO_CHANGE + newVal !== NoChange - fun update(v: Any?): Unit { - newVal = if (initialVal === v) NO_CHANGE else v + fun update(v: Any?) { + newVal = if (initialVal === v) NoChange else v } fun getValue(): Any? = if (isWrite()) newVal else initialVal @@ -32,8 +34,8 @@ internal class STMFrame(val parent: STMFrame? = null) : STM { /** * Helper to search the entire hierarchy for stored previous reads */ - private fun readVar(v: TVar): Any? = - accessMap[v]?.getValue() ?: parent?.readVar(v) ?: Entry.NOT_PRESENT + private fun readVar(v: TVar): Any = + accessMap[v]?.getValue() ?: parent?.readVar(v) ?: Entry.NotPresent override fun retry(): Nothing = throw RetryException @@ -57,18 +59,18 @@ internal class STMFrame(val parent: STMFrame? = null) : STM { // If we are already invalid here there is no point in continuing. if (frame.validate()) { this@STMFrame.merge(frame) - return@runLocal res as A + return res } } catch (ignored: RetryException) { if (frame.validate()) { this@STMFrame.mergeReads(frame) - return@runLocal onRetry() + return onRetry() } } catch (e: Throwable) { // An invalid frame retries even if it throws, so our sub-frame also needs to handle this correctly if (frame.validate()) { this@STMFrame.mergeReads(frame) - return@runLocal onError(e) + return onError(e) } } } @@ -79,7 +81,7 @@ internal class STMFrame(val parent: STMFrame? = null) : STM { */ override fun TVar.read(): A = when (val r = readVar(this as TVar)) { - Entry.NOT_PRESENT -> readI().also { accessMap[this] = Entry(it, Entry.NO_CHANGE) } + Entry.NotPresent -> readI().also { accessMap[this] = Entry(it, Entry.NoChange) } else -> r as A } @@ -140,11 +142,11 @@ internal class STMFrame(val parent: STMFrame? = null) : STM { return true } - private fun mergeReads(other: STMFrame): Unit { + private fun mergeReads(other: STMFrame) { accessMap.putAll(other.accessMap.filter { (_, e) -> e.isWrite().not() }) } - private fun merge(other: STMFrame): Unit { + private fun merge(other: STMFrame) { accessMap.putAll(other.accessMap) } } @@ -184,12 +186,12 @@ internal class STMTransaction(val f: STM.() -> A) { try { val res = frame.f() - if (frame.validateAndCommit()) return@commit res + if (frame.validateAndCommit()) return res } catch (ignored: RetryException) { if (frame.accessMap.isEmpty()) throw BlockedIndefinitely() val registered = mutableListOf>() - suspendCancellableCoroutine susp@{ k -> + suspendCancellableCoroutine susp@{ k -> cont.value = k frame.accessMap diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-06.kt b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-06.kt index 8c59628188e..fdd248d9144 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-06.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-06.kt @@ -6,7 +6,7 @@ import arrow.fx.stm.atomically suspend fun main() { //sampleStart val result = atomically { - catch({ throw Throwable() }) { e -> "caught" } + catch({ throw Throwable() }) { _ -> "caught" } } //sampleEnd println("Result $result") diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-41.kt b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-41.kt index 1f2ef07826f..6402fe8de66 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-41.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-41.kt @@ -11,4 +11,5 @@ suspend fun main() { tarr.transform { it + 1 } } //sampleEnd + println("Result $result") } diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-tarray-04.kt b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-tarray-04.kt index 5af06152e32..6e2bb9b5e56 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-tarray-04.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-tarray-04.kt @@ -11,4 +11,5 @@ suspend fun main() { tarr.transform { it + 1 } } //sampleEnd + println("Result $result") } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts b/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts index cff4ecbb9e3..fc49da7d902 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts @@ -44,7 +44,7 @@ dependencies { testRuntimeOnly(projects.arrowOptics) } -tasks.withType { +tasks.withType().configureEach { maxParallelForks = 1 useJUnitPlatform() } diff --git a/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts b/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts index 202c9d680e7..34c9a211738 100644 --- a/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-reflect/build.gradle.kts @@ -36,6 +36,6 @@ tasks.jar { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/optics/arrow-optics/build.gradle.kts b/arrow-libs/optics/arrow-optics/build.gradle.kts index e7a2843075a..04f76a9e3e5 100644 --- a/arrow-libs/optics/arrow-optics/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics/build.gradle.kts @@ -61,6 +61,6 @@ kotlin { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt index 2557601ed5c..068f82cd1e2 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt @@ -38,10 +38,10 @@ public fun Optional(getOption: (source: S) -> Option, set: (source: S, * } * } * - * fun main(args: Array) { + * fun main() { * val original = User("arrow-user", None) * val set = User.email.set(original, "arRoW-UsEr@arrow-Kt.IO") - * val modified = User.email.modify(set, String::toLowerCase) + * val modified = User.email.modify(set, String::lowercase) * println("original: $original, set: $set, modified: $modified") * } * ``` diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt index 56a97dd0d4a..dd37b22dd59 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt @@ -195,11 +195,11 @@ public interface PTraversal { set: (B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = - combine(f(get1(s)), f(get2(s))) + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + combine(map(get1(source)), map(get2(source))) - override fun modify(s: S, transform: (focus: A) -> B): T = - set(transform(get1(s)), transform(get2(s)), s) + override fun modify(source: S, map: (focus: A) -> B): T = + set(map(get1(source)), map(get2(source)), source) } public operator fun invoke( @@ -209,11 +209,11 @@ public interface PTraversal { set: (B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = - combine(combine(f(get1(s)), f(get2(s))), f(get3(s))) + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + combine(combine(map(get1(source)), map(get2(source))), map(get3(source))) - override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), s) + override fun modify(source: S, map: (focus: A) -> B): T = + set(map(get1(source)), map(get2(source)), map(get3(source)), source) } public operator fun invoke( @@ -224,11 +224,11 @@ public interface PTraversal { set: (B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = - combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get4(s))) + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + combine(combine(combine(map(get1(source)), map(get2(source))), map(get3(source))), map(get4(source))) - override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), s) + override fun modify(source: S, map: (focus: A) -> B): T = + set(map(get1(source)), map(get2(source)), map(get3(source)), map(get4(source)), source) } public operator fun invoke( @@ -240,11 +240,11 @@ public interface PTraversal { set: (B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = - combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))) + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + combine(combine(combine(map(get1(source)), map(get2(source))), map(get3(source))), map(get5(source))) - override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), s) + override fun modify(source: S, map: (focus: A) -> B): T = + set(map(get1(source)), map(get2(source)), map(get3(source)), map(get4(source)), map(get5(source)), source) } public operator fun invoke( @@ -257,11 +257,11 @@ public interface PTraversal { set: (B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = - combine(combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), f(get6(s))) + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = + combine(combine(combine(combine(map(get1(source)), map(get2(source))), map(get3(source))), map(get5(source))), map(get6(source))) - override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), s) + override fun modify(source: S, map: (focus: A) -> B): T = + set(map(get1(source)), map(get2(source)), map(get3(source)), map(get4(source)), map(get5(source)), map(get6(source)), source) } public operator fun invoke( @@ -275,14 +275,14 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = combine( - combine(combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), f(get6(s))), - f(get7(s)) + combine(combine(combine(combine(map(get1(source)), map(get2(source))), map(get3(source))), map(get5(source))), map(get6(source))), + map(get7(source)) ) - override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), s) + override fun modify(source: S, map: (focus: A) -> B): T = + set(map(get1(source)), map(get2(source)), map(get3(source)), map(get4(source)), map(get5(source)), map(get6(source)), map(get7(source)), source) } public operator fun invoke( @@ -297,18 +297,18 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = combine( combine( combine( - combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), - f(get6(s)) - ), f(get7(s)) - ), f(get8(s)) + combine(combine(combine(map(get1(source)), map(get2(source))), map(get3(source))), map(get5(source))), + map(get6(source)) + ), map(get7(source)) + ), map(get8(source)) ) - override fun modify(s: S, f: (focus: A) -> B): T = - set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), s) + override fun modify(source: S, map: (focus: A) -> B): T = + set(map(get1(source)), map(get2(source)), map(get3(source)), map(get4(source)), map(get5(source)), map(get6(source)), map(get7(source)), map(get8(source)), source) } public operator fun invoke( @@ -324,30 +324,30 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = combine( combine( combine( combine( - combine(combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), f(get5(s))), - f(get6(s)) - ), f(get7(s)) - ), f(get8(s)) - ), f(get9(s)) + combine(combine(combine(map(get1(source)), map(get2(source))), map(get3(source))), map(get5(source))), + map(get6(source)) + ), map(get7(source)) + ), map(get8(source)) + ), map(get9(source)) ) - override fun modify(s: S, f: (focus: A) -> B): T = + override fun modify(source: S, map: (focus: A) -> B): T = set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - f(get9(s)), - s + map(get1(source)), + map(get2(source)), + map(get3(source)), + map(get4(source)), + map(get5(source)), + map(get6(source)), + map(get7(source)), + map(get8(source)), + map(get9(source)), + source ) } @@ -365,35 +365,35 @@ public interface PTraversal { set: (B, B, B, B, B, B, B, B, B, B, S) -> T ): PTraversal = object : PTraversal { - override fun foldMap(initial: R, combine: (R, R) -> R, s: S, f: (focus: A) -> R): R = + override fun foldMap(initial: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R = combine( combine( combine( combine( combine( combine( - combine(combine(f(get1(s)), f(get2(s))), f(get3(s))), - f(get5(s)) - ), f(get6(s)) - ), f(get7(s)) - ), f(get8(s)) - ), f(get9(s)) - ), f(get10(s)) + combine(combine(map(get1(source)), map(get2(source))), map(get3(source))), + map(get5(source)) + ), map(get6(source)) + ), map(get7(source)) + ), map(get8(source)) + ), map(get9(source)) + ), map(get10(source)) ) - override fun modify(s: S, f: (focus: A) -> B): T = + override fun modify(source: S, map: (focus: A) -> B): T = set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - f(get9(s)), - f(get10(s)), - s + map(get1(source)), + map(get2(source)), + map(get3(source)), + map(get4(source)), + map(get5(source)), + map(get6(source)), + map(get7(source)), + map(get8(source)), + map(get9(source)), + map(get10(source)), + source ) } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt index 12164872f23..1887aec247b 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt @@ -2,7 +2,7 @@ package arrow.optics @Suppress("ClassName") internal object EMPTY_VALUE { - @Suppress("UNCHECKED_CAST") + @Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE") inline fun unbox(value: Any?): T = if (value === this) null as T else value as T } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt index f9d299003a7..5cd0e6feab2 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt @@ -15,9 +15,9 @@ data class User(val username: String, val email: Option) { } } -fun main(args: Array) { +fun main() { val original = User("arrow-user", None) val set = User.email.set(original, "arRoW-UsEr@arrow-Kt.IO") - val modified = User.email.modify(set, String::toLowerCase) + val modified = User.email.modify(set, String::lowercase) println("original: $original, set: $set, modified: $modified") } diff --git a/arrow-libs/resilience/arrow-resilience/build.gradle.kts b/arrow-libs/resilience/arrow-resilience/build.gradle.kts index 4517c8504a9..678b74b3a37 100644 --- a/arrow-libs/resilience/arrow-resilience/build.gradle.kts +++ b/arrow-libs/resilience/arrow-resilience/build.gradle.kts @@ -41,6 +41,6 @@ kotlin { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } diff --git a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt index c4a427b5927..c38831bdd0a 100644 --- a/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt +++ b/arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Saga.kt @@ -84,6 +84,7 @@ public interface SagaScope { * By doing so we can guarantee that any transactional like operations made by the [Saga] will * guarantee that it results in the correct state. */ +@Suppress("NOTHING_TO_INLINE") public inline fun saga(noinline block: suspend SagaScope.() -> A): Saga = block /** Create a lazy [Saga] that will only run when the [Saga] is invoked. */ diff --git a/arrow-libs/stack/build.gradle.kts b/arrow-libs/stack/build.gradle.kts index 4ef59eb748a..e1d70965c07 100644 --- a/arrow-libs/stack/build.gradle.kts +++ b/arrow-libs/stack/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { api("io.arrow-kt:arrow-core:$version") api("io.arrow-kt:arrow-functions:$version") api("io.arrow-kt:arrow-core-retrofit:$version") + api("io.arrow-kt:arrow-core-serialization:$version") api("io.arrow-kt:arrow-fx-coroutines:$version") api("io.arrow-kt:arrow-fx-stm:$version") api("io.arrow-kt:arrow-resilience:$version") From ad9484009209659f8e3adb6ae7fbeccb773555be Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 9 Nov 2023 12:06:53 +0100 Subject: [PATCH 100/114] Finish transition to `kotlin.test` of `retrofit` and `fx-coroutines` (#3291) --- .github/workflows/publish.yml | 2 +- .github/workflows/pull_request.yml | 20 +- .../core/arrow-core-retrofit/build.gradle.kts | 2 - .../NetworkEitherCallAdapterTest.kt | 133 ++++++++-- .../kotlin/arrow/core/NonEmptyListTest.kt | 2 +- .../kotlin/arrow/core/raise/EffectSpec.kt | 24 +- .../fx/arrow-fx-coroutines/build.gradle.kts | 24 +- .../fx/coroutines/DeprecationWarnings.kt | 4 - .../arrow/fx/coroutines/CountDownLatchSpec.kt | 8 +- .../arrow/fx/coroutines/CyclicBarrierSpec.kt | 10 +- .../kotlin/arrow/fx/coroutines/FlowTest.kt | 127 +++++----- .../kotlin/arrow/fx/coroutines/Generators.kt | 2 +- .../arrow/fx/coroutines/KotestConfig.kt | 10 - .../kotlin/arrow/fx/coroutines/ParMapTest.kt | 26 +- .../kotlin/arrow/fx/coroutines/ParZip2Test.kt | 17 +- .../kotlin/arrow/fx/coroutines/ParZip3Test.kt | 16 +- .../kotlin/arrow/fx/coroutines/ParZip4Test.kt | 16 +- .../kotlin/arrow/fx/coroutines/ParZip5Test.kt | 16 +- .../kotlin/arrow/fx/coroutines/ParZip6Test.kt | 16 +- .../kotlin/arrow/fx/coroutines/ParZip7Test.kt | 16 +- .../kotlin/arrow/fx/coroutines/ParZip8Test.kt | 16 +- .../kotlin/arrow/fx/coroutines/ParZip9Test.kt | 16 +- .../kotlin/arrow/fx/coroutines/Platform.kt | 5 +- .../kotlin/arrow/fx/coroutines/RaceNTest.kt | 239 +++++++++--------- .../arrow/fx/coroutines/ResourceTest.kt | 96 ++++--- .../kotlin/arrow/fx/coroutines/FlowJvmTest.kt | 11 +- .../arrow/fx/coroutines/ParMapJvmTest.kt | 13 +- .../arrow/fx/coroutines/ParZip2JvmTest.kt | 11 +- .../arrow/fx/coroutines/ParZip3JvmTest.kt | 13 +- .../arrow/fx/coroutines/ParZip4JvmTest.kt | 15 +- .../arrow/fx/coroutines/ParZip5JvmTest.kt | 17 +- .../arrow/fx/coroutines/ParZip6JvmTest.kt | 19 +- .../arrow/fx/coroutines/ParZip7JvmTest.kt | 21 +- .../arrow/fx/coroutines/ParZip8JvmTest.kt | 23 +- .../arrow/fx/coroutines/ParZip9JvmTest.kt | 25 +- .../arrow/fx/coroutines/RaceNJvmTest.kt | 27 +- 36 files changed, 552 insertions(+), 506 deletions(-) delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/DeprecationWarnings.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/KotestConfig.kt diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2bd4ed30072..cd7026c800b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -36,7 +36,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: assemble diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 27e260108cc..4fb1d8c4e9d 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: ios and watchos tests @@ -49,7 +49,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: macos and tvos tests @@ -76,7 +76,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: mingwX64Test @@ -103,7 +103,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: check @@ -130,7 +130,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: jvmTest @@ -173,7 +173,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: jvmTest (K2 enabled) @@ -200,7 +200,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: kotlinUpgradeYarnLock @@ -232,7 +232,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: linuxX64Test @@ -259,7 +259,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: apiDump @@ -285,7 +285,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' + distribution: 'temurin' java-version: 11 - name: spotlessApply diff --git a/arrow-libs/core/arrow-core-retrofit/build.gradle.kts b/arrow-libs/core/arrow-core-retrofit/build.gradle.kts index 8a1af47a255..7dc88f6b054 100644 --- a/arrow-libs/core/arrow-core-retrofit/build.gradle.kts +++ b/arrow-libs/core/arrow-core-retrofit/build.gradle.kts @@ -25,11 +25,9 @@ dependencies { testImplementation(projects.arrowCore) testImplementation(libs.kotlin.test) testImplementation(libs.coroutines.test) - testImplementation(libs.kotest.frameworkEngine) testImplementation(libs.kotest.assertionsCore) testImplementation(libs.kotest.property) testCompileOnly(libs.kotlin.reflect) - testRuntimeOnly(libs.kotest.runnerJUnit5) testImplementation(libs.squareup.okhttpMockWebServer) testImplementation(libs.squareup.retrofitConverterGson) testImplementation(libs.squareup.retrofitConverterMoshi) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt index 5f211a1c195..6ef4a2de486 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/networkhandling/NetworkEitherCallAdapterTest.kt @@ -6,11 +6,9 @@ import arrow.core.right import arrow.retrofit.adapter.either.EitherCallAdapterFactory import arrow.retrofit.adapter.mock.ResponseMock import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory -import io.kotest.core.spec.style.StringSpec -import io.kotest.core.spec.style.stringSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf -import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.coroutines.test.runTest import kotlinx.serialization.json.Json import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient @@ -24,21 +22,17 @@ import retrofit2.converter.moshi.MoshiConverterFactory import java.net.SocketException import java.net.SocketTimeoutException import java.util.concurrent.TimeUnit +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test -@ExperimentalSerializationApi -class NetworkEitherCallAdapterTestSuite : StringSpec({ - include(networkEitherCallAdapterTests(GsonConverterFactory.create())) - include(networkEitherCallAdapterTests(MoshiConverterFactory.create())) - include(networkEitherCallAdapterTests(Json.asConverterFactory("application/json".toMediaType()))) -}) +abstract class NetworkEitherCallAdapterTest( + private val jsonConverterFactory: Converter.Factory, +) { + private var server: MockWebServer? = null + private var service: CallErrorTestClient? = null -private fun networkEitherCallAdapterTests( - jsonConverterFactory: Converter.Factory, -) = stringSpec { - var server: MockWebServer? = null - var service: CallErrorTestClient? = null - - beforeAny { + open fun initialize() { server = MockWebServer() server!!.start() val client = OkHttpClient.Builder() @@ -52,9 +46,12 @@ private fun networkEitherCallAdapterTests( .build() .create(CallErrorTestClient::class.java) } - afterAny { server!!.shutdown() } - "should return ResponseMock for 200 with valid JSON" { + open fun shutdown() { + server!!.shutdown() + } + + open fun shouldReturn200ForValidJson() = runTest { server!!.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val body = service!!.getEither() @@ -62,7 +59,7 @@ private fun networkEitherCallAdapterTests( body shouldBe ResponseMock("Arrow rocks").right() } - "should return HttpError for 400" { + open fun shouldReturnHttpErrorFor404() = runTest { server!!.enqueue(MockResponse().setBody("""{"errorCode":666}""").setResponseCode(400)) val body = service!!.getEither() @@ -74,7 +71,7 @@ private fun networkEitherCallAdapterTests( ).left() } - "should return CallError for 200 with invalid JSON" { + open fun shouldReturnCallErrorFor200InvalidJson() = runTest { server!!.enqueue(MockResponse().setBody("""not a valid JSON""")) val body = service!!.getEither() @@ -83,7 +80,7 @@ private fun networkEitherCallAdapterTests( .value.shouldBeInstanceOf() } - "should return HttpError for 400 and invalid JSON" { + open fun shouldReturnHttpErrorFor404InvalidJson() = runTest { server!!.enqueue(MockResponse().setBody("""not a valid JSON""").setResponseCode(400)) val body = service!!.getEither() @@ -95,7 +92,7 @@ private fun networkEitherCallAdapterTests( ).left() } - "should return IOError when server disconnects" { + open fun shouldReturnIOErrorDisconnect() = runTest { server!!.enqueue(MockResponse().apply { socketPolicy = SocketPolicy.DISCONNECT_AT_START }) val body = service!!.getEither() @@ -105,7 +102,7 @@ private fun networkEitherCallAdapterTests( .cause.shouldBeInstanceOf() } - "should return IOError when no response" { + open fun shouldReturnIOErrorNoResponse() = runTest { server!!.enqueue(MockResponse().apply { socketPolicy = SocketPolicy.NO_RESPONSE }) val body = service!!.getEither() @@ -115,7 +112,7 @@ private fun networkEitherCallAdapterTests( .cause.shouldBeInstanceOf() } - "should return Unit when service method returns Unit and null body received" { + open fun shouldReturnUnitForNullBody() = runTest { server!!.enqueue(MockResponse().setResponseCode(204)) val body = service!!.postSomething("Sample string") @@ -123,7 +120,7 @@ private fun networkEitherCallAdapterTests( body shouldBe Unit.right() } - "should return Unit when service method returns Unit and JSON body received" { + open fun shouldReturnUnitForUnitBody() = runTest { server!!.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val body = service!!.postSomething("Sample string") @@ -131,7 +128,7 @@ private fun networkEitherCallAdapterTests( body shouldBe Unit.right() } - "should return CallError when service method returns type other than Unit but null body received" { + open fun shouldReturnCallErrorWithUnitForNonNullBody() = runTest { server!!.enqueue(MockResponse()) val body = service!!.getEither() @@ -140,3 +137,87 @@ private fun networkEitherCallAdapterTests( .value.shouldBeInstanceOf() } } + +class NetworkEitherCallAdapterTestGson : NetworkEitherCallAdapterTest(GsonConverterFactory.create()) { + @BeforeTest override fun initialize() { + super.initialize() + } + + @AfterTest override fun shutdown() { + super.shutdown() + } + + @Test override fun shouldReturn200ForValidJson() = super.shouldReturn200ForValidJson() + + @Test override fun shouldReturnHttpErrorFor404() = super.shouldReturnHttpErrorFor404() + + @Test override fun shouldReturnCallErrorFor200InvalidJson() = super.shouldReturnCallErrorFor200InvalidJson() + + @Test override fun shouldReturnHttpErrorFor404InvalidJson() = super.shouldReturnHttpErrorFor404InvalidJson() + + @Test override fun shouldReturnIOErrorDisconnect() = super.shouldReturnIOErrorDisconnect() + + @Test override fun shouldReturnIOErrorNoResponse() = super.shouldReturnIOErrorNoResponse() + + @Test override fun shouldReturnUnitForNullBody() = super.shouldReturnUnitForNullBody() + + @Test override fun shouldReturnUnitForUnitBody() = super.shouldReturnUnitForUnitBody() + + @Test override fun shouldReturnCallErrorWithUnitForNonNullBody() = super.shouldReturnCallErrorWithUnitForNonNullBody() +} + +class NetworkEitherCallAdapterTestMoshi : NetworkEitherCallAdapterTest(MoshiConverterFactory.create()) { + @BeforeTest override fun initialize() { + super.initialize() + } + + @AfterTest override fun shutdown() { + super.shutdown() + } + + @Test override fun shouldReturn200ForValidJson() = super.shouldReturn200ForValidJson() + + @Test override fun shouldReturnHttpErrorFor404() = super.shouldReturnHttpErrorFor404() + + @Test override fun shouldReturnCallErrorFor200InvalidJson() = super.shouldReturnCallErrorFor200InvalidJson() + + @Test override fun shouldReturnHttpErrorFor404InvalidJson() = super.shouldReturnHttpErrorFor404InvalidJson() + + @Test override fun shouldReturnIOErrorDisconnect() = super.shouldReturnIOErrorDisconnect() + + @Test override fun shouldReturnIOErrorNoResponse() = super.shouldReturnIOErrorNoResponse() + + @Test override fun shouldReturnUnitForNullBody() = super.shouldReturnUnitForNullBody() + + @Test override fun shouldReturnUnitForUnitBody() = super.shouldReturnUnitForUnitBody() + + @Test override fun shouldReturnCallErrorWithUnitForNonNullBody() = super.shouldReturnCallErrorWithUnitForNonNullBody() +} + +class NetworkEitherCallAdapterTestKotlinxSerialization : NetworkEitherCallAdapterTest(Json.asConverterFactory("application/json".toMediaType())) { + @BeforeTest override fun initialize() { + super.initialize() + } + + @AfterTest override fun shutdown() { + super.shutdown() + } + + @Test override fun shouldReturn200ForValidJson() = super.shouldReturn200ForValidJson() + + @Test override fun shouldReturnHttpErrorFor404() = super.shouldReturnHttpErrorFor404() + + @Test override fun shouldReturnCallErrorFor200InvalidJson() = super.shouldReturnCallErrorFor200InvalidJson() + + @Test override fun shouldReturnHttpErrorFor404InvalidJson() = super.shouldReturnHttpErrorFor404InvalidJson() + + @Test override fun shouldReturnIOErrorDisconnect() = super.shouldReturnIOErrorDisconnect() + + @Test override fun shouldReturnIOErrorNoResponse() = super.shouldReturnIOErrorNoResponse() + + @Test override fun shouldReturnUnitForNullBody() = super.shouldReturnUnitForNullBody() + + @Test override fun shouldReturnUnitForUnitBody() = super.shouldReturnUnitForUnitBody() + + @Test override fun shouldReturnCallErrorWithUnitForNonNullBody() = super.shouldReturnCallErrorWithUnitForNonNullBody() +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index 5daf09ca177..e97b4d0c9f3 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -103,7 +103,7 @@ class NonEmptyListTest { @Test fun mapOrAccumulateAccumulatesErrorsWithCombineFunction() = runTest { - checkAll(Arb.nonEmptyList(Arb.negativeInt())) { nel -> + checkAll(Arb.nonEmptyList(Arb.negativeInt(), range = 0 .. 20)) { nel -> val res = nel.mapOrAccumulate(String::plus) { i -> if (i > 0) i else raise("Negative") } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt index 1db7c93608a..0cf3c58461c 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EffectSpec.kt @@ -601,7 +601,7 @@ class EffectSpec { } @Test fun accumulateReturnsEveryError() = runTest { - checkAll(Arb.list(Arb.int(), range = 2..100)) { errors -> + checkAll(Arb.list(Arb.int(), range = 2..20)) { errors -> either, List> { mapOrAccumulate(errors) { raise(it) } } shouldBe errors.toNonEmptyListOrNull()!!.left() @@ -609,7 +609,7 @@ class EffectSpec { } @Test fun accumulateReturnsNoError() = runTest { - checkAll(Arb.list(Arb.int())) { elements -> + checkAll(Arb.list(Arb.int(), range = 0..20)) { elements -> either, List> { mapOrAccumulate(elements) { it } } shouldBe elements.right() @@ -617,7 +617,7 @@ class EffectSpec { } @Test fun nonEmptyListMapOrAccumulateReturnsEveryError() = runTest { - checkAll(Arb.nonEmptyList(Arb.int(), range = 2..100)) { errors -> + checkAll(Arb.nonEmptyList(Arb.int(), range = 2..20)) { errors -> either, NonEmptyList> { mapOrAccumulate(errors) { raise(it) } } shouldBe errors.toNonEmptyListOrNull()!!.left() @@ -625,7 +625,7 @@ class EffectSpec { } @Test fun nonEmptyListMapOrAccumulateReturnsNoError() = runTest { - checkAll(Arb.nonEmptyList(Arb.int())) { elements -> + checkAll(Arb.nonEmptyList(Arb.int(), range = 0..20)) { elements -> either, NonEmptyList> { mapOrAccumulate(elements) { it } } shouldBe elements.right() @@ -633,7 +633,7 @@ class EffectSpec { } @Test fun nonEmptySetMapOrAccumulateReturnsEveryError() = runTest { - checkAll(Arb.nonEmptySet(Arb.int(), range = 2..100)) { errors -> + checkAll(Arb.nonEmptySet(Arb.int(), range = 2..20)) { errors -> either, NonEmptySet> { mapOrAccumulate(errors) { raise(it) } } shouldBe errors.toNonEmptyListOrNull()!!.left() @@ -641,7 +641,7 @@ class EffectSpec { } @Test fun nonEmptySetMapOrAccumulateReturnsNoError() = runTest { - checkAll(Arb.nonEmptySet(Arb.int())) { elements -> + checkAll(Arb.nonEmptySet(Arb.int(), range = 0..20)) { elements -> either, NonEmptySet> { mapOrAccumulate(elements) { it } } shouldBe elements.right() @@ -649,7 +649,7 @@ class EffectSpec { } @Test fun bindAllFailsOnFirstError() = runTest { - checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()))) { eithers -> + checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()), range = 0..20)) { eithers -> val expected = eithers.firstOrNull { it.isLeft() } ?: eithers.mapNotNull { it.getOrNull() }.right() either { eithers.bindAll() @@ -658,7 +658,7 @@ class EffectSpec { } @Test fun accumulateBindAll() = runTest { - checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()))) { eithers -> + checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()), range = 0..20)) { eithers -> val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.right() @@ -672,7 +672,7 @@ class EffectSpec { } @Test fun nonEmptyListBindAllFailsOnFirstError() = runTest { - checkAll(Arb.nonEmptyList(Arb.either(Arb.int(), Arb.int()))) { eithers -> + checkAll(Arb.nonEmptyList(Arb.either(Arb.int(), Arb.int()), range = 0..20)) { eithers -> val expected = eithers.firstOrNull { it.isLeft() } ?: eithers.mapNotNull { it.getOrNull() }.right() either { eithers.bindAll() @@ -681,7 +681,7 @@ class EffectSpec { } @Test fun nonEmptyListBindAllAccumulateErrors() = runTest { - checkAll(Arb.nonEmptyList(Arb.either(Arb.int(), Arb.int()))) { eithers -> + checkAll(Arb.nonEmptyList(Arb.either(Arb.int(), Arb.int()), range = 0..20)) { eithers -> val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.right() @@ -695,7 +695,7 @@ class EffectSpec { } @Test fun nonEmptySetBindAllFailsOnFirstError() = runTest { - checkAll(Arb.nonEmptySet(Arb.either(Arb.int(), Arb.int()))) { eithers -> + checkAll(Arb.nonEmptySet(Arb.either(Arb.int(), Arb.int()), range = 0..20)) { eithers -> val expected = eithers.firstOrNull { it.isLeft() } ?: eithers.mapNotNull { it.getOrNull() }.toSet().right() either { eithers.bindAll() @@ -704,7 +704,7 @@ class EffectSpec { } @Test fun nonEmptySetBindAllAccumulateErrors() = runTest { - checkAll(Arb.nonEmptySet(Arb.either(Arb.int(), Arb.int()))) { eithers -> + checkAll(Arb.nonEmptySet(Arb.either(Arb.int(), Arb.int()), range = 0..20)) { eithers -> val expected = eithers.mapNotNull { it.leftOrNull() }.toNonEmptyListOrNull()?.left() ?: eithers.mapNotNull { it.getOrNull() }.toSet().right() diff --git a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts index 884445b8ca9..1e0d1180284 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts @@ -1,5 +1,8 @@ @file:Suppress("DSL_SCOPE_VIOLATION") +import java.time.Duration + + plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) @@ -14,8 +17,6 @@ spotless { } } -apply(plugin = "io.kotest.multiplatform") - kotlin { sourceSets { commonMain { @@ -31,7 +32,6 @@ kotlin { implementation(projects.arrowCore) implementation(libs.kotlin.test) implementation(libs.coroutines.test) - implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } @@ -45,6 +45,24 @@ kotlin { } } } + + js { + nodejs { + testTask { + useMocha { + timeout = "60000" + } + } + } + browser { + testTask { + useKarma { + useChromeHeadless() + timeout.set(Duration.ofSeconds(60)) + } + } + } + } } tasks.withType().configureEach { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/DeprecationWarnings.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/DeprecationWarnings.kt deleted file mode 100644 index 562367c2cd6..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/DeprecationWarnings.kt +++ /dev/null @@ -1,4 +0,0 @@ -package arrow.fx.coroutines - -internal const val deprecatedInFavorOfArrowFxResilience = - "This is now part of the arrow-fx-resilience module, and will be removed from arrow-fx-coroutines in version 2.0. Please update your project dependencies." diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt index 1aceb561cf1..738c48ffdb0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CountDownLatchSpec.kt @@ -27,7 +27,7 @@ class CountDownLatchSpec { @Test fun releaseAndThenAwaitShouldComplete() = runTest { - checkAll(Arb.long(1, 100)) { count -> + checkAll(Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) repeat(count.toInt()) { latch.countDown() } latch.await() shouldBe Unit @@ -36,7 +36,7 @@ class CountDownLatchSpec { @Test fun awaitAndThenReleaseShouldComplete() = runTest { - checkAll(Arb.long(1, 100)) { count -> + checkAll(Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) val job = launch { latch.await() } repeat(count.toInt()) { latch.countDown() } @@ -46,7 +46,7 @@ class CountDownLatchSpec { @Test fun awaitWithMoreThanOneLatchUnreleasedShouldBlock() = runTest { - checkAll(Arb.long(1, 100)) { count -> + checkAll(Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) repeat(count.toInt() - 1) { latch.countDown() } withTimeoutOrNull(1) { latch.await() }.shouldBeNull() @@ -56,7 +56,7 @@ class CountDownLatchSpec { @Test fun multipleAwaitsShouldAllComplete() = runTest { - checkAll(Arb.long(1, 100)) { count -> + checkAll(Arb.long(1, 20)) { count -> val latch = CountDownLatch(count) val jobs = (0 until count).map { launch { latch.await() } } repeat(count.toInt()) { latch.countDown() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt index 64cbc6769b1..c678fa690e8 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/CyclicBarrierSpec.kt @@ -33,7 +33,7 @@ class CyclicBarrierSpec { } @Test - fun awaitingAllInParallelResumesAllCoroutines() = runTest { + fun awaitingAllInParallelResumesAllCoroutines() = runTestUsingDefaultDispatcher { checkAll(Arb.int(1, 20)) { i -> val barrier = CyclicBarrier(i) (0 until i).parMap { barrier.await() } @@ -41,7 +41,7 @@ class CyclicBarrierSpec { } @Test - fun shouldResetOnceFull() = runTest { + fun shouldResetOnceFull() = runTestUsingDefaultDispatcher { checkAll(Arb.constant(Unit)) { val barrier = CyclicBarrier(2) parZip({ barrier.await() }, { barrier.await() }) { _, _ -> } @@ -50,7 +50,7 @@ class CyclicBarrierSpec { } @Test - fun executesRunnableOnceFull() = runTest { + fun executesRunnableOnceFull() = runTestUsingDefaultDispatcher { var barrierRunnableInvoked = false val barrier = CyclicBarrier(2) { barrierRunnableInvoked = true } parZip({ barrier.await() }, { barrier.await() }) { _, _ -> } @@ -102,7 +102,7 @@ class CyclicBarrierSpec { } @Test - fun shouldCleanUpUponReset() = runTest { + fun shouldCleanUpUponReset() = runTestUsingDefaultDispatcher { checkAll(Arb.int(2, 20)) { i -> val barrier = CyclicBarrier(i) val exitCase = CompletableDeferred() @@ -118,7 +118,7 @@ class CyclicBarrierSpec { } @Test - fun raceFiberCancelAndBarrierFull() = runTest { + fun raceFiberCancelAndBarrierFull() = runTestUsingDefaultDispatcher { checkAll(Arb.constant(Unit)) { val barrier = CyclicBarrier(2) val job = launch(start = CoroutineStart.UNDISPATCHED) { barrier.await() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt index e79d057391d..aab722f57fd 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt @@ -5,44 +5,32 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf import io.kotest.property.Arb import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.map -import io.kotest.property.arbitrary.positiveInt import io.kotest.property.checkAll import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.cancelAndJoin -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toSet import kotlinx.coroutines.launch -import kotlinx.coroutines.test.advanceTimeBy -import kotlinx.coroutines.test.currentTime -import kotlinx.coroutines.test.runTest -import kotlinx.coroutines.withTimeoutOrNull import kotlin.test.Test -import kotlin.time.ExperimentalTime @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) -@ExperimentalTime class FlowTest { @Test - fun parMapConcurrentEqualOneMinusIdentity() = runTest { - checkAll(Arb.flow(Arb.int())) { flow -> + fun parMapConcurrentEqualOneMinusIdentity() = runTestUsingDefaultDispatcher { + checkAll(Arb.flow(Arb.int(), range = 1 .. 20)) { flow -> flow.parMap(1) { it } .toList() shouldBe flow.toList() } } @Test - fun parMapRunsInParallel() = runTest { + fun parMapRunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(1..2)) { i, n -> val latch = CompletableDeferred() flowOf(1, 2).parMap { index -> @@ -56,7 +44,7 @@ class FlowTest { } @Test - fun parMapTriggersCancelSignal() = runTest { + fun parMapTriggersCancelSignal() = runTestUsingDefaultDispatcher { val latch = CompletableDeferred() val exit = CompletableDeferred() @@ -75,7 +63,7 @@ class FlowTest { } @Test - fun parMapExceptionInParMapCancelsAllRunningTasks() = runTest { + fun parMapExceptionInParMapCancelsAllRunningTasks() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> val latch = CompletableDeferred() val exit = CompletableDeferred>() @@ -102,7 +90,7 @@ class FlowTest { } @Test - fun parMapCancellingParMapCancelsAllRunningJobs() = runTest { + fun parMapCancellingParMapCancelsAllRunningJobs() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int()) { i, i2 -> val latch = CompletableDeferred() val exitA = CompletableDeferred>() @@ -134,15 +122,15 @@ class FlowTest { } @Test - fun parMapUnorderedConcurrentEqualOneMinusIdentity() = runTest { - checkAll(Arb.flow(Arb.int())) { flow -> + fun parMapUnorderedConcurrentEqualOneMinusIdentity() = runTestUsingDefaultDispatcher { + checkAll(Arb.flow(Arb.int(), range = 1 .. 20)) { flow -> flow.parMapUnordered(concurrency = 1) { it } .toSet() shouldBe flow.toSet() } } @Test - fun parMapUnorderedRunsInParallel() = runTest { + fun parMapUnorderedRunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(1..2)) { i, n -> val latch = CompletableDeferred() flowOf(1, 2).parMapUnordered { index -> @@ -156,7 +144,7 @@ class FlowTest { } @Test - fun parMapUnorderedTriggersCancelSignal() = runTest { + fun parMapUnorderedTriggersCancelSignal() = runTestUsingDefaultDispatcher { val latch = CompletableDeferred() val exit = CompletableDeferred() @@ -176,7 +164,7 @@ class FlowTest { } @Test - fun parMapUnorderedExceptionInParMapCancelsAllRunningTasks() = runTest { + fun parMapUnorderedExceptionInParMapCancelsAllRunningTasks() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.throwable(), Arb.int(1..2)) { i, e, n -> val latch = CompletableDeferred() val exit = CompletableDeferred>() @@ -203,7 +191,7 @@ class FlowTest { } @Test - fun parMapUnorderedCancellingParMapCancelsAllRunningJobs() = runTest { + fun parMapUnorderedCancellingParMapCancelsAllRunningJobs() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int()) { i, i2 -> val latch = CompletableDeferred() val exitA = CompletableDeferred>() @@ -235,8 +223,28 @@ class FlowTest { } @Test - fun fixedDelay() = runTest { - checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..20)) { waitPeriod, n -> + fun mapIndexed() = runTestUsingDefaultDispatcher { + val flow = flowOf(1, 2, 3) + .mapIndexed { index, value -> IndexedValue(index, value) } + + flow.toList() shouldBe listOf( + IndexedValue(0, 1), + IndexedValue(1, 2), + IndexedValue(2, 3) + ) + + flow.toList() shouldBe listOf( + IndexedValue(0, 1), + IndexedValue(1, 2), + IndexedValue(2, 3) + ) + } + + /* These tests do not run properly in the coroutines-test environment + + @Test + fun fixedDelay() = runTestUsingDefaultDispatcher { + checkAll(Arb.long(10L .. 50L), Arb.int(3..20)) { waitPeriod, n -> val emissionDuration = waitPeriod / 10L var state: Long? = null @@ -260,8 +268,8 @@ class FlowTest { } @Test - fun fixedRate() = runTest { - checkAll(Arb.positiveInt().map(Int::toLong), Arb.int(1..20)) { waitPeriod, n -> + fun fixedRate() = runTestUsingDefaultDispatcher { + checkAll(Arb.long(10L..50L), Arb.int(3..20)) { waitPeriod, n -> val emissionDuration = waitPeriod / 10 var state: Long? = null @@ -283,50 +291,33 @@ class FlowTest { act shouldBe waitPeriod } } + } - @Test - fun fixedRateWithDampenTrue() = runTest { - val buffer = mutableListOf() - withTimeoutOrNull(4500) { - fixedRate(1000, true) { currentTime } - .mapIndexed { index, _ -> - if (index == 0) delay(3000) else Unit - advanceTimeBy(1) - }.collect(buffer::add) - } - buffer.size shouldBe 2 - } - - @Test - fun fixedRateWithDampenFalse() = runTest { - val buffer = mutableListOf() - withTimeoutOrNull(4500) { - fixedRate(1000, false) { currentTime } - .mapIndexed { index, _ -> - if (index == 0) delay(3000) else Unit - advanceTimeBy(1) - }.collect(buffer::add) - } - buffer.size shouldBe 4 + @Test + fun fixedRateWithDampenTrue() = runTestUsingDefaultDispatcher { + val buffer = mutableListOf() + withTimeoutOrNull(4500) { + fixedRate(1000, true) { currentTime } + .mapIndexed { index, _ -> + if (index == 0) delay(3000) else Unit + advanceTimeBy(1) + }.collect(buffer::add) } + buffer.size shouldBe 2 + } - @Test - fun mapIndexed() = runTest { - val flow = flowOf(1, 2, 3) - .mapIndexed { index, value -> IndexedValue(index, value) } - - flow.toList() shouldBe listOf( - IndexedValue(0, 1), - IndexedValue(1, 2), - IndexedValue(2, 3) - ) - - flow.toList() shouldBe listOf( - IndexedValue(0, 1), - IndexedValue(1, 2), - IndexedValue(2, 3) - ) + @Test + fun fixedRateWithDampenFalse() = runTestUsingDefaultDispatcher { + val buffer = mutableListOf() + withTimeoutOrNull(4500) { + fixedRate(1000, false) { currentTime } + .mapIndexed { index, _ -> + if (index == 0) delay(3000) else Unit + advanceTimeBy(1) + }.collect(buffer::add) } + buffer.size shouldBe 4 } + */ } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt index a164322d573..98996374d23 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Generators.kt @@ -38,7 +38,7 @@ fun Arb.Companion.functionAToB(arb: Arb): Arb<(A) -> B> = arb.map { b: B -> { _: A -> b } } fun Arb.Companion.throwable(): Arb = - Arb.of(listOf(RuntimeException(), NoSuchElementException(), IllegalArgumentException())) + Arb.of(listOf(IndexOutOfBoundsException(), NoSuchElementException(), IllegalArgumentException())) fun Arb.Companion.either(arbE: Arb, arbA: Arb): Arb> { val arbLeft = arbE.map { Either.Left(it) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/KotestConfig.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/KotestConfig.kt deleted file mode 100644 index e2c196cdbed..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/KotestConfig.kt +++ /dev/null @@ -1,10 +0,0 @@ -package arrow.fx.coroutines - -import io.kotest.core.config.AbstractProjectConfig -import io.kotest.property.PropertyTesting - -class KotestConfig : AbstractProjectConfig() { - override suspend fun beforeProject() { - PropertyTesting.defaultIterationCount = 250 - } -} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt index 0ee57f17021..5a925875cd2 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParMapTest.kt @@ -13,13 +13,13 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import kotlin.test.Test -import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.test.runTest +import kotlin.time.Duration.Companion.milliseconds class ParMapTest { - @Test fun parMapIsStackSafe() = runTestWithDelay { + @Test fun parMapIsStackSafe() = runTestUsingDefaultDispatcher { val count = stackSafeIteration() val ref = AtomicInt(0) (0 until count).parMap { _: Int -> @@ -28,7 +28,7 @@ class ParMapTest { ref.get() shouldBe count } - @Test fun parMapRunsInParallel() = runTest { + @Test fun parMapRunsInParallel() = runTestUsingDefaultDispatcher { val promiseA = CompletableDeferred() val promiseB = CompletableDeferred() val promiseC = CompletableDeferred() @@ -49,7 +49,7 @@ class ParMapTest { ).parMap { it.invoke() } } - @Test fun parTraverseResultsInTheCorrectError() = runTest { + @Test fun parTraverseResultsInTheCorrectError() = runTestUsingDefaultDispatcher { checkAll( Arb.int(min = 10, max = 20), Arb.int(min = 1, max = 9), @@ -74,7 +74,7 @@ class ParMapTest { } shouldBe null } - @Test fun parMapWithEitherResultsInTheCorrectLeft() = runTest { + @Test fun parMapWithEitherResultsInTheCorrectLeft() = runTestUsingDefaultDispatcher { checkAll( Arb.int(min = 10, max = 20), Arb.int(min = 1, max = 9), @@ -88,7 +88,7 @@ class ParMapTest { } } - @Test fun parMapOrAccumulateIsStackSafe() = runTestWithDelay { + @Test fun parMapOrAccumulateIsStackSafe() = runTestUsingDefaultDispatcher { val count = stackSafeIteration() val ref = AtomicInt(0) (0 until count).parMapOrAccumulate(combine = emptyError) { _: Int -> @@ -118,7 +118,7 @@ class ParMapTest { ).parMapOrAccumulate(combine = emptyError) { it.invoke() } } - @Test fun parMapOrAccumulateResultsInTheCorrectError() = runTest { + @Test fun parMapOrAccumulateResultsInTheCorrectError() = runTestUsingDefaultDispatcher { checkAll( Arb.int(min = 10, max = 20), Arb.int(min = 1, max = 9), @@ -143,7 +143,7 @@ class ParMapTest { } shouldBe null } - @Test fun parMapOrAccumulateAccumulatesShifts() = runTest { + @Test fun parMapOrAccumulateAccumulatesShifts() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { e -> (0 until 10).parMapOrAccumulate { _ -> raise(e) @@ -151,7 +151,7 @@ class ParMapTest { } } - @Test fun parMapNotNullIsStackSafe() = runTestWithDelay { + @Test fun parMapNotNullIsStackSafe() = runTestUsingDefaultDispatcher { val count = stackSafeIteration() val ref = AtomicInt(0) (0 until count).parMapNotNull { _: Int -> @@ -160,7 +160,7 @@ class ParMapTest { ref.get() shouldBe count } - @Test fun parMapNotNullRunsInParallel() = runTest { + @Test fun parMapNotNullRunsInParallel() = runTestUsingDefaultDispatcher { val promiseA = CompletableDeferred() val promiseB = CompletableDeferred() val promiseC = CompletableDeferred() @@ -181,7 +181,7 @@ class ParMapTest { ).parMapNotNull { it.invoke() } } - @Test fun parMapNotNullResultsInTheCorrectError() = runTest { + @Test fun parMapNotNullResultsInTheCorrectError() = runTestUsingDefaultDispatcher { checkAll( Arb.int(min = 10, max = 20), Arb.int(min = 1, max = 9), @@ -206,13 +206,13 @@ class ParMapTest { } shouldBe null } - @Test fun parMapNotNullDiscardsNulls() = runTest { + @Test fun parMapNotNullDiscardsNulls() = runTestUsingDefaultDispatcher { (0 until 10).parMapNotNull { _ -> null } shouldBe emptyList() } - @Test fun parMapNotNullRetainsNonNulls() = runTest { + @Test fun parMapNotNullRetainsNonNulls() = runTestUsingDefaultDispatcher { checkAll(Arb.int()) { i -> (0 until 10).parMapNotNull { _ -> i diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt index 33b2b0f31e9..86bd3478d4f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip2Test.kt @@ -1,15 +1,9 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.AtomicInt import arrow.atomic.update import arrow.atomic.value import arrow.core.Either -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.guaranteeCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -24,11 +18,10 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.test.runTest import kotlin.test.Test class ParZip2Test { - @Test fun parZip2RunsInParallel() = runTest { + @Test fun parZip2RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int()) { a, b -> val r = AtomicInt(0) val modifyGate = CompletableDeferred() @@ -50,7 +43,7 @@ class ParZip2Test { } } - @Test fun cancellingParZip2CancelsAllParticipants() = runTest { + @Test fun cancellingParZip2CancelsAllParticipants() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int()) { a, b -> val s = Channel() val pa = CompletableDeferred>() @@ -78,7 +71,7 @@ class ParZip2Test { } } - @Test fun parZip2CancelsLosersIfAFailtureOccursInOneOfTheTasts() = runTest { + @Test fun parZip2CancelsLosersIfAFailtureOccursInOneOfTheTasts() = runTestUsingDefaultDispatcher { checkAll(Arb.throwable(), Arb.boolean()) { e, leftWinner -> val s = Channel() val pa = CompletableDeferred() @@ -97,7 +90,7 @@ class ParZip2Test { } } - @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { msg -> val exit = CompletableDeferred() val start = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt index 1e2d05ff4c0..bf10afad390 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip3Test.kt @@ -1,14 +1,9 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.atomic.value import arrow.core.Either -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -22,11 +17,10 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.test.runTest import kotlin.test.Test class ParZip3Test { - @Test fun parZip3RunsInParallel() = runTest { + @Test fun parZip3RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -54,7 +48,7 @@ class ParZip3Test { } } - @Test fun cancellingParZip3CancelsAllParticipants() = runTest { + @Test fun cancellingParZip3CancelsAllParticipants() = runTestUsingDefaultDispatcher { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -79,7 +73,7 @@ class ParZip3Test { pc.await().shouldBeTypeOf() } - @Test fun parZip3CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + @Test fun parZip3CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTestUsingDefaultDispatcher { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3)), @@ -108,7 +102,7 @@ class ParZip3Test { } } - @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + @Test fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string(), Arb.int(1..3)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt index f3bd76a59e5..11b668e7f5e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip4Test.kt @@ -1,15 +1,10 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.atomic.value import arrow.core.Either import arrow.core.Tuple4 -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -23,12 +18,11 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.test.runTest import kotlin.test.Test class ParZip4Test { @Test - fun parZip4RunsInParallel() = runTest { + fun parZip4RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -63,7 +57,7 @@ class ParZip4Test { } @Test - fun CancellingParZip4CancelsAllParticipants() = runTest { + fun CancellingParZip4CancelsAllParticipants() = runTestUsingDefaultDispatcher { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -87,7 +81,7 @@ class ParZip4Test { } @Test - fun parZip4CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + fun parZip4CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTestUsingDefaultDispatcher { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4)), @@ -119,7 +113,7 @@ class ParZip4Test { } @Test - fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string(), Arb.int(1..4)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt index 8af58f145c2..a4ee82da26b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip5Test.kt @@ -1,15 +1,10 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.atomic.value import arrow.core.Either import arrow.core.Tuple5 -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -23,12 +18,11 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.test.runTest import kotlin.test.Test class ParZip5Test { @Test - fun parZip5RunsInParallel() = runTest { + fun parZip5RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -69,7 +63,7 @@ class ParZip5Test { } @Test - fun CancellingParZip5CancelsAllParticipants() = runTest { + fun CancellingParZip5CancelsAllParticipants() = runTestUsingDefaultDispatcher { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -106,7 +100,7 @@ class ParZip5Test { } @Test - fun parZip5CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + fun parZip5CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTestUsingDefaultDispatcher { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5)), @@ -142,7 +136,7 @@ class ParZip5Test { } @Test - fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string(), Arb.int(1..5)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt index 77eebeed8a9..8fef5baf9fe 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip6Test.kt @@ -1,15 +1,10 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.atomic.value import arrow.core.Either import arrow.core.Tuple6 -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -23,12 +18,11 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.test.runTest import kotlin.test.Test class ParZip6Test { @Test - fun parZip6RunsInParallel() = runTest { + fun parZip6RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -75,7 +69,7 @@ class ParZip6Test { } @Test - fun CancellingParZip6CancelsAllParticipants() = runTest { + fun CancellingParZip6CancelsAllParticipants() = runTestUsingDefaultDispatcher { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -109,7 +103,7 @@ class ParZip6Test { } @Test - fun parZip6CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + fun parZip6CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTestUsingDefaultDispatcher { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6)) @@ -149,7 +143,7 @@ class ParZip6Test { } @Test - fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string(), Arb.int(1..6)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt index 3c4be417dd5..cf7b672da48 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip7Test.kt @@ -1,15 +1,10 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.atomic.value import arrow.core.Either import arrow.core.Tuple7 -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -23,12 +18,11 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.test.runTest import kotlin.test.Test class ParZip7Test { @Test - fun parZip7RunsInParallel() = runTest { + fun parZip7RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -81,7 +75,7 @@ class ParZip7Test { } @Test - fun CancellingParZip7CancelsAllParticipants() = runTest { + fun CancellingParZip7CancelsAllParticipants() = runTestUsingDefaultDispatcher { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -118,7 +112,7 @@ class ParZip7Test { } @Test - fun parZip7CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + fun parZip7CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTestUsingDefaultDispatcher { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6, 7)) @@ -163,7 +157,7 @@ class ParZip7Test { } @Test - fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string(), Arb.int(1..7)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt index b92c6677542..cfae45a0450 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip8Test.kt @@ -1,15 +1,10 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.atomic.value import arrow.core.Either import arrow.core.Tuple8 -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -24,11 +19,10 @@ import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope import kotlin.test.Test -import kotlinx.coroutines.test.runTest class ParZip8Test { @Test - fun parZip8RunsInParallel() = runTest { + fun parZip8RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -87,7 +81,7 @@ class ParZip8Test { } @Test - fun CancellingParZip8CancelsAllParticipants() = runTest { + fun CancellingParZip8CancelsAllParticipants() = runTestUsingDefaultDispatcher { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -127,7 +121,7 @@ class ParZip8Test { } @Test - fun parZip8CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + fun parZip8CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTestUsingDefaultDispatcher { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6, 7, 8)) @@ -175,7 +169,7 @@ class ParZip8Test { } @Test - fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string(), Arb.int(1..8)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt index 8be40bbd564..7e22dd83592 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParZip9Test.kt @@ -1,14 +1,9 @@ -package arrow.fx.coroutines.parZip +package arrow.fx.coroutines import arrow.atomic.Atomic import arrow.atomic.update import arrow.core.Either import arrow.core.Tuple9 -import arrow.fx.coroutines.ExitCase -import arrow.fx.coroutines.awaitExitCase -import arrow.fx.coroutines.leftException -import arrow.fx.coroutines.parZip -import arrow.fx.coroutines.throwable import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf @@ -23,12 +18,11 @@ import kotlinx.coroutines.async import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.CoroutineScope import kotlin.test.Test -import kotlinx.coroutines.test.runTest class ParZip9Test { @Test - fun parZip9RunsInParallel() = runTest { + fun parZip9RunsInParallel() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d, e, f, g, h, i -> val r = Atomic("") val modifyGate1 = CompletableDeferred() @@ -93,7 +87,7 @@ class ParZip9Test { } @Test - fun CancellingParZip9CancelsAllParticipants() = runTest { + fun CancellingParZip9CancelsAllParticipants() = runTestUsingDefaultDispatcher { val s = Channel() val pa = CompletableDeferred() val pb = CompletableDeferred() @@ -136,7 +130,7 @@ class ParZip9Test { } @Test - fun parZip9CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTest { + fun parZip9CancelsLosersIfAFailureOccursInOneOfTheTasks() = runTestUsingDefaultDispatcher { checkAll( Arb.throwable(), Arb.element(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9)) @@ -188,7 +182,7 @@ class ParZip9Test { } @Test - fun parZipCancellationExceptionOnRightCanCancelRest() = runTest { + fun parZipCancellationExceptionOnRightCanCancelRest() = runTestUsingDefaultDispatcher { checkAll(Arb.string(), Arb.int(1..9)) { msg, cancel -> val s = Channel() val pa = CompletableDeferred() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt index 90c72caf9f9..c651c7bd63b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt @@ -4,6 +4,7 @@ import io.kotest.common.Platform import io.kotest.common.platform import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.test.TestResult +import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext @@ -12,7 +13,9 @@ fun stackSafeIteration(): Int = when (platform) { else -> 1000 } -fun runTestWithDelay(testBody: suspend () -> Unit): TestResult = runTest { +// The normal dispatcher with 'runTest' does some magic +// which doesn't go well with 'parZip', 'parMap', and 'raceN' +fun runTestUsingDefaultDispatcher(testBody: suspend TestScope.() -> Unit): TestResult = runTest { withContext(Dispatchers.Default) { testBody() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt index 8a1e9e3e3e0..8fc5a0cdddd 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/RaceNTest.kt @@ -4,7 +4,6 @@ import arrow.core.Either import arrow.core.identity import arrow.core.merge import io.kotest.assertions.retry -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf @@ -18,154 +17,116 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.channels.Channel +import kotlin.test.Test import kotlin.time.Duration.Companion.seconds fun Either.rethrow(): A = fold({ throw it }, ::identity) -class RaceNTest : StringSpec({ - "race2 can join first" { - checkAll(Arb.int()) { i -> - raceN({ i }, { awaitCancellation() }) shouldBe Either.Left(i) - } +class RaceNTest { + @Test fun race2JoinFirst() = runTestUsingDefaultDispatcher { + checkAll(Arb.int()) { i -> + raceN({ i }, { awaitCancellation() }) shouldBe Either.Left(i) } + } - "race2 can join second" { - checkAll(Arb.int()) { i -> - raceN({ awaitCancellation() }, { i }) shouldBe Either.Right(i) - } + @Test fun race2JoinSecond() = runTestUsingDefaultDispatcher { + checkAll(Arb.int()) { i -> + raceN({ awaitCancellation() }, { i }) shouldBe Either.Right(i) } + } - "Cancelling race 2 cancels all participants" { - checkAll(Arb.int(), Arb.int()) { a, b -> - val s = Channel() - val pa = CompletableDeferred>() - val pb = CompletableDeferred>() + @Test fun race2CancelsAll() = runTestUsingDefaultDispatcher { + checkAll(Arb.int(), Arb.int()) { a, b -> + val s = Channel() + val pa = CompletableDeferred>() + val pb = CompletableDeferred>() - val loserA: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } - val loserB: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } + val loserA: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } + val loserB: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } - val f = async { raceN(loserA, loserB) } + val f = async { raceN(loserA, loserB) } - // Suspend until all racers started - s.send(Unit) - s.send(Unit) - f.cancel() + // Suspend until all racers started + s.send(Unit) + s.send(Unit) + f.cancel() - pa.await().let { (res, exit) -> - res shouldBe a - exit.shouldBeInstanceOf() - } - pb.await().let { (res, exit) -> - res shouldBe b - exit.shouldBeInstanceOf() - } + pa.await().let { (res, exit) -> + res shouldBe a + exit.shouldBeInstanceOf() } - } - - "race 2 cancels losers with first success or failure determining winner" { - checkAll( - Arb.either(Arb.throwable(), Arb.int()), - Arb.boolean(), - Arb.int() - ) { eith, leftWinner, a -> - val s = Channel() - val pa = CompletableDeferred>() - - val winner: suspend CoroutineScope.() -> Int = { s.send(Unit); eith.rethrow() } - val loserA: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } - - val res = Either.catch { - if (leftWinner) raceN(winner, loserA) - else raceN(loserA, winner) - }.map { it.merge() } - - pa.await().let { (res, exit) -> - res shouldBe a - exit.shouldBeInstanceOf() - } - res shouldBe either(eith) + pb.await().let { (res, exit) -> + res shouldBe b + exit.shouldBeInstanceOf() } } + } - "race3 can join first" { - checkAll(Arb.int()) { i -> - raceN({ i }, { awaitCancellation() }, { awaitCancellation() }) shouldBe Race3.First(i) + @Test fun race2CancelsWithFirstSuccess() = runTestUsingDefaultDispatcher { + checkAll( + Arb.either(Arb.throwable(), Arb.int()), + Arb.boolean(), + Arb.int() + ) { eith, leftWinner, a -> + val s = Channel() + val pa = CompletableDeferred>() + + val winner: suspend CoroutineScope.() -> Int = { s.send(Unit); eith.rethrow() } + val loserA: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } + + val res = Either.catch { + if (leftWinner) raceN(winner, loserA) + else raceN(loserA, winner) + }.map { it.merge() } + + pa.await().let { (res, exit) -> + res shouldBe a + exit.shouldBeInstanceOf() } + res shouldBe either(eith) } + } - "race3 can join second" { - checkAll(Arb.int()) { i -> - raceN({ awaitCancellation() }, { i }, { awaitCancellation() }) shouldBe Race3.Second(i) - } + @Test fun race3JoinFirst() = runTestUsingDefaultDispatcher { + checkAll(Arb.int()) { i -> + raceN({ i }, { awaitCancellation() }, { awaitCancellation() }) shouldBe Race3.First(i) } + } - "race3 can join third" { - checkAll(Arb.int()) { i -> - raceN({ awaitCancellation() }, { awaitCancellation() }, { i }) shouldBe Race3.Third(i) - } + @Test fun race3JoinSecond() = runTestUsingDefaultDispatcher { + checkAll(Arb.int()) { i -> + raceN({ awaitCancellation() }, { i }, { awaitCancellation() }) shouldBe Race3.Second(i) } + } - "Cancelling race 3 cancels all participants" { - retry(10, 1.seconds) { - checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> - val s = Channel() - val pa = CompletableDeferred>() - val pb = CompletableDeferred>() - val pc = CompletableDeferred>() - - val loserA: suspend CoroutineScope.() -> Int = - { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } - val loserB: suspend CoroutineScope.() -> Int = - { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } - val loserC: suspend CoroutineScope.() -> Int = - { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pc.complete(Pair(c, ex)) } } - - val f = async { raceN(loserA, loserB, loserC) } - - s.send(Unit) // Suspend until all racers started - s.send(Unit) - s.send(Unit) - f.cancel() - - pa.await().let { (res, exit) -> - res shouldBe a - exit.shouldBeInstanceOf() - } - pb.await().let { (res, exit) -> - res shouldBe b - exit.shouldBeInstanceOf() - } - pc.await().let { (res, exit) -> - res shouldBe c - exit.shouldBeInstanceOf() - } - } - } + @Test fun race3JoinThird() = runTestUsingDefaultDispatcher { + checkAll(Arb.int()) { i -> + raceN({ awaitCancellation() }, { awaitCancellation() }, { i }) shouldBe Race3.Third(i) } + } - "race 3 cancels losers with first success or failure determining winner" { - checkAll( - Arb.either(Arb.throwable(), Arb.int()), - Arb.element(listOf(1, 2, 3)), - Arb.int(), - Arb.int() - ) { eith, leftWinner, a, b -> + @Test fun race3CancelsAll() = runTestUsingDefaultDispatcher { + retry(10, 1.seconds) { + checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c -> val s = Channel() val pa = CompletableDeferred>() val pb = CompletableDeferred>() + val pc = CompletableDeferred>() - val winner: suspend CoroutineScope.() -> Int = { s.send(Unit); s.send(Unit); eith.rethrow() } - val loserA: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } - val loserB: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } + val loserA: suspend CoroutineScope.() -> Int = + { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } + val loserB: suspend CoroutineScope.() -> Int = + { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } + val loserC: suspend CoroutineScope.() -> Int = + { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pc.complete(Pair(c, ex)) } } - val res = Either.catch { - when (leftWinner) { - 1 -> raceN(winner, loserA, loserB) - 2 -> raceN(loserA, winner, loserB) - else -> raceN(loserA, loserB, winner) - } - }.map { it.fold(::identity, ::identity, ::identity) } + val f = async { raceN(loserA, loserB, loserC) } + + s.send(Unit) // Suspend until all racers started + s.send(Unit) + s.send(Unit) + f.cancel() pa.await().let { (res, exit) -> res shouldBe a @@ -175,8 +136,46 @@ class RaceNTest : StringSpec({ res shouldBe b exit.shouldBeInstanceOf() } - res should either(eith) + pc.await().let { (res, exit) -> + res shouldBe c + exit.shouldBeInstanceOf() + } + } + } + } + + @Test fun race3CancelsWithFirstSuccess() = runTestUsingDefaultDispatcher { + checkAll( + Arb.either(Arb.throwable(), Arb.int()), + Arb.element(listOf(1, 2, 3)), + Arb.int(), + Arb.int() + ) { eith, leftWinner, a, b -> + val s = Channel() + val pa = CompletableDeferred>() + val pb = CompletableDeferred>() + + val winner: suspend CoroutineScope.() -> Int = { s.send(Unit); s.send(Unit); eith.rethrow() } + val loserA: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pa.complete(Pair(a, ex)) } } + val loserB: suspend CoroutineScope.() -> Int = { guaranteeCase({ s.receive(); awaitCancellation() }) { ex -> pb.complete(Pair(b, ex)) } } + + val res = Either.catch { + when (leftWinner) { + 1 -> raceN(winner, loserA, loserB) + 2 -> raceN(loserA, winner, loserB) + else -> raceN(loserA, loserB, winner) + } + }.map { it.fold(::identity, ::identity, ::identity) } + + pa.await().let { (res, exit) -> + res shouldBe a + exit.shouldBeInstanceOf() + } + pb.await().let { (res, exit) -> + res shouldBe b + exit.shouldBeInstanceOf() } + res should either(eith) } } -) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt index cb1e08161f6..f7ddafdd940 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ResourceTest.kt @@ -6,7 +6,6 @@ import arrow.core.raise.either import arrow.fx.coroutines.ExitCase.Companion.ExitCase import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.should @@ -24,14 +23,18 @@ import io.kotest.property.checkAll import io.kotest.property.arbitrary.string import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.async import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ResourceTest : StringSpec({ +class ResourceTest { - "acquire - success - identity" { + @Test + fun acquireSuccessIdentity() = runTest { checkAll(Arb.int()) { n -> resourceScope { install({ n }) { _, _ -> } shouldBe n @@ -39,7 +42,8 @@ class ResourceTest : StringSpec({ } } - "respect FIFO order installed release functions" { + @Test + fun respectFIFOOrderInstalledFunction() = runTest { checkAll(Arb.positiveInt(), Arb.negativeInt()) { a, b -> val order = mutableListOf() @@ -56,7 +60,8 @@ class ResourceTest : StringSpec({ } } - "value resource is released with Complete" { + @Test + fun resourceReleasedWithComplete() = runTest { checkAll(Arb.int()) { n -> val p = CompletableDeferred() resourceScope { @@ -66,7 +71,8 @@ class ResourceTest : StringSpec({ } } - "error resource finishes with error" { + @Test + fun errorFinishesWithError() = runTest { checkAll(Arb.throwable()) { e -> val p = CompletableDeferred() suspend fun ResourceScope.failingScope(): Nothing = @@ -78,7 +84,8 @@ class ResourceTest : StringSpec({ } } - "never use can be cancelled with ExitCase.Completed" { + @Test + fun neverCancelled() = runTest { checkAll(Arb.int()) { n -> val p = CompletableDeferred() val start = CompletableDeferred() @@ -98,7 +105,8 @@ class ResourceTest : StringSpec({ } } - "Map + bind (traverse)" { + @Test + fun mapBind() = runTest { checkAll( Arb.list(Arb.int()), Arb.functionAToB(Arb.string()) @@ -111,7 +119,8 @@ class ResourceTest : StringSpec({ } } - "Resource can close from either" { + @Test + fun resourceCloseFromEither() = runTest { val exit = CompletableDeferred() either { resourceScope { @@ -124,7 +133,7 @@ class ResourceTest : StringSpec({ exit.await().shouldBeTypeOf() } - val depth = 10 + private val depth = 10 class CheckableAutoClose { var started = true @@ -133,7 +142,8 @@ class ResourceTest : StringSpec({ } } - "parZip - success" { + @Test + fun parZipSuccess() = runTestUsingDefaultDispatcher { suspend fun ResourceScope.closeable(): CheckableAutoClose = install({ CheckableAutoClose() }) { a: CheckableAutoClose, _: ExitCase -> a.close() } @@ -146,7 +156,7 @@ class ResourceTest : StringSpec({ } } - fun generate(): Pair>, Resource> { + private fun generate(): Pair>, Resource> { val promises = (1..depth).map { Pair(it, CompletableDeferred()) } val res = promises.fold(resource({ 0 }, { _, _ -> })) { acc, (i, promise) -> resource { @@ -159,7 +169,8 @@ class ResourceTest : StringSpec({ return Pair(promises.map { it.second }, res) } - "parZip - deep finalizers are called when final one blows" { + @Test + fun parZipFinalizersBlow() = runTestUsingDefaultDispatcher { checkAll(3, Arb.int(10..100)) { val (promises, resource) = generate() shouldThrow { @@ -178,7 +189,8 @@ class ResourceTest : StringSpec({ } } - "parZip - deep finalizers are called when final one cancels" { + @Test + fun parZipFinalizersCancel() = runTestUsingDefaultDispatcher { checkAll(3, Arb.int(10..100)) { val cancel = CancellationException(null, null) val (promises, resource) = generate() @@ -199,7 +211,8 @@ class ResourceTest : StringSpec({ } // Test multiple release triggers on acquire fail. - "parZip - Deep finalizers get called on left or right cancellation" { + @Test + fun parZipFinalizersLeftOrRightCancellation() = runTestUsingDefaultDispatcher { checkAll(Arb.boolean()) { isLeft -> val cancel = CancellationException(null, null) val (promises, resource) = generate() @@ -233,7 +246,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Right CancellationException on acquire" { + @Test + fun parZipRightCancellationExceptionOnAcquire() = runTestUsingDefaultDispatcher { checkAll(Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() @@ -261,7 +275,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Left CancellationException on acquire" { + @Test + fun parZipLeftCancellationExceptionOnAcquire() = runTestUsingDefaultDispatcher { checkAll(Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() @@ -290,7 +305,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Right error on acquire" { + @Test + fun parZipRightErrorOnAcquire() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() val started = CompletableDeferred() @@ -317,7 +333,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Left error on acquire" { + @Test + fun parZipLeftErrorOnAcquire() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() val started = CompletableDeferred() @@ -343,7 +360,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Right CancellationException on release" { + @Test + fun parZipRightCancellationExceptionOnRelease() = runTestUsingDefaultDispatcher { checkAll(Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() @@ -364,7 +382,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Left CancellationException on release" { + @Test + fun parZipLeftCancellationExceptionOnRelease() = runTestUsingDefaultDispatcher { checkAll(Arb.int()) { i -> val cancel = CancellationException(null, null) val released = CompletableDeferred>() @@ -385,7 +404,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Right error on release" { + @Test + fun parZipRightErrorOnRelease() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() @@ -405,7 +425,8 @@ class ResourceTest : StringSpec({ } } - "parZip - Left error on release" { + @Test + fun parZipLeftErrorOnRelease() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.throwable()) { i, throwable -> val released = CompletableDeferred>() @@ -425,7 +446,8 @@ class ResourceTest : StringSpec({ } } - "parZip - error in use" { + @Test + fun parZipErrorInUse() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int(), Arb.throwable()) { a, b, throwable -> val releasedA = CompletableDeferred>() val releasedB = CompletableDeferred>() @@ -451,7 +473,8 @@ class ResourceTest : StringSpec({ } } - "parZip - cancellation in use" { + @Test + fun parZipCancellationInUse() = runTestUsingDefaultDispatcher { checkAll(Arb.int(), Arb.int()) { a, b -> val releasedA = CompletableDeferred>() val releasedB = CompletableDeferred>() @@ -477,7 +500,8 @@ class ResourceTest : StringSpec({ } } - "resource.asFlow()" { + @Test + fun resourceAsFlow() = runTest { checkAll(Arb.int()) { n -> val released = CompletableDeferred() val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) @@ -488,7 +512,8 @@ class ResourceTest : StringSpec({ } } - "resource.asFlow() - failed" { + @Test + fun resourceAsFlowFail() = runTest { checkAll(Arb.int(), Arb.throwable()) { n, throwable -> val released = CompletableDeferred() val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) @@ -501,7 +526,8 @@ class ResourceTest : StringSpec({ } } - "resource.asFlow() - cancelled" { + @Test + fun resourceAsFlowCancel() = runTest { checkAll(Arb.int()) { n -> val released = CompletableDeferred() val r = resource({ n }, { _, ex -> require(released.complete(ex)) }) @@ -514,7 +540,9 @@ class ResourceTest : StringSpec({ } } - "allocated" { + @OptIn(DelicateCoroutinesApi::class) + @Test + fun allocatedWorks() = runTest { checkAll(Arb.int()) { seed -> val released = CompletableDeferred() val (allocate, release) = resource({ seed }) { _, exitCase -> released.complete(exitCase) } @@ -526,7 +554,9 @@ class ResourceTest : StringSpec({ } } - "allocated - suppressed exception" { + @OptIn(DelicateCoroutinesApi::class) + @Test + fun allocatedSupressedException() = runTest { checkAll( Arb.int(), Arb.string().map(::RuntimeException), @@ -554,7 +584,9 @@ class ResourceTest : StringSpec({ } } - "allocated - cancellation exception" { + @OptIn(DelicateCoroutinesApi::class) + @Test + fun allocatedCancellationException() = runTest { checkAll( Arb.int(), Arb.string().map { CancellationException(it, null) }, @@ -581,4 +613,4 @@ class ResourceTest : StringSpec({ released.await().shouldBeTypeOf() } } -}) +} diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt index 1ca0f21b4d9..7e1421a311f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/FlowJvmTest.kt @@ -10,14 +10,11 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toSet -import kotlin.time.ExperimentalTime import kotlinx.coroutines.flow.flowOn -import kotlinx.coroutines.test.runTest @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) -@ExperimentalTime class FlowJvmTest { - @Test fun parMapSingleThreadIdentity() = runTest { + @Test fun parMapSingleThreadIdentity() = runTestUsingDefaultDispatcher { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> @@ -27,7 +24,7 @@ class FlowJvmTest { } } - @Test fun parMapflowOn() = runTest { + @Test fun parMapflowOn() = runTestUsingDefaultDispatcher { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> @@ -39,7 +36,7 @@ class FlowJvmTest { } } - @Test fun parMapUnorderedSingleThreadIdentity() = runTest { + @Test fun parMapUnorderedSingleThreadIdentity() = runTestUsingDefaultDispatcher { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> @@ -49,7 +46,7 @@ class FlowJvmTest { } } - @Test fun parMapUnorderedFlowOn() = runTest { + @Test fun parMapUnorderedFlowOn() = runTestUsingDefaultDispatcher { resourceScope { val ctx = singleThreadContext("single") checkAll(Arb.flow(Arb.int())) { flow -> diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt index c40ea02e221..71f1617df6b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParMapJvmTest.kt @@ -5,11 +5,10 @@ import io.kotest.matchers.string.shouldStartWith import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll -import kotlinx.coroutines.test.runTest import kotlin.test.Test class ParMapJvmTest { - @Test fun parMapRunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list + @Test fun parMapRunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMap(single()) { Thread.currentThread().name } @@ -18,7 +17,7 @@ class ParMapJvmTest { } } - @Test fun parMapConcurrency3RunsOnProvidedContext() = runTest { + @Test fun parMapConcurrency3RunsOnProvidedContext() = runTestUsingDefaultDispatcher { checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMap(single(), concurrency = 3) { @@ -29,7 +28,7 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateCombineEmptyErrorRunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateCombineEmptyErrorRunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate(single(), combine = emptyError) { Thread.currentThread().name } @@ -41,7 +40,7 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateCombineEmptyErrorConcurrency3RunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateCombineEmptyErrorConcurrency3RunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate( @@ -57,7 +56,7 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateRunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateRunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { (0 until i).parMapOrAccumulate(single()) { @@ -71,7 +70,7 @@ class ParMapJvmTest { } } - @Test fun parMapOrAccumulateConcurrency3RunsOnProvidedContext() = runTest { // 100 is same default length as Arb.list + @Test fun parMapOrAccumulateConcurrency3RunsOnProvidedContext() = runTestUsingDefaultDispatcher { // 100 is same default length as Arb.list checkAll(Arb.int(min = Int.MIN_VALUE, max = 100)) { i -> val res = resourceScope { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt index f79c1567376..59198b7b1c0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt @@ -11,13 +11,12 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.coroutines.CoroutineContext import kotlin.test.Test class ParZip2JvmTest { - @Test fun parZip2ReturnsToOriginalContext() = runTest { + @Test fun parZip2ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip2" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } @@ -36,7 +35,7 @@ class ParZip2JvmTest { } } - @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip2" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } @@ -46,8 +45,8 @@ class ParZip2JvmTest { Either.catch { when (choose) { - 1 -> parZip(zipCtx, { e.suspend() }, { awaitCancellation() }) { _, _ -> Unit } - else -> parZip(zipCtx, { awaitCancellation() }, { e.suspend() }) { _, _ -> Unit } + 1 -> parZip(zipCtx, { throw e }, { awaitCancellation() }) { _, _ -> Unit } + else -> parZip(zipCtx, { awaitCancellation() }, { throw e }) { _, _ -> Unit } } } should leftException(e) @@ -57,7 +56,7 @@ class ParZip2JvmTest { } } - @Test fun parZip2FinishesOnSingleThread() = runTest { + @Test fun parZip2FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt index b29ea698f8e..4ee71a370e4 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt @@ -11,12 +11,11 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test class ParZip3JvmTest { - @Test fun parZip3ReturnsToOriginalContext() = runTest { + @Test fun parZip3ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } @@ -36,7 +35,7 @@ class ParZip3JvmTest { } } - @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } @@ -49,7 +48,7 @@ class ParZip3JvmTest { when (choose) { 1 -> parZip( zipCtx, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() } ) { _, _, _ -> Unit } @@ -57,7 +56,7 @@ class ParZip3JvmTest { 2 -> parZip( zipCtx, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() } ) { _, _, _ -> Unit } @@ -65,7 +64,7 @@ class ParZip3JvmTest { zipCtx, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() } + { throw e } ) { _, _, _ -> Unit } } } should leftException(e) @@ -76,7 +75,7 @@ class ParZip3JvmTest { } } - @Test fun parZip3FinishesOnSingleThread() = runTest { + @Test fun parZip3FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt index 92fb66836fa..3a4a3a859e5 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt @@ -12,12 +12,11 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test class ParZip4JvmTest { - @Test fun parZip4ReturnsToOriginalContext() = runTest { + @Test fun parZip4ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } @@ -42,7 +41,7 @@ class ParZip4JvmTest { } } - @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } @@ -55,7 +54,7 @@ class ParZip4JvmTest { when (choose) { 1 -> parZip( zipCtx, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() } @@ -64,7 +63,7 @@ class ParZip4JvmTest { 2 -> parZip( zipCtx, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() } ) { _, _, _, _ -> Unit } @@ -73,7 +72,7 @@ class ParZip4JvmTest { zipCtx, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() } ) { _, _, _, _ -> Unit } @@ -82,7 +81,7 @@ class ParZip4JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() } + { throw e } ) { _, _, _, _ -> Unit } } } should leftException(e) @@ -93,7 +92,7 @@ class ParZip4JvmTest { } } - @Test fun parZip4FinishesOnSingleThread() = runTest { + @Test fun parZip4FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt index 98ede0dcf03..35ed03b0699 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt @@ -13,7 +13,6 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test @@ -21,7 +20,7 @@ class ParZip5JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip5ReturnsToOriginalContext() = runTest { + @Test fun parZip5ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } @@ -43,7 +42,7 @@ class ParZip5JvmTest { } } - @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } @@ -56,7 +55,7 @@ class ParZip5JvmTest { when (choose) { 1 -> parZip( zipCtx, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -66,7 +65,7 @@ class ParZip5JvmTest { 2 -> parZip( zipCtx, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() } @@ -76,7 +75,7 @@ class ParZip5JvmTest { zipCtx, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() } ) { _, _, _, _, _ -> Unit } @@ -86,7 +85,7 @@ class ParZip5JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() } ) { _, _, _, _, _ -> Unit } @@ -96,7 +95,7 @@ class ParZip5JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() } + { throw e } ) { _, _, _, _, _ -> Unit } } } should leftException(e) @@ -107,7 +106,7 @@ class ParZip5JvmTest { } } - @Test fun parZip5FinishesOnSingleThread() = runTest { + @Test fun parZip5FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt index 40fc8124137..43ce8ffac94 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt @@ -13,7 +13,6 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test @@ -21,7 +20,7 @@ class ParZip6JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip6ReturnsToOriginalContext() = runTest { + @Test fun parZip6ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } @@ -46,7 +45,7 @@ class ParZip6JvmTest { } } - @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } @@ -59,7 +58,7 @@ class ParZip6JvmTest { when (choose) { 1 -> parZip( zipCtx, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -70,7 +69,7 @@ class ParZip6JvmTest { 2 -> parZip( zipCtx, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -81,7 +80,7 @@ class ParZip6JvmTest { zipCtx, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() } @@ -92,7 +91,7 @@ class ParZip6JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() } ) { _, _, _, _, _, _ -> Unit } @@ -103,7 +102,7 @@ class ParZip6JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() } ) { _, _, _, _, _, _ -> Unit } @@ -114,7 +113,7 @@ class ParZip6JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() } + { throw e } ) { _, _, _, _, _, _ -> Unit } } } should leftException(e) @@ -124,7 +123,7 @@ class ParZip6JvmTest { } } - @Test fun parZip6FinishesOnSingleThread() = runTest { + @Test fun parZip6FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt index 1af73d38194..f413ad93ab9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt @@ -13,7 +13,6 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test @@ -21,7 +20,7 @@ class ParZip7JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip7ReturnsToOriginalContext() = runTest { + @Test fun parZip7ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } @@ -47,7 +46,7 @@ class ParZip7JvmTest { } } - @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } @@ -60,7 +59,7 @@ class ParZip7JvmTest { when (choose) { 1 -> parZip( zipCtx, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -72,7 +71,7 @@ class ParZip7JvmTest { 2 -> parZip( zipCtx, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -84,7 +83,7 @@ class ParZip7JvmTest { zipCtx, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -96,7 +95,7 @@ class ParZip7JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() } @@ -108,7 +107,7 @@ class ParZip7JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() } ) { _, _, _, _, _, _, _ -> Unit } @@ -120,7 +119,7 @@ class ParZip7JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() } ) { _, _, _, _, _, _, _ -> Unit } @@ -132,7 +131,7 @@ class ParZip7JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() } + { throw e } ) { _, _, _, _, _, _, _ -> Unit } } } should leftException(e) @@ -142,7 +141,7 @@ class ParZip7JvmTest { } } - @Test fun parZip7FinishesOnSingleThread() = runTest { + @Test fun parZip7FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt index 52b2febd22f..dceab097d6f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt @@ -13,7 +13,6 @@ import io.kotest.property.checkAll import java.util.concurrent.Executors import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test @@ -21,7 +20,7 @@ class ParZip8JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip8ReturnsToOriginalContext() = runTest { + @Test fun parZip8ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } @@ -48,7 +47,7 @@ class ParZip8JvmTest { } - @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } @@ -61,7 +60,7 @@ class ParZip8JvmTest { when (choose) { 1 -> parZip( zipCtx, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -74,7 +73,7 @@ class ParZip8JvmTest { 2 -> parZip( zipCtx, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -86,7 +85,7 @@ class ParZip8JvmTest { 3 -> parZip( { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -98,7 +97,7 @@ class ParZip8JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -111,7 +110,7 @@ class ParZip8JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() } @@ -124,7 +123,7 @@ class ParZip8JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() } ) { _, _, _, _, _, _, _, _ -> Unit } @@ -137,7 +136,7 @@ class ParZip8JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() } ) { _, _, _, _, _, _, _, _ -> Unit } @@ -150,7 +149,7 @@ class ParZip8JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() } + { throw e } ) { _, _, _, _, _, _, _, _ -> Unit } } } should leftException(e) @@ -160,7 +159,7 @@ class ParZip8JvmTest { } } - @Test fun parZip8FinishesOnSingleThread() = runTest { + @Test fun parZip8FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { val ctx = singleThreadContext("single") diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt index fdd3a74b23a..6a2abe501e0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt @@ -12,7 +12,6 @@ import io.kotest.property.arbitrary.string import io.kotest.property.checkAll import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test import java.util.concurrent.Executors @@ -21,7 +20,7 @@ class ParZip9JvmTest { val threadName: suspend CoroutineScope.() -> String = { Thread.currentThread().name } - @Test fun parZip9ReturnsToOriginalContext() = runTest { + @Test fun parZip9ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } @@ -58,7 +57,7 @@ class ParZip9JvmTest { } - @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTest { + @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } @@ -71,7 +70,7 @@ class ParZip9JvmTest { when (choose) { 1 -> parZip( zipCtx, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -85,7 +84,7 @@ class ParZip9JvmTest { 2 -> parZip( zipCtx, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -99,7 +98,7 @@ class ParZip9JvmTest { zipCtx, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -113,7 +112,7 @@ class ParZip9JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -127,7 +126,7 @@ class ParZip9JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, @@ -141,7 +140,7 @@ class ParZip9JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() } @@ -155,7 +154,7 @@ class ParZip9JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() }, { awaitCancellation() } ) { _, _, _, _, _, _, _, _, _ -> Unit } @@ -169,7 +168,7 @@ class ParZip9JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() }, + { throw e }, { awaitCancellation() } ) { _, _, _, _, _, _, _, _, _ -> Unit } @@ -183,7 +182,7 @@ class ParZip9JvmTest { { awaitCancellation() }, { awaitCancellation() }, { awaitCancellation() }, - { e.suspend() } + { throw e } ) { _, _, _, _, _, _, _, _, _ -> Unit } } } should leftException(e) @@ -193,7 +192,7 @@ class ParZip9JvmTest { } } - @Test fun parZip9FinishesOnSingleThread() = runTest { + @Test fun parZip9FinishesOnSingleThread() = runTestUsingDefaultDispatcher { checkAll(Arb.string()) { val res = resourceScope { parZip( diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt index 6b2e553114e..6fe60f03036 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt @@ -8,12 +8,11 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.checkAll import kotlinx.coroutines.awaitCancellation -import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlin.test.Test class RaceNJvmTest { - @Test fun race2ReturnsToOriginalContext() = runTest { + @Test fun race2ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val racerName = "race2" checkAll(Arb.int(1..2)) { choose -> resourceScope { @@ -33,7 +32,7 @@ class RaceNJvmTest { } } - @Test fun race2ReturnsToOriginalContextOnFailure() = runTest { + @Test fun race2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val racerName = "race2" checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> @@ -44,8 +43,8 @@ class RaceNJvmTest { Either.catch { when (choose) { - 1 -> raceN(pool, { e.suspend() }, { awaitCancellation() }).swap().getOrNull() - else -> raceN(pool, { awaitCancellation() }, { e.suspend() }).getOrNull() + 1 -> raceN(pool, { throw e }, { awaitCancellation() }).swap().getOrNull() + else -> raceN(pool, { awaitCancellation() }, { throw e }).getOrNull() } } should leftException(e) @@ -55,14 +54,14 @@ class RaceNJvmTest { } } - @Test fun firstRacerOutOf2AlwaysWinsOnASingleThread() = runTest { + @Test fun firstRacerOutOf2AlwaysWinsOnASingleThread() = runTestUsingDefaultDispatcher { resourceScope { val ctx = singleThreadContext("single") raceN(ctx, { Thread.currentThread().name }, { Thread.currentThread().name }) }.swap().getOrNull() shouldStartWith "single" } - @Test fun race3ReturnsToOriginalContext() = runTest { + @Test fun race3ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { val racerName = "race3" checkAll(Arb.int(1..3)) { choose -> @@ -91,7 +90,7 @@ class RaceNJvmTest { } } - @Test fun race3ReturnsToOriginalContextOnFailure() = runTest { + @Test fun race3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val racerName = "race3" checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> @@ -102,16 +101,16 @@ class RaceNJvmTest { Either.catch { when (choose) { 1 -> - raceN(raceCtx, { e.suspend() }, { awaitCancellation() }, { awaitCancellation() }) - .fold(::identity, { null }, { null }) + raceN(raceCtx, { throw e }, { awaitCancellation() }, { awaitCancellation() }) + .fold({ x: String? -> x }, { null }, { null }) 2 -> - raceN(raceCtx, { awaitCancellation() }, { e.suspend() }, { awaitCancellation() }) - .fold({ null }, ::identity, { null }) + raceN(raceCtx, { awaitCancellation() }, { throw e }, { awaitCancellation() }) + .fold({ null }, { x: String? -> x }, { null }) else -> - raceN(raceCtx, { awaitCancellation() }, { awaitCancellation() }, { e.suspend() }) - .fold({ null }, { null }, ::identity) + raceN(raceCtx, { awaitCancellation() }, { awaitCancellation() }, { throw e }) + .fold({ null }, { null }, { x: String? -> x }) } } should leftException(e) From da9d42e15f590a64a1d512f76e73e2a9f2978780 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Thu, 9 Nov 2023 12:16:30 +0100 Subject: [PATCH 101/114] Fix problems with concurrency in tests, take 8 --- .../src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt | 7 ++++++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt | 3 ++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt | 3 ++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt | 3 ++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt | 3 ++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt | 3 ++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt | 3 ++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt | 3 ++- .../jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt | 3 ++- .../src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt | 5 +++-- 10 files changed, 25 insertions(+), 11 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt index c651c7bd63b..8479f0f5806 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt @@ -7,6 +7,8 @@ import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext +import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds fun stackSafeIteration(): Int = when (platform) { Platform.JVM -> 20_000 @@ -15,7 +17,10 @@ fun stackSafeIteration(): Int = when (platform) { // The normal dispatcher with 'runTest' does some magic // which doesn't go well with 'parZip', 'parMap', and 'raceN' -fun runTestUsingDefaultDispatcher(testBody: suspend TestScope.() -> Unit): TestResult = runTest { +fun runTestUsingDefaultDispatcher( + timeout: Duration = 10.seconds, + testBody: suspend TestScope.() -> Unit +): TestResult = runTest(timeout = timeout) { withContext(Dispatchers.Default) { testBody() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt index 59198b7b1c0..cb31b71bc85 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.coroutines.CoroutineContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class ParZip2JvmTest { @Test fun parZip2ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { @@ -35,7 +36,7 @@ class ParZip2JvmTest { } } - @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip2" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt index 4ee71a370e4..7d1b9c83d58 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt @@ -13,6 +13,7 @@ import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class ParZip3JvmTest { @Test fun parZip3ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { @@ -35,7 +36,7 @@ class ParZip3JvmTest { } } - @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt index 3a4a3a859e5..bae34c72a2f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt @@ -14,6 +14,7 @@ import java.util.concurrent.Executors import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class ParZip4JvmTest { @Test fun parZip4ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { @@ -41,7 +42,7 @@ class ParZip4JvmTest { } } - @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt index 35ed03b0699..39ac21b608a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class ParZip5JvmTest { val threadName: suspend CoroutineScope.() -> String = @@ -42,7 +43,7 @@ class ParZip5JvmTest { } } - @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt index 43ce8ffac94..3772cb318e0 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class ParZip6JvmTest { val threadName: suspend CoroutineScope.() -> String = @@ -45,7 +46,7 @@ class ParZip6JvmTest { } } - @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt index f413ad93ab9..9cd78e1470b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class ParZip7JvmTest { val threadName: suspend CoroutineScope.() -> String = @@ -46,7 +47,7 @@ class ParZip7JvmTest { } } - @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt index dceab097d6f..6594ec48d9f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class ParZip8JvmTest { val threadName: suspend CoroutineScope.() -> String = @@ -47,7 +48,7 @@ class ParZip8JvmTest { } - @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt index 6a2abe501e0..2695c684080 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test import java.util.concurrent.Executors +import kotlin.time.Duration.Companion.seconds class ParZip9JvmTest { val threadName: suspend CoroutineScope.() -> String = @@ -57,7 +58,7 @@ class ParZip9JvmTest { } - @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt index 6fe60f03036..e5706ae8394 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt @@ -10,6 +10,7 @@ import io.kotest.property.checkAll import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.withContext import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class RaceNJvmTest { @Test fun race2ReturnsToOriginalContext() = runTestUsingDefaultDispatcher { @@ -32,7 +33,7 @@ class RaceNJvmTest { } } - @Test fun race2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun race2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val racerName = "race2" checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> @@ -90,7 +91,7 @@ class RaceNJvmTest { } } - @Test fun race3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { + @Test fun race3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { val racerName = "race3" checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> From 457fcadc68b845214358a88484a445e1d3a86022 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Sat, 11 Nov 2023 07:52:28 +0100 Subject: [PATCH 102/114] Port rest of `arrow-core` to `kotlin.test` (#3292) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- arrow-libs/core/arrow-core/build.gradle.kts | 29 +- arrow-libs/core/arrow-core/knit.test.template | 9 +- .../kotlin/arrow/core/BooleanTest.kt | 7 +- .../kotlin/arrow/core/ComparisonKtTest.kt | 4 +- .../kotlin/arrow/core/EitherTest.kt | 329 ++++----- .../commonTest/kotlin/arrow/core/IorTest.kt | 57 +- .../kotlin/arrow/core/IterableTest.kt | 73 +- .../kotlin/arrow/core/KotestConfig.kt | 12 - .../commonTest/kotlin/arrow/core/ListKTest.kt | 10 +- .../commonTest/kotlin/arrow/core/MapKTest.kt | 148 ++-- .../kotlin/arrow/core/NonEmptyListTest.kt | 2 +- .../kotlin/arrow/core/NonFatalTest.kt | 12 +- .../kotlin/arrow/core/OptionTest.kt | 650 +++++++++--------- .../kotlin/arrow/core/SequenceKTest.kt | 41 +- .../commonTest/kotlin/arrow/core/TupleTest.kt | 19 +- .../core/extensions/NumberInstancesTest.kt | 47 +- .../arrow/core/raise/EagerEffectSpec.kt | 1 - .../kotlin/arrow/core/raise/IorSpec.kt | 2 +- .../kotlin/arrow/core/test/Generators.kt | 4 +- .../commonTest/kotlin/arrow/core/test/Laws.kt | 23 +- .../jvmTest/java/arrow/core/DeadlockTest.kt | 13 +- .../kotlin/examples/test/EitherKnitTest.kt | 37 +- .../kotlin/examples/test/IterableKnitTest.kt | 43 +- .../kotlin/examples/test/OptionKnitTest.kt | 11 +- .../kotlin/examples/test/RaiseKnitTest.kt | 29 +- .../kotlin/examples/test/SequenceKnitTest.kt | 17 +- .../fx/arrow-fx-coroutines/build.gradle.kts | 4 +- .../kotlin/arrow/fx/coroutines/Platform.kt | 2 +- .../arrow/fx/coroutines/ParZip2JvmTest.kt | 2 +- .../arrow/fx/coroutines/ParZip3JvmTest.kt | 2 +- .../arrow/fx/coroutines/ParZip4JvmTest.kt | 2 +- .../arrow/fx/coroutines/ParZip5JvmTest.kt | 2 +- .../arrow/fx/coroutines/ParZip6JvmTest.kt | 2 +- .../arrow/fx/coroutines/ParZip7JvmTest.kt | 2 +- .../arrow/fx/coroutines/ParZip8JvmTest.kt | 2 +- .../arrow/fx/coroutines/ParZip9JvmTest.kt | 2 +- .../arrow/fx/coroutines/RaceNJvmTest.kt | 4 +- 37 files changed, 830 insertions(+), 825 deletions(-) delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/KotestConfig.kt diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index 5cba44a0899..c1841844ac0 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -1,13 +1,13 @@ @file:Suppress("DSL_SCOPE_VIOLATION") import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.time.Duration plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) alias(libs.plugins.kotlinx.kover) - alias(libs.plugins.kotest.multiplatform) alias(libs.plugins.spotless) } @@ -34,17 +34,10 @@ kotlin { implementation(projects.arrowFxCoroutines) implementation(libs.kotlin.test) implementation(libs.coroutines.test) - implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } } - - jvmTest { - dependencies { - runtimeOnly(libs.kotest.runnerJUnit5) - } - } } jvm { @@ -54,13 +47,31 @@ kotlin { } } } + + js { + nodejs { + testTask { + useMocha { + timeout = "300s" + } + } + } + browser { + testTask { + useKarma { + useChromeHeadless() + timeout.set(Duration.ofMinutes(5)) + } + } + } + } } -// enables context receivers for Jvm Tests tasks.withType().configureEach { kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes" } +// enables context receivers for Jvm Tests tasks.named("compileTestKotlinJvm") { kotlinOptions.freeCompilerArgs += "-Xcontext-receivers" } diff --git a/arrow-libs/core/arrow-core/knit.test.template b/arrow-libs/core/arrow-core/knit.test.template index 7b3f20935a9..081b5998b41 100644 --- a/arrow-libs/core/arrow-core/knit.test.template +++ b/arrow-libs/core/arrow-core/knit.test.template @@ -1,15 +1,14 @@ // This file was automatically generated from ${file.name} by Knit tool. Do not edit. package ${test.package} -import io.kotest.core.spec.style.StringSpec +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class ${test.name} : StringSpec({ +class ${test.name} { <#list cases as case> - "${case.name}" { + @Test fun ${case.knit.name}() = runTest { ${case.knit.package}.${case.knit.name}.test() } -}) { - override fun timeout(): Long = 1000 } \ No newline at end of file diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/BooleanTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/BooleanTest.kt index b53fa2bc8e6..1ee68bcbcb8 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/BooleanTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/BooleanTest.kt @@ -2,12 +2,13 @@ package arrow.core import arrow.core.test.laws.MonoidLaws import arrow.core.test.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean +import kotlin.test.Test -class BooleanTest : StringSpec({ +class BooleanTest{ + @Test fun monoidLaws() = testLaws( MonoidLaws("Boolean", true, { x, y -> x && y }, Arb.boolean()) ) -}) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt index 1be9f189a4c..bde7a4b8ba4 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ComparisonKtTest.kt @@ -28,7 +28,7 @@ data class Person(val age: Int, val name: String) : Comparable { } fun Arb.Companion.person(): Arb = - Arb.bind(Arb.int(), Arb.string(), ::Person) + Arb.bind(Arb.int(0, 100), Arb.string(0 .. 10), ::Person) class ComparisonKtTest { @Test fun arbericSort2() = runTest { @@ -57,7 +57,7 @@ class ComparisonKtTest { } @Test fun arbericSortAll() = runTest { - checkAll(Arb.person(), Arb.list(Arb.person(), 0..50)) { a, lst -> + checkAll(Arb.person(), Arb.list(Arb.person(), 0..20)) { a, lst -> val aas = lst.toTypedArray() val res = sort(a, *aas) val expected = listOf(a, *aas).sorted() diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt index ab111b619d3..8e570bcec97 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt @@ -2,19 +2,12 @@ package arrow.core import arrow.core.Either.Left import arrow.core.Either.Right -import arrow.core.test.any import arrow.core.test.either import arrow.core.test.intSmall import arrow.core.test.laws.MonoidLaws import arrow.core.test.nonEmptyList -import arrow.core.test.suspendFunThatReturnsAnyLeft -import arrow.core.test.suspendFunThatReturnsAnyRight -import arrow.core.test.suspendFunThatReturnsEitherAnyOrAnyOrThrows -import arrow.core.test.suspendFunThatThrows import arrow.core.test.testLaws import io.kotest.assertions.fail -import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean @@ -23,182 +16,204 @@ import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.double import io.kotest.property.arbitrary.float import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.long -import io.kotest.property.arbitrary.nonPositiveInt import io.kotest.property.arbitrary.short import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class EitherTest : StringSpec({ +class EitherTest { val ARB = Arb.either(Arb.string(), Arb.int()) + @Test + fun monoidLaws() = testLaws( MonoidLaws("Either", 0.right(), { x, y -> x.combine(y, String::plus, Int::plus) }, ARB) ) - "isLeft should return true if Left and false if Right" { - checkAll(Arb.int()) { a: Int -> - val x = Left(a) - if (x.isLeft()) x.value shouldBe a - else fail("Left(a).isLeft() cannot be false") - x.isRight() shouldBe false - } + @Test + fun leftIsLeftIsRight() = runTest { + checkAll(Arb.int()) { a: Int -> + val x = Left(a) + if (x.isLeft()) x.value shouldBe a + else fail("Left(a).isLeft() cannot be false") + x.isRight() shouldBe false } - - "isRight should return false if Left and true if Right" { - checkAll(Arb.int()) { a: Int -> - val x = Right(a) - if (x.isRight()) x.value shouldBe a - else fail("Right(a).isRight() cannot be false") - x.isLeft() shouldBe false - } - } - - "tap applies effects returning the original value" { - checkAll(Arb.either(Arb.long(), Arb.int())) { either -> - var effect = 0 - val res = either.onRight { effect += 1 } - val expected = when (either) { - is Left -> 0 - is Right -> 1 - } - effect shouldBe expected - res shouldBe either - } - } - - "tapLeft applies effects returning the original value" { - checkAll(Arb.either(Arb.long(), Arb.int())) { either -> - var effect = 0 - val res = either.onLeft { effect += 1 } - val expected = when (either) { - is Left -> 1 - is Right -> 0 - } - effect shouldBe expected - res shouldBe either - } + } + + @Test + fun rightIsLeftIsRight() = runTest { + checkAll(Arb.int()) { a: Int -> + val x = Right(a) + if (x.isRight()) x.value shouldBe a + else fail("Right(a).isRight() cannot be false") + x.isLeft() shouldBe false } - - "fold should apply first op if Left and second op if Right" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val right: Either = Right(a) - val left: Either = Left(b) - - right.fold({ it + 2 }, { it + 1 }) shouldBe a + 1 - left.fold({ it + 2 }, { it + 1 }) shouldBe b + 2 + } + + @Test + fun tapAppliesEffects() = runTest { + checkAll(Arb.either(Arb.long(), Arb.int())) { either -> + var effect = 0 + val res = either.onRight { effect += 1 } + val expected = when (either) { + is Left -> 0 + is Right -> 1 } + effect shouldBe expected + res shouldBe either } + } - "combine two rights should return a right of the combine of the inners" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - Right(a + b) shouldBe Right(a).combine( - Right(b), - Int::plus, - String::plus - ) + @Test + fun tapLeftAppliesEffects() = runTest { + checkAll(Arb.either(Arb.long(), Arb.int())) { either -> + var effect = 0 + val res = either.onLeft { effect += 1 } + val expected = when (either) { + is Left -> 1 + is Right -> 0 } + effect shouldBe expected + res shouldBe either } - - "combine two lefts should return a left of the combine of the inners" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - Left(a + b) shouldBe Left(a).combine( - Left(b), - String::plus, - Int::plus - ) - } + } + + @Test + fun foldOk() = runTest { + checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> + val right: Either = Right(a) + val left: Either = Left(b) + + right.fold({ it + 2 }, { it + 1 }) shouldBe a + 1 + left.fold({ it + 2 }, { it + 1 }) shouldBe b + 2 } - - "combine a right and a left should return left" { - checkAll(Arb.string(), Arb.string()) { a: String, b: String -> - Left(a) shouldBe Left(a).combine(Right(b), String::plus, String::plus) - Left(a) shouldBe Right(b).combine(Left(a), String::plus, String::plus) - } + } + + @Test + fun combineTwoRights() = runTest { + checkAll(Arb.string(), Arb.string()) { a: String, b: String -> + Right(a + b) shouldBe Right(a).combine( + Right(b), + Int::plus, + String::plus + ) } - - "getOrElse should return value" { - checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> - Right(a).getOrElse { b } shouldBe a - Left(a).getOrElse { b } shouldBe b - } + } + + @Test + fun combineTwoLefts() = runTest { + checkAll(Arb.string(), Arb.string()) { a: String, b: String -> + Left(a + b) shouldBe Left(a).combine( + Left(b), + String::plus, + Int::plus + ) } - - "getOrNull should return value" { - checkAll(Arb.int()) { a: Int -> - Right(a).getOrNull() shouldBe a - } + } + + @Test + fun combineRightLeft() = runTest { + checkAll(Arb.string(), Arb.string()) { a: String, b: String -> + Left(a) shouldBe Left(a).combine(Right(b), String::plus, String::plus) + Left(a) shouldBe Right(b).combine(Left(a), String::plus, String::plus) } - - "getOrNone should return Some(value)" { - checkAll(Arb.int()) { a: Int -> - Right(a).getOrNone() shouldBe Some(a) - } + } + + @Test + fun getOrElseOk() = runTest { + checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> + Right(a).getOrElse { b } shouldBe a + Left(a).getOrElse { b } shouldBe b } - - "getOrNone should return None when left" { - checkAll(Arb.string()) { a: String -> - Left(a).getOrNone() shouldBe None - } + } + + @Test + fun getOrNullOk() = runTest { + checkAll(Arb.int()) { a: Int -> + Right(a).getOrNull() shouldBe a } + } - "swap should interchange values" { - checkAll(Arb.int()) { a: Int -> - Left(a).swap() shouldBe Right(a) - Right(a).swap() shouldBe Left(a) - } + @Test + fun getOrNoneRight() = runTest { + checkAll(Arb.int()) { a: Int -> + Right(a).getOrNone() shouldBe Some(a) } + } - "map should alter right instance only" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val right: Either = Right(a) - val left: Either = Left(b) - - right.map { it + 1 } shouldBe Right(a + 1) - left.map { it + 1 } shouldBe left - } + @Test + fun getOrNoneLeft() = runTest { + checkAll(Arb.string()) { a: String -> + Left(a).getOrNone() shouldBe None } - - "mapLeft should alter left instance only" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val right: Either = Right(a) - val left: Either = Left(b) - - right.mapLeft { it + 1 } shouldBe right - left.mapLeft { it + 1 } shouldBe Left(b + 1) - } + } + + @Test + fun swapOk() = runTest { + checkAll(Arb.int()) { a: Int -> + Left(a).swap() shouldBe Right(a) + Right(a).swap() shouldBe Left(a) } + } - "flatMap should map right instance only" { - checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> - val right: Either = Right(a) - val left: Either = Left(b) - - right.flatMap { Right(it + 1) } shouldBe Right(a + 1) - left.flatMap { Right(it + 1) } shouldBe left - } + @Test + fun mapOnlyRight() = runTest { + checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> + val right: Either = Right(a) + val left: Either = Left(b) + + right.map { it + 1 } shouldBe Right(a + 1) + left.map { it + 1 } shouldBe left } + } - "handleErrorWith should handle left instance otherwise return Right" { - checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> - Left(a).recover { Right(b).bind() } shouldBe Right(b) - Right(a).recover { Right(a + 1).bind() } shouldBe Right(a) - Left(a).recover { Left(b).bind() } shouldBe Left(b) - } + @Test + fun mapLeftOnlyLeft() = runTest { + checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> + val right: Either = Right(a) + val left: Either = Left(b) + + right.mapLeft { it + 1 } shouldBe right + left.mapLeft { it + 1 } shouldBe Left(b + 1) } - - "catch should return Right(result) when f does not throw" { - Either.catch { 1 } shouldBe Right(1) + } + + @Test + fun flatMapOnlyRight() = runTest { + checkAll(Arb.intSmall(), Arb.intSmall()) { a, b -> + val right: Either = Right(a) + val left: Either = Left(b) + + right.flatMap { Right(it + 1) } shouldBe Right(a + 1) + left.flatMap { Right(it + 1) } shouldBe left } - - "catch should return Left(result) when f throws" { - val exception = Exception("Boom!") - Either.catch { throw exception } shouldBe Left(exception) + } + + @Test + fun handleErrorWithOk() = runTest { + checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> + Left(a).recover { Right(b).bind() } shouldBe Right(b) + Right(a).recover { Right(a + 1).bind() } shouldBe Right(a) + Left(a).recover { Left(b).bind() } shouldBe Left(b) } + } + + @Test + fun catchRight() = runTest { + Either.catch { 1 } shouldBe Right(1) + } + + @Test + fun catchLeft() = runTest { + val exception = Exception("Boom!") + Either.catch { throw exception } shouldBe Left(exception) + } - "zipOrAccumulate results in all Right transformed, or all Left combined according to combine" { + @Test + fun zipOrAccumulateList() = runTest { checkAll( Arb.either(Arb.string(), Arb.short()), Arb.either(Arb.string(), Arb.byte()), @@ -225,7 +240,8 @@ class EitherTest : StringSpec({ } } - "zipOrAccumulate without Semigroup results in all Right transformed, or all Left in a NonEmptyList" { + @Test + fun zipOrAccumulateSemigroup() = runTest { checkAll( Arb.either(Arb.string(), Arb.short()), Arb.either(Arb.string(), Arb.byte()), @@ -252,7 +268,8 @@ class EitherTest : StringSpec({ } } - "zipOrAccumulate EitherNel results in all Right transformed, or all Left in a NonEmptyList" { + @Test + fun zipOrAccumulateEitherNel() = runTest { checkAll( Arb.either(Arb.nonEmptyList(Arb.int()), Arb.short()), Arb.either(Arb.nonEmptyList(Arb.int()), Arb.byte()), @@ -280,18 +297,4 @@ class EitherTest : StringSpec({ res shouldBe expected } } -}) - -@Suppress("RedundantSuspendModifier", "UNUSED_PARAMETER") -suspend fun handleWithPureFunction(a: Any, b: Any): Either = - b.right() - -@Suppress("RedundantSuspendModifier", "UNUSED_PARAMETER") -suspend fun handleWithPureFunction(throwable: Throwable): Either = - Unit.right() - -@Suppress("RedundantSuspendModifier", "UNUSED_PARAMETER") -private suspend fun throwException( - a: A, -): Either = - throw RuntimeException("An Exception is thrown while handling the result of the supplied function.") +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt index c01bebf56c7..3452062bb3f 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt @@ -3,29 +3,28 @@ package arrow.core import arrow.core.test.ior import arrow.core.test.laws.SemigroupLaws import arrow.core.test.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.data.forAll import io.kotest.data.row import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.property.Arb import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.long -import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class IorTest : StringSpec({ +class IorTest { val ARB = Arb.ior(Arb.string(), Arb.int()) - testLaws( + @Test fun semigroupLaws() = testLaws( SemigroupLaws("Ior", { a, b -> a.combine(b, String::plus, Int::plus) }, ARB) ) - "map() should just right side of an Ior" { + @Test fun mapRightOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).map { l: String -> l.length } shouldBe Ior.Left(a) Ior.Right(b).map { it.length } shouldBe Ior.Right(b.length) @@ -33,7 +32,7 @@ class IorTest : StringSpec({ } } - "mapLeft() should modify only left value" { + @Test fun mapLeftOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Right(b).mapLeft { a * 2 } shouldBe Ior.Right(b) Ior.Left(a).mapLeft { b } shouldBe Ior.Left(b) @@ -41,20 +40,20 @@ class IorTest : StringSpec({ } } - "swap() should interchange value" { + @Test fun swapBoth() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Both(a, b).swap() shouldBe Ior.Both(b, a) } } - "swap() should interchange entity" { + @Test fun swapLeftRight() = runTest { checkAll(Arb.int()) { a: Int -> Ior.Left(a).swap() shouldBe Ior.Right(a) Ior.Right(a).swap() shouldBe Ior.Left(a) } } - "unwrap() should return the isomorphic either" { + @Test fun unwrapOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).unwrap() shouldBe Either.Left(Either.Left(a)) Ior.Right(b).unwrap() shouldBe Either.Left(Either.Right(b)) @@ -62,7 +61,7 @@ class IorTest : StringSpec({ } } - "toEither() should convert values into a valid Either" { + @Test fun toEitherOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).toEither() shouldBe Either.Left(a) Ior.Right(b).toEither() shouldBe Either.Right(b) @@ -70,7 +69,7 @@ class IorTest : StringSpec({ } } - "getOrNull() should convert right values into a nullable, or return null if left" { + @Test fun getOrNullOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).getOrNull() shouldBe null Ior.Right(b).getOrNull() shouldBe b @@ -79,7 +78,7 @@ class IorTest : StringSpec({ } - "leftOrNull() should convert left values into a nullable" { + @Test fun leftOrNullOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.Left(a).leftOrNull() shouldBe a Ior.Right(b).leftOrNull() shouldBe null @@ -87,7 +86,7 @@ class IorTest : StringSpec({ } } - "fromNullables() should build a correct Ior" { + @Test fun fromNullablesOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.fromNullables(a, null) shouldBe Ior.Left(a) Ior.fromNullables(a, b) shouldBe Ior.Both(a, b) @@ -96,19 +95,19 @@ class IorTest : StringSpec({ } } - "leftNel() should build a correct Ior" { + @Test fun leftNelOk() = runTest { checkAll(Arb.int()) { a: Int -> Ior.leftNel(a) shouldBe Ior.Left(nonEmptyListOf(a)) } } - "bothNel() should build a correct Ior" { + @Test fun bothNelOk() = runTest { checkAll(Arb.int(), Arb.string()) { a: Int, b: String -> Ior.bothNel(a, b) shouldBe Ior.Both(nonEmptyListOf(a), b) } } - "getOrElse() should return value" { + @Test fun getOrElseOk() = runTest { checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> Ior.Right(a).getOrElse { b } shouldBe a Ior.Left(a).getOrElse { b } shouldBe b @@ -116,13 +115,13 @@ class IorTest : StringSpec({ } } - "Ior.monad.flatMap should combine left values" { + @Test fun flatMapCombinesLeft() = runTest { val ior1 = Ior.Both(3, "Hello, world!") val iorResult = ior1.flatMap(Int::plus) { Ior.Left(7) } iorResult shouldBe Ior.Left(10) } - "Ior.monad.flatMap should combine Both values" { + @Test fun flatMapCombinesBoth() = runTest { val ior1 = Ior.Both(3, "Hello, world!") val iorResult1 = ior1.flatMap(Int::plus) { Ior.Both(7, "Again!") } iorResult1 shouldBe Ior.Both(10, "Again!") @@ -131,7 +130,7 @@ class IorTest : StringSpec({ iorResult2 shouldBe Ior.Both(3, "Again!") } - "combine cases for Semigroup" { + @Test fun combineSemigroup() = runTest { forAll( row("Hello, ".leftIor(), Ior.Left("Arrow!"), Ior.Left("Hello, Arrow!")), row(Ior.Left("Hello"), Ior.Right(2020), Ior.Both("Hello", 2020)), @@ -147,7 +146,7 @@ class IorTest : StringSpec({ } } - "isLeft() should return true with Left and false otherwise"{ + @Test fun isLeftOk() = runTest { checkAll(Arb.int(), Arb.string()){ a, b -> Ior.Left(a).isLeft() shouldBe true Ior.Right(b).isLeft() shouldBe false @@ -155,7 +154,7 @@ class IorTest : StringSpec({ } } - "isRight() should return true with Right and false otherwise" { + @Test fun isRightOk() = runTest { checkAll(Arb.int(), Arb.string()) { a, b -> Ior.Left(a).isRight() shouldBe false Ior.Right(b).isRight() shouldBe true @@ -163,7 +162,7 @@ class IorTest : StringSpec({ } } - "isBoth() should return true with Both and false otherwise" { + @Test fun isBothOk() = runTest { checkAll(Arb.int(), Arb.string()) { a, b -> Ior.Left(a).isBoth() shouldBe false Ior.Right(b).isBoth() shouldBe false @@ -171,7 +170,7 @@ class IorTest : StringSpec({ } } - "isLeft(predicate) should return true with Left, if satisfies the predicate, and false otherwise" { + @Test fun isLeftPredicateOk() = runTest { checkAll(Arb.int(), Arb.string()) { a, b -> val predicate = { i: Int -> i % 2 == 0 } @@ -183,7 +182,7 @@ class IorTest : StringSpec({ } } - "isRight(predicate) should return true with Right, if satisfies the predicate, and false otherwise" { + @Test fun isRightPredicateOk() = runTest { checkAll(Arb.int(), Arb.string()) { a, b -> val predicate = { s: String -> s.length % 2 == 0 } @@ -195,7 +194,7 @@ class IorTest : StringSpec({ } } - "isBoth(predicate) should return true with Both, if satisfies the predicate, and false otherwise" { + @Test fun isBothPredicateOk() = runTest { checkAll(Arb.int(), Arb.string()) { a, b -> val leftPredicate = { i: Int -> i % 2 == 0 } val rightPredicate = { s: String -> s.length % 2 == 0 } @@ -207,14 +206,14 @@ class IorTest : StringSpec({ } } - "widen should retype Right" { + @Test fun widenOk() = runTest { checkAll(Arb.int(), Arb.string()) { a, b -> val ior = Ior.Both(a, b) ior.widen().shouldBeInstanceOf>() } } - "compareTo should compare 2 Ior" { + @Test fun compareToOk() = runTest { val left1 = Ior.Left(1) val left2 = Ior.Left(2) val right1 = Ior.Right(1) @@ -237,4 +236,4 @@ class IorTest : StringSpec({ both11.compareTo(left1) shouldBe 1 both11.compareTo(right1) shouldBe 1 } -}) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index 0ee9cf24f08..5f449328f2f 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -5,7 +5,6 @@ package arrow.core import arrow.core.test.either import arrow.core.test.ior import arrow.core.test.option -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.nulls.shouldBeNull import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.property.Arb @@ -13,16 +12,18 @@ import io.kotest.matchers.shouldBe import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list -import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest import kotlin.math.max import kotlin.math.min +import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds -class IterableTest : StringSpec({ - "flattenOrAccumulate(combine)" { - checkAll(Arb.list(Arb.either(Arb.string(), Arb.int()))) { list -> +class IterableTest { + @Test fun flattenOrAccumulateCombine() = runTest(timeout = 30.seconds) { + checkAll(Arb.list(Arb.either(Arb.string(maxSize = 10), Arb.int()), range = 0 .. 20)) { list -> val expected = if (list.any { it.isLeft() }) list.filterIsInstance>() .fold("") { acc, either -> "$acc${either.value}" }.left() @@ -32,8 +33,8 @@ class IterableTest : StringSpec({ } } - "flattenOrAccumulate" { - checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()))) { list -> + @Test fun flattenOrAccumulateOk() = runTest { + checkAll(Arb.list(Arb.either(Arb.int(), Arb.int()), range = 0 .. 20)) { list -> val expected = if (list.any { it.isLeft() }) list.filterIsInstance>() .map { it.value }.toNonEmptyListOrNull().shouldNotBeNull().left() @@ -43,7 +44,7 @@ class IterableTest : StringSpec({ } } - "mapAccumulating stack-safe, and runs in original order" { + @Test fun mapOrAccumulateOrder() = runTest { val acc = mutableListOf() val res = (0..20_000).mapOrAccumulate(String::plus) { acc.add(it) @@ -53,8 +54,8 @@ class IterableTest : StringSpec({ res shouldBe (0..20_000).toList().right() } - "mapAccumulating accumulates" { - checkAll(Arb.list(Arb.int())) { ints -> + @Test fun mapOrAccumulateAccumulates() = runTest { + checkAll(Arb.list(Arb.int(), range = 0 .. 20)) { ints -> val res= ints.mapOrAccumulate { i -> if (i % 2 == 0) i else raise(i) } @@ -65,13 +66,13 @@ class IterableTest : StringSpec({ } } - "mapAccumulating with String::plus" { + @Test fun mapOrAccumulateString() = runTest { listOf(1, 2, 3).mapOrAccumulate(String::plus) { i -> raise("fail") } shouldBe Either.Left("failfailfail") } - "zip3" { + @Test fun zip3Ok() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b, c -> val result = a.zip(b, c, ::Triple) val expected = a.zip(b, ::Pair).zip(c) { (a, b), c -> Triple(a, b, c) } @@ -79,7 +80,7 @@ class IterableTest : StringSpec({ } } - "zip4" { + @Test fun zip4Ok() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int()), Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b, c, d -> val result = a.zip(b, c, d, ::Tuple4) val expected = a.zip(b, ::Pair) @@ -90,7 +91,7 @@ class IterableTest : StringSpec({ } } - "zip5" { + @Test fun zip5Ok() = runTest { checkAll( Arb.list(Arb.int()), Arb.list(Arb.int()), @@ -108,7 +109,7 @@ class IterableTest : StringSpec({ } } - "zip6" { + @Test fun zip6Ok() = runTest { checkAll( Arb.list(Arb.int()), Arb.list(Arb.int()), @@ -128,7 +129,7 @@ class IterableTest : StringSpec({ } } - "zip7" { + @Test fun zip7Ok() = runTest { checkAll( Arb.list(Arb.int()), Arb.list(Arb.int()), @@ -150,7 +151,7 @@ class IterableTest : StringSpec({ } } - "zip8" { + @Test fun zip8Ok() = runTest { checkAll( Arb.list(Arb.int()), Arb.list(Arb.int()), @@ -174,7 +175,7 @@ class IterableTest : StringSpec({ } } - "zip9" { + @Test fun zip9Ok() = runTest { checkAll( Arb.list(Arb.int()), Arb.list(Arb.int()), @@ -200,7 +201,7 @@ class IterableTest : StringSpec({ } } - "can align lists with different lengths" { + @Test fun alignDifferentLength() = runTest { checkAll(Arb.list(Arb.boolean()), Arb.list(Arb.boolean())) { a, b -> a.align(b).size shouldBe max(a.size, b.size) } @@ -222,7 +223,7 @@ class IterableTest : StringSpec({ } } - "leftPadZip (with map)" { + @Test fun leftPadZipMap() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b -> val left = a.map { it } + List(max(0, b.count() - a.count())) { null } val right = b.map { it } + List(max(0, a.count() - b.count())) { null } @@ -233,7 +234,7 @@ class IterableTest : StringSpec({ } } - "leftPadZip (without map)" { + @Test fun leftPadZipNoMap() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b -> val left = a.map { it } + List(max(0, b.count() - a.count())) { null } val right = b.map { it } + List(max(0, a.count() - b.count())) { null } @@ -244,7 +245,7 @@ class IterableTest : StringSpec({ } } - "rightPadZip (without map)" { + @Test fun rightPadZipNoMap() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b -> val left = a.map { it } + List(max(0, b.count() - a.count())) { null } val right = b.map { it } + List(max(0, a.count() - b.count())) { null } @@ -256,7 +257,7 @@ class IterableTest : StringSpec({ } } - "rightPadZip (with map)" { + @Test fun rightPadZipMap() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b -> val left = a.map { it } + List(max(0, b.count() - a.count())) { null } val right = b.map { it } + List(max(0, a.count() - b.count())) { null } @@ -268,7 +269,7 @@ class IterableTest : StringSpec({ } } - "padZip" { + @Test fun padZipOk() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b -> val left = a.map { it } + List(max(0, b.count() - a.count())) { null } val right = b.map { it } + List(max(0, a.count() - b.count())) { null } @@ -276,7 +277,7 @@ class IterableTest : StringSpec({ } } - "padZipWithNull" { + @Test fun padZipNull() = runTest { checkAll(Arb.list(Arb.int()), Arb.list(Arb.int())) { a, b -> val left = a.map { it } + List(max(0, b.count() - a.count())) { null } val right = b.map { it } + List(max(0, a.count() - b.count())) { null } @@ -285,19 +286,19 @@ class IterableTest : StringSpec({ } } - "filterOption" { + @Test fun filterOptionOk() = runTest { checkAll(Arb.list(Arb.option(Arb.int()))) { listOfOption -> listOfOption.filterOption() shouldBe listOfOption.mapNotNull { it.getOrNull() } } } - "flattenOption" { + @Test fun flattenOptionOk() = runTest { checkAll(Arb.list(Arb.option(Arb.int()))) { listOfOption -> listOfOption.flattenOption() shouldBe listOfOption.mapNotNull { it.getOrNull() } } } - "separateEither" { + @Test fun separateEitherOk() = runTest { checkAll(Arb.list(Arb.int())) { ints -> val list = ints.separateEither { if (it % 2 == 0) it.left() @@ -307,7 +308,7 @@ class IterableTest : StringSpec({ } } - "unzip is the inverse of zip" { + @Test fun unzipInverseOfZip() = runTest { checkAll(Arb.list(Arb.int())) { xs -> val zipped = xs.zip(xs) @@ -318,13 +319,13 @@ class IterableTest : StringSpec({ } } - "unzip(fn)" { + @Test fun unzipOk() = runTest { checkAll(Arb.list(Arb.pair(Arb.int(), Arb.int()))) { xs -> xs.unzip { it } shouldBe xs.unzip() } } - "unalign is the inverse of align" { + @Test fun unalignInverseOfAlign() = runTest { fun Pair, List>.fix(): Pair, List> = first.mapNotNull { it } to second.mapNotNull { it } @@ -333,7 +334,7 @@ class IterableTest : StringSpec({ } } - "align is the inverse of unalign" { + @Test fun alignInverseOfUnalign() = runTest { fun Ior.fix(): Ior = fold({ Ior.Left(it!!) }, { Ior.Right(it!!) }, { a, b -> when { @@ -351,13 +352,13 @@ class IterableTest : StringSpec({ } } - "unalign(fn)" { + @Test fun unalignOk() = runTest { checkAll(Arb.list(Arb.ior(Arb.int(), Arb.int()))) { xs -> xs.unalign { it } shouldBe xs.unalign() } } - "reduceOrNull is compatible with reduce from stdlib" { + @Test fun reduceOrNullCompatibleWithReduce() = runTest { checkAll(Arb.list(Arb.int())) { xs -> val rs = xs.reduceOrNull({ it }) { a, b -> @@ -374,7 +375,7 @@ class IterableTest : StringSpec({ } } - "reduceRightNull is compatible with reduce from stdlib" { + @Test fun reduceRightNullCompatibleWithReduce() = runTest { checkAll(Arb.list(Arb.int())) { xs -> val rs = xs.reduceRightNull({ it }) { a, b -> @@ -390,4 +391,4 @@ class IterableTest : StringSpec({ } } } -}) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/KotestConfig.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/KotestConfig.kt deleted file mode 100644 index ce7f493fad2..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/KotestConfig.kt +++ /dev/null @@ -1,12 +0,0 @@ -package arrow.core - -import io.kotest.core.config.AbstractProjectConfig -import io.kotest.property.PropertyTesting -import kotlin.time.Duration -import kotlin.time.Duration.Companion.seconds - -class KotestConfig : AbstractProjectConfig() { - override suspend fun beforeProject() { - PropertyTesting.defaultIterationCount = 250 - } -} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ListKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ListKTest.kt index a3ef444a513..08ed5566c53 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ListKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ListKTest.kt @@ -2,18 +2,20 @@ package arrow.core import arrow.core.test.laws.MonoidLaws import arrow.core.test.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class ListKTest : StringSpec({ +class ListKTest { + @Test fun monoidLaws() = testLaws(MonoidLaws("List", emptyList(), List::plus, Arb.list(Arb.int()))) - "mapNotNull() should map list and filter out null values" { + @Test fun mapNotNullOk() = runTest { checkAll(Arb.list(Arb.int())) { listk -> listk.mapNotNull { when (it % 2 == 0) { @@ -24,4 +26,4 @@ class ListKTest : StringSpec({ } } -}) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt index fd89cae7826..e6ba1a9d7e1 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt @@ -9,11 +9,7 @@ import arrow.core.test.map2 import arrow.core.test.map3 import arrow.core.test.option import arrow.core.test.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.inspectors.forAll -import io.kotest.inspectors.forAllValues -import io.kotest.matchers.booleans.shouldBeTrue -import io.kotest.matchers.collections.shouldBeIn import io.kotest.matchers.collections.shouldContainAll import io.kotest.matchers.maps.shouldBeEmpty import io.kotest.matchers.maps.shouldContain @@ -26,13 +22,15 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.choice import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.pair import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class MapKTest : StringSpec({ +class MapKTest { + @Test fun monoidLaws() = testLaws( MonoidLaws( "Map", @@ -42,7 +40,7 @@ class MapKTest : StringSpec({ ) ) - "can align maps" { + @Test fun alignMaps() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -64,7 +62,7 @@ class MapKTest : StringSpec({ } } - "zip is idempotent" { + @Test fun zipIsIdempotent() = runTest { checkAll( Arb.map(Arb.int(), Arb.intSmall())) { a -> @@ -72,7 +70,7 @@ class MapKTest : StringSpec({ } } - "align is idempotent" { + @Test fun alignIsIdempotent() = runTest { checkAll( Arb.map(Arb.int(), Arb.intSmall())) { a -> @@ -80,7 +78,7 @@ class MapKTest : StringSpec({ } } - "zip is commutative" { + @Test fun zipIsCommutative() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -89,7 +87,7 @@ class MapKTest : StringSpec({ } } - "align is commutative" { + @Test fun alignIsCommutative() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -98,7 +96,7 @@ class MapKTest : StringSpec({ } } - "zip is associative" { + @Test fun zipIsAssociative() = runTest { checkAll( Arb.map3(Arb.int(), Arb.int(), Arb.int(), Arb.int()) ) { (a, b, c) -> @@ -110,7 +108,7 @@ class MapKTest : StringSpec({ } } - "align is associative" { + @Test fun alignIsAssociative() = runTest { checkAll( Arb.map3(Arb.int(), Arb.int(), Arb.int(), Arb.int()) ) { (a, b, c) -> @@ -134,7 +132,7 @@ class MapKTest : StringSpec({ } } - "zip with" { + @Test fun zipWith() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()), Arb.functionABCToD(Arb.int()) @@ -143,7 +141,7 @@ class MapKTest : StringSpec({ } } - "align with" { + @Test fun alignWith() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()), Arb.functionAToB>, Int>(Arb.int()) @@ -152,7 +150,7 @@ class MapKTest : StringSpec({ } } - "zip functoriality" { + @Test fun zipFunctor() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()), Arb.functionAToB(Arb.int()), @@ -169,7 +167,7 @@ class MapKTest : StringSpec({ } } - "align functoriality" { + @Test fun alignFunctor() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()), Arb.functionAToB(Arb.int()), @@ -184,7 +182,7 @@ class MapKTest : StringSpec({ } } - "alignedness" { + @Test fun alignedness() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -210,7 +208,7 @@ class MapKTest : StringSpec({ } } - "zippyness1" { + @Test fun zippyness1() = runTest { checkAll( Arb.map(Arb.int(), Arb.int())) { xs -> @@ -218,23 +216,23 @@ class MapKTest : StringSpec({ } } - "zippyness2" { + @Test fun zipyness2() = runTest { checkAll( - Arb.map(Arb.int(), Arb.int())) { + Arb.map(Arb.int(), Arb.int(), maxSize = 30)) { xs -> xs.zip(xs).mapValues { it.value.second } shouldBe xs } } - "zippyness3" { + @Test fun zipyness3() = runTest { checkAll( - Arb.map(Arb.int(), Arb.pair(Arb.int(), Arb.int()))) { + Arb.map(Arb.int(), Arb.pair(Arb.int(), Arb.int()), maxSize = 30)) { xs -> xs.mapValues { it.value.first }.zip(xs.mapValues { it.value.second }) shouldBe xs } } - "distributivity1" { + @Test fun distributivity1() = runTest { checkAll( Arb.map3(Arb.int(), Arb.int(), Arb.int(), Arb.int()) ) {(x,y,z) -> @@ -263,7 +261,7 @@ class MapKTest : StringSpec({ } } - "distributivity2" { + @Test fun distributivity2() = runTest { checkAll( Arb.map3(Arb.int(), Arb.int(), Arb.int(), Arb.int()) ) {(x,y,z) -> @@ -282,7 +280,7 @@ class MapKTest : StringSpec({ } } - "distributivity3" { + @Test fun distributivity3() = runTest { checkAll( Arb.map3(Arb.int(), Arb.int(), Arb.int(), Arb.int()) ) {(x,y,z) -> @@ -301,9 +299,9 @@ class MapKTest : StringSpec({ } } - "unzip is the inverse of zip" { + @Test fun unzipInverseOfZip() = runTest { checkAll( - Arb.map(Arb.int(), Arb.int()) + Arb.map(Arb.int(), Arb.int(), maxSize = 30) ) { xs -> val ls = xs.zip(xs).unzip() val rs = xs to xs @@ -312,34 +310,34 @@ class MapKTest : StringSpec({ } } - "zip is the inverse of unzip" { + @Test fun zipInverseOfUnzip() = runTest { checkAll( - Arb.map(Arb.int(), Arb.pair(Arb.int(), Arb.int())) + Arb.map(Arb.int(), Arb.pair(Arb.int(), Arb.int()), maxSize = 30) ) { xs -> val (a,b) = xs.unzip() a.zip(b) shouldBe xs } } - "unzip with" { + @Test fun unzipWith() = runTest { checkAll( - Arb.map(Arb.int(), Arb.pair(Arb.int(), Arb.int())) + Arb.map(Arb.int(), Arb.pair(Arb.int(), Arb.int()), maxSize = 30) ) { xs -> xs.unzip { it.value.first to it.value.second } shouldBe xs.unzip() } } - "unalign with" { + @Test fun unalignWith() = runTest { checkAll( - Arb.map(Arb.int(), Arb.ior(Arb.int(), Arb.int())) + Arb.map(Arb.int(), Arb.ior(Arb.int(), Arb.int()), maxSize = 30) ) { xs -> xs.unalign { it.value } shouldBe xs.unalign() } } - "getOrNone" { + @Test fun getOrNoneOk() = runTest { checkAll( - Arb.map(Arb.int(0 .. 1000), Arb.int()) + Arb.map(Arb.int(0 .. 1000), Arb.int(), maxSize = 30) ) { xs -> val (found, notFound) = (0 .. 1000).partition { xs.containsKey(it) } @@ -356,7 +354,7 @@ class MapKTest : StringSpec({ } } - "unalign is the inverse of align" { + @Test fun unalignInverseOfAlign() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -364,9 +362,9 @@ class MapKTest : StringSpec({ } } - "align is the inverse of unalign" { + @Test fun alignInverseOfUnalign() = runTest { checkAll( - Arb.map(Arb.int(), Arb.ior(Arb.int(), Arb.int())) + Arb.map(Arb.int(), Arb.ior(Arb.int(), Arb.int()), maxSize = 30) ) { xs -> val (a,b) = xs.unalign() @@ -374,7 +372,7 @@ class MapKTest : StringSpec({ } } - "padZip" { + @Test fun padZipOk() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -394,7 +392,7 @@ class MapKTest : StringSpec({ } } - "padZip with" { + @Test fun padZipWith() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()), Arb.functionABCToD(Arb.int()) @@ -403,7 +401,7 @@ class MapKTest : StringSpec({ } } - "salign" { + @Test fun salignOk() = runTest { checkAll( Arb.map2(Arb.int(), Arb.intSmall(), Arb.intSmall()) ) { (a, b) -> @@ -411,9 +409,9 @@ class MapKTest : StringSpec({ } } - "mapNotNull" { + @Test fun mapNotNullOk() = runTest { checkAll( - Arb.map(Arb.int(), Arb.boolean()) + Arb.map(Arb.int(), Arb.boolean(), maxSize = 30) ) { xs -> val rs = xs.mapNotNull { (_, pred) -> if(pred) true else null } @@ -426,9 +424,9 @@ class MapKTest : StringSpec({ } } - "filterOption" { + @Test fun filterOptionOk() = runTest { checkAll( - Arb.map(Arb.int(), Arb.option(Arb.int())) + Arb.map(Arb.int(), Arb.option(Arb.int()), maxSize = 30) ) { xs -> val rs = xs.filterOption() @@ -442,9 +440,9 @@ class MapKTest : StringSpec({ } } - "filterInstance" { + @Test fun filterInstanceOk() = runTest { checkAll( - Arb.map(Arb.int(), Arb.choice(Arb.int(), Arb.int())) + Arb.map(Arb.int(), Arb.choice(Arb.int(), Arb.int()), maxSize = 30) ) { xs -> val a = xs.filterIsInstance() val b = xs.filterIsInstance() @@ -453,19 +451,19 @@ class MapKTest : StringSpec({ } } - "filterInstance: identity" { - checkAll(Arb.map(Arb.int(), Arb.int())) { xs -> + @Test fun filterInstanceIdentity() = runTest { + checkAll(Arb.map(Arb.int(), Arb.int(), maxSize = 30)) { xs -> xs.filterIsInstance() shouldBe xs } } - "filterInstance: identity with null" { - checkAll(Arb.map(Arb.int(), Arb.int().orNull())) { xs -> + @Test fun filterInstanceIdentityNull() = runTest { + checkAll(Arb.map(Arb.int(), Arb.int().orNull(), maxSize = 30)) { xs -> xs.filterIsInstance() shouldBe xs } } - "zip2" { + @Test fun zip2Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -478,7 +476,7 @@ class MapKTest : StringSpec({ } } - "zip2 with nullables" { + @Test fun zip2Null() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -491,7 +489,7 @@ class MapKTest : StringSpec({ } } - "zip3" { + @Test fun zip3Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -505,7 +503,7 @@ class MapKTest : StringSpec({ } } - "zip3 with nullables" { + @Test fun zip3Null() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -518,7 +516,7 @@ class MapKTest : StringSpec({ } } - "zip4" { + @Test fun zip4Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -532,7 +530,7 @@ class MapKTest : StringSpec({ } } - "zip4 with nullables" { + @Test fun zip4Null() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -545,7 +543,7 @@ class MapKTest : StringSpec({ } } - "zip5" { + @Test fun zip5Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -559,7 +557,7 @@ class MapKTest : StringSpec({ } } - "zip5 with nullables" { + @Test fun zip5Null() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -572,7 +570,7 @@ class MapKTest : StringSpec({ } } - "zip6" { + @Test fun zip6Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -586,7 +584,7 @@ class MapKTest : StringSpec({ } } - "zip6 with nullables" { + @Test fun zip6Null() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -599,7 +597,7 @@ class MapKTest : StringSpec({ } } - "zip7" { + @Test fun zip7Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -613,7 +611,7 @@ class MapKTest : StringSpec({ } } - "zip7 with nullables" { + @Test fun zip7Null() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -626,7 +624,7 @@ class MapKTest : StringSpec({ } } - "zip8" { + @Test fun zip8Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -641,7 +639,7 @@ class MapKTest : StringSpec({ } } - "zip8 with nullables" { + @Test fun zip8Null() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -654,7 +652,7 @@ class MapKTest : StringSpec({ } } - "zip9" { + @Test fun zip9Ok() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -680,7 +678,7 @@ class MapKTest : StringSpec({ } } - "flatMap" { + @Test fun flatMapOk() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int()) ) { (a, b) -> @@ -692,7 +690,7 @@ class MapKTest : StringSpec({ } } - "mapOrAccumulate of empty should be empty" { + @Test fun mapOrAccumulateEmpty() = runTest { val result: Either, Map> = emptyMap().mapOrAccumulate { it.value.toString() } @@ -701,9 +699,9 @@ class MapKTest : StringSpec({ .value.shouldBeEmpty() } - "mapOrAccumulate can map" { + @Test fun mapOrAccumulateMaps() = runTest { checkAll( - Arb.map(Arb.int(), Arb.int()) + Arb.map(Arb.int(), Arb.int(), maxSize = 30) ) { xs -> val result: Either, Map> = xs.mapOrAccumulate { @@ -716,9 +714,9 @@ class MapKTest : StringSpec({ } } - "mapOrAccumulate accumulates errors" { + @Test fun mapOrAccumulateAccumulates() = runTest { checkAll( - Arb.map(Arb.int(), Arb.int(), minSize = 1) + Arb.map(Arb.int(), Arb.int(), minSize = 1, maxSize = 30) ) { xs -> xs.mapOrAccumulate { raise(it.value) @@ -727,7 +725,7 @@ class MapKTest : StringSpec({ } } - "flatMap with nullables" { + @Test fun flatMapNull() = runTest { checkAll( Arb.map2(Arb.int(), Arb.int(), Arb.int().orNull()) ) { (mapA, mapB) -> @@ -738,4 +736,4 @@ class MapKTest : StringSpec({ result shouldBe expected } } -}) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index e97b4d0c9f3..5c68a672267 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -89,7 +89,7 @@ class NonEmptyListTest { @Test fun mapOrAccumulateAccumulatesErrors() = runTest { - checkAll(Arb.nonEmptyList(Arb.int())) { nel -> + checkAll(Arb.nonEmptyList(Arb.int(), range = 0 .. 20)) { nel -> val res = nel.mapOrAccumulate { i -> if (i % 2 == 0) i else raise(i) } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonFatalTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonFatalTest.kt index 541e500ecc8..054574958ac 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonFatalTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonFatalTest.kt @@ -1,9 +1,9 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import kotlin.test.Test -class NonFatalTest : StringSpec({ +class NonFatalTest { val nonFatals: List = listOf( RuntimeException(), @@ -12,14 +12,16 @@ class NonFatalTest : StringSpec({ NotImplementedError() ) - "Test nonfatals using #invoke()" { + @Test + fun usingInvoke() { nonFatals.forEach { NonFatal(it) shouldBe true } } - "Test nonfatals using Throwable#nonFatalOrThrow" { + + @Test fun usingNotFatalOrThrow() { nonFatals.forEach { it.nonFatalOrThrow() shouldBe it } } -}) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt index 267f2574854..eb446936303 100755 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt @@ -3,7 +3,7 @@ package arrow.core import arrow.core.raise.option import arrow.core.test.laws.MonoidLaws import arrow.core.test.option -import arrow.core.test.testLawsCommon +import arrow.core.test.testLaws import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.property.Arb @@ -21,336 +21,336 @@ class OptionTest { val some: Option = Some("kotlin") val none: Option = None - @Test fun testMonoidLaws() = testLawsCommon( - MonoidLaws("Option", None, { x, y -> x.combine(y, Int::plus) }, Arb.option(Arb.int())) - ) + @Test fun testMonoidLaws() = testLaws( + MonoidLaws("Option", None, { x, y -> x.combine(y, Int::plus) }, Arb.option(Arb.int())) + ) - @Test fun ensureNullInOptionComputation() = runTest { - checkAll(Arb.boolean(), Arb.int()) { predicate, i -> - option { - ensure(predicate) - i - } shouldBe if (predicate) Some(i) else None - } - } - - @Test fun ensureNotNullInOptionComputation() = runTest { - fun square(i: Int): Int = i * i - checkAll(Arb.int().orNull()) { i: Int? -> - option { - ensureNotNull(i) - square(i) // Smart-cast by contract - } shouldBe i.toOption().map(::square) - } - } - - @Test fun shortCircuitNull() = runTest { + @Test fun ensureNullInOptionComputation() = runTest { + checkAll(Arb.boolean(), Arb.int()) { predicate, i -> option { - val number: Int = "s".length - ensureNotNull(number.takeIf { it > 1 }) - throw IllegalStateException("This should not be executed") - } shouldBe None - } - - @Test fun tapAppliesEffectsReturningTheOriginalValue() = runTest { - checkAll(Arb.option(Arb.long())) { option -> - var effect = 0 - val res = option.onSome { effect += 1 } - val expected = when (option) { - is Some -> 1 - is None -> 0 - } - effect shouldBe expected - res shouldBe option - } - } - - @Test fun tapNoneAppliesEffectsReturningTheOriginalValue() = runTest { - checkAll(Arb.option(Arb.long())) { option -> - var effect = 0 - val res = option.onNone { effect += 1 } - val expected = when (option) { - is Some -> 0 - is None -> 1 - } - effect shouldBe expected - res shouldBe option - } - } - - @Test fun fromNullableShouldWorkForBothNullAndNonNullValuesOfNullableTypes() = runTest { - checkAll(Arb.int().orNull()) { a: Int? -> - // This seems to be generating only non-null values, so it is complemented by the next test - val o: Option = Option.fromNullable(a) - if (a == null) o shouldBe None else o shouldBe Some(a) - } - } - - @Test fun fromNullableShouldReturnNoneForNullValuesOfNullableTypes() = runTest { - val a: Int? = null - Option.fromNullable(a) shouldBe None + ensure(predicate) + i + } shouldBe if (predicate) Some(i) else None } + } - @Test fun getOrElse() = runTest { - some.getOrElse { "java" } shouldBe "kotlin" - none.getOrElse { "java" } shouldBe "java" - } - - @Test fun getOrNull() = runTest { - some.getOrNull() shouldNotBe null - none.getOrNull() shouldBe null - } - - @Test fun map() = runTest { - some.map(String::uppercase) shouldBe Some("KOTLIN") - none.map(String::uppercase) shouldBe None - } - - @Test fun fold() = runTest { - some.fold({ 0 }) { it.length } shouldBe 6 - none.fold({ 0 }) { it.length } shouldBe 0 - } - - @Test fun flatMap() = runTest { - some.flatMap { Some(it.uppercase()) } shouldBe Some("KOTLIN") - none.flatMap { Some(it.uppercase()) } shouldBe None - } - - @Test fun filter() = runTest { - some.filter { it == "java" } shouldBe None - none.filter { it == "java" } shouldBe None - some.filter { it.startsWith('k') } shouldBe Some("kotlin") - } - - @Test fun filterNot() = runTest { - some.filterNot { it == "java" } shouldBe Some("kotlin") - none.filterNot { it == "java" } shouldBe None - some.filterNot { it.startsWith('k') } shouldBe None - } - - @Test fun filterIsInstance() = runTest { - val someAny: Option = some - someAny.filterIsInstance() shouldBe Some("kotlin") - someAny.filterIsInstance() shouldBe None - - val someNullableAny: Option = null.some() - someNullableAny.filterIsInstance() shouldBe Some(null) - someNullableAny.filterIsInstance() shouldBe None - - val noneAny: Option = none - noneAny.filterIsInstance() shouldBe None - noneAny.filterIsInstance() shouldBe None - } - - @Test fun toList() = runTest { - some.toList() shouldBe listOf("kotlin") - none.toList() shouldBe listOf() - } - - @Test fun iterableFirstOrNone() = runTest { - val iterable = iterableOf(1, 2, 3, 4, 5, 6) - iterable.firstOrNone() shouldBe Some(1) - iterable.firstOrNone { it > 2 } shouldBe Some(3) - iterable.firstOrNone { it > 7 } shouldBe None - - val emptyIterable = iterableOf() - emptyIterable.firstOrNone() shouldBe None - - val nullableIterable1 = iterableOf(null, 2, 3, 4, 5, 6) - nullableIterable1.firstOrNone() shouldBe Some(null) - - val nullableIterable2 = iterableOf(1, 2, 3, null, 5, null) - nullableIterable2.firstOrNone { it == null } shouldBe Some(null) - } - - @Test fun collectionFirstOrNone() = runTest { - val list = listOf(1, 2, 3, 4, 5, 6) - list.firstOrNone() shouldBe Some(1) - - val emptyList = emptyList() - emptyList.firstOrNone() shouldBe None - - val nullableList = listOf(null, 2, 3, 4, 5, 6) - nullableList.firstOrNone() shouldBe Some(null) - } - - @Test fun iterableSingleOrNone() = runTest { - val iterable = iterableOf(1, 2, 3, 4, 5, 6) - iterable.singleOrNone() shouldBe None - iterable.singleOrNone { it > 2 } shouldBe None - - val singleIterable = iterableOf(3) - singleIterable.singleOrNone() shouldBe Some(3) - singleIterable.singleOrNone { it == 3 } shouldBe Some(3) - - val nullableSingleIterable1 = iterableOf(null) - nullableSingleIterable1.singleOrNone() shouldBe Some(null) - - val nullableSingleIterable2 = iterableOf(1, 2, 3, null, 5, 6) - nullableSingleIterable2.singleOrNone { it == null } shouldBe Some(null) - - val nullableSingleIterable3 = iterableOf(1, 2, 3, null, 5, null) - nullableSingleIterable3.singleOrNone { it == null } shouldBe None - } - - @Test fun collectionSingleOrNone() = runTest { - val list = listOf(1, 2, 3, 4, 5, 6) - list.singleOrNone() shouldBe None - - val singleList = listOf(3) - singleList.singleOrNone() shouldBe Some(3) - - val nullableSingleList = listOf(null) - nullableSingleList.singleOrNone() shouldBe Some(null) - } - - @Test fun iterableLastOrNone() = runTest { - val iterable = iterableOf(1, 2, 3, 4, 5, 6) - iterable.lastOrNone() shouldBe Some(6) - iterable.lastOrNone { it < 4 } shouldBe Some(3) - iterable.lastOrNone { it > 7 } shouldBe None - - val emptyIterable = iterableOf() - emptyIterable.lastOrNone() shouldBe None - - val nullableIterable1 = iterableOf(1, 2, 3, 4, 5, null) - nullableIterable1.lastOrNone() shouldBe Some(null) - - val nullableIterable2 = iterableOf(null, 2, 3, null, 5, 6) - nullableIterable2.lastOrNone { it == null } shouldBe Some(null) - } - - @Test fun collectionLastOrNone() = runTest { - val list = listOf(1, 2, 3, 4, 5, 6) - list.lastOrNone() shouldBe Some(6) - - val emptyList = emptyList() - emptyList.lastOrNone() shouldBe None - - val nullableList = listOf(1, 2, 3, 4, 5, null) - nullableList.lastOrNone() shouldBe Some(null) - } - - @Test fun iterableElementAtOrNone() = runTest { - val iterable = iterableOf(1, 2, 3, 4, 5, 6) - iterable.elementAtOrNone(index = 3 - 1) shouldBe Some(3) - iterable.elementAtOrNone(index = -1) shouldBe None - iterable.elementAtOrNone(index = 100) shouldBe None - - val nullableIterable = iterableOf(1, 2, null, 4, 5, 6) - nullableIterable.elementAtOrNone(index = 3 - 1) shouldBe Some(null) - } - - @Test fun collectionElementAtOrNone() = runTest { - val list = listOf(1, 2, 3, 4, 5, 6) - list.elementAtOrNone(index = 3 - 1) shouldBe Some(3) - list.elementAtOrNone(index = -1) shouldBe None - list.elementAtOrNone(index = 100) shouldBe None - - val nullableList = listOf(1, 2, null, 4, 5, 6) - nullableList.elementAtOrNone(index = 3 - 1) shouldBe Some(null) - } - - @Test fun toLeftOption() = runTest { - 1.leftIor().leftOrNull() shouldBe 1 - 2.rightIor().leftOrNull() shouldBe null - (1 to 2).bothIor().leftOrNull() shouldBe 1 - } - - @Test fun optionPairToMap() = runTest { - val some: Option> = Some("key" to "value") - val none: Option> = None - some.toMap() shouldBe mapOf("key" to "value") - none.toMap() shouldBe emptyMap() - } - - @Test fun catchShouldReturnSomeResultWhenFDoesNotThrow() = runTest { - val recover: (Throwable) -> Option = { _ -> None} - Option.catch(recover) { 1 } shouldBe Some(1) - } - - @Test fun catchWithDefaultRecoverShouldReturnSomeResultWhenFDoesNotThrow() = runTest { - Option.catch { 1 } shouldBe Some(1) - } - - @Test fun catchShouldReturnSomeRecoverValueWhenFThrows() = runTest { - val exception = Exception("Boom!") - val recoverValue = 10 - val recover: (Throwable) -> Option = { _ -> Some(recoverValue) } - Option.catch(recover) { throw exception } shouldBe Some(recoverValue) - } - - @Test fun catchShouldReturnNoneWhenFThrows() = runTest { - val exception = Exception("Boom!") - Option.catch { throw exception } shouldBe None - } - - @Test fun invokeOperatorShouldReturnSome() = runTest { - checkAll(Arb.int()) { a: Int -> - Option(a) shouldBe Some(a) - } - } - - @Test fun isNoneShouldReturnTrueIfNoneAndFalseIfSome() = runTest { - none.isNone() shouldBe true - none.isSome() shouldBe false - } - - @Test fun isSomeShouldReturnTrueIfSomeAndFalseIfNone() = runTest { - some.isSome() shouldBe true - some.isNone() shouldBe false - } - - @Test fun isSomeWithPredicate() = runTest { - some.isSome { it.startsWith('k') } shouldBe true - some.isSome { it.startsWith('j') } shouldBe false - none.isSome { it.startsWith('k') } shouldBe false - } - - @Test fun flatten() = runTest { - checkAll(Arb.int()) { a: Int -> - Some(Some(a)).flatten() shouldBe Some(a) - Some(None).flatten() shouldBe None - } - } - - @Test fun widen() = runTest { - checkAll(Arb.string()) { a: String -> - val widen: Option = Option(a).widen() - widen.map { it.length } shouldBe Some(a.length) + @Test fun ensureNotNullInOptionComputation() = runTest { + fun square(i: Int): Int = i * i + checkAll(Arb.int().orNull()) { i: Int? -> + option { + ensureNotNull(i) + square(i) // Smart-cast by contract + } shouldBe i.toOption().map(::square) + } + } + + @Test fun shortCircuitNull() = runTest { + option { + val number: Int = "s".length + ensureNotNull(number.takeIf { it > 1 }) + throw IllegalStateException("This should not be executed") + } shouldBe None + } + + @Test fun tapAppliesEffectsReturningTheOriginalValue() = runTest { + checkAll(Arb.option(Arb.long())) { option -> + var effect = 0 + val res = option.onSome { effect += 1 } + val expected = when (option) { + is Some -> 1 + is None -> 0 } - } - - @Test fun compareToWithSomeValues() = runTest { - checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> - val opA = Option(a) - val opB = Option(b) - (opA > opB) shouldBe (a > b) - (opA >= opB) shouldBe (a >= b) - (opA < opB) shouldBe (a < b) - (opA <= opB) shouldBe (a <= b) - (opA == opB) shouldBe (a == b) - (opA != opB) shouldBe (a != b) + effect shouldBe expected + res shouldBe option + } + } + + @Test fun tapNoneAppliesEffectsReturningTheOriginalValue() = runTest { + checkAll(Arb.option(Arb.long())) { option -> + var effect = 0 + val res = option.onNone { effect += 1 } + val expected = when (option) { + is Some -> 0 + is None -> 1 } - } - - @Test fun compareToWithNoneValues() = runTest { - val opA = Option(1) - val opB = None - (opA > opB) shouldBe true - (opA >= opB) shouldBe true - (opA < opB) shouldBe false - (opA <= opB) shouldBe false - (opA == opB) shouldBe false - (opA != opB) shouldBe true - - (none > some) shouldBe false - (none >= some) shouldBe false - (none < some) shouldBe true - (none <= some) shouldBe true - (none == some) shouldBe false - (none != some) shouldBe true - } + effect shouldBe expected + res shouldBe option + } + } + + @Test fun fromNullableShouldWorkForBothNullAndNonNullValuesOfNullableTypes() = runTest { + checkAll(Arb.int().orNull()) { a: Int? -> + // This seems to be generating only non-null values, so it is complemented by the next test + val o: Option = Option.fromNullable(a) + if (a == null) o shouldBe None else o shouldBe Some(a) + } + } + + @Test fun fromNullableShouldReturnNoneForNullValuesOfNullableTypes() = runTest { + val a: Int? = null + Option.fromNullable(a) shouldBe None + } + + @Test fun getOrElse() = runTest { + some.getOrElse { "java" } shouldBe "kotlin" + none.getOrElse { "java" } shouldBe "java" + } + + @Test fun getOrNull() = runTest { + some.getOrNull() shouldNotBe null + none.getOrNull() shouldBe null + } + + @Test fun map() = runTest { + some.map(String::uppercase) shouldBe Some("KOTLIN") + none.map(String::uppercase) shouldBe None + } + + @Test fun fold() = runTest { + some.fold({ 0 }) { it.length } shouldBe 6 + none.fold({ 0 }) { it.length } shouldBe 0 + } + + @Test fun flatMap() = runTest { + some.flatMap { Some(it.uppercase()) } shouldBe Some("KOTLIN") + none.flatMap { Some(it.uppercase()) } shouldBe None + } + + @Test fun filter() = runTest { + some.filter { it == "java" } shouldBe None + none.filter { it == "java" } shouldBe None + some.filter { it.startsWith('k') } shouldBe Some("kotlin") + } + + @Test fun filterNot() = runTest { + some.filterNot { it == "java" } shouldBe Some("kotlin") + none.filterNot { it == "java" } shouldBe None + some.filterNot { it.startsWith('k') } shouldBe None + } + + @Test fun filterIsInstance() = runTest { + val someAny: Option = some + someAny.filterIsInstance() shouldBe Some("kotlin") + someAny.filterIsInstance() shouldBe None + + val someNullableAny: Option = null.some() + someNullableAny.filterIsInstance() shouldBe Some(null) + someNullableAny.filterIsInstance() shouldBe None + + val noneAny: Option = none + noneAny.filterIsInstance() shouldBe None + noneAny.filterIsInstance() shouldBe None + } + + @Test fun toList() = runTest { + some.toList() shouldBe listOf("kotlin") + none.toList() shouldBe listOf() + } + + @Test fun iterableFirstOrNone() = runTest { + val iterable = iterableOf(1, 2, 3, 4, 5, 6) + iterable.firstOrNone() shouldBe Some(1) + iterable.firstOrNone { it > 2 } shouldBe Some(3) + iterable.firstOrNone { it > 7 } shouldBe None + + val emptyIterable = iterableOf() + emptyIterable.firstOrNone() shouldBe None + + val nullableIterable1 = iterableOf(null, 2, 3, 4, 5, 6) + nullableIterable1.firstOrNone() shouldBe Some(null) + + val nullableIterable2 = iterableOf(1, 2, 3, null, 5, null) + nullableIterable2.firstOrNone { it == null } shouldBe Some(null) + } + + @Test fun collectionFirstOrNone() = runTest { + val list = listOf(1, 2, 3, 4, 5, 6) + list.firstOrNone() shouldBe Some(1) + + val emptyList = emptyList() + emptyList.firstOrNone() shouldBe None + + val nullableList = listOf(null, 2, 3, 4, 5, 6) + nullableList.firstOrNone() shouldBe Some(null) + } + + @Test fun iterableSingleOrNone() = runTest { + val iterable = iterableOf(1, 2, 3, 4, 5, 6) + iterable.singleOrNone() shouldBe None + iterable.singleOrNone { it > 2 } shouldBe None + + val singleIterable = iterableOf(3) + singleIterable.singleOrNone() shouldBe Some(3) + singleIterable.singleOrNone { it == 3 } shouldBe Some(3) + + val nullableSingleIterable1 = iterableOf(null) + nullableSingleIterable1.singleOrNone() shouldBe Some(null) + + val nullableSingleIterable2 = iterableOf(1, 2, 3, null, 5, 6) + nullableSingleIterable2.singleOrNone { it == null } shouldBe Some(null) + + val nullableSingleIterable3 = iterableOf(1, 2, 3, null, 5, null) + nullableSingleIterable3.singleOrNone { it == null } shouldBe None + } + + @Test fun collectionSingleOrNone() = runTest { + val list = listOf(1, 2, 3, 4, 5, 6) + list.singleOrNone() shouldBe None + + val singleList = listOf(3) + singleList.singleOrNone() shouldBe Some(3) + + val nullableSingleList = listOf(null) + nullableSingleList.singleOrNone() shouldBe Some(null) + } + + @Test fun iterableLastOrNone() = runTest { + val iterable = iterableOf(1, 2, 3, 4, 5, 6) + iterable.lastOrNone() shouldBe Some(6) + iterable.lastOrNone { it < 4 } shouldBe Some(3) + iterable.lastOrNone { it > 7 } shouldBe None + + val emptyIterable = iterableOf() + emptyIterable.lastOrNone() shouldBe None + + val nullableIterable1 = iterableOf(1, 2, 3, 4, 5, null) + nullableIterable1.lastOrNone() shouldBe Some(null) + + val nullableIterable2 = iterableOf(null, 2, 3, null, 5, 6) + nullableIterable2.lastOrNone { it == null } shouldBe Some(null) + } + + @Test fun collectionLastOrNone() = runTest { + val list = listOf(1, 2, 3, 4, 5, 6) + list.lastOrNone() shouldBe Some(6) + + val emptyList = emptyList() + emptyList.lastOrNone() shouldBe None + + val nullableList = listOf(1, 2, 3, 4, 5, null) + nullableList.lastOrNone() shouldBe Some(null) + } + + @Test fun iterableElementAtOrNone() = runTest { + val iterable = iterableOf(1, 2, 3, 4, 5, 6) + iterable.elementAtOrNone(index = 3 - 1) shouldBe Some(3) + iterable.elementAtOrNone(index = -1) shouldBe None + iterable.elementAtOrNone(index = 100) shouldBe None + + val nullableIterable = iterableOf(1, 2, null, 4, 5, 6) + nullableIterable.elementAtOrNone(index = 3 - 1) shouldBe Some(null) + } + + @Test fun collectionElementAtOrNone() = runTest { + val list = listOf(1, 2, 3, 4, 5, 6) + list.elementAtOrNone(index = 3 - 1) shouldBe Some(3) + list.elementAtOrNone(index = -1) shouldBe None + list.elementAtOrNone(index = 100) shouldBe None + + val nullableList = listOf(1, 2, null, 4, 5, 6) + nullableList.elementAtOrNone(index = 3 - 1) shouldBe Some(null) + } + + @Test fun toLeftOption() = runTest { + 1.leftIor().leftOrNull() shouldBe 1 + 2.rightIor().leftOrNull() shouldBe null + (1 to 2).bothIor().leftOrNull() shouldBe 1 + } + + @Test fun optionPairToMap() = runTest { + val some: Option> = Some("key" to "value") + val none: Option> = None + some.toMap() shouldBe mapOf("key" to "value") + none.toMap() shouldBe emptyMap() + } + + @Test fun catchShouldReturnSomeResultWhenFDoesNotThrow() = runTest { + val recover: (Throwable) -> Option = { _ -> None} + Option.catch(recover) { 1 } shouldBe Some(1) + } + + @Test fun catchWithDefaultRecoverShouldReturnSomeResultWhenFDoesNotThrow() = runTest { + Option.catch { 1 } shouldBe Some(1) + } + + @Test fun catchShouldReturnSomeRecoverValueWhenFThrows() = runTest { + val exception = Exception("Boom!") + val recoverValue = 10 + val recover: (Throwable) -> Option = { _ -> Some(recoverValue) } + Option.catch(recover) { throw exception } shouldBe Some(recoverValue) + } + + @Test fun catchShouldReturnNoneWhenFThrows() = runTest { + val exception = Exception("Boom!") + Option.catch { throw exception } shouldBe None + } + + @Test fun invokeOperatorShouldReturnSome() = runTest { + checkAll(Arb.int()) { a: Int -> + Option(a) shouldBe Some(a) + } + } + + @Test fun isNoneShouldReturnTrueIfNoneAndFalseIfSome() = runTest { + none.isNone() shouldBe true + none.isSome() shouldBe false + } + + @Test fun isSomeShouldReturnTrueIfSomeAndFalseIfNone() = runTest { + some.isSome() shouldBe true + some.isNone() shouldBe false + } + + @Test fun isSomeWithPredicate() = runTest { + some.isSome { it.startsWith('k') } shouldBe true + some.isSome { it.startsWith('j') } shouldBe false + none.isSome { it.startsWith('k') } shouldBe false + } + + @Test fun flatten() = runTest { + checkAll(Arb.int()) { a: Int -> + Some(Some(a)).flatten() shouldBe Some(a) + Some(None).flatten() shouldBe None + } + } + + @Test fun widen() = runTest { + checkAll(Arb.string()) { a: String -> + val widen: Option = Option(a).widen() + widen.map { it.length } shouldBe Some(a.length) + } + } + + @Test fun compareToWithSomeValues() = runTest { + checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> + val opA = Option(a) + val opB = Option(b) + (opA > opB) shouldBe (a > b) + (opA >= opB) shouldBe (a >= b) + (opA < opB) shouldBe (a < b) + (opA <= opB) shouldBe (a <= b) + (opA == opB) shouldBe (a == b) + (opA != opB) shouldBe (a != b) + } + } + + @Test fun compareToWithNoneValues() = runTest { + val opA = Option(1) + val opB = None + (opA > opB) shouldBe true + (opA >= opB) shouldBe true + (opA < opB) shouldBe false + (opA <= opB) shouldBe false + (opA == opB) shouldBe false + (opA != opB) shouldBe true + + (none > some) shouldBe false + (none >= some) shouldBe false + (none < some) shouldBe true + (none <= some) shouldBe true + (none == some) shouldBe false + (none != some) shouldBe true + } } // Utils diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt index 17d2c11c917..ec58ddef409 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/SequenceKTest.kt @@ -7,23 +7,24 @@ import arrow.core.test.option import arrow.core.test.sequence import arrow.core.test.testLaws import arrow.core.test.unit -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.sequences.shouldBeEmpty import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list -import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.positiveInt import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest import kotlin.math.max import kotlin.math.min +import kotlin.test.Test -class SequenceKTest : StringSpec({ +class SequenceKTest { + @Test fun monoidLaws() = testLaws(MonoidLaws("Sequence", emptySequence(), { a, b -> sequenceOf(a, b).flatten()} , Arb.sequence(Arb.int())) { s1, s2 -> s1.toList() == s2.toList() }) - "zip3" { + @Test fun zip3Ok() = runTest { checkAll(Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), Arb.sequence(Arb.int())) { a, b, c -> val result = a.zip(b, c, ::Triple) val expected = a.zip(b, ::Pair).zip(c) { (a, b), c -> Triple(a, b, c) } @@ -31,7 +32,7 @@ class SequenceKTest : StringSpec({ } } - "zip4" { + @Test fun zip4Ok() = runTest { checkAll( Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), @@ -47,7 +48,7 @@ class SequenceKTest : StringSpec({ } } - "zip5" { + @Test fun zip5Ok() = runTest { checkAll( Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), @@ -65,7 +66,7 @@ class SequenceKTest : StringSpec({ } } - "zip6" { + @Test fun zip6Ok() = runTest { checkAll( Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), @@ -85,7 +86,7 @@ class SequenceKTest : StringSpec({ } } - "zip7" { + @Test fun zip7Ok() = runTest { checkAll( Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), @@ -107,7 +108,7 @@ class SequenceKTest : StringSpec({ } } - "zip8" { + @Test fun zip8Ok() = runTest { checkAll( Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), @@ -131,7 +132,7 @@ class SequenceKTest : StringSpec({ } } - "zip9" { + @Test fun zip9Ok() = runTest { checkAll( Arb.sequence(Arb.int()), Arb.sequence(Arb.int()), @@ -157,7 +158,7 @@ class SequenceKTest : StringSpec({ } } - "crosswalk the sequence to a List function" { + @Test fun crosswalkOk() = runTest { checkAll(Arb.list(Arb.int())){ list -> val obtained = list.asSequence().crosswalk { listOf(it) } val expected = if (list.isEmpty()) emptyList() @@ -166,13 +167,13 @@ class SequenceKTest : StringSpec({ } } - "can align sequences - 1" { + @Test fun align1() = runTest { checkAll(Arb.sequence(Arb.unit()), Arb.sequence(Arb.unit())) { a, b -> a.align(b).toList().size shouldBe max(a.toList().size, b.toList().size) } } - "can align sequences - 2" { + @Test fun align2() = runTest { checkAll(Arb.sequence(Arb.unit()), Arb.sequence(Arb.unit())) { a, b -> a.align(b).take(min(a.toList().size, b.toList().size)).forEach { it.isBoth() shouldBe true @@ -180,7 +181,7 @@ class SequenceKTest : StringSpec({ } } - "can align sequences - 3" { + @Test fun align3() = runTest { checkAll(Arb.sequence(Arb.unit()), Arb.sequence(Arb.unit())) { a, b -> val ls = a.toList() val rs = b.toList() @@ -191,12 +192,12 @@ class SequenceKTest : StringSpec({ } } - "align empty sequences" { + @Test fun alignEmpty() = runTest { val a = emptyList().asSequence() a.align(a).shouldBeEmpty() } - "align infinite sequences" { + @Test fun alignInfinite() = runTest { val seq1 = generateSequence("A") { it } val seq2 = generateSequence(0) { it + 1 } @@ -208,7 +209,7 @@ class SequenceKTest : StringSpec({ } } - "mapNotNull" { + @Test fun mapNotNullOk() = runTest { checkAll(Arb.sequence(Arb.int())) { a -> val result = a.mapNotNull { when (it % 2 == 0) { @@ -230,13 +231,13 @@ class SequenceKTest : StringSpec({ } } - "filterOption should filter None" { + @Test fun filterOptionOk() = runTest { checkAll(Arb.list(Arb.option(Arb.int()))) { ints -> ints.asSequence().filterOption().toList() shouldBe ints.filterOption() } } - "separateEither" { + @Test fun separateEitherOk() = runTest { checkAll(Arb.sequence(Arb.int())) { ints -> val sequence = ints.map { if (it % 2 == 0) it.left() @@ -249,4 +250,4 @@ class SequenceKTest : StringSpec({ } } -}) +} diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt index 8a625392dca..ac135664d37 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/TupleTest.kt @@ -1,21 +1,20 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.double import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.long -import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class TupleTest : StringSpec({ +class TupleTest { - "shortToString" { + @Test fun shortToString() = runTest { checkAll( Arb.int(), Arb.int(), @@ -36,7 +35,7 @@ class TupleTest : StringSpec({ } } - "plus" { + @Test fun plus() = runTest { checkAll( Arb.int(), Arb.int(), @@ -58,7 +57,7 @@ class TupleTest : StringSpec({ } } - "compareTo(equals)" { + @Test fun compareToEquals() = runTest { checkAll( Arb.int(), Arb.string(), @@ -81,7 +80,7 @@ class TupleTest : StringSpec({ } } - "compareTo(not equals)" { + @Test fun compareToNotEquals() = runTest { checkAll( Arb.intOpenEnded(), Arb.intOpenEnded(), @@ -104,7 +103,7 @@ class TupleTest : StringSpec({ } } - "compareTo(deep not equals)" { + @Test fun compareToDeepNotEquals() = runTest { checkAll( Arb.intOpenEnded(), Arb.intOpenEnded(), @@ -161,6 +160,6 @@ class TupleTest : StringSpec({ Tuple9(a, b, c, d, e, f, g, h, i).compareTo(Tuple9(a, b, c, d, e, f, g, h, i + 1)) shouldBe -1 } } -}) +} private fun Arb.Companion.intOpenEnded() = Arb.int(Int.MIN_VALUE + 1, Int.MAX_VALUE - 1) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt index 59709b7e86a..534e6f4b21e 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/extensions/NumberInstancesTest.kt @@ -2,7 +2,7 @@ package arrow.core.extensions import arrow.core.test.laws.MonoidLaws import arrow.core.test.laws.SemiringLaws -import arrow.core.test.testLawsCommon +import arrow.core.test.testLaws import io.kotest.property.Arb import io.kotest.property.arbitrary.byte import io.kotest.property.arbitrary.int @@ -12,28 +12,45 @@ import kotlin.test.Test class NumberInstancesTest { - fun testAllLaws( + private fun testAllLawsSemiring( name: String, zero: F, combine: (F, F) -> F, one: F, combineMultiplicate: (F, F) -> F, - GEN: Arb, + gen: Arb, eq: (F, F) -> Boolean = { a, b -> a == b } - ) { - testLawsCommon(SemiringLaws(name, zero, combine, one, combineMultiplicate, GEN, eq)) - testLawsCommon(MonoidLaws(name, zero, combine, GEN, eq)) - } + ) = testLaws(SemiringLaws(name, zero, combine, one, combineMultiplicate, gen, eq)) - @Test fun testByteLaws() = - testAllLaws("Byte", 0, { x, y -> (x + y).toByte() }, 1, { x, y -> (x * y).toByte() }, Arb.byte()) + private fun testAllLawsMonoid( + name: String, + zero: F, + combine: (F, F) -> F, + gen: Arb, + eq: (F, F) -> Boolean = { a, b -> a == b } + ) = testLaws(MonoidLaws(name, zero, combine, gen, eq)) + + @Test fun testByteSemiring() = + testAllLawsSemiring("Byte", 0, { x, y -> (x + y).toByte() }, 1, { x, y -> (x * y).toByte() }, Arb.byte()) + + @Test fun testShortSemiring() = + testAllLawsSemiring("Short", 0, { x, y -> (x + y).toShort() }, 1, { x, y -> (x * y).toShort() }, Arb.short()) + + @Test fun testIntSemiring() = + testAllLawsSemiring("Int", 0, Int::plus, 1, Int::times, Arb.int()) + + @Test fun testLongSemiring() = + testAllLawsSemiring("Long", 0, Long::plus, 1, Long::times, Arb.long()) + + @Test fun testByteMonoid() = + testAllLawsMonoid("Byte", 0, { x, y -> (x + y).toByte() }, Arb.byte()) - @Test fun testShortLaws() = - testAllLaws("Short", 0, { x, y -> (x + y).toShort() }, 1, { x, y -> (x * y).toShort() }, Arb.short()) + @Test fun testShortMonoid() = + testAllLawsMonoid("Short", 0, { x, y -> (x + y).toShort() }, Arb.short()) - @Test fun testIntLaws() = - testAllLaws("Int", 0, Int::plus, 1, Int::times, Arb.int()) + @Test fun testIntMonoid() = + testAllLawsMonoid("Int", 0, Int::plus, Arb.int()) - @Test fun testLongLaws() = - testAllLaws("Long", 0, Long::plus, 1, Long::times, Arb.long()) + @Test fun testLongMonoid() = + testAllLawsMonoid("Long", 0, Long::plus, Arb.long()) } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt index 80e5881c9d3..804d0d35d38 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/EagerEffectSpec.kt @@ -6,7 +6,6 @@ import arrow.core.left import arrow.core.right import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldStartWith diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt index 87d4b9e22f0..7b90b497240 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/IorSpec.kt @@ -45,7 +45,7 @@ class IorSpec { } @Test fun concurrentArrowIorBind() = runTest { - checkAll(Arb.nonEmptyList(Arb.int())) { xs -> + checkAll(Arb.nonEmptyList(Arb.int(), range = 0 .. 20)) { xs -> ior(List::plus) { xs.mapIndexed { index, s -> async { Ior.Both(listOf(s), index).bind() } }.awaitAll() } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index d0d0166edad..3c947fe22b5 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -220,7 +220,7 @@ private fun Map?, Option?>>.destructured(): Pair< } fun Arb.Companion.map2(arbK: Arb, arbA: Arb, arbB: Arb): Arb, Map>> = - Arb.map(keyArb = arbK, valueArb = value2(arbA, arbB)) + Arb.map(keyArb = arbK, valueArb = value2(arbA, arbB), maxSize = 30) .map { it.destructured() } fun Arb.Companion.map3( @@ -229,5 +229,5 @@ fun Arb.Companion.map3( arbB: Arb, arbC: Arb ): Arb, Map, Map>> = - Arb.map(arbK, value3(arbA, arbB, arbC)) + Arb.map(arbK, value3(arbA, arbB, arbC), maxSize = 30) .map { it.destructured() } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt index c5221757595..6f5f25a6dc9 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Laws.kt @@ -2,10 +2,9 @@ package arrow.core.test import io.kotest.assertions.fail import io.kotest.assertions.withClue -import io.kotest.core.names.TestName -import io.kotest.core.spec.style.StringSpec -import io.kotest.core.spec.style.scopes.addTest +import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.runTest +import kotlin.time.Duration.Companion.seconds interface LawSet { val laws: List @@ -16,22 +15,11 @@ data class Law(val name: String, val test: suspend () -> Unit) fun A.equalUnderTheLaw(b: A, f: (A, A) -> Boolean = { x, y -> x == y }): Boolean = if (f(this, b)) true else fail("Found $this but expected: $b") -fun StringSpec.testLaws(lawSet: LawSet): Unit = testLaws(lawSet.laws) - -fun StringSpec.testLaws(vararg laws: List): Unit = laws - .flatMap { list: List -> list.asIterable() } - .distinctBy { law: Law -> law.name } - .forEach { law: Law -> - addTest(TestName(null, law.name, false), false, null) { - runTest { law.test() } - } - } - -fun testLawsCommon(lawSet: LawSet) = withClue("In $lawSet") { - testLawsCommon(lawSet.laws) +fun testLaws(lawSet: LawSet): TestResult = withClue("In $lawSet") { + testLaws(lawSet.laws) } -fun testLawsCommon(vararg laws: List) = runTest { +fun testLaws(vararg laws: List): TestResult = runTest(timeout = (30 * laws.size).seconds) { laws .flatMap(List::asIterable) .distinctBy(Law::name) @@ -41,3 +29,4 @@ fun testLawsCommon(vararg laws: List) = runTest { } } } + diff --git a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt index 0c5699f0da6..f35bc066d08 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/java/arrow/core/DeadlockTest.kt @@ -1,14 +1,15 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.joinAll import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class DeadlockTest : StringSpec({ +class DeadlockTest { - "classloader should not deadlock Either initialization" { + @Test fun classLoaderShouldNotDeadlockEither() = runTest { runBlocking { (0..10).map { i -> GlobalScope.launch { @@ -22,7 +23,7 @@ class DeadlockTest : StringSpec({ }.joinAll() } - "classloader should not deadlock Option initialization" { + @Test fun classLoaderShouldNotDeadlockOption() = runTest { runBlocking { (0..10).map { i -> GlobalScope.launch { @@ -36,7 +37,7 @@ class DeadlockTest : StringSpec({ } } - "classloader should not deadlock Ior initialization" { + @Test fun classLoaderShouldNotDeadlockIor() = runTest { runBlocking { (0..10).map { i -> GlobalScope.launch { @@ -49,4 +50,4 @@ class DeadlockTest : StringSpec({ }.joinAll() } } -}) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt index 406d7612658..5b340762099 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt @@ -1,69 +1,68 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.test -import io.kotest.core.spec.style.StringSpec +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class EitherKnitTest : StringSpec({ - "ExampleEither21" { +class EitherKnitTest { + @Test fun exampleEither21() = runTest { arrow.core.examples.exampleEither21.test() } - "ExampleEither22" { + @Test fun exampleEither22() = runTest { arrow.core.examples.exampleEither22.test() } - "ExampleEither23" { + @Test fun exampleEither23() = runTest { arrow.core.examples.exampleEither23.test() } - "ExampleEither25" { + @Test fun exampleEither25() = runTest { arrow.core.examples.exampleEither25.test() } - "ExampleEither26" { + @Test fun exampleEither26() = runTest { arrow.core.examples.exampleEither26.test() } - "ExampleEither27" { + @Test fun exampleEither27() = runTest { arrow.core.examples.exampleEither27.test() } - "ExampleEither28" { + @Test fun exampleEither28() = runTest { arrow.core.examples.exampleEither28.test() } - "ExampleEither29" { + @Test fun exampleEither29() = runTest { arrow.core.examples.exampleEither29.test() } - "ExampleEither30" { + @Test fun exampleEither30() = runTest { arrow.core.examples.exampleEither30.test() } - "ExampleEither31" { + @Test fun exampleEither31() = runTest { arrow.core.examples.exampleEither31.test() } - "ExampleEither32" { + @Test fun exampleEither32() = runTest { arrow.core.examples.exampleEither32.test() } - "ExampleEither33" { + @Test fun exampleEither33() = runTest { arrow.core.examples.exampleEither33.test() } - "ExampleEither35" { + @Test fun exampleEither35() = runTest { arrow.core.examples.exampleEither35.test() } - "ExampleEither36" { + @Test fun exampleEither36() = runTest { arrow.core.examples.exampleEither36.test() } - "ExampleEither37" { + @Test fun exampleEither37() = runTest { arrow.core.examples.exampleEither37.test() } -}) { - override fun timeout(): Long = 1000 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt index 3a9e1d068ca..b4cac12b2ea 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/IterableKnitTest.kt @@ -1,81 +1,80 @@ // This file was automatically generated from Iterable.kt by Knit tool. Do not edit. package arrow.core.examples.test -import io.kotest.core.spec.style.StringSpec +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class IterableKnitTest : StringSpec({ - "ExampleIterable01" { +class IterableKnitTest { + @Test fun exampleIterable01() = runTest { arrow.core.examples.exampleIterable01.test() } - "ExampleIterable02" { + @Test fun exampleIterable02() = runTest { arrow.core.examples.exampleIterable02.test() } - "ExampleIterable03" { + @Test fun exampleIterable03() = runTest { arrow.core.examples.exampleIterable03.test() } - "ExampleIterable04" { + @Test fun exampleIterable04() = runTest { arrow.core.examples.exampleIterable04.test() } - "ExampleIterable05" { + @Test fun exampleIterable05() = runTest { arrow.core.examples.exampleIterable05.test() } - "ExampleIterable06" { + @Test fun exampleIterable06() = runTest { arrow.core.examples.exampleIterable06.test() } - "ExampleIterable07" { + @Test fun exampleIterable07() = runTest { arrow.core.examples.exampleIterable07.test() } - "ExampleIterable08" { + @Test fun exampleIterable08() = runTest { arrow.core.examples.exampleIterable08.test() } - "ExampleIterable09" { + @Test fun exampleIterable09() = runTest { arrow.core.examples.exampleIterable09.test() } - "ExampleIterable10" { + @Test fun exampleIterable10() = runTest { arrow.core.examples.exampleIterable10.test() } - "ExampleIterable11" { + @Test fun exampleIterable11() = runTest { arrow.core.examples.exampleIterable11.test() } - "ExampleIterable12" { + @Test fun exampleIterable12() = runTest { arrow.core.examples.exampleIterable12.test() } - "ExampleIterable13" { + @Test fun exampleIterable13() = runTest { arrow.core.examples.exampleIterable13.test() } - "ExampleIterable14" { + @Test fun exampleIterable14() = runTest { arrow.core.examples.exampleIterable14.test() } - "ExampleIterable15" { + @Test fun exampleIterable15() = runTest { arrow.core.examples.exampleIterable15.test() } - "ExampleIterable16" { + @Test fun exampleIterable16() = runTest { arrow.core.examples.exampleIterable16.test() } - "ExampleIterable18" { + @Test fun exampleIterable18() = runTest { arrow.core.examples.exampleIterable18.test() } - "ExampleIterable19" { + @Test fun exampleIterable19() = runTest { arrow.core.examples.exampleIterable19.test() } -}) { - override fun timeout(): Long = 1000 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt index b53549e94d6..88e12b46299 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt @@ -1,17 +1,16 @@ // This file was automatically generated from Option.kt by Knit tool. Do not edit. package arrow.core.examples.test -import io.kotest.core.spec.style.StringSpec +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class OptionKnitTest : StringSpec({ - "ExampleOption21" { +class OptionKnitTest { + @Test fun exampleOption21() = runTest { arrow.core.examples.exampleOption21.test() } - "ExampleOption22" { + @Test fun exampleOption22() = runTest { arrow.core.examples.exampleOption22.test() } -}) { - override fun timeout(): Long = 1000 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt index 97e2e8158e6..f1710a181f9 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/RaiseKnitTest.kt @@ -1,53 +1,52 @@ // This file was automatically generated from Raise.kt by Knit tool. Do not edit. package arrow.core.examples.test -import io.kotest.core.spec.style.StringSpec +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class RaiseKnitTest : StringSpec({ - "ExampleRaiseDsl02" { +class RaiseKnitTest { + @Test fun exampleRaiseDsl02() = runTest { arrow.core.examples.exampleRaiseDsl02.test() } - "ExampleRaiseDsl03" { + @Test fun exampleRaiseDsl03() = runTest { arrow.core.examples.exampleRaiseDsl03.test() } - "ExampleRaiseDsl04" { + @Test fun exampleRaiseDsl04() = runTest { arrow.core.examples.exampleRaiseDsl04.test() } - "ExampleRaiseDsl05" { + @Test fun exampleRaiseDsl05() = runTest { arrow.core.examples.exampleRaiseDsl05.test() } - "ExampleRaiseDsl06" { + @Test fun exampleRaiseDsl06() = runTest { arrow.core.examples.exampleRaiseDsl06.test() } - "ExampleRaiseDsl07" { + @Test fun exampleRaiseDsl07() = runTest { arrow.core.examples.exampleRaiseDsl07.test() } - "ExampleRaiseDsl08" { + @Test fun exampleRaiseDsl08() = runTest { arrow.core.examples.exampleRaiseDsl08.test() } - "ExampleRaiseDsl09" { + @Test fun exampleRaiseDsl09() = runTest { arrow.core.examples.exampleRaiseDsl09.test() } - "ExampleRaiseDsl10" { + @Test fun exampleRaiseDsl10() = runTest { arrow.core.examples.exampleRaiseDsl10.test() } - "ExampleRaiseDsl11" { + @Test fun exampleRaiseDsl11() = runTest { arrow.core.examples.exampleRaiseDsl11.test() } - "ExampleRaiseDsl12" { + @Test fun exampleRaiseDsl12() = runTest { arrow.core.examples.exampleRaiseDsl12.test() } -}) { - override fun timeout(): Long = 1000 } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt index 789cef676ae..0aaa302b213 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt @@ -1,29 +1,28 @@ // This file was automatically generated from Sequence.kt by Knit tool. Do not edit. package arrow.core.examples.test -import io.kotest.core.spec.style.StringSpec +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class SequenceKnitTest : StringSpec({ - "ExampleSequence01" { +class SequenceKnitTest { + @Test fun exampleSequence01() = runTest { arrow.core.examples.exampleSequence01.test() } - "ExampleSequence02" { + @Test fun exampleSequence02() = runTest { arrow.core.examples.exampleSequence02.test() } - "ExampleSequence03" { + @Test fun exampleSequence03() = runTest { arrow.core.examples.exampleSequence03.test() } - "ExampleSequence10" { + @Test fun exampleSequence10() = runTest { arrow.core.examples.exampleSequence10.test() } - "ExampleSequence17" { + @Test fun exampleSequence17() = runTest { arrow.core.examples.exampleSequence17.test() } -}) { - override fun timeout(): Long = 1000 } diff --git a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts index 1e0d1180284..7e8d48035e1 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts +++ b/arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts @@ -50,7 +50,7 @@ kotlin { nodejs { testTask { useMocha { - timeout = "60000" + timeout = "60s" } } } @@ -58,7 +58,7 @@ kotlin { testTask { useKarma { useChromeHeadless() - timeout.set(Duration.ofSeconds(60)) + timeout.set(Duration.ofMinutes(1)) } } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt index 8479f0f5806..b516d7a1d5c 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/Platform.kt @@ -18,7 +18,7 @@ fun stackSafeIteration(): Int = when (platform) { // The normal dispatcher with 'runTest' does some magic // which doesn't go well with 'parZip', 'parMap', and 'raceN' fun runTestUsingDefaultDispatcher( - timeout: Duration = 10.seconds, + timeout: Duration = 40.seconds, testBody: suspend TestScope.() -> Unit ): TestResult = runTest(timeout = timeout) { withContext(Dispatchers.Default) { diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt index cb31b71bc85..09b631ff251 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip2JvmTest.kt @@ -36,7 +36,7 @@ class ParZip2JvmTest { } } - @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip2" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(2, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt index 7d1b9c83d58..4a2bc4ae88e 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip3JvmTest.kt @@ -36,7 +36,7 @@ class ParZip3JvmTest { } } - @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip3" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(3, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt index bae34c72a2f..763b8c14f2b 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip4JvmTest.kt @@ -42,7 +42,7 @@ class ParZip4JvmTest { } } - @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip4ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip4" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(4, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt index 39ac21b608a..ad6869b306f 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip5JvmTest.kt @@ -43,7 +43,7 @@ class ParZip5JvmTest { } } - @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip5ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip5" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(5, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt index 3772cb318e0..1e37b0e8768 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip6JvmTest.kt @@ -46,7 +46,7 @@ class ParZip6JvmTest { } } - @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip6ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip6" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(6, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt index 9cd78e1470b..fe8d2fc5e85 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip7JvmTest.kt @@ -47,7 +47,7 @@ class ParZip7JvmTest { } } - @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip7ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip7" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(7, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt index 6594ec48d9f..25d90771a30 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip8JvmTest.kt @@ -48,7 +48,7 @@ class ParZip8JvmTest { } - @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip8ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip8" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(8, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt index 2695c684080..89d18c47c86 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/ParZip9JvmTest.kt @@ -58,7 +58,7 @@ class ParZip9JvmTest { } - @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun parZip9ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val zipCtxName = "parZip9" resourceScope { val zipCtx = executor { Executors.newFixedThreadPool(9, NamedThreadFactory(zipCtxName)) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt index e5706ae8394..83f56602c8d 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/jvmTest/kotlin/arrow/fx/coroutines/RaceNJvmTest.kt @@ -33,7 +33,7 @@ class RaceNJvmTest { } } - @Test fun race2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun race2ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val racerName = "race2" checkAll(Arb.int(1..2), Arb.throwable()) { choose, e -> @@ -91,7 +91,7 @@ class RaceNJvmTest { } } - @Test fun race3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher(20.seconds) { + @Test fun race3ReturnsToOriginalContextOnFailure() = runTestUsingDefaultDispatcher { val racerName = "race3" checkAll(Arb.int(1..3), Arb.throwable()) { choose, e -> From 708a872d858fdb709e8414a5da50a024d64aaff2 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Sat, 11 Nov 2023 08:18:49 +0100 Subject: [PATCH 103/114] Implement `fixedRate` using monotonic time source (#3294) Co-authored-by: serras Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../api/arrow-fx-coroutines.api | 4 -- .../kotlin/arrow/fx/coroutines/flow.kt | 27 ++++---- .../kotlin/arrow/fx/coroutines/predef.kt | 11 ---- .../kotlin/arrow/fx/coroutines/FlowTest.kt | 64 +++++++++++-------- .../kotlin/arrow/fx/coroutines/predef.kt | 6 -- .../kotlin/arrow/fx/coroutines/predef.kt | 15 ----- .../kotlin/arrow/fx/coroutines/predef.kt | 6 -- 7 files changed, 53 insertions(+), 80 deletions(-) delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/predef.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jsMain/kotlin/arrow/fx/coroutines/predef.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/predef.kt delete mode 100644 arrow-libs/fx/arrow-fx-coroutines/src/nativeMain/kotlin/arrow/fx/coroutines/predef.kt diff --git a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api index 9fb92334cef..5b6d473f2bb 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api +++ b/arrow-libs/fx/arrow-fx-coroutines/api/arrow-fx-coroutines.api @@ -163,10 +163,6 @@ public final class arrow/fx/coroutines/ParZipOrAccumulateKt { public static final fun parZipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class arrow/fx/coroutines/PredefKt { - public static final fun timeInMillis ()J -} - public final class arrow/fx/coroutines/Race2Kt { public static final fun raceN (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun raceN (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt index d12aa01c3ad..f0fbac3fa8a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt @@ -19,15 +19,17 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.retryWhen import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.produceIn import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.zip +import kotlin.time.ComparableTimeMark import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.ExperimentalTime +import kotlin.time.TimeSource /** * Like [map], but will evaluate [transform] in parallel, emitting the results @@ -209,16 +211,17 @@ public fun Flow.repeat(): Flow = public fun Flow.metered(period: Duration): Flow = fixedRate(period).zip(this) { _, a -> a } +@ExperimentalTime public fun Flow.metered(period: Long): Flow = fixedRate(period).zip(this) { _, a -> a } @ExperimentalTime public fun fixedRate( - period: Duration, + periodInMillis: Long, dampen: Boolean = true, - timeStampInMillis: () -> Long = { timeInMillis() } + timeStamp: () -> ComparableTimeMark = { TimeSource.Monotonic.markNow() } ): Flow = - fixedRate(period.inWholeMilliseconds, dampen, timeStampInMillis) + fixedRate(periodInMillis.milliseconds, dampen, timeStamp) /** * Flow that emits [Unit] every [period] while taking into account how much time it takes downstream to consume the emission. @@ -234,19 +237,19 @@ public fun fixedRate( * * @param period period between [Unit] emits of the resulting [Flow]. * @param dampen if you set [dampen] to false it will send `n` times [period] time it took downstream to process the emission. - * @param timeStampInMillis allows for supplying a different timestamp function, useful to override with `runBlockingTest` + * @param timeStamp allows for supplying a different timestamp function, useful to override with `runBlockingTest` */ public fun fixedRate( - period: Long, + period: Duration, dampen: Boolean = true, - timeStampInMillis: () -> Long = { timeInMillis() } + timeStamp: () -> ComparableTimeMark = { TimeSource.Monotonic.markNow() } ): Flow = - if (period == 0L) flowOf(Unit).repeat() + if (period == Duration.ZERO) flowOf(Unit).repeat() else flow { - var lastAwakeAt = timeStampInMillis() + var lastAwakeAt = timeStamp() while (true) { - val now = timeStampInMillis() + val now = timeStamp() val next = lastAwakeAt + period if (next > now) { @@ -254,13 +257,13 @@ public fun fixedRate( emit(Unit) lastAwakeAt = next } else { - val ticks: Long = (now - lastAwakeAt - 1) / period + val ticks: Long = ((now - lastAwakeAt).inWholeMilliseconds - 1) / period.inWholeMilliseconds when { ticks < 0L -> Unit ticks == 0L || dampen -> emit(Unit) else -> repeat(ticks.toInt()) { emit(Unit) } } - lastAwakeAt += (period * ticks) + lastAwakeAt += (period * ticks.toDouble()) } } } 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 deleted file mode 100644 index d033195a842..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/predef.kt +++ /dev/null @@ -1,11 +0,0 @@ -package arrow.fx.coroutines - -/** - * Gets current system time in milliseconds since certain moment in the past, - * only delta between two subsequent calls makes sense. - * - * For the JVM target this delegates to `java.lang.System.currentTimeMillis()` - * For the native targets this delegates to `kotlin.system.getTimeMillis` - * For Javascript it relies on `new Date().getTime()` - */ -public expect fun timeInMillis(): Long diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt index aab722f57fd..8c4f3baf500 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/FlowTest.kt @@ -5,18 +5,31 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf import io.kotest.property.Arb import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.long import io.kotest.property.checkAll import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.cancelAndJoin +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toSet import kotlinx.coroutines.launch +import kotlinx.coroutines.test.advanceTimeBy +import kotlinx.coroutines.test.runTest +import kotlinx.coroutines.test.testTimeSource +import kotlinx.coroutines.withTimeoutOrNull import kotlin.test.Test +import kotlin.time.ComparableTimeMark +import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.ExperimentalTime @OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) class FlowTest { @@ -240,18 +253,17 @@ class FlowTest { ) } - /* These tests do not run properly in the coroutines-test environment - - @Test - fun fixedDelay() = runTestUsingDefaultDispatcher { - checkAll(Arb.long(10L .. 50L), Arb.int(3..20)) { waitPeriod, n -> - val emissionDuration = waitPeriod / 10L - var state: Long? = null + @Test @ExperimentalTime + fun fixedDelay() = runTest { + checkAll(Arb.long(10L .. 50L), Arb.int(3..20)) { waitPeriodInMillis, n -> + val waitPeriod = waitPeriodInMillis.milliseconds + val emissionDuration = (waitPeriodInMillis / 10L).milliseconds + var state: ComparableTimeMark? = null val rate = flow { emit(delay(waitPeriod)) }.repeat() .map { - val now = state ?: currentTime - val nextNow = currentTime + val now = state ?: testTimeSource.markNow() + val nextNow = testTimeSource.markNow() val lapsed = nextNow - now state = nextNow delay(emissionDuration) @@ -260,23 +272,24 @@ class FlowTest { .take(n) .toList() - rate.first() shouldBe 0 // First element is immediately + rate.first() shouldBe Duration.ZERO // First element is immediately rate.drop(1).forEach { act -> act shouldBe (waitPeriod + emissionDuration) // Remaining elements all take delay + emission duration } } } - @Test - fun fixedRate() = runTestUsingDefaultDispatcher { - checkAll(Arb.long(10L..50L), Arb.int(3..20)) { waitPeriod, n -> - val emissionDuration = waitPeriod / 10 - var state: Long? = null + @Test @ExperimentalTime + fun fixedRate() = runTest { + checkAll(Arb.long(10L..50L), Arb.int(3..20)) { waitPeriodInMillis, n -> + val waitPeriod = waitPeriodInMillis.milliseconds + val emissionDuration = (waitPeriodInMillis / 10L).milliseconds + var state: ComparableTimeMark? = null - val rate = fixedRate(waitPeriod) { currentTime } + val rate = fixedRate(waitPeriod) { testTimeSource.markNow() } .map { - val now = state ?: currentTime - val nextNow = currentTime + val now = state ?: testTimeSource.markNow() + val nextNow = testTimeSource.markNow() val lapsed = nextNow - now state = nextNow delay(emissionDuration) @@ -285,7 +298,7 @@ class FlowTest { .take(n) .toList() - rate.first() shouldBe 0 // First element is immediately + rate.first() shouldBe Duration.ZERO // First element is immediately rate.drop(1).forEach { act -> // Remaining elements all take total of waitPeriod, emissionDuration is correctly taken into account. act shouldBe waitPeriod @@ -294,11 +307,11 @@ class FlowTest { } - @Test - fun fixedRateWithDampenTrue() = runTestUsingDefaultDispatcher { + @Test @ExperimentalTime + fun fixedRateWithDampenTrue() = runTest { val buffer = mutableListOf() withTimeoutOrNull(4500) { - fixedRate(1000, true) { currentTime } + fixedRate(1000, true) { testTimeSource.markNow() } .mapIndexed { index, _ -> if (index == 0) delay(3000) else Unit advanceTimeBy(1) @@ -307,11 +320,11 @@ class FlowTest { buffer.size shouldBe 2 } - @Test - fun fixedRateWithDampenFalse() = runTestUsingDefaultDispatcher { + @Test @ExperimentalTime + fun fixedRateWithDampenFalse() = runTest { val buffer = mutableListOf() withTimeoutOrNull(4500) { - fixedRate(1000, false) { currentTime } + fixedRate(1000, false) { testTimeSource.markNow() } .mapIndexed { index, _ -> if (index == 0) delay(3000) else Unit advanceTimeBy(1) @@ -319,5 +332,4 @@ class FlowTest { } buffer.size shouldBe 4 } - */ } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/jsMain/kotlin/arrow/fx/coroutines/predef.kt b/arrow-libs/fx/arrow-fx-coroutines/src/jsMain/kotlin/arrow/fx/coroutines/predef.kt deleted file mode 100644 index 27e1ac7d0ca..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jsMain/kotlin/arrow/fx/coroutines/predef.kt +++ /dev/null @@ -1,6 +0,0 @@ -package arrow.fx.coroutines - -public actual fun timeInMillis(): Long { - val x: Number = js("new Date().getTime()") - return x.toLong() -} 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 deleted file mode 100644 index 3edd9239d69..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/jvmMain/kotlin/arrow/fx/coroutines/predef.kt +++ /dev/null @@ -1,15 +0,0 @@ -package arrow.fx.coroutines - -/* - * 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 - */ -public actual fun timeInMillis(): Long = - System.currentTimeMillis() diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/nativeMain/kotlin/arrow/fx/coroutines/predef.kt b/arrow-libs/fx/arrow-fx-coroutines/src/nativeMain/kotlin/arrow/fx/coroutines/predef.kt deleted file mode 100644 index 96685114130..00000000000 --- a/arrow-libs/fx/arrow-fx-coroutines/src/nativeMain/kotlin/arrow/fx/coroutines/predef.kt +++ /dev/null @@ -1,6 +0,0 @@ -package arrow.fx.coroutines - -import kotlin.system.getTimeMillis - -public actual fun timeInMillis(): Long = - getTimeMillis() From 36e63e3d93437744985e942898b0b57cc9a38cf7 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Sat, 11 Nov 2023 14:14:42 +0100 Subject: [PATCH 104/114] Port `optics` tests to `kotlin.test` (#3295) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../arrow-optics-ksp-plugin/build.gradle.kts | 2 +- .../kotlin/arrow/optics/plugin/Compilation.kt | 35 +-- .../optics/arrow-optics/build.gradle.kts | 17 -- .../kotlin/arrow/optics/CopyTest.kt | 13 +- .../kotlin/arrow/optics/EveryTest.kt | 123 +++++------ .../commonTest/kotlin/arrow/optics/IsoTest.kt | 172 ++++++++------- .../kotlin/arrow/optics/LensTest.kt | 153 ++++++++------ .../kotlin/arrow/optics/OptionalTest.kt | 200 ++++++++++-------- .../kotlin/arrow/optics/PrismTest.kt | 192 +++++++++-------- .../kotlin/arrow/optics/TraversalTest.kt | 18 +- .../arrow/optics/instances/AtInstanceTest.kt | 12 +- .../optics/instances/ConsInstanceTest.kt | 12 +- .../optics/instances/EitherInstanceTest.kt | 8 +- .../instances/FilterIndexInstanceTest.kt | 21 +- .../optics/instances/IndexInstanceTest.kt | 21 +- .../optics/instances/SnocInstanceTest.kt | 13 +- .../kotlin/arrow/optics/std/ListTest.kt | 15 +- .../kotlin/arrow/optics/std/MapTest.kt | 21 +- .../arrow/optics/std/NonEmptyListTest.kt | 12 +- .../kotlin/arrow/optics/std/OptionTest.kt | 18 +- .../kotlin/arrow/optics/std/StringTest.kt | 9 +- .../kotlin/arrow/optics/std/TupleTest.kt | 45 ++-- .../kotlin/arrow/optics/test/laws/Laws.kt | 40 ++-- build.gradle.kts | 1 - gradle/libs.versions.toml | 16 -- 25 files changed, 620 insertions(+), 569 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts b/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts index fc49da7d902..fc326c9f5d4 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/build.gradle.kts @@ -25,7 +25,7 @@ dependencies { testImplementation(libs.kotlin.stdlib) testImplementation(libs.kotlin.test) - testImplementation(libs.assertj) + testImplementation(libs.kotest.assertionsCore) testImplementation(libs.classgraph) testImplementation(libs.kotlinCompileTesting) { exclude( diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt index f2c70b03b2a..310c47509f3 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt @@ -5,7 +5,11 @@ import com.tschuchort.compiletesting.SourceFile import com.tschuchort.compiletesting.kspSourcesDir import com.tschuchort.compiletesting.symbolProcessorProviders import io.github.classgraph.ClassGraph -import org.assertj.core.api.Assertions +import io.kotest.assertions.withClue +import io.kotest.matchers.booleans.shouldBeTrue +import io.kotest.matchers.nulls.shouldNotBeNull +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe import java.io.File import java.net.URLClassLoader import java.nio.file.Files @@ -17,30 +21,30 @@ const val CLASS_FILENAME = "SourceKt" fun String.failsWith(check: (String) -> Boolean) { val compilationResult = compile(this) - Assertions.assertThat(compilationResult.exitCode).isNotEqualTo(KotlinCompilation.ExitCode.OK) - Assertions.assertThat(check(compilationResult.messages)).isTrue + compilationResult.exitCode shouldNotBe KotlinCompilation.ExitCode.OK + check(compilationResult.messages).shouldBeTrue() } fun String.compilationFails() { val compilationResult = compile(this) - Assertions.assertThat(compilationResult.exitCode).isNotEqualTo(KotlinCompilation.ExitCode.OK) + compilationResult.exitCode shouldNotBe KotlinCompilation.ExitCode.OK } fun String.compilationSucceeds(allWarningsAsErrors: Boolean = false) { val compilationResult = compile(this, allWarningsAsErrors = allWarningsAsErrors) - Assertions.assertThat(compilationResult.exitCode) - .withFailMessage(compilationResult.messages) - .isEqualTo(KotlinCompilation.ExitCode.OK) + withClue(compilationResult.messages) { + compilationResult.exitCode shouldBe KotlinCompilation.ExitCode.OK + } } fun String.evals(thing: Pair) { val compilationResult = compile(this) - Assertions.assertThat(compilationResult.exitCode) - .withFailMessage(compilationResult.messages) - .isEqualTo(KotlinCompilation.ExitCode.OK) + withClue(compilationResult.messages) { + compilationResult.exitCode shouldBe KotlinCompilation.ExitCode.OK + } val classesDirectory = compilationResult.outputDirectory val (variable, output) = thing - Assertions.assertThat(eval(variable, classesDirectory)).isEqualTo(output) + eval(variable, classesDirectory) shouldBe output } // UTILITY FUNCTIONS COPIED FROM META-TEST @@ -79,10 +83,9 @@ private fun classpathOf(dependency: String): File { ClassGraph().classpathFiles.firstOrNull { classpath -> dependenciesMatch(classpath, dependency) } -// println("classpath: ${ClassGraph().classpathFiles}") - Assertions.assertThat(file) - .`as`("$dependency not found in test runtime. Check your build configuration.") - .isNotNull + withClue("$dependency not found in test runtime. Check your build configuration.") { + file.shouldNotBeNull() + } return file!! } @@ -94,7 +97,7 @@ private fun dependenciesMatch(classpath: File, dependency: String): Boolean { } private fun sanitizeClassPathFileName(dep: String): String = - buildList { + buildList { var skip = false add(dep.first()) dep.reduce { a, b -> diff --git a/arrow-libs/optics/arrow-optics/build.gradle.kts b/arrow-libs/optics/arrow-optics/build.gradle.kts index 04f76a9e3e5..55ad127fd24 100644 --- a/arrow-libs/optics/arrow-optics/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics/build.gradle.kts @@ -5,7 +5,6 @@ plugins { alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) alias(libs.plugins.kotlinx.kover) - alias(libs.plugins.kotest.multiplatform) alias(libs.plugins.spotless) } @@ -30,26 +29,10 @@ kotlin { dependencies { implementation(libs.kotlin.test) implementation(libs.coroutines.test) - implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } } - - jvmTest { - dependencies { - implementation(libs.kotlin.stdlib) - implementation(libs.kotest.frameworkEngine) - implementation(libs.junitJupiterEngine) - implementation(libs.kotlin.reflect) - } - } - - jvmMain { - dependencies { - api(libs.kotlin.reflect) - } - } } jvm { diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt index 2426b4730ac..6a406d861b5 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/CopyTest.kt @@ -1,7 +1,8 @@ package arrow.optics -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import kotlinx.coroutines.test.runTest +import kotlin.test.Test // from https://kotlinlang.slack.com/archives/C5UPMM0A0/p1688822411819599 // and https://github.com/overfullstack/my-lab/blob/master/arrow/src/test/kotlin/ga/overfullstack/optics/OpticsLab.kt @@ -61,8 +62,8 @@ fun Person.moveToAmsterdamInside(): Person = copy { } } -class CopyTest : StringSpec({ - "optics" { +class CopyTest { + @Test fun copyOptics() = runTest { val me = Person( "Gopal", @@ -81,7 +82,7 @@ class CopyTest : StringSpec({ Person.address.get(meAfterMoving) shouldBe newAddress } - "optics composition" { + @Test fun copyOpticsComposition() = runTest { val personCity: Lens = Person.address compose Address.city compose City.name val me = @@ -96,7 +97,7 @@ class CopyTest : StringSpec({ meAtTheCapital.address.city.name shouldBe "Amsterdam" } - "optics copy to modify multiple fields" { + @Test fun copyMultiple() = runTest { val me = Person( "Alejandro", @@ -108,4 +109,4 @@ class CopyTest : StringSpec({ meAfterMoving1 shouldBe meAfterMoving2 meAfterMoving1.address.city.name shouldBe "Amsterdam" } -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/EveryTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/EveryTest.kt index b9919f09a24..650705a7b3a 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/EveryTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/EveryTest.kt @@ -1,92 +1,71 @@ package arrow.optics -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.orNull import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class EveryTest : StringSpec({ +class EveryTest { - with(Every.list()) { - - "asFold should behave as valid Fold: size" { - checkAll(Arb.list(Arb.int())) { ints -> - size(ints) shouldBe ints.size - } - } - - "asFold should behave as valid Fold: nonEmpty" { - checkAll(Arb.list(Arb.int())) { ints -> - isNotEmpty(ints) shouldBe ints.isNotEmpty() - } - } - - "asFold should behave as valid Fold: isEmpty" { - checkAll(Arb.list(Arb.int())) { ints -> - isEmpty(ints) shouldBe ints.isEmpty() - } - } - - "asFold should behave as valid Fold: getAll" { - checkAll(Arb.list(Arb.int())) { ints -> - getAll(ints) shouldBe ints - } - } - - "asFold should behave as valid Fold: fold" { - checkAll(Arb.list(Arb.int())) { ints -> - fold(0, { x, y -> x + y }, ints) shouldBe ints.sum() - } - } - - "asFold should behave as valid Fold: headOption" { - checkAll(Arb.list(Arb.int().orNull())) { ints -> - Every.list().firstOrNull(ints) shouldBe ints.firstOrNull() - } - } + @Test + fun sizeOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints -> + Every.list().size(ints) shouldBe ints.size + } + } - "asFold should behave as valid Fold: lastOption" { - checkAll(Arb.list(Arb.int().orNull())) { ints -> - Every.list().lastOrNull(ints) shouldBe ints.lastOrNull() - } - } + @Test + fun nonEmptyOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints -> + Every.list().isNotEmpty(ints) shouldBe ints.isNotEmpty() } + } - with(Every.list()) { + @Test + fun isEmptyOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints -> + Every.list().isEmpty(ints) shouldBe ints.isEmpty() + } + } - "Getting all targets of a traversal" { - checkAll(Arb.list(Arb.int())) { ints -> - getAll(ints) shouldBe ints - } - } + @Test + fun getAllOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints -> + Every.list().getAll(ints) shouldBe ints + } + } - "Folding all the values of a traversal" { - checkAll(Arb.list(Arb.int())) { ints -> - fold(0, { x, y -> x + y }, ints) shouldBe ints.sum() - } - } + @Test + fun foldOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints -> + Every.list().fold(0, { x, y -> x + y }, ints) shouldBe ints.sum() + } + } - "Combining all the values of a traversal" { - checkAll(Arb.list(Arb.int())) { ints -> - fold(0, { x, y -> x + y }, ints) shouldBe ints.sum() - } - } + @Test + fun firstOrNullOk() = runTest { + checkAll(Arb.list(Arb.int().orNull())) { ints -> + Every.list().firstOrNull(ints) shouldBe ints.firstOrNull() + } + } - "Finding an number larger than 10" { - checkAll(Arb.list(Arb.int(-100..100).orNull())) { ints -> - val predicate = { i: Int? -> i?.let { it > 10 } ?: false } - Every.list().findOrNull(ints, predicate) shouldBe ints.firstOrNull(predicate) - } - } + @Test + fun lastOrNullOk() = runTest { + checkAll(Arb.list(Arb.int().orNull())) { ints -> + Every.list().lastOrNull(ints) shouldBe ints.lastOrNull() + } + } - "Get the length from a traversal" { - checkAll(Arb.list(Arb.int())) { ints -> - size(ints) shouldBe ints.size - } - } + @Test + fun firstOrNullPredicateOk() = runTest { + checkAll(Arb.list(Arb.int(-100..100).orNull())) { ints -> + val predicate = { i: Int? -> i?.let { it > 10 } ?: false } + Every.list().findOrNull(ints, predicate) shouldBe ints.firstOrNull(predicate) } + } -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt index 4f7d0d8d7e8..3d7cd9f6e7f 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt @@ -8,125 +8,136 @@ import arrow.optics.test.laws.OptionalLaws import arrow.optics.test.laws.PrismLaws import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class IsoTest : StringSpec({ +class IsoTest { - val aIso: Iso = Iso( + private val aIso: Iso = Iso( get = { a: SumType.A -> a.string }, reverseGet = SumType::A ) - testLaws( - "Iso token - ", - LensLaws( - lens = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - PrismLaws( - prism = aIso, - aGen = Arb.sumTypeA(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - TraversalLaws( - traversal = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - OptionalLaws( - optional = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - IsoLaws( - iso = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) + @Test + fun isoTokenLaws() = + testLaws( + LensLaws( + lens = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + PrismLaws( + prism = aIso, + aGen = Arb.sumTypeA(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + TraversalLaws( + traversal = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + OptionalLaws( + optional = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ), + + IsoLaws( + iso = Iso.token(), + aGen = Arb.token(), + bGen = Arb.string(), + funcGen = Arb.functionAToB(Arb.string()) + ) ) - ) - with(Iso.token()) { - "asFold should behave as valid Fold: size" { - checkAll(Arb.token()) { token -> - size(token) shouldBe 1 - } + @Test + fun sizeOk() = runTest { + checkAll(Arb.token()) { token -> + Iso.token().size(token) shouldBe 1 } + } - "asFold should behave as valid Fold: nonEmpty" { - checkAll(Arb.token()) { token -> - isNotEmpty(token) shouldBe true - } + @Test + fun isNotEmptyOk() = runTest { + checkAll(Arb.token()) { token -> + Iso.token().isNotEmpty(token) shouldBe true } + } - "asFold should behave as valid Fold: isEmpty" { - checkAll(Arb.token()) { token -> - !isEmpty(token) shouldBe true - } + @Test + fun isEmptyOk() = runTest { + checkAll(Arb.token()) { token -> + !Iso.token().isEmpty(token) shouldBe true } + } - "asFold should behave as valid Fold: getAll" { - checkAll(Arb.token()) { token -> - getAll(token) shouldBe listOf(token.value) - } + @Test + fun getAllOk() = runTest { + checkAll(Arb.token()) { token -> + Iso.token().getAll(token) shouldBe listOf(token.value) } + } - "asFold should behave as valid Fold: fold" { - checkAll(Arb.token()) { token -> - fold("", { x, y -> x + y }, token) shouldBe token.value - } + @Test + fun foldOk() = runTest { + checkAll(Arb.token()) { token -> + Iso.token().fold("", { x, y -> x + y }, token) shouldBe token.value } + } - "asFold should behave as valid Fold: headOption" { - checkAll(Arb.token()) { token -> - firstOrNull(token) shouldBe token.value - } + @Test + fun firstOrNullOk() = runTest { + checkAll(Arb.token()) { token -> + Iso.token().firstOrNull(token) shouldBe token.value } + } - "asFold should behave as valid Fold: lastOption" { - checkAll(Arb.token()) { token -> - lastOrNull(token) shouldBe token.value - } + @Test + fun lastOrNullOk() = runTest { + checkAll(Arb.token()) { token -> + Iso.token().lastOrNull(token) shouldBe token.value } } - "Lifting a function should yield the same result as not yielding" { + @Test + fun modifyOk() = runTest { checkAll(Arb.token(), Arb.string()) { token, value -> Iso.token().modify(token) { value } shouldBe Iso.token().lift { value }(token) } } - "Creating a first pair with a type should result in the target to value" { + @Test + fun firstOk() = runTest { val first = Iso.token().first() checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> first.get(token to int) shouldBe (token.value to int) } } - "Creating a second pair with a type should result in the value to target" { + @Test + fun secondOk() = runTest { val second = Iso.token().second() checkAll(Arb.int(), Arb.token()) { int: Int, token: Token -> second.get(int to token) shouldBe (int to token.value) } } - "Creating a left with a type should result in a sum target to value" { + @Test + fun leftOk() = runTest { val left = Iso.token().left() checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> left.get(Either.Left(token)) shouldBe Either.Left(token.value) @@ -134,7 +145,8 @@ class IsoTest : StringSpec({ } } - "Creating a right with a type should result in a sum value to target" { + @Test + fun rightOk() = runTest { val left = Iso.token().right() checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> left.get(Either.Left(int)) shouldBe Either.Left(int) @@ -142,19 +154,22 @@ class IsoTest : StringSpec({ } } - "Finding a target using a predicate within a Iso should be wrapped in the correct option result" { + @Test + fun firstOrNullPredicateOk() = runTest { checkAll(Arb.boolean()) { predicate: Boolean -> (Iso.token().findOrNull(Token("any value")) { predicate }?.let { true } ?: false) shouldBe predicate } } - "Checking existence predicate over the target should result in same result as predicate" { + @Test + fun anyOk() = runTest { checkAll(Arb.boolean()) { predicate: Boolean -> Iso.token().any(Token("any value")) { predicate } shouldBe predicate } } - "Pairing two disjoint isos together" { + @Test + fun splitOk() = runTest { val joinedIso = Iso.token() split Iso.user() checkAll(Arb.string()) { tokenValue: String -> @@ -164,7 +179,8 @@ class IsoTest : StringSpec({ } } - "Composing isos should result in an iso of the first iso's value with the second iso's target" { + @Test + fun composeOk() = runTest { val composedIso = Iso.user() compose Iso.token() checkAll(Arb.string()) { tokenValue: String -> @@ -174,4 +190,4 @@ class IsoTest : StringSpec({ } } -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt index 9ec3610600e..a30cdb46d16 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt @@ -7,18 +7,20 @@ import arrow.optics.test.laws.LensLaws import arrow.optics.test.laws.OptionalLaws import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class LensTest : StringSpec({ +class LensTest { + @Test + fun lensTokenLaws() = testLaws( - "TokenLens - ", LensLaws( lens = Lens.token(), aGen = Arb.token(), @@ -41,8 +43,9 @@ class LensTest : StringSpec({ ) ) + @Test + fun identityLens() = testLaws( - "Identity Lens - ", LensLaws( lens = Lens.id(), aGen = Arb.int(), @@ -51,96 +54,110 @@ class LensTest : StringSpec({ ) ) - "asFold should behave as valid Fold: size" { - checkAll(Arb.token()) { token -> - Lens.token().size(token) shouldBe 1 - } + @Test + fun sizeOk() = runTest { + checkAll(Arb.token()) { token -> + Lens.token().size(token) shouldBe 1 } + } - "asFold should behave as valid Fold: nonEmpty" { - checkAll(Arb.token()) { token -> - Lens.token().isNotEmpty(token) shouldBe true - } + @Test + fun isNonEmptyOk() = runTest { + checkAll(Arb.token()) { token -> + Lens.token().isNotEmpty(token) shouldBe true } + } - "asFold should behave as valid Fold: isEmpty" { - checkAll(Arb.token()) { token -> - !Lens.token().isEmpty(token) shouldBe true - } + @Test + fun isEmptyOk() = runTest { + checkAll(Arb.token()) { token -> + !Lens.token().isEmpty(token) shouldBe true } + } - "asFold should behave as valid Fold: getAll" { - checkAll(Arb.token()) { token -> - Lens.token().getAll(token) shouldBe listOf(token.value) - } + @Test + fun getAllOk() = runTest { + checkAll(Arb.token()) { token -> + Lens.token().getAll(token) shouldBe listOf(token.value) } + } - "asFold should behave as valid Fold: fold" { - checkAll(Arb.token()) { token -> - Lens.token().fold("", { x, y -> x + y }, token) shouldBe token.value - } + @Test + fun foldOk() = runTest { + checkAll(Arb.token()) { token -> + Lens.token().fold("", { x, y -> x + y }, token) shouldBe token.value } + } - "asFold should behave as valid Fold: headOption" { - checkAll(Arb.token()) { token -> - Lens.token().firstOrNull(token) shouldBe token.value - } + @Test + fun firstOrNullOk() = runTest { + checkAll(Arb.token()) { token -> + Lens.token().firstOrNull(token) shouldBe token.value } + } - "asFold should behave as valid Fold: lastOption" { - checkAll(Arb.token()) { token -> - Lens.token().lastOrNull(token) shouldBe token.value - } + @Test + fun lastOrNullOk() = runTest { + checkAll(Arb.token()) { token -> + Lens.token().lastOrNull(token) shouldBe token.value } + } - "Lifting a function should yield the same result as not yielding" { - checkAll(Arb.token(), Arb.string()) { token, value -> - Lens.token().set(token, value) shouldBe Lens.token().lift { value }(token) - } + @Test + fun setOrLift() = runTest { + checkAll(Arb.token(), Arb.string()) { token, value -> + Lens.token().set(token, value) shouldBe Lens.token().lift { value }(token) } + } - "Finding a target using a predicate within a Lens should be wrapped in the correct option result" { - checkAll(Arb.boolean()) { predicate: Boolean -> - (Lens.token().findOrNull(Token("any value")) { predicate }?.let { true } ?: false) shouldBe predicate - } + @Test + fun findOrNullPredicate() = runTest { + checkAll(Arb.boolean()) { predicate: Boolean -> + (Lens.token().findOrNull(Token("any value")) { predicate }?.let { true } ?: false) shouldBe predicate } + } - "Checking existence predicate over the target should result in same result as predicate" { - checkAll(Arb.boolean()) { predicate: Boolean -> - Lens.token().any(Token("any value")) { predicate } shouldBe predicate - } + @Test + fun anyOk() = runTest { + checkAll(Arb.boolean()) { predicate: Boolean -> + Lens.token().any(Token("any value")) { predicate } shouldBe predicate } + } - "Joining two lenses together with same target should yield same result" { - val userTokenStringLens = Lens.user() compose Lens.token() - val joinedLens = Lens.token() choice userTokenStringLens + @Test + fun joinOk() = runTest { + val userTokenStringLens = Lens.user() compose Lens.token() + val joinedLens = Lens.token() choice userTokenStringLens - checkAll(Arb.string()) { tokenValue: String -> - val token = Token(tokenValue) - val user = User(token) - joinedLens.get(Left(token)) shouldBe joinedLens.get(Right(user)) - } + checkAll(Arb.string()) { tokenValue: String -> + val token = Token(tokenValue) + val user = User(token) + joinedLens.get(Left(token)) shouldBe joinedLens.get(Right(user)) } + } - "Pairing two disjoint lenses should yield a pair of their results" { - val spiltLens: Lens, Pair> = Lens.token() split Lens.user() - checkAll(Arb.token(), Arb.user()) { token: Token, user: User -> - spiltLens.get(token to user) shouldBe (token.value to user.token) - } + @Test + fun splitOk() = runTest { + val spiltLens: Lens, Pair> = Lens.token() split Lens.user() + checkAll(Arb.token(), Arb.user()) { token: Token, user: User -> + spiltLens.get(token to user) shouldBe (token.value to user.token) } + } - "Creating a first pair with a type should result in the target to value" { - val first = Lens.token().first() - checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> - first.get(token to int) shouldBe (token.value to int) - } + @Test + fun firstOk() = runTest { + val first = Lens.token().first() + checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> + first.get(token to int) shouldBe (token.value to int) } + } - "Creating a second pair with a type should result in the value target" { - val second = Lens.token().second() - checkAll(Arb.int(), Arb.token()) { int: Int, token: Token -> - second.get(int to token) shouldBe (int to token.value) - } + @Test + fun secondOk() = runTest { + val second = Lens.token().second() + checkAll(Arb.int(), Arb.token()) { int: Int, token: Token -> + second.get(int to token) shouldBe (int to token.value) } + } -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalTest.kt index 00fb2d5e344..f8977ee7943 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalTest.kt @@ -8,7 +8,6 @@ import arrow.core.toOption import arrow.optics.test.functionAToB import arrow.optics.test.laws.OptionalLaws import arrow.optics.test.laws.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe import io.kotest.property.Arb @@ -19,11 +18,14 @@ import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class OptionalTest : StringSpec({ +class OptionalTest { + @Test + fun identityLaws() = testLaws( - "Optional identity - ", OptionalLaws( optional = Optional.id(), aGen = Arb.int(), @@ -32,8 +34,9 @@ class OptionalTest : StringSpec({ ) ) + @Test + fun optionalFirstHeadLaws() = testLaws( - "Optional first head - ", OptionalLaws( optional = Optional.listHead().first(), aGen = Arb.pair(Arb.list(Arb.int()), Arb.boolean()), @@ -42,8 +45,9 @@ class OptionalTest : StringSpec({ ) ) + @Test + fun optionalSecondHeadLaws() = testLaws( - "Optional second head - ", OptionalLaws( optional = Optional.listHead().second(), aGen = Arb.pair(Arb.boolean(), Arb.list(Arb.int())), @@ -52,121 +56,135 @@ class OptionalTest : StringSpec({ ) ) - "asSetter should set absent optional" { - checkAll(Arb.incompleteUser(), Arb.token()) { user, token -> - val updatedUser = Optional.incompleteUserToken().set(user, token) - Optional.incompleteUserToken().getOrNull(updatedUser).shouldNotBeNull() - } + @Test + fun setAbsentOptional() = runTest { + checkAll(Arb.incompleteUser(), Arb.token()) { user, token -> + val updatedUser = Optional.incompleteUserToken().set(user, token) + Optional.incompleteUserToken().getOrNull(updatedUser).shouldNotBeNull() } + } - with(Optional.listHead()) { - - "asFold should behave as valid Fold: size" { - checkAll(Arb.list(Arb.int())) { ints: List -> - size(ints) shouldBe ints.firstOrNull().toOption().map { 1 }.getOrElse { 0 } - } - } + @Test + fun sizeOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints: List -> + Optional.listHead().size(ints) shouldBe ints.firstOrNull().toOption().map { 1 }.getOrElse { 0 } + } + } - "asFold should behave as valid Fold: nonEmpty" { - checkAll(Arb.list(Arb.int())) { ints: List -> - isNotEmpty(ints) shouldBe ints.firstOrNull().toOption().isSome() - } - } + @Test + fun nonEmptyOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints: List -> + Optional.listHead().isNotEmpty(ints) shouldBe ints.firstOrNull().toOption().isSome() + } + } - "asFold should behave as valid Fold: isEmpty" { - checkAll(Arb.list(Arb.int())) { ints: List -> - isEmpty(ints) shouldBe ints.firstOrNull().toOption().isNone() - } - } + @Test + fun isEmptyOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints: List -> + Optional.listHead().isEmpty(ints) shouldBe ints.firstOrNull().toOption().isNone() + } + } - "asFold should behave as valid Fold: getAll" { - checkAll(Arb.list(Arb.int())) { ints: List -> - getAll(ints) shouldBe ints.firstOrNull().toOption().toList() - } - } + @Test + fun getAllOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints: List -> + Optional.listHead().getAll(ints) shouldBe ints.firstOrNull().toOption().toList() + } + } - "asFold should behave as valid Fold: fold" { - checkAll(Arb.list(Arb.int())) { ints: List -> - fold(0, { x, y -> x + y }, ints) shouldBe - ints.firstOrNull().toOption().fold({ 0 }, ::identity) - } - } + @Test + fun foldOk() = runTest { + checkAll(Arb.list(Arb.int())) { ints: List -> + Optional.listHead().fold(0, { x, y -> x + y }, ints) shouldBe + ints.firstOrNull().toOption().fold({ 0 }, ::identity) } + } - "listHead.firstOrNull == firstOrNull" { - checkAll(Arb.list(Arb.int().orNull())) { ints -> - Optional.listHead().firstOrNull(ints) shouldBe ints.firstOrNull() - } + @Test + fun firstOrNullOk() = runTest { + checkAll(Arb.list(Arb.int().orNull())) { ints -> + Optional.listHead().firstOrNull(ints) shouldBe ints.firstOrNull() } + } - "listHead.lastOrNull == firstOrNull" { - checkAll(Arb.list(Arb.int().orNull())) { ints -> - Optional.listHead().lastOrNull(ints) shouldBe ints.firstOrNull() - } + @Test + fun lastOrNullOk() = runTest { + checkAll(Arb.list(Arb.int().orNull())) { ints -> + Optional.listHead().lastOrNull(ints) shouldBe ints.firstOrNull() } + } - "unit should always " { - checkAll(Arb.string()) { string: String -> - Optional.void().getOrNull(string) shouldBe null - } + @Test + fun unitAlwaysNull() = runTest { + checkAll(Arb.string()) { string: String -> + Optional.void().getOrNull(string) shouldBe null } + } - "unit should always return source when setting target" { - checkAll(Arb.int(), Arb.string()) { int: Int, string: String -> - Optional.void().set(string, int) shouldBe string - } + @Test + fun unitDoesNothing() = runTest { + checkAll(Arb.int(), Arb.string()) { int: Int, string: String -> + Optional.void().set(string, int) shouldBe string } + } - "Checking if there is no target" { - checkAll(Arb.list(Arb.int())) { list -> - Optional.listHead().isNotEmpty(list) shouldBe list.isNotEmpty() - } + @Test + fun noTarget() = runTest { + checkAll(Arb.list(Arb.int())) { list -> + Optional.listHead().isNotEmpty(list) shouldBe list.isNotEmpty() } + } - "Lift should be consistent with modify" { - checkAll(Arb.list(Arb.int())) { list -> - val f = { i: Int -> i + 5 } - Optional.listHead().lift(f)(list) shouldBe Optional.listHead().modify(list, f) - } + @Test + fun liftConsistentWithModify() = runTest { + checkAll(Arb.list(Arb.int())) { list -> + val f = { i: Int -> i + 5 } + Optional.listHead().lift(f)(list) shouldBe Optional.listHead().modify(list, f) } + } - "Checking if a target exists" { - checkAll(Arb.list(Arb.int())) { list -> - Optional.listHead().isEmpty(list) shouldBe list.isEmpty() - } + @Test + fun checkTargetExists() = runTest { + checkAll(Arb.list(Arb.int())) { list -> + Optional.listHead().isEmpty(list) shouldBe list.isEmpty() } + } - "Finding a target using a predicate should be wrapped in the correct option result" { - checkAll(Arb.list(Arb.int()), Arb.boolean()) { list, predicate -> - (Optional.listHead().findOrNull(list) { predicate }?.let { true } - ?: false) shouldBe (predicate && list.isNotEmpty()) - } + @Test + fun findOrNullOk() = runTest { + checkAll(Arb.list(Arb.int()), Arb.boolean()) { list, predicate -> + (Optional.listHead().findOrNull(list) { predicate }?.let { true } + ?: false) shouldBe (predicate && list.isNotEmpty()) } + } - "Checking existence predicate over the target should result in same result as predicate" { - checkAll(Arb.list(Arb.int().orNull()), Arb.boolean()) { list, predicate -> - Optional.listHead().exists(list) { predicate } shouldBe (predicate && list.isNotEmpty()) - } + @Test + fun existsOk() = runTest { + checkAll(Arb.list(Arb.int().orNull()), Arb.boolean()) { list, predicate -> + Optional.listHead().exists(list) { predicate } shouldBe (predicate && list.isNotEmpty()) } + } - "Checking satisfaction of predicate over the target should result in opposite result as predicate" { - checkAll(Arb.list(Arb.int()), Arb.boolean()) { list, predicate -> - Optional.listHead().all(list) { predicate } shouldBe if (list.isEmpty()) true else predicate - } + @Test + fun allOk() = runTest { + checkAll(Arb.list(Arb.int()), Arb.boolean()) { list, predicate -> + Optional.listHead().all(list) { predicate } shouldBe if (list.isEmpty()) true else predicate } + } - "Set a value over a non empty list target then the first item of the result should be the value" { - checkAll(Arb.list(Arb.int(), 1..200), Arb.int()) { list, value -> - Optional.listHead().set(list, value)[0] shouldBe value - } + @Test + fun setNonEmptyList() = runTest { + checkAll(Arb.list(Arb.int(), 1..200), Arb.int()) { list, value -> + Optional.listHead().set(list, value)[0] shouldBe value } + } - "Joining two optionals together with same target should yield same result" { - val joinedOptional = Optional.listHead().choice(Optional.defaultHead()) + @Test + fun joinOk() = runTest { + val joinedOptional = Optional.listHead().choice(Optional.defaultHead()) - checkAll(Arb.int()) { int -> - joinedOptional.getOrNull(Left(listOf(int))) shouldBe joinedOptional.getOrNull(Right(int)) - } + checkAll(Arb.int()) { int -> + joinedOptional.getOrNull(Left(listOf(int))) shouldBe joinedOptional.getOrNull(Right(int)) } - -}) + } +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt index a237f0c7a77..e0a2b7dabca 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt @@ -6,7 +6,6 @@ import arrow.optics.test.laws.OptionalLaws import arrow.optics.test.laws.PrismLaws import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean @@ -14,11 +13,14 @@ import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlinx.coroutines.test.runTest +import kotlin.test.Test -class PrismTest : StringSpec({ +class PrismTest { + @Test + fun prismSumLaws() = testLaws( - "Prism sum - ", PrismLaws( prism = Prism.sumType(), aGen = Arb.sumType(), @@ -41,8 +43,9 @@ class PrismTest : StringSpec({ ) ) + @Test + fun prismSumFirstLaws() = testLaws( - "Prism sum first - ", PrismLaws( prism = Prism.sumType().first(), aGen = Arb.pair(Arb.sumType(), Arb.int()), @@ -51,8 +54,9 @@ class PrismTest : StringSpec({ ) ) + @Test + fun prismSumSecondLaws() = testLaws( - "Prism sum second - ", PrismLaws( prism = Prism.sumType().second(), aGen = Arb.pair(Arb.int(), Arb.sumType()), @@ -61,8 +65,9 @@ class PrismTest : StringSpec({ ) ) + @Test + fun prismSumRightLaws() = testLaws( - "Prism sum right - ", PrismLaws( prism = Prism.sumType().right(), aGen = Arb.either(Arb.int(), Arb.sumType()), @@ -71,8 +76,9 @@ class PrismTest : StringSpec({ ) ) + @Test + fun prismSumLeftLaws() = testLaws( - "Prism sum left - ", PrismLaws( prism = Prism.sumType().left(), aGen = Arb.either(Arb.sumType(), Arb.int()), @@ -81,8 +87,9 @@ class PrismTest : StringSpec({ ) ) + @Test + fun prismIdentityLaws() = testLaws( - "Prism identity - ", PrismLaws( prism = Prism.id(), aGen = Arb.either(Arb.int(), Arb.int()), @@ -91,99 +98,112 @@ class PrismTest : StringSpec({ ) ) - with(Prism.sumType()) { - "asFold should behave as valid Fold: size" { - checkAll(Arb.sumType()) { sum: SumType -> - size(sum) shouldBe (Prism.sumType().getOrNull(sum)?.let { 1 } ?: 0) - } - } - - "asFold should behave as valid Fold: nonEmpty" { - checkAll(Arb.sumType()) { sum: SumType -> - isNotEmpty(sum) shouldBe (Prism.sumType().getOrNull(sum) != null) - } - } - - "asFold should behave as valid Fold: isEmpty" { - checkAll(Arb.sumType()) { sum: SumType -> - isEmpty(sum) shouldBe (Prism.sumType().getOrNull(sum) == null) - } - } - - "asFold should behave as valid Fold: getAll" { - checkAll(Arb.sumType()) { sum: SumType -> - getAll(sum) shouldBe listOfNotNull(Prism.sumType().getOrNull(sum)) - } - } - - "asFold should behave as valid Fold: fold" { - checkAll(Arb.sumType()) { sum: SumType -> - fold("", { x, y -> x + y }, sum) shouldBe - (Prism.sumType().getOrNull(sum) ?: "") - } - } - - "asFold should behave as valid Fold: headOption" { - checkAll(Arb.sumType()) { sum: SumType -> - firstOrNull(sum) shouldBe Prism.sumType().getOrNull(sum) - } - } - - "asFold should behave as valid Fold: lastOption" { - checkAll(Arb.sumType()) { sum: SumType -> - lastOrNull(sum) shouldBe Prism.sumType().getOrNull(sum) - } - } + @Test + fun sizeOk() = runTest { + checkAll(Arb.sumType()) { sum: SumType -> + Prism.sumType().size(sum) shouldBe (Prism.sumType().getOrNull(sum)?.let { 1 } ?: 0) } + } - "Joining two prisms together with same target should yield same result" { - checkAll(Arb.sumType()) { a -> - (Prism.sumType() compose Prism.string()).getOrNull(a) shouldBe Prism.sumType().getOrNull(a) - ?.let(Prism.string()::getOrNull) - (Prism.sumType() + Prism.string()).getOrNull(a) shouldBe (Prism.sumType() compose Prism.string()).getOrNull(a) - } + @Test + fun nonEmptyOk() = runTest { + checkAll(Arb.sumType()) { sum: SumType -> + Prism.sumType().isNotEmpty(sum) shouldBe (Prism.sumType().getOrNull(sum) != null) } + } - "Checking if a prism exists with a target" { - checkAll(Arb.sumType(), Arb.sumType(), Arb.boolean()) { a, other, bool -> - Prism.only(a) { _, _ -> bool }.isEmpty(other) shouldBe bool - } + @Test + fun isEmptyOk() = runTest { + checkAll(Arb.sumType()) { sum: SumType -> + Prism.sumType().isEmpty(sum) shouldBe (Prism.sumType().getOrNull(sum) == null) } + } - "Checking if there is no target" { - checkAll(Arb.sumType()) { sum -> - Prism.sumType().isEmpty(sum) shouldBe (sum !is SumType.A) - } + @Test + fun getAllOk() = runTest { + checkAll(Arb.sumType()) { sum: SumType -> + Prism.sumType().getAll(sum) shouldBe listOfNotNull(Prism.sumType().getOrNull(sum)) } + } - "Checking if a target exists" { - checkAll(Arb.sumType()) { sum -> - Prism.sumType().isNotEmpty(sum) shouldBe (sum is SumType.A) - } + @Test + fun foldOk() = runTest { + checkAll(Arb.sumType()) { sum: SumType -> + Prism.sumType().fold("", { x, y -> x + y }, sum) shouldBe + (Prism.sumType().getOrNull(sum) ?: "") } + } - "Setting a target on a prism should set the correct target" { - checkAll(Arb.sumTypeA(), Arb.string()) { a, string -> - (Prism.sumType().setNullable(a, string)!!) shouldBe a.copy(string = string) - } + @Test + fun firstOrNullOk() = runTest { + checkAll(Arb.sumType()) { sum: SumType -> + Prism.sumType().firstOrNull(sum) shouldBe Prism.sumType().getOrNull(sum) } + } - "Finding a target using a predicate within a Lens should be wrapped in the correct option result" { - checkAll(Arb.sumType(), Arb.boolean()) { sum, predicate -> - (Prism.sumType().findOrNull(sum) { predicate }?.let { true } ?: false) shouldBe (predicate && sum is SumType.A) - } + @Test + fun lastOrNullOk() = runTest { + checkAll(Arb.sumType()) { sum: SumType -> + Prism.sumType().lastOrNull(sum) shouldBe Prism.sumType().getOrNull(sum) } + } + + @Test + fun joinOk() = runTest { + checkAll(Arb.sumType()) { a -> + (Prism.sumType() compose Prism.string()).getOrNull(a) shouldBe Prism.sumType().getOrNull(a) + ?.let(Prism.string()::getOrNull) + (Prism.sumType() + Prism.string()).getOrNull(a) shouldBe (Prism.sumType() compose Prism.string()).getOrNull(a) + } + } + + @Test + fun checkExists() = runTest { + checkAll(Arb.sumType(), Arb.sumType(), Arb.boolean()) { a, other, bool -> + Prism.only(a) { _, _ -> bool }.isEmpty(other) shouldBe bool + } + } + + @Test + fun checkNoTarget() = runTest { + checkAll(Arb.sumType()) { sum -> + Prism.sumType().isEmpty(sum) shouldBe (sum !is SumType.A) + } + } + + @Test + fun checkTargetExists() = runTest { + checkAll(Arb.sumType()) { sum -> + Prism.sumType().isNotEmpty(sum) shouldBe (sum is SumType.A) + } + } + + @Test + fun setOk() = runTest { + checkAll(Arb.sumTypeA(), Arb.string()) { a, string -> + (Prism.sumType().setNullable(a, string)!!) shouldBe a.copy(string = string) + } + } + + @Test + fun findOrNullOk() = runTest { + checkAll(Arb.sumType(), Arb.boolean()) { sum, predicate -> + (Prism.sumType().findOrNull(sum) { predicate }?.let { true } ?: false) shouldBe (predicate && sum is SumType.A) + } + } - "Checking existence predicate over the target should result in same result as predicate" { - checkAll(Arb.sumType(), Arb.boolean()) { sum, predicate -> - Prism.sumType().any(sum) { predicate } shouldBe (predicate && sum is SumType.A) - } + @Test + fun anyOk() = runTest { + checkAll(Arb.sumType(), Arb.boolean()) { sum, predicate -> + Prism.sumType().any(sum) { predicate } shouldBe (predicate && sum is SumType.A) } + } - "Checking satisfaction of predicate over the target should result in opposite result as predicate" { - checkAll(Arb.sumType(), Arb.boolean()) { sum, predicate -> - Prism.sumType().all(sum) { predicate } shouldBe (predicate || sum is SumType.B) - } + @Test + fun allOk() = runTest { + checkAll(Arb.sumType(), Arb.boolean()) { sum, predicate -> + Prism.sumType().all(sum) { predicate } shouldBe (predicate || sum is SumType.B) } + } -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt index 4e6cdb33d09..f83db44314f 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt @@ -5,7 +5,6 @@ import arrow.optics.test.option import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.nonEmptyList -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.int @@ -13,11 +12,12 @@ import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.string +import kotlin.test.Test -class TraversalTest : StringSpec({ +class TraversalTest { + @Test fun traversalListLaws() = testLaws( - "Traversal list - ", TraversalLaws( traversal = Traversal.list(), aGen = Arb.list(Arb.int()), @@ -26,8 +26,8 @@ class TraversalTest : StringSpec({ ) ) + @Test fun traversalNonEmptyListLaws() = testLaws( - "Traversal Nel - ", TraversalLaws( traversal = Traversal.nonEmptyList(), aGen = Arb.nonEmptyList(Arb.int()), @@ -36,8 +36,8 @@ class TraversalTest : StringSpec({ ) ) + @Test fun traversalSequenceLaws() = testLaws( - "Traversal sequence - ", TraversalLaws( traversal = Traversal.sequence(), aGen = Arb.list(Arb.int()).map { it.asSequence() }, @@ -47,8 +47,8 @@ class TraversalTest : StringSpec({ ) ) + @Test fun traversalMapLaws() = testLaws( - "Traversal map - ", TraversalLaws( traversal = Traversal.map(), aGen = Arb.map(Arb.int(), Arb.long()), @@ -57,8 +57,8 @@ class TraversalTest : StringSpec({ ) ) + @Test fun traversalOptionLaws() = testLaws( - "Traversal option - ", TraversalLaws( traversal = Traversal.option(), aGen = Arb.option(Arb.string()), @@ -67,8 +67,8 @@ class TraversalTest : StringSpec({ ) ) + @Test fun traversalStringLaws() = testLaws( - "Traversal string - ", TraversalLaws( traversal = Traversal.string(), aGen = Arb.string(), @@ -77,4 +77,4 @@ class TraversalTest : StringSpec({ ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/AtInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/AtInstanceTest.kt index ef5138dfdf7..d83a564d084 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/AtInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/AtInstanceTest.kt @@ -5,17 +5,18 @@ import arrow.optics.test.laws.LensLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.option import arrow.optics.typeclasses.At -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.set +import kotlin.test.Test -class AtInstanceTest : StringSpec({ +class AtInstanceTest { + @Test + fun atMapLaws() = testLaws( - "At map - ", LensLaws( lensGen = Arb.long().map { At.map().at(it) }, aGen = Arb.map(Arb.long(), Arb.int()), @@ -24,8 +25,9 @@ class AtInstanceTest : StringSpec({ ) ) + @Test + fun atSetLaws() = testLaws( - "At set - ", LensLaws( lensGen = Arb.long().map { At.set().at(it) }, aGen = Arb.set(Arb.long()), @@ -33,4 +35,4 @@ class AtInstanceTest : StringSpec({ funcGen = Arb.functionAToB(Arb.boolean()), ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt index 4b07238130e..2b3cf3bb9d3 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt @@ -4,17 +4,18 @@ import arrow.optics.test.functionAToB import arrow.optics.test.laws.PrismLaws import arrow.optics.test.laws.testLaws import arrow.optics.typeclasses.Cons -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string +import kotlin.test.Test -class ConsInstanceTest : StringSpec({ +class ConsInstanceTest { + @Test + fun consListLaws() = testLaws( - "Const list - ", PrismLaws( prism = Cons.list().cons(), aGen = Arb.list(Arb.int()), @@ -23,8 +24,9 @@ class ConsInstanceTest : StringSpec({ ) ) + @Test + fun consStringLaws() = testLaws( - "Cons string - ", PrismLaws( prism = Cons.string().cons(), aGen = Arb.string(), @@ -32,4 +34,4 @@ class ConsInstanceTest : StringSpec({ funcGen = Arb.functionAToB(Arb.pair(Arb.char(), Arb.string())), ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/EitherInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/EitherInstanceTest.kt index 8a6d2c33eb7..da75829afb0 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/EitherInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/EitherInstanceTest.kt @@ -5,12 +5,14 @@ import arrow.optics.test.either import arrow.optics.test.functionAToB import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string +import kotlin.test.Test -class EitherInstanceTest : StringSpec({ +class EitherInstanceTest { + @Test + fun eitherLaws() = testLaws( TraversalLaws( traversal = Traversal.either(), @@ -19,4 +21,4 @@ class EitherInstanceTest : StringSpec({ funcGen = Arb.functionAToB(Arb.int()), ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt index 45de0915b60..e8765846ec1 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/FilterIndexInstanceTest.kt @@ -5,18 +5,19 @@ import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.nonEmptyList import arrow.optics.typeclasses.FilterIndex -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.string +import kotlin.test.Test -class FilterIndexInstanceTest : StringSpec({ +class FilterIndexInstanceTest { + @Test + fun filterIndexListLaws() = testLaws( - "FilterIndex list - ", TraversalLaws( traversal = FilterIndex.list().filter { true }, aGen = Arb.list(Arb.int()), @@ -25,8 +26,9 @@ class FilterIndexInstanceTest : StringSpec({ ) ) + @Test + fun filterIndexSequenceLaws() = testLaws( - "FilterIndex sequence - ", TraversalLaws( traversal = FilterIndex.sequence().filter { true }, aGen = Arb.list(Arb.int()).map { it.asSequence() }, @@ -35,8 +37,9 @@ class FilterIndexInstanceTest : StringSpec({ ) { a, b -> a.toList() == b.toList() } ) + @Test + fun filterIndexNonEmptyListLaws() = testLaws( - "FilterIndex Nel - ", TraversalLaws( traversal = FilterIndex.nonEmptyList().filter { true }, aGen = Arb.nonEmptyList(Arb.int()), @@ -45,8 +48,9 @@ class FilterIndexInstanceTest : StringSpec({ ) ) + @Test + fun filterIndexMapLaws() = testLaws( - "FilterIndex map - ", TraversalLaws( traversal = FilterIndex.map().filter { true }, aGen = Arb.map(Arb.char(), Arb.int()), @@ -55,8 +59,9 @@ class FilterIndexInstanceTest : StringSpec({ ) ) + @Test + fun filterIndexStringLaws() = testLaws( - "FilterIndex string - ", TraversalLaws( traversal = FilterIndex.string().filter { true }, aGen = Arb.string(), @@ -64,4 +69,4 @@ class FilterIndexInstanceTest : StringSpec({ funcGen = Arb.functionAToB(Arb.char()), ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt index d77cc5b185f..e0e1e4efde1 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/IndexInstanceTest.kt @@ -5,7 +5,6 @@ import arrow.optics.test.nonEmptyList import arrow.optics.test.laws.OptionalLaws import arrow.optics.test.laws.testLaws import arrow.optics.typeclasses.Index -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.int @@ -13,11 +12,13 @@ import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.long import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.string +import kotlin.test.Test -class IndexInstanceTest : StringSpec({ +class IndexInstanceTest { + @Test + fun indexListLaws() = testLaws( - "Index list - ", OptionalLaws( optionalGen = Arb.int().map { Index.list().index(it) }, aGen = Arb.list(Arb.long()), @@ -26,8 +27,9 @@ class IndexInstanceTest : StringSpec({ ) ) + @Test + fun indexSequenceLaws() = testLaws( - "Index sequence - ", OptionalLaws( optionalGen = Arb.int().map { Index.sequence().index(it) }, aGen = Arb.list(Arb.long()).map { it.asSequence() }, @@ -37,8 +39,9 @@ class IndexInstanceTest : StringSpec({ ) ) + @Test + fun indexMapLaws() = testLaws( - "Index map - ", OptionalLaws( optionalGen = Arb.int().map { Index.list().index(it) }, aGen = Arb.list(Arb.long()), @@ -47,8 +50,9 @@ class IndexInstanceTest : StringSpec({ ) ) + @Test + fun indexNonEmptyListLaws() = testLaws( - "Index Nel - ", OptionalLaws( optionalGen = Arb.int().map { Index.nonEmptyList().index(it) }, aGen = Arb.nonEmptyList(Arb.long()), @@ -57,8 +61,9 @@ class IndexInstanceTest : StringSpec({ ) ) + @Test + fun indexStringLaws() = testLaws( - "Index string - ", OptionalLaws( optionalGen = Arb.int().map { Index.string().index(it) }, aGen = Arb.string(), @@ -67,4 +72,4 @@ class IndexInstanceTest : StringSpec({ ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/SnocInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/SnocInstanceTest.kt index 7eb5059a95e..403b38c17b5 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/SnocInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/SnocInstanceTest.kt @@ -4,17 +4,18 @@ import arrow.optics.test.functionAToB import arrow.optics.test.laws.PrismLaws import arrow.optics.test.laws.testLaws import arrow.optics.typeclasses.Snoc -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string +import kotlin.test.Test -class SnocInstanceTest : StringSpec({ +class SnocInstanceTest { + @Test + fun snocListLaws() = testLaws( - "Snoc list - ", PrismLaws( prism = Snoc.list().snoc(), aGen = Arb.list(Arb.int()), @@ -22,8 +23,10 @@ class SnocInstanceTest : StringSpec({ funcGen = Arb.functionAToB(Arb.pair(Arb.list(Arb.int()), Arb.int())), ) ) + + @Test + fun snocStringLaws() = testLaws( - "Snoc string - ", PrismLaws( prism = Snoc.string().snoc(), aGen = Arb.string(), @@ -31,4 +34,4 @@ class SnocInstanceTest : StringSpec({ funcGen = Arb.functionAToB(Arb.pair(Arb.string(), Arb.char())), ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt index 6f44f00e158..6af753918ff 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt @@ -9,15 +9,16 @@ import arrow.optics.test.laws.TraversalLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.nonEmptyList import arrow.optics.test.option -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list +import kotlin.test.Test -class ListTest : StringSpec({ +class ListTest { + @Test + fun headLaws() = testLaws( - "Optional list head - ", OptionalLaws( optional = Optional.listHead(), aGen = Arb.list(Arb.int()), @@ -32,8 +33,9 @@ class ListTest : StringSpec({ ) ) + @Test + fun tailLaws() = testLaws( - "Optional list tail - ", OptionalLaws( optional = Optional.listTail(), aGen = Arb.list(Arb.int()), @@ -42,8 +44,9 @@ class ListTest : StringSpec({ ) ) + @Test + fun isoToOptionNelLaws() = testLaws( - "Iso list to Option Nel - ", IsoLaws( iso = Iso.listToOptionNel(), aGen = Arb.list(Arb.int()), @@ -52,4 +55,4 @@ class ListTest : StringSpec({ ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt index 070d980f532..67f4eee46ac 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt @@ -4,22 +4,23 @@ import arrow.optics.Iso import arrow.optics.test.functionAToB import arrow.optics.test.laws.IsoLaws import arrow.optics.test.laws.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.constant import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.set import io.kotest.property.arbitrary.string +import kotlin.test.Test -class MapTest : StringSpec({ +class MapTest { - testLaws( - IsoLaws( - iso = Iso.mapToSet(), - aGen = Arb.map(Arb.string(), Arb.constant(Unit)), - bGen = Arb.set(Arb.string()), - funcGen = Arb.functionAToB(Arb.set(Arb.string())), - ) + @Test + fun mapToSetLaws() = testLaws( + IsoLaws( + iso = Iso.mapToSet(), + aGen = Arb.map(Arb.string(), Arb.constant(Unit), maxSize = 20), + bGen = Arb.set(Arb.string(), range = 0 .. 20), + funcGen = Arb.functionAToB(Arb.set(Arb.string(), range = 0 .. 20)), ) + ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/NonEmptyListTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/NonEmptyListTest.kt index c6d7f48aa02..878aee071c0 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/NonEmptyListTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/NonEmptyListTest.kt @@ -5,16 +5,16 @@ import arrow.optics.test.functionAToB import arrow.optics.test.laws.LensLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.nonEmptyList -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list -import io.kotest.property.arbitrary.string +import kotlin.test.Test -class NonEmptyListTest : StringSpec({ +class NonEmptyListTest { + @Test + fun headLaws() = testLaws( - "Lens Nel head - ", LensLaws( lens = Lens.nonEmptyListHead(), aGen = Arb.nonEmptyList(Arb.int()), @@ -23,8 +23,8 @@ class NonEmptyListTest : StringSpec({ ) ) + @Test fun tailLaws() = testLaws( - "Lens Nel tail - ", LensLaws( lens = Lens.nonEmptyListTail(), aGen = Arb.nonEmptyList(Arb.int()), @@ -33,4 +33,4 @@ class NonEmptyListTest : StringSpec({ ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt index f00588377c4..15705124bdf 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt @@ -8,16 +8,17 @@ import arrow.optics.test.laws.IsoLaws import arrow.optics.test.laws.PrismLaws import arrow.optics.test.laws.testLaws import arrow.optics.test.option -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.constant import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.orNull +import kotlin.test.Test -class OptionTest : StringSpec({ +class OptionTest { + @Test + fun someLaws() = testLaws( - "Prism some - ", PrismLaws( prism = Prism.some(), aGen = Arb.option(Arb.int()), @@ -26,8 +27,9 @@ class OptionTest : StringSpec({ ) ) + @Test + fun noneLaws() = testLaws( - "Prism none - ", PrismLaws( prism = Prism.none(), aGen = Arb.option(Arb.int()), @@ -36,8 +38,9 @@ class OptionTest : StringSpec({ ) ) + @Test + fun isoToNullable() = testLaws( - "Iso option to nullable - ", IsoLaws( iso = Iso.optionToNullable().reverse(), aGen = Arb.int().orNull(), @@ -46,8 +49,9 @@ class OptionTest : StringSpec({ ) ) + @Test + fun isoToEither() = testLaws( - "Iso option to either - ", IsoLaws( iso = Iso.optionToEither(), aGen = Arb.option(Arb.int()), @@ -56,4 +60,4 @@ class OptionTest : StringSpec({ ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt index 9703d4d3453..1d4162ba971 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt @@ -3,17 +3,18 @@ package arrow.optics.std import arrow.optics.Iso import arrow.optics.test.laws.IsoLaws import arrow.optics.test.laws.testLaws -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.string +import kotlin.test.Test -class StringTest : StringSpec({ +class StringTest { + @Test + fun isoToList() = testLaws( - "Iso string to list - ", IsoLaws( iso = Iso.stringToList(), aGen = Arb.string(), @@ -22,4 +23,4 @@ class StringTest : StringSpec({ ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt index 19cb340714f..e250dd58b50 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/TupleTest.kt @@ -12,18 +12,19 @@ import arrow.optics.test.tuple6 import arrow.optics.test.tuple7 import arrow.optics.test.tuple8 import arrow.optics.test.tuple9 -import io.kotest.core.spec.style.StringSpec import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string import io.kotest.property.arbitrary.triple +import kotlin.test.Test -class TupleTest : StringSpec({ +class TupleTest { + @Test + fun firstLaws() = testLaws( - "Lens pair first - ", LensLaws( lens = Lens.pairFirst(), aGen = Arb.pair(Arb.int(), Arb.string()), @@ -32,8 +33,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun secondLaws() = testLaws( - "Lens pair second - ", LensLaws( lens = Lens.pairSecond(), aGen = Arb.pair(Arb.int(), Arb.string()), @@ -42,8 +44,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tripleFirstLaws() = testLaws( - "Lens triple first - ", LensLaws( lens = Lens.tripleFirst(), aGen = Arb.triple(Arb.int(), Arb.string(), Arb.string()), @@ -52,8 +55,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tripleSecondLaws() = testLaws( - "Lens triple second - ", LensLaws( lens = Lens.tripleSecond(), aGen = Arb.triple(Arb.int(), Arb.string(), Arb.int()), @@ -62,8 +66,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tripleThirdLaws() = testLaws( - "Lens triple third - ", LensLaws( lens = Lens.tripleThird(), aGen = Arb.triple(Arb.int(), Arb.int(), Arb.string()), @@ -72,8 +77,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun pairLaws() = testLaws( - "Traversal pair - ", TraversalLaws( traversal = Traversal.pair(), aGen = Arb.pair(Arb.boolean(), Arb.boolean()), @@ -82,8 +88,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tripleLaws() = testLaws( - "Traversal triple - ", TraversalLaws( traversal = Traversal.triple(), aGen = Arb.triple(Arb.boolean(), Arb.boolean(), Arb.boolean()), @@ -92,8 +99,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tuple4Laws() = testLaws( - "Traversal tuple4 - ", TraversalLaws( traversal = Traversal.tuple4(), aGen = Arb.tuple4(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), @@ -102,8 +110,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tuple5Laws() = testLaws( - "Traversal tuple5 - ", TraversalLaws( traversal = Traversal.tuple5(), aGen = Arb.tuple5(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), @@ -112,8 +121,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tuple6Laws() = testLaws( - "Traversal tuple6 - ", TraversalLaws( traversal = Traversal.tuple6(), aGen = Arb.tuple6(Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean(), Arb.boolean()), @@ -122,8 +132,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tuple7Laws() = testLaws( - "Traversal tuple7 - ", TraversalLaws( traversal = Traversal.tuple7(), aGen = Arb.tuple7( @@ -140,8 +151,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tuple8Laws() = testLaws( - "Traversal tuple8 - ", TraversalLaws( traversal = Traversal.tuple8(), aGen = Arb.tuple8( @@ -159,8 +171,9 @@ class TupleTest : StringSpec({ ) ) + @Test + fun tuple9Laws() = testLaws( - "Traversal tuple9 - ", TraversalLaws( traversal = Traversal.tuple9(), aGen = Arb.tuple9( @@ -179,4 +192,4 @@ class TupleTest : StringSpec({ ) ) -}) +} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt index 4ecef3b4528..4c97cf56e6b 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/test/laws/Laws.kt @@ -1,39 +1,29 @@ package arrow.optics.test.laws import io.kotest.assertions.fail -import io.kotest.core.names.TestName -import io.kotest.core.spec.style.StringSpec -import io.kotest.core.spec.style.scopes.StringSpecScope -import io.kotest.core.spec.style.scopes.addTest -import io.kotest.core.test.TestContext +import io.kotest.assertions.withClue +import kotlinx.coroutines.test.TestResult +import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.runTest interface LawSet { val laws: List } -data class Law(val name: String, val test: suspend TestContext.() -> Unit) +data class Law(val name: String, val test: suspend TestScope.() -> Unit) fun A.equalUnderTheLaw(b: A, f: (A, A) -> Boolean = { x, y -> x == y }): Boolean = if (f(this, b)) true else fail("Found $this but expected: $b") -fun StringSpec.testLaws(vararg lawSets: LawSet): Unit = testLaws(lawSets.flatMap { it.laws }) +fun testLaws(vararg lawSets: LawSet): TestResult = testLaws(lawSets.flatMap { it.laws }) -fun StringSpec.testLaws(prefix: String, vararg lawSets: LawSet): Unit = testLaws(prefix, lawSets.flatMap { it.laws }) - -fun StringSpec.testLaws(vararg laws: List): Unit = laws - .flatMap { list: List -> list.asIterable() } - .distinctBy { law: Law -> law.name } - .forEach { law: Law -> - addTest(TestName(null, law.name, false), false, null) { - law.test(StringSpecScope(this.coroutineContext, testCase)) - } - } - -fun StringSpec.testLaws(prefix: String, vararg laws: List): Unit = laws - .flatMap { list: List -> list.asIterable() } - .distinctBy { law: Law -> law.name } - .forEach { law: Law -> - addTest(TestName(prefix, law.name, false), false, null) { - law.test(StringSpecScope(this.coroutineContext, testCase)) +fun testLaws(vararg laws: List): TestResult = runTest { + laws + .flatMap(List::asIterable) + .distinctBy(Law::name) + .forEach { law: Law -> + withClue("Testing ${law.name}") { + law.test(this@runTest) + } } - } +} diff --git a/build.gradle.kts b/build.gradle.kts index 072f06ed65f..b274fb6d644 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,7 +39,6 @@ plugins { base alias(libs.plugins.dokka) alias(libs.plugins.animalSniffer) apply false - alias(libs.plugins.kotest.multiplatform) apply false alias(libs.plugins.kotlinx.kover) alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.kotlinx.serialization) apply false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6a30b72c037..3df133cba55 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,15 +1,10 @@ [versions] animalSniffer = "1.7.1" arrowGradleConfig = "0.12.0-rc.6" -assertj = "3.24.2" coroutines = "1.7.3" classgraph = "4.8.164" dokka = "1.9.10" -jUnit = "4.13.2" -jUnitJupiter = "5.10.1" -jUnitVintage = "5.10.1" kotest = "5.8.0" -kotestGradle = "5.8.0" kover = "0.7.3" kotlin = "1.9.20" kotlinxSerializationPlugin = "1.9.20" @@ -26,19 +21,10 @@ spotlessVersion = "6.22.0" [libraries] coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" } -jUnitJUnit = { module = "junit:junit", version.ref = "jUnit" } -jUnitVintageEngine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "jUnitVintage" } -junitJupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "jUnitJupiter" } -junitJupiterEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "jUnitJupiter" } kotest-assertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } -kotest-frameworkApi = { module = "io.kotest:kotest-framework-api", version.ref = "kotest" } -kotest-frameworkEngine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } kotest-property = { module = "io.kotest:kotest-property", version.ref = "kotest" } -kotest-runnerJUnit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" } -kotlin-stdlibCommon = { module = "org.jetbrains.kotlin:kotlin-stdlib-common" } kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" } -kotlin-stdlibJS = { module = "org.jetbrains.kotlin:kotlin-stdlib-js" } kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" } kotlinx-knit = { module = "org.jetbrains.kotlinx:kotlinx-knit", version.ref = "knit" } kotlinx-serializationCore = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerialization" } @@ -50,7 +36,6 @@ jakewharton-retrofitConverterKotlinxSerialization = { module = "com.jakewharton. squareup-retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" } ksp = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "kspVersion" } kspGradlePlugin = { module = "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin", version.ref = "kspVersion" } -assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } classgraph = { module = "io.github.classgraph:classgraph", version.ref = "classgraph" } kotlinCompileTesting = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "kotlinCompileTesting" } kotlinCompileTestingKsp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref = "kotlinCompileTesting" } @@ -63,7 +48,6 @@ arrowGradleConfig-nexus = { id = "io.arrow-kt.arrow-gradle-config-nexus", versio arrowGradleConfig-publish = { id = "io.arrow-kt.arrow-gradle-config-publish", version.ref = "arrowGradleConfig" } arrowGradleConfig-versioning = { id = "io.arrow-kt.arrow-gradle-config-versioning", version.ref = "arrowGradleConfig" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } -kotest-multiplatform = { id = "io.kotest.multiplatform", version.ref = "kotestGradle" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlin-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinBinaryCompatibilityValidator" } From e94a9b513306e3933609887227df7ae1754a6cdf Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Wed, 15 Nov 2023 12:41:16 +0100 Subject: [PATCH 105/114] Add or fix contracts in Raise (#3293) * Add or fix contracts in Raise * Make contracts less strict * Get back contract on Either * ignoreErrors should also be AT_MOST_ONCE --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../src/commonMain/kotlin/arrow/core/Ior.kt | 12 +-- .../commonMain/kotlin/arrow/core/Option.kt | 12 +-- .../kotlin/arrow/core/raise/Builders.kt | 81 ++++++++++++++----- .../kotlin/arrow/core/raise/Fold.kt | 6 ++ .../kotlin/arrow/core/raise/Raise.kt | 52 ++++++++++-- .../arrow/core/raise/RaiseAccumulate.kt | 9 ++- 6 files changed, 129 insertions(+), 43 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt index 92e39d6efe0..1c8661edcec 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt @@ -175,7 +175,7 @@ public sealed class Ior { public inline fun map(f: (B) -> D): Ior { contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } return when (this) { - is Left -> Left(value) + is Left -> this is Right -> Right(f(value)) is Both -> Both(leftValue, f(rightValue)) } @@ -198,11 +198,11 @@ public sealed class Ior { */ public inline fun mapLeft(fa: (A) -> C): Ior { contract { callsInPlace(fa, InvocationKind.AT_MOST_ONCE) } - return fold( - { Left(fa(it)) }, - ::Right, - { a, b -> Both(fa(a), b) } - ) + return when (this) { + is Left -> Left(fa(value)) + is Right -> this + is Both -> Both(fa(leftValue), rightValue) + } } /** diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 6a5216dc8e0..283555bae23 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -311,15 +311,14 @@ public sealed class Option { */ public inline fun catch(f: () -> A): Option { contract { callsInPlace(f, InvocationKind.AT_MOST_ONCE) } - val recover: (Throwable) -> Option = { None } - return catch(recover, f) + return catch({ None }, f) } @JvmStatic @JvmName("tryCatch") public inline fun catch(recover: (Throwable) -> Option, f: () -> A): Option { contract { - callsInPlace(f, InvocationKind.EXACTLY_ONCE) + callsInPlace(f, InvocationKind.AT_MOST_ONCE) callsInPlace(recover, InvocationKind.AT_MOST_ONCE) } return try { @@ -429,7 +428,7 @@ public sealed class Option { */ public inline fun isSome(predicate: (A) -> Boolean): Boolean { contract { - callsInPlace(predicate, InvocationKind.EXACTLY_ONCE) + callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) returns(true) implies (this@Option is Some) } return this@Option is Some && predicate(value) @@ -555,7 +554,10 @@ public data class Some(val value: T) : Option() { */ public inline fun Option.getOrElse(default: () -> T): T { contract { callsInPlace(default, InvocationKind.AT_MOST_ONCE) } - return fold({ default() }, ::identity) + return when (this) { + is Some -> value + else -> default() + } } public fun T?.toOption(): Option = this?.let { Some(it) } ?: None diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt index 362ec819819..49936d38ab1 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt @@ -17,6 +17,7 @@ import arrow.core.Some import arrow.core.getOrElse import arrow.core.identity import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass @@ -32,8 +33,10 @@ import kotlin.jvm.JvmName * Read more about running a [Raise] computation in the * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). */ -public inline fun either(@BuilderInference block: Raise.() -> A): Either = - fold({ block.invoke(this) }, { Either.Left(it) }, { Either.Right(it) }) +public inline fun either(@BuilderInference block: Raise.() -> A): Either { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } + return fold({ block.invoke(this) }, { Either.Left(it) }, { Either.Right(it) }) +} /** * Runs a computation [block] using [Raise], and return its outcome as nullable type, @@ -47,8 +50,10 @@ public inline fun either(@BuilderInference block: Raise.() -> * @see NullableRaise.ignoreErrors By default, `nullable` only allows raising `null`. * Calling [ignoreErrors][NullableRaise.ignoreErrors] inside `nullable` allows to raise any error, which will be returned to the caller as if `null` was raised. */ -public inline fun nullable(block: NullableRaise.() -> A): A? = - merge { block(NullableRaise(this)) } +public inline fun nullable(block: NullableRaise.() -> A): A? { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } + return merge { block(NullableRaise(this)) } +} /** * Runs a computation [block] using [Raise], and return its outcome as [Result]. @@ -57,8 +62,10 @@ public inline fun nullable(block: NullableRaise.() -> A): A? = * Read more about running a [Raise] computation in the * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). */ -public inline fun result(block: ResultRaise.() -> A): Result = - fold({ block(ResultRaise(this)) }, Result.Companion::failure, Result.Companion::failure, Result.Companion::success) +public inline fun result(block: ResultRaise.() -> A): Result { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } + return fold({ block(ResultRaise(this)) }, Result.Companion::failure, Result.Companion::failure, Result.Companion::success) +} /** * Runs a computation [block] using [Raise], and return its outcome as [Option]. @@ -70,8 +77,10 @@ public inline fun result(block: ResultRaise.() -> A): Result = * Read more about running a [Raise] computation in the * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). */ -public inline fun option(block: OptionRaise.() -> A): Option = - fold({ block(OptionRaise(this)) }, ::identity, ::Some) +public inline fun option(block: OptionRaise.() -> A): Option { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } + return fold({ block(OptionRaise(this)) }, ::identity, ::Some) +} /** * Runs a computation [block] using [Raise], and return its outcome as [Ior]. @@ -89,6 +98,7 @@ public inline fun option(block: OptionRaise.() -> A): Option = * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). */ public inline fun ior(noinline combineError: (Error, Error) -> Error, @BuilderInference block: IorRaise.() -> A): Ior { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } val state: Atomic> = Atomic(None) return fold>( { block(IorRaise(combineError, state, this)) }, @@ -115,6 +125,7 @@ public inline fun ior(noinline combineError: (Error, Error) -> Error, * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). */ public inline fun iorNel(noinline combineError: (NonEmptyList, NonEmptyList) -> NonEmptyList = { a, b -> a + b }, @BuilderInference block: IorRaise>.() -> A): IorNel { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } val state: Atomic>> = Atomic(None) return fold, A, Ior, A>>( { block(IorRaise(combineError, state, this)) }, @@ -193,9 +204,15 @@ public class NullableRaise(private val raise: Raise) : Raise by rais public inline fun recover( @BuilderInference block: NullableRaise.() -> A, recover: () -> A, - ): A = when (val nullable = nullable(block)) { - null -> recover() - else -> nullable + ): A { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + callsInPlace(recover, InvocationKind.AT_MOST_ONCE) + } + return when (val nullable = nullable(block)) { + null -> recover() + else -> nullable + } } /** @@ -205,7 +222,10 @@ public class NullableRaise(private val raise: Raise) : Raise by rais @RaiseDSL public inline fun ignoreErrors( @BuilderInference block: IgnoreErrorsRaise.() -> A, - ): A = block(IgnoreErrorsRaise(this) { null }) + ): A { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } + return block(IgnoreErrorsRaise(this) { null }) + } } /** @@ -285,9 +305,15 @@ public class OptionRaise(private val raise: Raise) : Raise by raise public inline fun recover( @BuilderInference block: OptionRaise.() -> A, recover: () -> A, - ): A = when (val option = option(block)) { - is None -> recover() - is Some -> option.value + ): A { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + callsInPlace(recover, InvocationKind.AT_MOST_ONCE) + } + return when (val option = option(block)) { + is None -> recover() + is Some -> option.value + } } /** @@ -297,7 +323,12 @@ public class OptionRaise(private val raise: Raise) : Raise by raise @RaiseDSL public inline fun ignoreErrors( @BuilderInference block: IgnoreErrorsRaise.() -> A, - ): A = block(IgnoreErrorsRaise(this) { None }) + ): A { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + } + return block(IgnoreErrorsRaise(this) { None }) + } } /** @@ -353,13 +384,19 @@ public class IorRaise @PublishedApi internal constructor( public inline fun recover( @BuilderInference block: IorRaise.() -> A, recover: (error: Error) -> A, - ): A = when (val ior = ior(combineError, block)) { - is Ior.Both -> { - combine(ior.leftValue) - ior.rightValue + ): A { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + callsInPlace(recover, InvocationKind.AT_MOST_ONCE) } + return when (val ior = ior(combineError, block)) { + is Ior.Both -> { + combine(ior.leftValue) + ior.rightValue + } - is Ior.Left -> recover(ior.value) - is Ior.Right -> ior.value + is Ior.Left -> recover(ior.value) + is Ior.Right -> ior.value + } } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Fold.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Fold.kt index ee344a3e487..25e5831f9ff 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Fold.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Fold.kt @@ -107,6 +107,7 @@ public inline fun fold( transform: (value: A) -> B, ): B { contract { + callsInPlace(block, AT_MOST_ONCE) callsInPlace(recover, AT_MOST_ONCE) callsInPlace(transform, AT_MOST_ONCE) } @@ -131,6 +132,7 @@ public inline fun fold( transform: (value: A) -> B, ): B { contract { + callsInPlace(block, AT_MOST_ONCE) callsInPlace(catch, AT_MOST_ONCE) callsInPlace(recover, AT_MOST_ONCE) callsInPlace(transform, AT_MOST_ONCE) @@ -193,6 +195,10 @@ public inline fun Raise.traced( @BuilderInference block: Raise.() -> A, trace: (trace: Trace, error: Error) -> Unit ): A { + contract { + callsInPlace(block, AT_MOST_ONCE) + callsInPlace(trace, AT_MOST_ONCE) + } val isOuterTraced = this is DefaultRaise && isTraced val nested: DefaultRaise = if (isOuterTraced) this as DefaultRaise else DefaultRaise(true) return try { diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt index 3f3617f65ef..aa01e7663d8 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt @@ -14,6 +14,7 @@ import arrow.core.recover import kotlin.coroutines.cancellation.CancellationException import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind.AT_MOST_ONCE +import kotlin.contracts.InvocationKind.EXACTLY_ONCE import kotlin.contracts.contract import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass @@ -336,7 +337,13 @@ public interface Raise { public inline fun recover( @BuilderInference block: Raise.() -> A, @BuilderInference recover: (error: Error) -> A, -): A = fold(block, { throw it }, recover, ::identity) +): A { + contract { + callsInPlace(block, AT_MOST_ONCE) + callsInPlace(recover, AT_MOST_ONCE) + } + return fold(block, { throw it }, recover, ::identity) +} /** * Execute the [Raise] context function resulting in [A] or any _logical error_ of type [Error], @@ -371,7 +378,14 @@ public inline fun recover( @BuilderInference block: Raise.() -> A, @BuilderInference recover: (error: Error) -> A, @BuilderInference catch: (throwable: Throwable) -> A, -): A = fold(block, catch, recover, ::identity) +): A { + contract { + callsInPlace(block, AT_MOST_ONCE) + callsInPlace(recover, AT_MOST_ONCE) + callsInPlace(catch, AT_MOST_ONCE) + } + return fold(block, catch, recover, ::identity) +} /** * Execute the [Raise] context function resulting in [A] or any _logical error_ of type [Error], @@ -407,7 +421,14 @@ public inline fun recover( @BuilderInference block: Raise.() -> A, @BuilderInference recover: (error: Error) -> A, @BuilderInference catch: (t: T) -> A, -): A = fold(block, { t -> if (t is T) catch(t) else throw t }, recover, ::identity) +): A { + contract { + callsInPlace(block, AT_MOST_ONCE) + callsInPlace(recover, AT_MOST_ONCE) + callsInPlace(catch, AT_MOST_ONCE) + } + return fold(block, { t -> if (t is T) catch(t) else throw t }, recover, ::identity) +} /** * Allows safely catching exceptions without capturing [CancellationException], @@ -441,12 +462,17 @@ public inline fun recover( * This API offers a similar syntax as the top-level [catch] functions like [Either.catch]. */ @RaiseDSL -public inline fun catch(block: () -> A, catch: (throwable: Throwable) -> A): A = - try { +public inline fun catch(block: () -> A, catch: (throwable: Throwable) -> A): A { + contract { + callsInPlace(block, AT_MOST_ONCE) + callsInPlace(catch, AT_MOST_ONCE) + } + return try { block() } catch (t: Throwable) { catch(t.nonFatalOrThrow()) } +} /** * Allows safely catching exceptions of type `T` without capturing [CancellationException], @@ -481,8 +507,13 @@ public inline fun catch(block: () -> A, catch: (throwable: Throwable) -> A): */ @RaiseDSL @JvmName("catchReified") -public inline fun catch(block: () -> A, catch: (t: T) -> A): A = - catch(block) { t: Throwable -> if (t is T) catch(t) else throw t } +public inline fun catch(block: () -> A, catch: (t: T) -> A): A { + contract { + callsInPlace(block, AT_MOST_ONCE) + callsInPlace(catch, AT_MOST_ONCE) + } + return catch(block) { t: Throwable -> if (t is T) catch(t) else throw t } +} /** * Ensures that the [condition] is met; @@ -656,4 +687,9 @@ public inline fun Raise.withError( @JvmName("_merge") public inline fun merge( @BuilderInference block: Raise.() -> A, -): A = recover(block, ::identity) +): A { + contract { + callsInPlace(block, AT_MOST_ONCE) + } + return recover(block, ::identity) +} diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt index f16ce69eec2..6e7fae7c370 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt @@ -17,6 +17,7 @@ import arrow.core.toNonEmptyListOrNull import arrow.core.toNonEmptySetOrNull import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind.AT_MOST_ONCE +import kotlin.contracts.InvocationKind.EXACTLY_ONCE import kotlin.contracts.contract import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass @@ -654,6 +655,10 @@ public open class RaiseAccumulate( } @RaiseDSL - public inline fun withNel(block: Raise>.() -> A): A = - block(raise) + public inline fun withNel(block: Raise>.() -> A): A { + contract { + callsInPlace(block, EXACTLY_ONCE) + } + return block(raise) + } } From de48969e247fedb1a7cb6a9843864249cd6fd878 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Tue, 23 Jan 2024 17:07:11 +0100 Subject: [PATCH 106/114] Alternate `SingletonRaise` (#3328) Co-authored-by: Youssef Shoaib Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: serras --- arrow-libs/core/arrow-core/api/arrow-core.api | 98 +++------ .../commonMain/kotlin/arrow/core/Option.kt | 6 +- .../kotlin/arrow/core/raise/Builders.kt | 196 ++++++++---------- .../kotlin/arrow/core/raise/Raise.kt | 1 - .../kotlin/arrow/core/raise/NullableSpec.kt | 21 ++ .../kotlin/arrow/core/raise/OptionSpec.kt | 16 +- arrow-libs/core/arrow-eval/api/arrow-eval.api | 1 - 7 files changed, 148 insertions(+), 191 deletions(-) diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 4b177726463..67d7be634f2 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -620,7 +620,7 @@ public final class arrow/core/OptionKt { public static final fun flatten (Larrow/core/Option;)Larrow/core/Option; public static final fun getOrElse (Larrow/core/Option;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; public static final fun none ()Larrow/core/Option; - public static final fun recover (Larrow/core/Option;Lkotlin/jvm/functions/Function2;)Larrow/core/Option; + public static final fun recover (Larrow/core/Option;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun some (Ljava/lang/Object;)Larrow/core/Option; public static final fun toMap (Larrow/core/Option;)Ljava/util/Map; public static final fun toOption (Ljava/lang/Object;)Larrow/core/Option; @@ -901,24 +901,6 @@ public abstract interface annotation class arrow/core/raise/DelicateRaiseApi : j public abstract interface annotation class arrow/core/raise/ExperimentalTraceApi : java/lang/annotation/Annotation { } -public final class arrow/core/raise/IgnoreErrorsRaise : arrow/core/raise/Raise { - public fun (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function0;)V - public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Option;)Ljava/lang/Object; - public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; - public fun bindAll (Ljava/util/Map;)Ljava/util/Map; - public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; - public final fun ensure (Z)V - public final fun ensureNotNull (Ljava/lang/Object;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun raise (Ljava/lang/Object;)Ljava/lang/Void; -} - public final class arrow/core/raise/IorRaise : arrow/core/raise/Raise { public fun (Lkotlin/jvm/functions/Function2;Ljava/util/concurrent/atomic/AtomicReference;Larrow/core/raise/Raise;)V public fun bind (Larrow/core/Either;)Ljava/lang/Object; @@ -941,53 +923,6 @@ public final class arrow/core/raise/IorRaise : arrow/core/raise/Raise { public final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } -public final class arrow/core/raise/NullableRaise : arrow/core/raise/Raise { - public fun (Larrow/core/raise/Raise;)V - public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Option;)Ljava/lang/Object; - public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; - public fun bindAll (Ljava/util/Map;)Ljava/util/Map; - public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; - public final fun bindAllNullable (Ljava/lang/Iterable;)Ljava/util/List; - public final fun bindAllNullable (Ljava/util/Map;)Ljava/util/Map; - public final fun ensure (Z)V - public final fun ensureNotNull (Ljava/lang/Object;)Ljava/lang/Object; - public final fun ignoreErrors (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public fun raise (Ljava/lang/Void;)Ljava/lang/Void; - public final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; -} - -public final class arrow/core/raise/OptionRaise : arrow/core/raise/Raise { - public fun (Larrow/core/raise/Raise;)V - public fun bind (Larrow/core/Either;)Ljava/lang/Object; - public final fun bind (Larrow/core/Option;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; - public fun bindAll (Ljava/util/Map;)Ljava/util/Map; - public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; - public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; - public final fun bindAllOption (Ljava/lang/Iterable;)Ljava/util/List; - public final fun bindAllOption (Ljava/util/List;)Ljava/util/List; - public final fun bindAllOption (Ljava/util/Map;)Ljava/util/Map; - public final fun bindAllOption (Ljava/util/Set;)Ljava/util/Set; - public final fun ensure (Z)V - public final fun ensureNotNull (Ljava/lang/Object;)Ljava/lang/Object; - public final fun ignoreErrors (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun raise (Larrow/core/None;)Ljava/lang/Void; - public synthetic fun raise (Ljava/lang/Object;)Ljava/lang/Void; - public final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; -} - public abstract interface class arrow/core/raise/Raise { public abstract fun bind (Larrow/core/Either;)Ljava/lang/Object; public abstract fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -1067,6 +1002,7 @@ public final class arrow/core/raise/RaiseKt { public static final fun getOrElse (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun getOrNull (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun getOrNull (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun impure (Lkotlin/jvm/functions/Function1;)V public static final fun ior (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; public static final fun iorNel (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; public static synthetic fun iorNel$default (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Larrow/core/Ior; @@ -1086,6 +1022,7 @@ public final class arrow/core/raise/RaiseKt { public static final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; public static final fun recover (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lkotlin/jvm/functions/Function2; public static final fun result (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun singleton (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun toEither (Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun toEither (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun toIor (Lkotlin/jvm/functions/Function1;)Larrow/core/Ior; @@ -1138,6 +1075,35 @@ public final class arrow/core/raise/ResultRaise : arrow/core/raise/Raise { public final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } +public final class arrow/core/raise/SingletonRaise : arrow/core/raise/Raise { + public fun (Larrow/core/raise/Raise;)V + public fun bind (Larrow/core/Either;)Ljava/lang/Object; + public final fun bind (Larrow/core/Option;)Ljava/lang/Object; + public final fun bind (Ljava/lang/Object;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun bindAll (Ljava/lang/Iterable;)Ljava/util/List; + public fun bindAll (Ljava/util/Map;)Ljava/util/Map; + public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; + public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; + public final fun bindAllNullable (Ljava/lang/Iterable;)Ljava/util/List; + public final fun bindAllNullable (Ljava/util/List;)Ljava/util/List; + public final fun bindAllNullable (Ljava/util/Map;)Ljava/util/Map; + public final fun bindAllNullable (Ljava/util/Set;)Ljava/util/Set; + public final fun bindAllOption (Ljava/lang/Iterable;)Ljava/util/List; + public final fun bindAllOption (Ljava/util/List;)Ljava/util/List; + public final fun bindAllOption (Ljava/util/Map;)Ljava/util/Map; + public final fun bindAllOption (Ljava/util/Set;)Ljava/util/Set; + public final fun ensure (Z)V + public final fun ensureNotNull (Ljava/lang/Object;)Ljava/lang/Object; + public final fun ignoreErrors (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun raise ()Ljava/lang/Void; + public fun raise (Ljava/lang/Object;)Ljava/lang/Void; + public final fun recover (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; +} + public final class arrow/core/raise/Trace { public static final synthetic fun box-impl (Ljava/util/concurrent/CancellationException;)Larrow/core/raise/Trace; public static fun constructor-impl (Ljava/util/concurrent/CancellationException;)Ljava/util/concurrent/CancellationException; diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 283555bae23..d63241aa6e4 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -3,7 +3,7 @@ package arrow.core import arrow.core.raise.EagerEffect import arrow.core.raise.Effect -import arrow.core.raise.OptionRaise +import arrow.core.raise.SingletonRaise import arrow.core.raise.option import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind @@ -671,8 +671,8 @@ public operator fun > Option.compareTo(other: Option): I * * */ -public inline fun Option.recover(recover: OptionRaise.(None) -> A): Option = +public inline fun Option.recover(recover: SingletonRaise.() -> A): Option = when (this@recover) { - is None -> option { recover(this, None) } + is None -> option { recover() } is Some -> this@recover } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt index 7b7aba6a051..1cac6b4d3cd 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt @@ -7,6 +7,7 @@ package arrow.core.raise import arrow.atomic.Atomic import arrow.atomic.updateAndGet import arrow.core.Either +import arrow.core.EmptyValue import arrow.core.Ior import arrow.core.IorNel import arrow.core.NonEmptyList @@ -16,7 +17,8 @@ import arrow.core.Option import arrow.core.Some import arrow.core.getOrElse import arrow.core.identity -import arrow.core.EmptyValue +import arrow.core.none +import arrow.core.some import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -24,6 +26,18 @@ import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName +@RaiseDSL +public inline fun singleton( + raise: () -> A, + @BuilderInference block: SingletonRaise.() -> A, +): A { + contract { + callsInPlace(raise, InvocationKind.AT_MOST_ONCE) + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + } + return recover({ block(SingletonRaise(this)) }) { raise() } +} + /** * Runs a computation [block] using [Raise], and return its outcome as [Either]. * - [Either.Right] represents success, @@ -36,7 +50,7 @@ import kotlin.jvm.JvmName */ public inline fun either(@BuilderInference block: Raise.() -> A): Either { contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } - return fold({ block.invoke(this) }, { Either.Left(it) }, { Either.Right(it) }) + return fold(block, { Either.Left(it) }, { Either.Right(it) }) } /** @@ -48,12 +62,12 @@ public inline fun either(@BuilderInference block: Raise.() -> * Read more about running a [Raise] computation in the * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). * - * @see NullableRaise.ignoreErrors By default, `nullable` only allows raising `null`. - * Calling [ignoreErrors][NullableRaise.ignoreErrors] inside `nullable` allows to raise any error, which will be returned to the caller as if `null` was raised. + * @see SingletonRaise.ignoreErrors By default, `nullable` only allows raising `null`. + * Calling [ignoreErrors][SingletonRaise.ignoreErrors] inside `nullable` allows to raise any error, which will be returned to the caller as if `null` was raised. */ -public inline fun nullable(block: NullableRaise.() -> A): A? { +public inline fun nullable(block: SingletonRaise.() -> A): A? { contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } - return merge { block(NullableRaise(this)) } + return singleton({ null }, block) } /** @@ -78,9 +92,9 @@ public inline fun result(block: ResultRaise.() -> A): Result { * Read more about running a [Raise] computation in the * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). */ -public inline fun option(block: OptionRaise.() -> A): Option { +public inline fun option(block: SingletonRaise.() -> A): Option { contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } - return fold({ block(OptionRaise(this)) }, ::identity, ::Some) + return singleton(::none) { block().some() } } /** @@ -130,83 +144,98 @@ public inline fun iorNel(noinline combineError: (NonEmptyList, } /** - * Implementation of [Raise] used by `ignoreErrors`. - * You should never use this directly. + * Runs a computation [block] using [Raise], and ignore its outcome. + * + * This function re-throws any exceptions thrown within the [Raise] block. + * + * Read more about running a [Raise] computation in the + * [Arrow docs](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#running-and-inspecting-results). */ -public class IgnoreErrorsRaise( - private val raise: Raise, - private val error: () -> N -) : Raise { +public inline fun impure(block: SingletonRaise.() -> Unit) { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } + return singleton({ }, block) +} + +public class SingletonRaise(private val raise: Raise): Raise { @RaiseDSL - override fun raise(r: Any?): Nothing = - raise.raise(error()) + public fun raise(): Nothing = raise.raise(Unit) @RaiseDSL - public fun ensure(value: Boolean): Unit = ensure(value) { null } + override fun raise(r: E): Nothing = raise() @RaiseDSL - public fun Option.bind(): A = getOrElse { raise(null) } + public fun ensure(condition: Boolean) { + contract { returns() implies condition } + return if (condition) Unit else raise() + } + + @RaiseDSL + public fun Option.bind(): A { + contract { returns() implies (this@bind is Some) } + return getOrElse { raise() } + } @RaiseDSL public fun A?.bind(): A { contract { returns() implies (this@bind != null) } - return this ?: raise(null) + return this ?: raise() } @RaiseDSL public fun ensureNotNull(value: A?): A { contract { returns() implies (value != null) } - return ensureNotNull(value) { null } + return value ?: raise() } -} -public typealias Null = Nothing? - -/** - * Implementation of [Raise] used by [nullable]. - * You should never use this directly. - */ -public class NullableRaise(private val raise: Raise) : Raise by raise { @RaiseDSL - public fun ensure(value: Boolean): Unit = ensure(value) { null } + @JvmName("bindAllNullable") + public fun Map.bindAll(): Map = + mapValues { (_, v) -> v.bind() } + + @JvmName("bindAllOption") + public fun Map>.bindAll(): Map = + mapValues { (_, v) -> v.bind() } @RaiseDSL - public fun Option.bind(): A = getOrElse { raise(null) } + @JvmName("bindAllNullable") + public fun Iterable.bindAll(): List = + map { it.bind() } @RaiseDSL - public fun A?.bind(): A { - contract { returns() implies (this@bind != null) } - return this ?: raise(null) - } + @JvmName("bindAllOption") + public fun Iterable>.bindAll(): List = + map { it.bind() } + @RaiseDSL @JvmName("bindAllNullable") - public fun Map.bindAll(): Map = - mapValues { (_, v) -> v.bind() } + public fun NonEmptyList.bindAll(): NonEmptyList = + map { it.bind() } @RaiseDSL - @JvmName("bindAllNullable") - public fun Iterable.bindAll(): List = + @JvmName("bindAllOption") + public fun NonEmptyList>.bindAll(): NonEmptyList = map { it.bind() } @RaiseDSL - public fun ensureNotNull(value: A?): A { - contract { returns() implies (value != null) } - return ensureNotNull(value) { null } - } + @JvmName("bindAllNullable") + public fun NonEmptySet.bindAll(): NonEmptySet = + map { it.bind() }.toNonEmptySet() + + @RaiseDSL + @JvmName("bindAllOption") + public fun NonEmptySet>.bindAll(): NonEmptySet = + map { it.bind() }.toNonEmptySet() @RaiseDSL public inline fun recover( - @BuilderInference block: NullableRaise.() -> A, + block: SingletonRaise.() -> A, recover: () -> A, ): A { contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) callsInPlace(recover, InvocationKind.AT_MOST_ONCE) } - return when (val nullable = nullable(block)) { - null -> recover() - else -> nullable - } + return singleton(recover) { ignoreErrors(block) } } /** @@ -215,10 +244,13 @@ public class NullableRaise(private val raise: Raise) : Raise by rais */ @RaiseDSL public inline fun ignoreErrors( - @BuilderInference block: IgnoreErrorsRaise.() -> A, + block: SingletonRaise.() -> A, ): A { contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } - return block(IgnoreErrorsRaise(this) { null }) + // This is safe because SingletonRaise never leaks the e from `raise(e: E)`, instead always calling `raise()`. + // and hence the type parameter of SingletonRaise merely states what errors it accepts and ignores. + @Suppress("UNCHECKED_CAST") + return block(this as SingletonRaise) } } @@ -259,72 +291,6 @@ public class ResultRaise(private val raise: Raise) : Raise ) } -/** - * Implementation of [Raise] used by [option]. - * You should never use this directly. - */ -public class OptionRaise(private val raise: Raise) : Raise by raise { - @RaiseDSL - public fun Option.bind(): A = getOrElse { raise(None) } - - @JvmName("bindAllOption") - public fun Map>.bindAll(): Map = - mapValues { (_, v) -> v.bind() } - - @RaiseDSL - @JvmName("bindAllOption") - public fun Iterable>.bindAll(): List = - map { it.bind() } - - @RaiseDSL - @JvmName("bindAllOption") - public fun NonEmptyList>.bindAll(): NonEmptyList = - map { it.bind() } - - @RaiseDSL - @JvmName("bindAllOption") - public fun NonEmptySet>.bindAll(): NonEmptySet = - map { it.bind() }.toNonEmptySet() - - @RaiseDSL - public fun ensure(value: Boolean): Unit = ensure(value) { None } - - @RaiseDSL - public fun ensureNotNull(value: A?): A { - contract { returns() implies (value != null) } - return ensureNotNull(value) { None } - } - - @RaiseDSL - public inline fun recover( - @BuilderInference block: OptionRaise.() -> A, - recover: () -> A, - ): A { - contract { - callsInPlace(block, InvocationKind.AT_MOST_ONCE) - callsInPlace(recover, InvocationKind.AT_MOST_ONCE) - } - return when (val option = option(block)) { - is None -> recover() - is Some -> option.value - } - } - - /** - * Introduces a scope where you can [bind] errors of any type, - * but no information is saved in the [raise] case. - */ - @RaiseDSL - public inline fun ignoreErrors( - @BuilderInference block: IgnoreErrorsRaise.() -> A, - ): A { - contract { - callsInPlace(block, InvocationKind.AT_MOST_ONCE) - } - return block(IgnoreErrorsRaise(this) { None }) - } -} - /** * Implementation of [Raise] used by [ior]. * You should never use this directly. diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt index aa01e7663d8..429d2ddd12d 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt @@ -14,7 +14,6 @@ import arrow.core.recover import kotlin.coroutines.cancellation.CancellationException import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind.AT_MOST_ONCE -import kotlin.contracts.InvocationKind.EXACTLY_ONCE import kotlin.contracts.contract import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt index 213d4eacca1..51469c4ea9f 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt @@ -2,6 +2,7 @@ package arrow.core.raise import arrow.core.Either import arrow.core.Some +import arrow.core.test.any import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe @@ -13,6 +14,7 @@ import io.kotest.property.checkAll import kotlin.test.Test import kotlinx.coroutines.test.runTest +@Suppress("IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION") class NullableSpec { @Test fun ensureNullInNullableComputation() = runTest { checkAll(Arb.boolean(), Arb.int()) { predicate, i -> @@ -87,6 +89,25 @@ class NullableSpec { } shouldBe "1" } + @Test fun raisingInIgnoreErrorsReturnsNone() = runTest { + checkAll(Arb.any()) { a -> + nullable { + ignoreErrors { raise(a) } + } shouldBe null + } + } + + @Test fun ignoreErrorsAcceptsCallableReferences() = runTest { + fun Raise.foo(): Int = raise(42) + val bar: Raise.() -> Unit = { raise("s") } + nullable { + ignoreErrors(Raise::foo) + } shouldBe null + nullable { + ignoreErrors(bar) + } shouldBe null + } + @Test fun shortCircuitOption() = runTest { nullable { val number = Some("s".length) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt index 3cd9d552dee..f7718213a8e 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/OptionSpec.kt @@ -1,9 +1,7 @@ package arrow.core.raise -import arrow.core.None -import arrow.core.Some -import arrow.core.some -import arrow.core.toOption +import arrow.core.* +import arrow.core.test.any import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean @@ -13,6 +11,7 @@ import io.kotest.property.checkAll import kotlin.test.Test import kotlinx.coroutines.test.runTest +@Suppress("IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION") class OptionSpec { @Test fun ensure() = runTest { @@ -35,13 +34,20 @@ class OptionSpec { } @Test fun shortCircuitOption() = runTest { - @Suppress("UNREACHABLE_CODE") option { ensureNotNull(null) throw IllegalStateException("This should not be executed") } shouldBe None } + @Test fun raisingInIgnoreErrorsReturnsNone() = runTest { + checkAll(Arb.any()) { a -> + option { + ignoreErrors { raise(a) } + } shouldBe None + } + } + @Test fun RecoverWorksAsExpected() = runTest { option { val one: Int = recover({ None.bind() }) { 1 } diff --git a/arrow-libs/core/arrow-eval/api/arrow-eval.api b/arrow-libs/core/arrow-eval/api/arrow-eval.api index 7015bbad624..588bf738e18 100644 --- a/arrow-libs/core/arrow-eval/api/arrow-eval.api +++ b/arrow-libs/core/arrow-eval/api/arrow-eval.api @@ -90,7 +90,6 @@ public final class arrow/eval/Eval$Now$Companion { public final class arrow/eval/EvalKt { public static final fun iterateRight (Ljava/util/Iterator;Larrow/eval/Eval;Lkotlin/jvm/functions/Function2;)Larrow/eval/Eval; public static final fun replicate (Larrow/eval/Eval;I)Larrow/eval/Eval; - public static final fun replicate (Larrow/eval/Eval;ILarrow/typeclasses/Monoid;)Larrow/eval/Eval; public static final fun replicate (Larrow/eval/Eval;ILkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Larrow/eval/Eval; public static final fun zip (Larrow/eval/Eval;Larrow/eval/Eval;)Larrow/eval/Eval; public static final fun zip (Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Larrow/eval/Eval;Lkotlin/jvm/functions/Function10;)Larrow/eval/Eval; From 071d4301c5799869888ecce9203f8601b538fc66 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Tue, 6 Feb 2024 20:19:51 +0100 Subject: [PATCH 107/114] Remove (unused) tests for high-arity module --- arrow-libs/core/arrow-core-high-arity/build.gradle.kts | 6 ------ .../src/commonTest/kotlin/arrow/core/MemoizationTest.kt | 3 --- .../src/commonTest/kotlin/arrow/core/OptionTest.kt | 5 ----- .../src/commonTest/kotlin/arrow/core/TupleTest.kt | 6 ------ 4 files changed, 20 deletions(-) delete mode 100644 arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/MemoizationTest.kt delete mode 100755 arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/OptionTest.kt delete mode 100644 arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/TupleTest.kt diff --git a/arrow-libs/core/arrow-core-high-arity/build.gradle.kts b/arrow-libs/core/arrow-core-high-arity/build.gradle.kts index 583e861af5d..f074a6c5b2d 100644 --- a/arrow-libs/core/arrow-core-high-arity/build.gradle.kts +++ b/arrow-libs/core/arrow-core-high-arity/build.gradle.kts @@ -26,12 +26,6 @@ kotlin { api(libs.kotlin.stdlib) } } - - commonTest { - dependencies { - implementation(libs.kotlin.test) - } - } } jvm { diff --git a/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/MemoizationTest.kt b/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/MemoizationTest.kt deleted file mode 100644 index 5dc5ce2cbf3..00000000000 --- a/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/MemoizationTest.kt +++ /dev/null @@ -1,3 +0,0 @@ -package arrow.core - -private fun consecSumResult(n: Int): Int = (n * (n + 1)) / 2 diff --git a/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/OptionTest.kt deleted file mode 100755 index abdb08c5884..00000000000 --- a/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ /dev/null @@ -1,5 +0,0 @@ -package arrow.core - -// Utils - -private fun iterableOf(vararg elements: T): Iterable = Iterable { iterator { yieldAll(elements.toList()) } } diff --git a/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/TupleTest.kt b/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/TupleTest.kt deleted file mode 100644 index 466e1314e96..00000000000 --- a/arrow-libs/core/arrow-core-high-arity/src/commonTest/kotlin/arrow/core/TupleTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package arrow.core - -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int - -private fun Arb.Companion.intOpenEnded() = Arb.int(Int.MIN_VALUE + 1, Int.MAX_VALUE - 1) From af86f9fb0550d0eae2ce3bb555a07bcfac1c5b79 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Tue, 6 Feb 2024 21:55:39 +0100 Subject: [PATCH 108/114] Fix tests + Knit --- .../commonMain/kotlin/arrow/core/Either.kt | 6 +++--- .../commonMain/kotlin/arrow/core/Option.kt | 4 ++-- .../commonMain/kotlin/arrow/core/Sequence.kt | 2 +- .../commonTest/kotlin/arrow/core/IorTest.kt | 7 ------- .../kotlin/arrow/core/OptionTest.kt | 7 ------- .../kotlin/examples/example-either-34.kt | 15 +++++++------ .../kotlin/examples/example-either-35.kt | 4 ++-- .../kotlin/examples/example-either-36.kt | 17 +++++++++++---- .../kotlin/examples/example-either-37.kt | 21 ------------------- .../jvmTest/kotlin/examples/example-ior-12.kt | 13 ------------ .../kotlin/examples/example-option-20.kt | 11 ++++++++++ .../kotlin/examples/example-option-21.kt | 7 +++++-- .../kotlin/examples/example-option-22.kt | 17 --------------- .../kotlin/examples/example-sequence-16.kt | 14 +++++++++---- .../kotlin/examples/example-sequence-17.kt | 15 ------------- .../kotlin/examples/test/EitherKnitTest.kt | 8 +++---- .../kotlin/examples/test/OptionKnitTest.kt | 8 +++---- .../kotlin/examples/test/SequenceKnitTest.kt | 4 ++-- 18 files changed, 64 insertions(+), 116 deletions(-) delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt delete mode 100644 arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 83d19bde550..0f435f523b2 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -1397,7 +1397,7 @@ public fun E.leftNel(): EitherNel = * fallback shouldBe Either.Right(5) * } * ``` - * + * * * * When shifting a new error [EE] into the [Either.Left] channel, @@ -1414,7 +1414,7 @@ public fun E.leftNel(): EitherNel = * listOfErrors shouldBe Either.Left(listOf('e', 'r', 'r', 'o', 'r')) * } * ``` - * + * * */ @OptIn(ExperimentalTypeInference::class) @@ -1451,7 +1451,7 @@ public inline fun Either.recover(@BuilderInference recover: Rai * failure shouldBe Either.Left("failure") * } * ``` - * + * * */ @OptIn(ExperimentalTypeInference::class) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt index 978a5af8f3f..d445d134165 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt @@ -624,7 +624,7 @@ public operator fun > Option.compareTo(other: Option): I * fallback shouldBe Some(5) * } * ``` - * + * * * * When shifting a new error [None] into the [Option]: @@ -645,7 +645,7 @@ public operator fun > Option.compareTo(other: Option): I * error.recover { failure().bind() } shouldBe none() * } * ``` - * + * * */ public inline fun Option.recover(recover: SingletonRaise.() -> A): Option = diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt index 1f14d216da6..dcb096161d3 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Sequence.kt @@ -747,7 +747,7 @@ public fun Sequence.unzip(fc: (C) -> Pair): Pair, * .toList() shouldBe listOf(0, 2, 4, 6, 8) * } * ``` - * + * * */ public fun Sequence>.filterOption(): Sequence = diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt index 3452062bb3f..502dbe63c2c 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IorTest.kt @@ -206,13 +206,6 @@ class IorTest { } } - @Test fun widenOk() = runTest { - checkAll(Arb.int(), Arb.string()) { a, b -> - val ior = Ior.Both(a, b) - ior.widen().shouldBeInstanceOf>() - } - } - @Test fun compareToOk() = runTest { val left1 = Ior.Left(1) val left2 = Ior.Left(2) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt index eb446936303..16e7e3f4fc3 100755 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt @@ -314,13 +314,6 @@ class OptionTest { } } - @Test fun widen() = runTest { - checkAll(Arb.string()) { a: String -> - val widen: Option = Option(a).widen() - widen.map { it.length } shouldBe Some(a.length) - } - } - @Test fun compareToWithSomeValues() = runTest { checkAll(Arb.int(), Arb.int()) { a: Int, b: Int -> val opA = Option(a) diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt index 1bacd88ffa1..e103fb5e04e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-34.kt @@ -1,13 +1,12 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither34 -import arrow.core.* +import arrow.core.Either +import arrow.core.recover +import io.kotest.matchers.shouldBe -fun main(args: Array) { - //sampleStart - val string: Either = "Hello".right() - val chars: Either = - string.widen() - //sampleEnd - println(chars) +fun test() { + val error: Either = Either.Left("error") + val fallback: Either = error.recover { it.length } + fallback shouldBe Either.Right(5) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt index 3703db7da68..25a2d584171 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-35.kt @@ -7,6 +7,6 @@ import io.kotest.matchers.shouldBe fun test() { val error: Either = Either.Left("error") - val fallback: Either = error.recover { it.length } - fallback shouldBe Either.Right(5) + val listOfErrors: Either, Int> = error.recover { raise(it.toList()) } + listOfErrors shouldBe Either.Left(listOf('e', 'r', 'r', 'o', 'r')) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt index 026cd08d0f9..c20356b7aa8 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-36.kt @@ -2,11 +2,20 @@ package arrow.core.examples.exampleEither36 import arrow.core.Either -import arrow.core.recover +import arrow.core.catch +import io.kotest.assertions.throwables.shouldThrowUnit import io.kotest.matchers.shouldBe fun test() { - val error: Either = Either.Left("error") - val listOfErrors: Either, Int> = error.recover { raise(it.toList()) } - listOfErrors shouldBe Either.Left(listOf('e', 'r', 'r', 'o', 'r')) + val left: Either = Either.catch { throw RuntimeException("Boom!") } + + val caught: Either = left.catch { _: RuntimeException -> 1 } + val failure: Either = left.catch { _: RuntimeException -> raise("failure") } + + shouldThrowUnit { + val caught2: Either = left.catch { _: IllegalStateException -> 1 } + } + + caught shouldBe Either.Right(1) + failure shouldBe Either.Left("failure") } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt deleted file mode 100644 index b2d8cbf42ca..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-37.kt +++ /dev/null @@ -1,21 +0,0 @@ -// This file was automatically generated from Either.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleEither37 - -import arrow.core.Either -import arrow.core.catch -import io.kotest.assertions.throwables.shouldThrowUnit -import io.kotest.matchers.shouldBe - -fun test() { - val left: Either = Either.catch { throw RuntimeException("Boom!") } - - val caught: Either = left.catch { _: RuntimeException -> 1 } - val failure: Either = left.catch { _: RuntimeException -> raise("failure") } - - shouldThrowUnit { - val caught2: Either = left.catch { _: IllegalStateException -> 1 } - } - - caught shouldBe Either.Right(1) - failure shouldBe Either.Left("failure") -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt deleted file mode 100644 index 8bd57d483da..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-ior-12.kt +++ /dev/null @@ -1,13 +0,0 @@ -// This file was automatically generated from Ior.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleIor12 - -import arrow.core.* - -fun main(args: Array) { - //sampleStart - val string: Ior = Ior.Right("Hello") - val chars: Ior = - string.widen() - //sampleEnd - println(chars) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt index 861cfe12561..8e11226743e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-20.kt @@ -1,3 +1,14 @@ // This file was automatically generated from Option.kt by Knit tool. Do not edit. package arrow.core.examples.exampleOption20 +import arrow.core.Option +import arrow.core.none +import arrow.core.Some +import arrow.core.recover +import io.kotest.matchers.shouldBe + +fun test() { + val error: Option = none() + val fallback: Option = error.recover { 5 } + fallback shouldBe Some(5) +} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt index 29e610af12b..a4e6dae74d9 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-21.kt @@ -9,6 +9,9 @@ import io.kotest.matchers.shouldBe fun test() { val error: Option = none() - val fallback: Option = error.recover { 5 } - fallback shouldBe Some(5) + fun fallback(): Option = Some(5) + fun failure(): Option = none() + + error.recover { fallback().bind() } shouldBe Some(5) + error.recover { failure().bind() } shouldBe none() } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt deleted file mode 100644 index da330d95bd4..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-option-22.kt +++ /dev/null @@ -1,17 +0,0 @@ -// This file was automatically generated from Option.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleOption22 - -import arrow.core.Option -import arrow.core.none -import arrow.core.Some -import arrow.core.recover -import io.kotest.matchers.shouldBe - -fun test() { - val error: Option = none() - fun fallback(): Option = Some(5) - fun failure(): Option = none() - - error.recover { fallback().bind() } shouldBe Some(5) - error.recover { failure().bind() } shouldBe none() -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt index 8eed0fd16b7..bef9a73013e 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-16.kt @@ -1,9 +1,15 @@ // This file was automatically generated from Sequence.kt by Knit tool. Do not edit. package arrow.core.examples.exampleSequence16 -import arrow.core.widen +import arrow.core.None +import arrow.core.Some +import arrow.core.filterOption +import io.kotest.matchers.shouldBe -fun main() { - val original: Sequence = sequenceOf("Hello World") - val result: Sequence = original.widen() +fun test() { +generateSequence(0) { it + 1 } + .map { if (it % 2 == 0) Some(it) else None } + .filterOption() + .take(5) + .toList() shouldBe listOf(0, 2, 4, 6, 8) } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt deleted file mode 100644 index dfb3ab6b47b..00000000000 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-sequence-17.kt +++ /dev/null @@ -1,15 +0,0 @@ -// This file was automatically generated from Sequence.kt by Knit tool. Do not edit. -package arrow.core.examples.exampleSequence17 - -import arrow.core.None -import arrow.core.Some -import arrow.core.filterOption -import io.kotest.matchers.shouldBe - -fun test() { -generateSequence(0) { it + 1 } - .map { if (it % 2 == 0) Some(it) else None } - .filterOption() - .take(5) - .toList() shouldBe listOf(0, 2, 4, 6, 8) -} diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt index 5b340762099..e8d56994cfe 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/EitherKnitTest.kt @@ -53,6 +53,10 @@ class EitherKnitTest { arrow.core.examples.exampleEither33.test() } + @Test fun exampleEither34() = runTest { + arrow.core.examples.exampleEither34.test() + } + @Test fun exampleEither35() = runTest { arrow.core.examples.exampleEither35.test() } @@ -61,8 +65,4 @@ class EitherKnitTest { arrow.core.examples.exampleEither36.test() } - @Test fun exampleEither37() = runTest { - arrow.core.examples.exampleEither37.test() - } - } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt index 88e12b46299..7c575f41326 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/OptionKnitTest.kt @@ -5,12 +5,12 @@ import kotlin.test.Test import kotlinx.coroutines.test.runTest class OptionKnitTest { - @Test fun exampleOption21() = runTest { - arrow.core.examples.exampleOption21.test() + @Test fun exampleOption20() = runTest { + arrow.core.examples.exampleOption20.test() } - @Test fun exampleOption22() = runTest { - arrow.core.examples.exampleOption22.test() + @Test fun exampleOption21() = runTest { + arrow.core.examples.exampleOption21.test() } } diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt index 0aaa302b213..58b5ceedf85 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/test/SequenceKnitTest.kt @@ -21,8 +21,8 @@ class SequenceKnitTest { arrow.core.examples.exampleSequence10.test() } - @Test fun exampleSequence17() = runTest { - arrow.core.examples.exampleSequence17.test() + @Test fun exampleSequence16() = runTest { + arrow.core.examples.exampleSequence16.test() } } From 680ecf04d5d24797fde6f6d9ebe63797dab1a969 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Sun, 14 Apr 2024 14:35:29 +0200 Subject: [PATCH 109/114] Fix merge NullableSpec --- .../src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt index b2a61486799..433ddd713ca 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/NullableSpec.kt @@ -3,8 +3,6 @@ package arrow.core.raise import arrow.core.Either import arrow.core.Some import arrow.core.test.any -import io.kotest.assertions.throwables.shouldThrow -import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean @@ -165,4 +163,4 @@ class NullableSpec { one + two } shouldBe 3 } -}) +} From d5b188ca702a783d3ad9a607c519c949e54e4f39 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Sun, 14 Apr 2024 18:04:04 +0200 Subject: [PATCH 110/114] Regression in Arb.list? --- .../src/commonTest/kotlin/arrow/core/test/Generators.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index 3c947fe22b5..3885baf1f0f 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -7,6 +7,7 @@ import io.kotest.property.arbitrary.bind import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.choice import io.kotest.property.arbitrary.constant +import io.kotest.property.arbitrary.filter import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.set @@ -29,7 +30,9 @@ import kotlin.coroutines.startCoroutine // copied from kotest-extensions-arrow fun Arb.Companion.nonEmptyList(arb: Arb, range: IntRange = 0 .. 100): Arb> = - Arb.list(arb, max(range.first, 1) .. range.last).map { NonEmptyList(it) } + Arb.list(arb, max(range.first, 1) .. range.last) + .filter { it.isNotEmpty() } + .map { NonEmptyList(it) } fun Arb.Companion.nonEmptySet(arb: Arb, range: IntRange = 0 .. 100): Arb> = Arb.set(arb, max(range.first, 1) .. range.last).map { it.toNonEmptySetOrNull()!! } From 8d1779513c3221d81b7addbbb4aa9c73b6679ab2 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 17 Apr 2024 11:40:19 +0200 Subject: [PATCH 111/114] Fix test for nonEmptyList --- .../src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index 5c68a672267..b031c930bc5 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -50,8 +50,12 @@ class NonEmptyListTest { @Test fun iterableToNonEmptyListOrNullShouldWorkCorrectlyWhenTheIterableStartsWithOrContainsNull() = runTest { - checkAll(Arb.nonEmptyList(Arb.int().orNull())) { nonEmptyList -> - nonEmptyList.all.toNonEmptyListOrNull().shouldNotBeNull() shouldBe nonEmptyList + checkAll(Arb.list(Arb.int())) { list -> + checkAll(Arb.int(min = 0, max = list.size)) { ix -> + val mutableList: MutableList = list.toMutableList() + mutableList.add(ix, null) + mutableList.toNonEmptyListOrNull().shouldNotBeNull() shouldBe mutableList + } } } From 32322076d56c5b2d1c8f354d9f453d7cbad1ed6f Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 17 Apr 2024 11:43:34 +0200 Subject: [PATCH 112/114] Develocity warning --- settings.gradle.kts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 05065747ba0..e39b26e16d4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id("com.gradle.enterprise") version "3.17.1" + id("com.gradle.develocity") version "3.17.1" id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") } @@ -114,9 +114,9 @@ project(":arrow-optics-ksp-plugin").projectDir = file("arrow-libs/optics/arrow-o include("arrow-stack") project(":arrow-stack").projectDir = file("arrow-libs/stack") -gradleEnterprise { +develocity { buildScan { - termsOfServiceUrl = "https://gradle.com/terms-of-service" - termsOfServiceAgree = "yes" + termsOfUseUrl = "https://gradle.com/terms-of-service" + termsOfUseAgree = "yes" } } From 14ebd4282ba9fe42fab17c107838b244c6ac58a4 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 17 Apr 2024 20:48:33 +0200 Subject: [PATCH 113/114] Fix merge problem with optics-ksp-plugin --- .../kotlin/arrow/optics/plugin/internals/processor.kt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index a04992d8a7c..0426ef26475 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -155,15 +155,6 @@ internal fun evalAnnotatedDataClass( } } -fun KSPropertyDeclaration.sameInChildren(subclasses: Sequence): Boolean = - subclasses.all { subclass -> - val property = subclass.getAllProperties().singleOrNull { it.simpleName == this.simpleName } - when (property) { - null -> false - else -> property.type.resolve() == this.type.resolve() - } - } - fun KSPropertyDeclaration.sameInChildren(subclasses: Sequence): Boolean = subclasses.all { subclass -> val property = subclass.getAllProperties().singleOrNull { it.simpleName == this.simpleName } From 5ba0e45be2cb04c2001a57aacf25925f3b178f68 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 17 Apr 2024 21:11:28 +0200 Subject: [PATCH 114/114] Fix timeout in test --- .../src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index b031c930bc5..29023d96cab 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -51,7 +51,7 @@ class NonEmptyListTest { @Test fun iterableToNonEmptyListOrNullShouldWorkCorrectlyWhenTheIterableStartsWithOrContainsNull() = runTest { checkAll(Arb.list(Arb.int())) { list -> - checkAll(Arb.int(min = 0, max = list.size)) { ix -> + checkAll(iterations = 5, Arb.int(min = 0, max = list.size)) { ix -> val mutableList: MutableList = list.toMutableList() mutableList.add(ix, null) mutableList.toNonEmptyListOrNull().shouldNotBeNull() shouldBe mutableList