-
Notifications
You must be signed in to change notification settings - Fork 443
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
AwaitAll for Traverse Deferred<T> #899
Conversation
"awaitAll called on a Traverse instance of DeferredK<T> should return a Traverse instance of T" { | ||
forAll(Gen.int(), { | ||
runBlocking { | ||
checkAwaitAll(ListK.applicative(), ListK.traverse(), it) |
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.
If any of these fails, it just returns a boolean that's ignored. You have to && them!
If you were not using forAll
you'd have to use shouldBe
in checkAwaitAll, which throws an AssertionException instead.
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.
eek, school boy error. Thanks
@@ -20,6 +31,9 @@ class DeferredKTest : UnitSpec() { | |||
a.unsafeAttemptSync() == b.unsafeAttemptSync() | |||
} | |||
|
|||
suspend fun <F, A> checkAwaitAll(AP: Applicative<F>, T: Traverse<F>, v: A) = | |||
AP.just(DeferredK { v }).awaitAll(T) == AP.just(v) |
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.
To have more than 1 element per test I'd suggest doing something like:
suspend fun <F, A> checkAwaitAll(AP: Applicative<F>, T: Traverse<F>, col: HK<F, A>) = AP.run {
col.map { v -> DeferredK { v }}.awaitAll(T) == col
}
checkAwaitAll(.., .., listOf(it, it, it, it, it).k()) // Or generate multiple ints instead
Note that we use 2-space indentation everywhere.
de0e6bc
to
07395b9
Compare
07395b9
to
d0e8c24
Compare
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.
Neat, let's roll!
For #884,
This adds awaitAll to any F<DeferredK> that returns F where F has a traverse instance