vanniktech / rxriddles Goto Github PK
View Code? Open in Web Editor NEWRiddling your way to master RxJava
License: Apache License 2.0
Riddling your way to master RxJava
License: Apache License 2.0
Sometimes it comes to a case when we need to have cold observable which shares its emissions between multiple observers. For example, presentation layer calls for data and we want to store it in repository at the same call. I use publish().autoConnect(N)
in that cases (N - number of observers). Here is an example of such usage:
public Observable<User> getUsersAndStore() {
Observable<User> listObservable = api.getUsers()
.publish()
.autoConnect(3);
// Here we store the result to ArrayMap<String, User>, 1st observer
listObservable
.collect(ArrayMap<String, User>::new,
(destinationMap, user) -> destinationMap.put(user.type, user))
.subscribe(typeWalletMap::putAll, Timber::e);
// 2nd
listObservable
.collect(ArrayMap<String, User>::new,
(destinationMap, user) -> destinationMap.put(user.id, user))
.subscribe(idWalletMap::putAll, Timber::e);
return listObservable; // and finally return needed observable, the code which subscribes to it will be
// 3rd observer. That subscriber will initiate the emissions in the source
// observable.
}
This approach seems to have side-effects(storing data to maps in this case), however we can't (or maybe just I can't) have code 100% free of side-effects, unfortunately. But the point is that all 3 observers use the same emissions without making source produce them 3 times.
Used literature: Thomas Nield, Learning RxJava '2017: Chapter 5 - Automatic connection
This is not an "issue", just wanting some clarification. The riddle says
Retry the given [source] up to three times unless an [IllegalArgumentException] has been emitted
However aren't we only "retrying" up to two times? We have an inital subscription, then comes the "retry" which happens twice. I was stuck on this because I kept setting retry(3, Predicate())
.
Firstly, thank you for this amazing Rx challenge you have put up, It has really helped me sharpen my Rx Skills.
Problem 26 confuses me because the test case passes for both delay()
and delaySubscription()
operator.
Looking at the marble diagram for delaySubscription()
it delays the subscription for the source but there is no delay for subsequent emission. But the problem states that there should be a delay for subsequent emission too!
Hey, I'd love to port this to Swift. I think it's a great idea. The Rx world on iOS is much less documented so I feel we need to port some of this RxJava knowledge to our side ;) Would you be open to me doing that?
I could write a medium post linking yours etc. Or however else you'd like to be credited in my port.
Currently Riddle24 returns Single<Int>
. I think it should return Single<Long>
, so that this solution works:
fun solve(source: Observable<Any>): Single<Long> {
return source.count()
}
The current solution Riddle24Solution works because the function does not specify a return-type.
Hey,
There is a small problem with riddle number 6 and it is up to you guys how you want to solve it. In the task description there is mentioned that
Execute both [first] and [second] Single's in parallel...
however you solution works sequentially. Thats because there are no schedulers running on mentioned Singles which means everything executes on main thread. Test is passing because it is not really checking for parallelism. If you would want to do that you could
val first = Single.timer(5, SECONDS, rxRule)
.map { 10 }
.doOnSubscribe { subscribeCounter.incrementAndGet() }
val second = Single.timer(3, SECONDS, rxRule)
.map { 5 }
.doOnSubscribe { subscribeCounter.incrementAndGet() }
// rest of the test goes here...
rxRule.advanceTimeBy(4, SECONDS)
// check if second already finished and the first one did not
first.test().assertNotComplete()
second.test().assertComplete()
You get the idea. So if the intention was to check for parallelism you need to adjust solution. If solution is good then you need to adjust the description.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
This repository currently has no open or pending branches.
.github/workflows/build.yml
actions/checkout v3
gradle/wrapper-validation-action v1
actions/setup-java v3
build.gradle
org.jetbrains.kotlin:kotlin-gradle-plugin 1.7.20
io.reactivex.rxjava3:rxjava 3.1.5
junit:junit 4.13.2
org.assertj:assertj-core 3.23.1
gradle/wrapper/gradle-wrapper.properties
gradle 7.5.1
Im getting the following error in Android Studio:
Class not found: "com.vanniktech.rxriddles.Riddle1Test"Empty test suite.
Already tried, deleting the configuration, invalidating cache, but it still doesnt find the class.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.