RxJava provides a few mapping functions: map()
, flatMap()
, concatMap()
, flatMapIterable()
, and switchMap()
. All these functions apply to an Observable sequence, transform its emitted values, and return them in a new form. Let's look at them one by one with proper real-world examples.
RxJava's map()
function receives a specific Func
object and applies it to every value emitted by Observable. The next figure shows how to apply a multiplying function to every emitted item, to create a new Observable, emitting transformed items:
Let's think about our installed applications' list. How could we show the same list, but with all the names in lowercase?
Our loadList()
function will change to this:
private void loadList(List<AppInfo> apps) { mRecyclerView.setVisibility(View.VISIBLE); Observable.from(apps) .map(new Func1<AppInfo, AppInfo>() { @Override public AppInfo call(AppInfo appInfo) { String currentName...