O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required