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

Improve wording in Riddle 6 and add Riddle 102 #20

Merged
merged 3 commits into from
Jan 20, 2019
Merged

Improve wording in Riddle 6 and add Riddle 102 #20

merged 3 commits into from
Jan 20, 2019

Conversation

lwasyl
Copy link
Contributor

@lwasyl lwasyl commented Jan 12, 2019

My suggestion to solving #4

I tried to keep the original code style, but it's not stored in the project, so I might've missed something


/** Solution [Riddle6Solution] */
class Riddle6Test {
@get:Rule val rxRule = RxRule()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't use RxRule because I couldn't figure out how to check that the observables were subscribed concurrently but by two different schedule* calls. This was necessary to disallow subscribing once for the entire zip

Copy link
Owner

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

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

How about we add to the description of Riddle that it can be assumed that each Single will run on it's own thread when passed. That way we only have to use one operator.

In the tests, we can create Observables and apply the schedulers.

I prefer having a Single line solution for Riddle6.

src/test/kotlin/com/vanniktech/rxriddles/tools/RxRule.kt Outdated Show resolved Hide resolved
@lwasyl
Copy link
Contributor Author

lwasyl commented Jan 14, 2019

How about we add to the description of Riddle that it can be assumed that each Single will run on it's own thread when passed.

That's of course up to you, but I don't think it's a good idea. I understand that one-operator solutions are preferable, but I still believe the entire difficulty in doing work in parallel requires understanding that inner observables need to be subscribed on a different thread. Doing it for someone is not very educational.

Would it be ok if I modify this riddle as you say to only add the comment, but add Riddle 38 (or 102?) which is essentially what I wrote here? Would such slightly more complicated riddle be ok as one of the later ones?

@vanniktech
Copy link
Owner

Yes. Let's do a one-liner for this riddle. And then the more complicated one with adding the scheduler yourself can be 102.

@lwasyl
Copy link
Contributor Author

lwasyl commented Jan 16, 2019

@vanniktech I've updated the PR, now Riddle6 has only a comment added, and there's new Riddle102 that requires more operators.

@mateuszkwiecinski I've also updated the test to require subscribeOn for both singles

Copy link
Owner

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

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

Final code review then we can merge this

src/main/kotlin/com/vanniktech/rxriddles/Riddle6.kt Outdated Show resolved Hide resolved
src/main/kotlin/com/vanniktech/rxriddles/Riddle6.kt Outdated Show resolved Hide resolved
src/test/kotlin/com/vanniktech/rxriddles/Riddle102Test.kt Outdated Show resolved Hide resolved

object Riddle102Solution {
fun solve(first: Single<Int>, second: Single<Int>)
= Single.zip(
Copy link
Owner

Choose a reason for hiding this comment

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

I think formatting is different here from the other solutions. Can you double check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I was looking at riddles < 100 and they have = in new lines, while 100+ have = just after function declaration. I adjusted it to have = Single.zip( in previous line and parameters in others. Let me know if you meant only = in previous line, and Single.zip in the next one, to have parameters indent themselves more.

As a side note, it'd be useful if you checked in intellij's code style settings file. From what I see it's somewhat similar to Square's codestyle? But there were differences anyway

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, it's similar to Square's codestyle but has some differences. I typically don't ues the formatting options though.

src/test/kotlin/com/vanniktech/rxriddles/Riddle102Test.kt Outdated Show resolved Hide resolved
RxJavaPlugins.setIoSchedulerHandler { testScheduler }
RxJavaPlugins.setSingleSchedulerHandler { testScheduler }
RxJavaPlugins.setNewThreadSchedulerHandler { testScheduler }
override fun apply(base: Statement, description: Description): Statement = object : Statement() {
Copy link
Owner

Choose a reason for hiding this comment

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

Can we you revert the object : Statement? Or is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need it, since apply returns Statement. We can't return base anymore, because now we call reset() after the test.

Copy link
Owner

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

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

Thank you very much!

@@ -5,6 +5,8 @@ import io.reactivex.Single
object Riddle6 {
/**
* Execute both [first] and [second] Single's in parallel and provide both results as a pair.
* Assume both [first] and [second] will execute on a different thread already.
* This is a slightly simpler version of [Riddle102], where no schedulers are applied by default.
Copy link
Owner

Choose a reason for hiding this comment

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

I like the wording!

@vanniktech vanniktech changed the title Require subscribing on a separate scheduler in Riddle 6 Improve wording in Riddle 6 and add Riddle 102 Jan 20, 2019
@vanniktech vanniktech merged commit fbcb224 into vanniktech:master Jan 20, 2019
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