Skip to content

Fx on typeclass#1435

Closed
nomisRev wants to merge 8 commits intomasterfrom
fx-on-typeclass
Closed

Fx on typeclass#1435
nomisRev wants to merge 8 commits intomasterfrom
fx-on-typeclass

Conversation

@nomisRev
Copy link
Member

@nomisRev nomisRev commented May 7, 2019

This PR will remove the current Fx hierarchy in favor from merging them in the current typeclass hierarchy.

[arrow.typeclasses.suspended.monad.Fx]
[arrow.typeclasses.suspended.monaderror.Fx]
[arrow.effects.typeclasses.suspended.monaddefer.Fx]
[arrow.effects.typeclasses.suspended.concurrent.Fx]

The corresponding fx will be available on the corresponding typeclasses and will be available in the following manner.

fun <F> Monad<F>.program(): Kind<F, Unit> = fx.monad { ... } 
fun <F> MonadThrow<F>.program(): Kind<F, Unit> = fx.monadThrow { ... } 
fun <F> Async<F>.program(): Kind<F, Unit> = fx.async { ... } 
fun <F> Concurrent<F>.program(): Kind<F, Unit> = fx.concurrent { ... } 

breaking changes

This PR will remove the currently deprecated binding, and it'll be replaced with fx as a typeclass method. Additionally bindingCancelable on MonadDefer will be removed, and binding on MonadDefer will be moved to Async.

}
}
else -> throw IllegalArgumentException("Required first 2 args as directory paths in this order: <required: source> <required: destination> <optional: classpath entries, one per arg..>")
fun main(vararg args: String) = unsafe {
Copy link
Member

Choose a reason for hiding this comment

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

IIRC Kotlin now supports suspend main.

Copy link
Member Author

Choose a reason for hiding this comment

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

Error: Could not find or load main class MainKt on Kotlin 1.3.31

Copy link
Member

Choose a reason for hiding this comment

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

Maybe not?

interface TryFx : arrow.typeclasses.suspended.monaderror.Fx<ForTry> {
override fun monadError(): MonadThrow<ForTry> = Try.monadThrow()
}
fun <A> Try.Companion.fx(c: suspend MonadContinuation<ForTry, *>.() -> A): Try<A> =
Copy link
Member

Choose a reason for hiding this comment

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

Cache the monad instance I'd say.

override fun monad(): Monad<ForOption> = Option.monad()
}
fun <A> Option.Companion.fx(c: suspend MonadContinuation<ForOption, *>.() -> A): Option<A> =
Option.monad().fx.monad(c).fix()
Copy link
Member

Choose a reason for hiding this comment

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

Cache the monad instance I'd say.

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
open class MonadDeferCancellableContinuation<F, A>(val SC: MonadDefer<F>, override val context: CoroutineContext = EmptyCoroutineContext) :
MonadErrorContinuation<F, A>(SC), MonadDefer<F> by SC, BindSyntax<F> {
open class AsyncContinuation<F, A>(val SC: Async<F>, override val context: CoroutineContext = EmptyCoroutineContext) :
Copy link
Member

@pakoito pakoito May 7, 2019

Choose a reason for hiding this comment

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

For another diff we should interface this, instead of passing the full class have a new interface that composes Async<F> by SC, BindSyntax<F> or whatever.

fun <A> async(c: suspend AsyncFxEnvironment<F>.() -> A): Kind<F, A>

@pakoito pakoito mentioned this pull request May 9, 2019
12 tasks
logW("Failed to generate kdoc file location: $kDocLocation", e)
}
} catch (e: Exception) {
logE(e.localizedMessage)
Copy link
Member

Choose a reason for hiding this comment

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

....can't we use Arrow for this?

Copy link
Member

Choose a reason for hiding this comment

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

No Arrow on the processors because the processors are used to build Arrow and we never figured out the shadow biz.

@nomisRev nomisRev mentioned this pull request May 19, 2019
@nomisRev
Copy link
Member Author

@pakoito I am closing this PR in favor of rr-bind-strategies, @raulraja went the extra mile for us and cached the instances in the generated code.

New generated code in rr-bind-strategies

@PublishedApi()
internal val monad_singleton: EvalMonad = object : arrow.core.extensions.EvalMonad {}
inline fun Companion.monad(): EvalMonad = monad_singleton

@nomisRev nomisRev closed this May 28, 2019
@nomisRev nomisRev deleted the fx-on-typeclass branch December 25, 2019 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants