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

AwaitAll for Traverse Deferred<T> #899

Merged
merged 1 commit into from
Jun 23, 2018

Conversation

richard-gibson
Copy link
Contributor

For #884,
This adds awaitAll to any F<DeferredK> that returns F where F has a traverse instance

"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)
Copy link
Member

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.

Copy link
Contributor Author

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

@pakoito pakoito Jun 22, 2018

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.

Copy link
Member

@pakoito pakoito left a 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!

@pakoito pakoito merged commit 8b26f11 into arrow-kt:master Jun 23, 2018
RawToast pushed a commit to RawToast/kategory that referenced this pull request Jul 18, 2018
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.

2 participants