rx-java

Combining 'n' Observables of the same type (RxJava)

时光怂恿深爱的人放手 提交于 2020-01-15 07:46:37
问题 I have a code flow that generates an Iterable of Observables of the same type. I then go through them all, combining them and returning the result as an Observable. At the moment I'm using zip with a FuncN, which seems horrible and I think I've missed the point somewhere. Here's an example that uses a Map, it's obviously nonsense but you get the idea. final ImmutableList.Builder<Map<String, Object>> observables = ImmutableList.builder(); for (String key: keys) { if (someTest(key)) {

How to subscribe to click events so exceptions don't unsubscribe?

て烟熏妆下的殇ゞ 提交于 2020-01-15 06:27:07
问题 I'm using RxJava for Android (RxAndroid) and I subscribe to click events of a view, and do something on them as follows: subscription = ViewObservable.clicks(view, false) .map(...) .subscribe(subscriberA); The problem is whenever there is an exception, subscriberA automatically unsubscribes, leading to the next click not triggering anything. How to handle exceptions so to intercept all the click events regardless of exceptions being thrown? 回答1: Use retry method: subscription = ViewObservable

How to use the state of one observable to skip values of another observable?

不羁的心 提交于 2020-01-15 02:29:31
问题 This is best explained with a short example. let's say this is my source observable that I want to filter Observable.interval(1, TimeUnit.SECONDS) I use a checkbox to handle the filter state. When the box is not checked, I want to skip all values. I use RxAndroid to get an observable for the checkbox like this: RxCompoundButton.checkedChanges(checkBox) here is my code: Observable.combineLatest( RxCompoundButton.checkedChanges(checkBox) , Observable.interval(1, TimeUnit.SECONDS) , (isChecked,

RxJava multiple loop with condition

别等时光非礼了梦想. 提交于 2020-01-14 04:06:21
问题 I am learning RxJava for a few week, i have some java code like below Code: String[] strings1 = new String[]{"a", "b", "c", "d", "e"}; Integer[] integers = {1, 2, 3, 4, 5}; String[] strings2 = new String[]{"f", "g", "h", "i"}; for (String str : strings1) { for (Integer integer : integers) { System.out.println(str + ":" + integer); if(integer == 4){ for (String str2 : strings2) { System.out.println(str2 + ":" + integer); } } } } How can i translate it to RxJava code? I trying to use

RxJava: Feed one stream (Observable) as the input of another stream

巧了我就是萌 提交于 2020-01-14 03:03:08
问题 I'm still learning RxJava. What is the best way to use a stream within another stream? Or is it against the principles of reactive programming? A toy example that I'm trying to write includes a TCP client and a server that sends back capitalized input. I'd like to take input from standard input, send it to the server and print out everything received by both the client and the server. The following is the expected output from the program: (User input) apple Server received: apple Client

RxJava alternative for map() operator to save emitted items

末鹿安然 提交于 2020-01-13 10:07:09
问题 I use Retrofit to interact with a REST API and RxJava do manipulate the data I receive. In the code snippet below I make an API call and use the map operator to save the data I receive before moving on with other operations against the stream. retrofitApi.registerDevice(mDevice) .map(new Func1<Device, Device>() { @Override public Device call(Device device) { // The only purpose of the map() operator // is to save the received device. magicBox.saveDeviceId(device.getId()); return device; } })

How to make RxErrorHandlingCallAdapterFactory?

帅比萌擦擦* 提交于 2020-01-12 05:30:10
问题 I found this. But in new ver compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0' at CallAdapter it has two params CallAdapter<?,?> How to modify RxCallAdapterWrapper to implement if from CallAdapter<?,?> 回答1: Disclaimer: I'm the author of the blog post you referenced The original post was meant as a proof of concept and for RxJava 2 so it's easier for me to explain with that version too, but I'll try and cover more ground. I'm guessing you're using version 1, since you talk about adapter

RxJava vs Java 8 Parallelism Stream

断了今生、忘了曾经 提交于 2020-01-11 15:47:11
问题 What are all the similarities and diferences between them, It looks like Java Parallel Stream has some of the element available in RXJava, is that right? 回答1: Rx is an API for creating and processing observable sequences. The Streams API is for processing iterable sequences. Rx sequences are push-based ; you are notified when an element is available. A Stream is pull-based ; it "asks" for items to process. They may appear similar because they both support similar operators/transforms, but the

How to ensure that all observers see the same result from multiple parallel subscription

℡╲_俬逩灬. 提交于 2020-01-11 13:15:10
问题 I have two observables. First - get session from internet or from cache; Observable<SessionKey> getSession = getSessionFromInternetOrCache(); Second - call to server api, using session Observable<MyResult> apiCall = getSession.flatMap(session -> { return myApi.getResult(session); }) Problem, that I have several independent components (gui). They are starting in parallel. apiCall also started in parallel. And i gets several session keys. What behavior I want: getSessions should calling once,

How to transform a nested list of double values into a Java class using RxJava?

眉间皱痕 提交于 2020-01-11 12:23:14
问题 In my Android client I receive this JSON data from a backend: [ [ 1427378400000, 553 ], [ 1427382000000, 553 ] ] Here is the routine which actually loads the data. I am using RxAndroid and Retrofit here. private void getProductLevels() { Observable<List<List<Double>>> responseObservable = mProductService.readProductLevels(); AppObservable.bindFragment(this, responseObservable) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) // TODO: Transform List<List<Double>> into