4 ms·
EDIT can you think of a destructuring method that operates with access by name, rather than by position? (lo, hi) = getLim(); It seems to me it would have t
by hyperpallium 7y ago
EDIT can you think of a destructuring method that operates with access by name, rather than by position?
(lo, hi) = getLim();
It seems to me it would have to be something like:
Lim lim = getLim();
lo = lim.minimum;
hi = lim.maximum
Pwrhaps records could define an ordering of their fields, so as to enable destructuring by position?
- frou_dh 7y ago> can you think of a destructuring method that operates with access by name, rather than by position? Yeah, this in JS: obj = {a: 1, b: 22, c: 333} const {b, a} = obj My original point was more that, even in languages that have both "proper" traditional tuple types and the parenthesised destructuring syntax, we're not obligated to use destructuring. i.e. writing the following is perfectly legitimate, if verbose: a_tup = function_returning_tuple() x = first(a_tup) y = second(a_tup)
- hyperpallium 7y agoI hadn't seen that. It is a bit shorter, because you needn't repeat the source object. My e.g. would be lim = getLim(); const {minimum: lo, maximum: hi} = lim;