Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List<String> gpsInString = Arrays.asList("GPS_1","GPS_2","GPS_3","GPS_4","GPS_5","GPS_6","GPS_7","GPS_8","GPS_9");
Observable.from(gpsInString).map(new Func1<String, Integer>() {
@Override
public Integer call(String s) {
int coordinate = Character.getNumericValue(s.charAt(4));
System.out.println("Converted "+s+" to "+coordinate);
return coordinate;
}
}).flatMap(new Func1<Integer, Observable<Hotel>>() {
//Example of flatmap, we have a list of coordinates now, but actually we want a list of locations close
@Override
public Observable<Hotel> call(Integer coordinate) {
System.out.println("Fetching hotel for "+ coordinate);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return Observable.just(new Hotel());
}
}).subscribeOn(Schedulers.computation()).toList().toBlocking().last();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.