Tuples

One solution to the problem of returning multiple values from the .map() are the tuples. A tuple is a finite ordered list of elements. By default, Android provides a tuple in the form of Pair from the android.util package. Let's see how this can be used:

import android.util.Pair;

Observable.just("UserID1", "UserID2", "UserID3")
.map(id -> Pair.create(id, id + "-access-token"))
.subscribe(pair -> log("subscribe-subscribe", pair.second));

Now the values of the Pair are accessible through the given fields with the values in the according to order they were supplied to Pair.create() in. The first is this:

pair.first

The second field is as follows:

pair.second
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.227.4