2 ms·
> What would you do if you need just the first 5 elements of a 100-element long list? Depending on the language, either you don't or you use a "everything else
by masklinn 15y ago
> What would you do if you need just the first 5 elements of a 100-element long list?
Depending on the language, either you don't or you use a "everything else" operator to an unused variable:
a, b, *_ = list
You could even alter the syntax slightly to put a "Don't care" placeholder:
a, b, * = list
same as above but does not require serializing the [2:] array slice.
- adgar 15y agoRuby unfortunately has non-strict destructuring, but it also has LHS splatting: a, *, c = list And people often use _ as a placeholder when not using splatting: a, _, _, c, d = list