Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Arrow Fx DSL #3443

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions arrow-libs/core/arrow-autoclose/api/arrow-scope.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
public abstract interface class arrow/AutoCloseScope {
public abstract fun autoClose (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public abstract fun autoClose (Lkotlin/jvm/functions/Function1;)V
public abstract fun install (Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/AutoCloseScope$DefaultImpls {
public static fun autoClose (Larrow/AutoCloseScope;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public static fun install (Larrow/AutoCloseScope;Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/AutoCloseScopeKt {
public static final fun autoCloseScope (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
}

public final class arrow/AutoCloseableExtensionsKt {
public static final fun install (Larrow/AutoCloseScope;Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/CoroutineScopeKt {
public static final fun coroutineScope (Larrow/Scope;Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class arrow/DefaultAutoCloseScope : arrow/AutoCloseScope {
public fun <init> ()V
public fun autoClose (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public fun autoClose (Lkotlin/jvm/functions/Function1;)V
public final fun close (Ljava/lang/Throwable;)Ljava/lang/Void;
public fun install (Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/SagaKt {
public static final fun saga (Larrow/Scope;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract interface class arrow/Scope : arrow/AutoCloseScope {
public abstract fun autoClose (Lkotlin/jvm/functions/Function1;)V
public abstract fun finalise (Lkotlin/jvm/functions/Function2;)V
}

public final class arrow/Scope$DefaultImpls {
public static fun autoClose (Larrow/Scope;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public static fun install (Larrow/Scope;Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/ScopeKt {
public static final fun scoped (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class arrow/ThrowIfFatalKt {
public static final fun throwIfFatal (Ljava/lang/Throwable;)Ljava/lang/Throwable;
}

27 changes: 27 additions & 0 deletions arrow-libs/core/arrow-autoclose/api/arrow-scope.klib.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Klib ABI Dump
// Targets: [iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosSimulatorArm64, watchosX64]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
// - Show declarations: true

// Library unique name: <io.arrow-kt:arrow-scope>
abstract interface arrow/AutoCloseScope { // arrow/AutoCloseScope|null[0]
abstract fun autoClose(kotlin/Function1<kotlin/Throwable?, kotlin/Unit>) // arrow/AutoCloseScope.autoClose|autoClose(kotlin.Function1<kotlin.Throwable?,kotlin.Unit>){}[0]
open fun <#A1: kotlin/Any?> autoClose(kotlin/Function0<#A1>, kotlin/Function2<#A1, kotlin/Throwable?, kotlin/Unit>): #A1 // arrow/AutoCloseScope.autoClose|autoClose(kotlin.Function0<0:0>;kotlin.Function2<0:0,kotlin.Throwable?,kotlin.Unit>){0§<kotlin.Any?>}[0]
open fun <#A1: kotlin/AutoCloseable> install(#A1): #A1 // arrow/AutoCloseScope.install|install(0:0){0§<kotlin.AutoCloseable>}[0]
}
abstract interface arrow/Scope : arrow/AutoCloseScope { // arrow/Scope|null[0]
abstract fun autoClose(kotlin/Function1<kotlin/Throwable?, kotlin/Unit>) // arrow/Scope.autoClose|autoClose(kotlin.Function1<kotlin.Throwable?,kotlin.Unit>){}[0]
abstract fun finalise(kotlin.coroutines/SuspendFunction1<kotlin/Throwable?, kotlin/Unit>) // arrow/Scope.finalise|finalise(kotlin.coroutines.SuspendFunction1<kotlin.Throwable?,kotlin.Unit>){}[0]
}
final class arrow/DefaultAutoCloseScope : arrow/AutoCloseScope { // arrow/DefaultAutoCloseScope|null[0]
constructor <init>() // arrow/DefaultAutoCloseScope.<init>|<init>(){}[0]
final fun autoClose(kotlin/Function1<kotlin/Throwable?, kotlin/Unit>) // arrow/DefaultAutoCloseScope.autoClose|autoClose(kotlin.Function1<kotlin.Throwable?,kotlin.Unit>){}[0]
final fun close(kotlin/Throwable?): kotlin/Nothing? // arrow/DefaultAutoCloseScope.close|close(kotlin.Throwable?){}[0]
}
final fun (kotlin/Throwable).arrow/throwIfFatal(): kotlin/Throwable // arrow/throwIfFatal|[email protected](){}[0]
final inline fun <#A: kotlin/Any?> arrow/autoCloseScope(kotlin/Function1<arrow/AutoCloseScope, #A>): #A // arrow/autoCloseScope|autoCloseScope(kotlin.Function1<arrow.AutoCloseScope,0:0>){0§<kotlin.Any?>}[0]
final suspend fun (arrow/Scope).arrow/coroutineScope(kotlin.coroutines/CoroutineContext): kotlinx.coroutines/CoroutineScope // arrow/coroutineScope|[email protected](kotlin.coroutines.CoroutineContext){}[0]
final suspend fun <#A: kotlin/Any?> (arrow/Scope).arrow/saga(kotlin.coroutines/SuspendFunction0<#A>, kotlin.coroutines/SuspendFunction2<#A, kotlin/Throwable?, kotlin/Unit>): #A // arrow/saga|[email protected](kotlin.coroutines.SuspendFunction0<0:0>;kotlin.coroutines.SuspendFunction2<0:0,kotlin.Throwable?,kotlin.Unit>){0§<kotlin.Any?>}[0]
final suspend fun <#A: kotlin/Any?> arrow/scoped(kotlin/Function1<arrow/Scope, #A>): #A // arrow/scoped|scoped(kotlin.Function1<arrow.Scope,0:0>){0§<kotlin.Any?>}[0]
1 change: 0 additions & 1 deletion arrow-libs/core/arrow-autoclose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ kotlin {
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(projects.arrowAtomic)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ import kotlin.coroutines.cancellation.CancellationException
* ```
* <!--- KNIT example-autocloseable-02.kt -->
*/
public interface AutoCloseScope {
public fun autoClose(close: (Throwable?) -> Unit): Unit

public fun <A> autoClose(
acquire: () -> A,
release: (A, Throwable?) -> Unit
): A =
acquire().also { a -> autoClose { e -> release(a, e) } }

@ExperimentalStdlibApi
public fun <A : AutoCloseable> install(autoCloseable: A): A =
autoClose({ autoCloseable }) { a, _ -> a.close() }
}

public inline fun <A> autoCloseScope(block: AutoCloseScope.() -> A): A {
val scope = DefaultAutoCloseScope()
return try {
Expand All @@ -73,29 +87,11 @@ public inline fun <A> autoCloseScope(block: AutoCloseScope.() -> A): A {
}
}

public interface AutoCloseScope {
public fun <A> autoClose(
acquire: () -> A,
release: (A, Throwable?) -> Unit
): A

@ExperimentalStdlibApi
public fun <A : AutoCloseable> install(autoCloseable: A): A =
autoClose({ autoCloseable }) { a, _ -> a.close() }
}

@PublishedApi
internal class DefaultAutoCloseScope : AutoCloseScope {
private val finalizers = Atomic(emptyList<(Throwable?) -> Unit>())

override fun <A> autoClose(acquire: () -> A, release: (A, Throwable?) -> Unit): A =
try {
acquire().also { a ->
finalizers.update { it + { e -> release(a, e) } }
}
} catch (e: Throwable) {
throw e
}
override fun autoClose(close: (Throwable?) -> Unit) =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd like onClose better to reflect onRelease from ResourceScope

finalizers.update { it + { e -> close(e) } }

fun close(error: Throwable?): Nothing? {
return finalizers.get().asReversed().fold(error) { acc, function ->
Expand Down
56 changes: 0 additions & 56 deletions arrow-libs/core/arrow-continuations/api/arrow-continuations.api

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion arrow-libs/core/arrow-core-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)

alias(libs.plugins.publish)
alias(libs.plugins.kotlinx.kover)
alias(libs.plugins.spotless)
id(libs.plugins.kotlinx.serialization.get().pluginId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public abstract interface class arrow/fx/coroutines/ResourceScope : arrow/AutoCl
}

public final class arrow/fx/coroutines/ResourceScope$DefaultImpls {
public static fun autoClose (Larrow/fx/coroutines/ResourceScope;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public static fun install (Larrow/fx/coroutines/ResourceScope;Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
public static fun onRelease (Larrow/fx/coroutines/ResourceScope;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun release (Larrow/fx/coroutines/ResourceScope;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
2 changes: 1 addition & 1 deletion arrow-libs/fx/arrow-fx-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kotlin {
commonMain {
dependencies {
api(projects.arrowCore)
api(projects.arrowAutoclose)
api(projects.arrowFxDsl)
api(libs.coroutines.core)
implementation(libs.kotlin.stdlib)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ private value class ResourceScopeImpl(
}
})

override fun autoClose(close: (Throwable?) -> Unit) =
autoClose({ }) { _, e -> close(e) }

override fun <A> autoClose(acquire: () -> A, release: (A, Throwable?) -> Unit): A =
acquire().also { a ->
val finalizer: suspend (ExitCase) -> Unit = { exitCase ->
Expand Down

This file was deleted.

28 changes: 28 additions & 0 deletions arrow-libs/fx/arrow-fx-dsl/api/arrow-autoclose.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public abstract interface class arrow/AutoCloseScope {
public abstract fun autoClose (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public abstract fun install (Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/AutoCloseScope$DefaultImpls {
public static fun install (Larrow/AutoCloseScope;Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/AutoCloseScopeKt {
public static final fun autoCloseScope (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
}

public final class arrow/AutoCloseableExtensionsKt {
public static final fun install (Larrow/AutoCloseScope;Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/DefaultAutoCloseScope : arrow/AutoCloseScope {
public fun <init> ()V
public fun autoClose (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public final fun close (Ljava/lang/Throwable;)Ljava/lang/Void;
public fun install (Ljava/lang/AutoCloseable;)Ljava/lang/AutoCloseable;
}

public final class arrow/ThrowIfFatalKt {
public static final fun throwIfFatal (Ljava/lang/Throwable;)Ljava/lang/Throwable;
}

Loading
Loading