Next, we will cover various common operators that transform emissions. A series of operators in an Observable
chain is a stream of transformations. You have already seen map()
, which is the most obvious operator in this category. We will start with that one.
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") ...