1. Stepan Koltsov
  2. bolts

Wiki

Clone wiki

bolts / Tuple

Home * На русском

TupleN

... 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.

Example:

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).

Updated