June 2017
Intermediate to advanced
400 pages
8h 44m
English
For a given Observable<T>, the map() operator will transform a T emission into an R emission using the provided Function<T,R> lambda. We have already used this operator many times, turning strings into lengths. Here is a new example: we can take raw date strings and use the map() operator to turn each one into a LocalDate emission, as shown in the following code snippet:
import io.reactivex.Observable;import java.time.LocalDate;import java.time.format.DateTimeFormatter;public class Launcher { public static void main(String[] args) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("M/d /yyyy"); Observable.just("1/3/2016", "5/9/2016", "10/12/2016") .map(s -> LocalDate.parse(s, dtf)) .subscribe(i -> System.out.println("RECEIVED: " ...
Read now
Unlock full access