-
-
Save Busata/ccd000ff6426a9cdb4d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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