A tuple is a sequence of at least two values. Orc does not have 0-tuples or 1-tuples.
Tuples are intended to be used for sequences with a fixed length and varying element types, whereas lists are intended to be used for sequences with varying length and a fixed element type.
The tuple expression ( E0 , … , En )
publishes the tuple value ( v0 , … , vn )
only if each expression Ei deflates to value vi.
Otherwise, it halts silently.
Notable tuple operations include:
Return the tuple element at position index, starting from 0: tuple(index)
Return the first element of a pair: fst(tuple)
Return the second element of a pair: snd(tuple)
The type of a tuple value (v0 , … , vn)
where vi has type Ti,
is a tuple type, written (T0 , … , Tn).
Orc tuples don't correspond to any Java value, so if a tuple is passed to Java code, it will be as a java.lang.Object of a type not specified here.
{- Unzip a list of tuples into a tuple of lists -} val squares = [(1,1), (2,4), (3,9), (4,16)] # ( map(fst,squares) , map(snd,squares) ) {- OUTPUT: ([1, 2, 3, 4], [1, 4, 9, 16]) -}
{- Print "fork", but wait at least 500ms before printing "join" -} ( Println("fork"), Rwait(500) ) >> Println("join") >> stop {- OUTPUT: fork join -}
Related Reference Topics