Tuple
Tuples are a ReScript-specific data structure that doesn't exist in JavaScript. They are:
immutable
ordered
fix-sized at creation time
heterogeneous (can contain different types of values)
Tuples' types can be used in type annotations as well. Tuple types visually resemble tuples values.
Note: there's no tuple of size 1. You'd just use the value itself.
Usage
To get a specific member of a tuple, destructure it:
The _
means you're ignoring the indicated members of the tuple.
Tuples aren't meant to be updated mutatively. You'd create new ones by destructuring the old ones:
Tips & Tricks
You'd use tuples in handy situations that pass around multiple values without too much ceremony. For example, to return many values:
Try to keep the usage of tuple local. For data structures that are long-living and passed around often, prefer a record, which has named fields.