-
Notifications
You must be signed in to change notification settings - Fork 450
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
Remove dependency on kotlinx.coroutines for effects #250
Conversation
…s. Add deriving for instances.
Codecov Report
@@ Coverage Diff @@
## master #250 +/- ##
=========================================
Coverage ? 45.07%
Complexity ? 318
=========================================
Files ? 148
Lines ? 3723
Branches ? 402
=========================================
Hits ? 1678
Misses ? 1924
Partials ? 121
Continue to review full report at Codecov.
|
typealias DeferredResult<A> = Either<Throwable, A> | ||
|
||
@higherkind | ||
@deriving(Monad::class, AsyncContext::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
@deriving(Functor::class, Applicative::class, Monad::class, AsyncContext::class)
fun <A, B> tailRecM(a: A, f: (A) -> DeferredKWKind<Either<A, B>>): DeferredKW<B> { | ||
tailrec fun go(coroutineContext: CoroutineContext, a: A, f: (A) -> DeferredKWKind<Either<A, B>>): DeferredKW<B> { | ||
val result: DeferredResult<Either<A, B>> = f(a).attempt(coroutineContext) | ||
/* FIXME(paco): KT-20075 If you remove return here tailrec stops working. Jetbrains Please. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense because otherwise you would not know what the stop condition in the translated loop would be. what it would be good to have by default in Kotlin is to have the last statement ina block always be the return value. Explicit returns suck.
|
||
fun <B> flatMap(f: (A) -> DeferredKWKind<B>): DeferredKW<B> = | ||
DeferredKW { context: CoroutineContext -> | ||
this@DeferredKW.attempt(context).fold( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think flatMap
with attempt
defeats the purpose of having this datatype. I recall reimplementing this in an fully async way. But if we cause to block what good does deffer provides over async/await
?
|
||
@higherkind | ||
@deriving(Monad::class, AsyncContext::class) | ||
data class DeferredKW<out A>(val thunk: (CoroutineContext) -> Deferred<A>) : DeferredKWKind<A> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just not consider this until we have a non-blocking solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to go if we get rid of DeferredKW
until we find a better way to implement it. 👏
# Conflicts: # kategory-core/src/test/kotlin/kategory/data/EitherTest.kt # kategory-core/src/test/kotlin/kategory/data/Function1Test.kt # kategory-core/src/test/kotlin/kategory/data/OptionTTest.kt # kategory-core/src/test/kotlin/kategory/data/OptionTest.kt # kategory-core/src/test/kotlin/kategory/free/CoYonedaTest.kt # kategory-effects/build.gradle # kategory-effects/src/main/kotlin/kategory/effects/data/IO.kt # kategory-effects/src/test/kotlin/kategory/effects/data/IOTest.kt # kategory/build.gradle # kategory/src/test/kotlin/kategory/data/CoproductTest.kt # kategory/src/test/kotlin/kategory/data/StateTTests.kt
* Rename circularBuffer to sliding, and adjust to Kotlin familiar semantics * Add Queue.dropping * Remove unused import QueueTest * Queue.dropping kdoc
This diff fixes a bunch of small issues related to coroutines:
1- New constructor for EQ
2- Remove bindingInContext temporarily until we work on a non-blocking solution
3- Remove JobKW, DeferredKW and other effects-kotlinx
4- Remove all dependencies on effects-kotlinx except for testing
5- Add support for CoroutineContext on Comonad
====
ORIGINAL POST (OUTDATED)
More fixes towards making effects stable:
1.- Remove dependency on kotlinx.coroutines. This is a helper library that'll be JVM-bound.
2.- New module effects-kotlinX for DeferredKW
2.- Remove bindingInContext. It didn't work unless blocking.
3.- Add support for CoroutineContext on Comonad
Depends on #246