Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Tuple access by index (range)

$
0
0

Rescript has only one way to access tuple elements: destructuring, this limitation prevents from using them as fixed length arrays

let ageAndName = (24, "Lil' ReScript")

// possible to get item by destructuring
let (_, name) = ageAndName

// NOT ALLOWED???
let name = ageAndName[2]

Access by index it’s type safe/sound when the compiler knows the length of the array, so index it’s limited to range {0,lenght-1} even typescript knows it

imagen

The generated tuple js is a plain array so, the only thing preventing {0,lenght-1} type safe random access is the language itself


Viewing all articles
Browse latest Browse all 2592

Trending Articles