Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • D

Idiom #220 Create a tuple value

Create t consisting of 3 values having different types.

Explain if the elements of t are strongly typed or not.

import std.typecons;
auto value = tuple(5, 6.7, "hello");
import std.typecons;
auto entry = tuple!("index", "value", "active")(4, "Hello", true);

Field names can be provided.

entry.index is 4, etc.
let t = 1, 'a', "b"

in OCaml, parenthesis for tuples are optional and only used to disambiguate.
Type inference can determine the type of the tuple without annotation.

New implementation...
programming-idioms.org