Clone wiki

bolts / Tuple

Home * На русском


... where N is a number — is a sequence of N objects of different types. For instance, Tuple2<String, Integer> — is a pair of String and Integer. getN method is used to extract Nth element from Tuple. Tuples can be constructed by calling static tuple() method of class TupleN.


Tuple3.tuple(1, 4, "fire").get3() // returns "fire"

Tuple is handy because you don't need to create new class each time you want to return a pair of objects from a method.

Tuple is used in many algorithms. CollecitonsF class has method that takes sequence of pairs (Tuple2) and returns MapF, and MapF interface has entries method that returns entries as list of pairs (Tuple2).

Tuple3, Tuple4 are rarely useful compared to Tuple2.

Tuple exists in many modern programming environments (Scala, Python, Haskell, C++/TR1).