A tuple expression consists of name/value pairs where the names are optionally labeled, otherwise they are inferred from expression identifiers or ass

manifold/manifold-deps-parent/manifold-tuple at master · manifold-systems/manifold · GitHub

submited by
Style Pass
2022-06-24 04:00:08

A tuple expression consists of name/value pairs where the names are optionally labeled, otherwise they are inferred from expression identifiers or assigned default names. The names are type-safely reflected in the corresponding tuple type, which is inferred from the expression using auto or var.

Note, var may be used in place of auto if using Java 11+, otherwise if using Java 8, you must use auto for variable type inference.

If a label is omitted, it is inferred from the value expression, or is given a default name. Default names are item1, item2, etc.

Here the combined use of tuples and auto provides a clear and concise syntax for type-safely returning multiple values. As with fields and local variables, using auto on a method infers its return type from its return statements. Additionally, for improved readability, in a return statement you can omit the parenthesis otherwise required for tuple expressions.

Tuple expressions are designed as a lightweight utility to group loosely related data items. Because their types are purely structural, they tend to be less desirable as they lack the basic qualities of nominal typing. For instance, a nominal type such as a class is centrally defined, which enables it to be easily referenced by name, allows it to be formally documented, and makes it available for deterministic tooling. Tuple types lack these fundamental capabilities.

Leave a Comment