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

Remove dependency on kotlinx.coroutines for effects #250

Merged
merged 28 commits into from
Sep 13, 2017
Merged

Conversation

pakoito
Copy link
Member

@pakoito pakoito commented Sep 3, 2017

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

@pakoito pakoito requested review from raulraja and a team September 3, 2017 17:20
@codecov-io
Copy link

codecov-io commented Sep 3, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@b9bc7d8). Click here to learn what that means.
The diff coverage is 68.75%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #250   +/-   ##
=========================================
  Coverage          ?   45.07%           
  Complexity        ?      318           
=========================================
  Files             ?      148           
  Lines             ?     3723           
  Branches          ?      402           
=========================================
  Hits              ?     1678           
  Misses            ?     1924           
  Partials          ?      121
Impacted Files Coverage Δ Complexity Δ
...t/src/main/kotlin/kategory/laws/MonadWriterLaws.kt 21.42% <ø> (ø) 2 <0> (?)
.../src/main/kotlin/kategory/generators/Generators.kt 57.14% <ø> (ø) 0 <0> (?)
...core/src/main/kotlin/kategory/typeclasses/Monad.kt 72.54% <ø> (ø) 0 <0> (?)
...ry-core/src/main/kotlin/kategory/typeclasses/Eq.kt 36.36% <0%> (ø) 0 <0> (?)
...ry-test/src/main/kotlin/kategory/laws/MonadLaws.kt 1.72% <0%> (ø) 2 <0> (?)
...test/src/main/kotlin/kategory/laws/TraverseLaws.kt 8.57% <0%> (ø) 1 <0> (?)
...ry-optics/src/main/kotlin/kategory/optics/Prism.kt 70% <100%> (ø) 12 <2> (?)
...ffects/src/main/kotlin/kategory/effects/data/IO.kt 76% <100%> (ø) 10 <1> (?)
...egory-core/src/main/kotlin/kategory/data/Option.kt 56.25% <100%> (ø) 7 <0> (?)
...re/src/main/kotlin/kategory/typeclasses/Comonad.kt 65% <100%> (ø) 0 <0> (?)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9bc7d8...365a6ac. Read the comment docs.

typealias DeferredResult<A> = Either<Throwable, A>

@higherkind
@deriving(Monad::class, AsyncContext::class)
Copy link
Member

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. */
Copy link
Member

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(
Copy link
Member

@raulraja raulraja Sep 13, 2017

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> {
Copy link
Member

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

Copy link
Member

@raulraja raulraja left a 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. 👏

pakoito added 3 commits September 13, 2017 20:39
# 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
@pakoito pakoito merged commit 9c81e7a into master Sep 13, 2017
@pakoito pakoito deleted the paco-effectsfix branch September 13, 2017 22:03
@wiyarmir wiyarmir mentioned this pull request Sep 15, 2017
rachelcarmena pushed a commit that referenced this pull request Feb 24, 2021
* Rename circularBuffer to sliding, and adjust to Kotlin familiar semantics

* Add Queue.dropping

* Remove unused import QueueTest

* Queue.dropping kdoc
rachelcarmena pushed a commit that referenced this pull request Feb 24, 2021
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