Description
(Feature request)
I was about to pull length
function implementation (as in #1542), but realized that it would first probably make sense to propose a minor improvement for the extract
function since it's closely related.
Currently, a scalar value (e.g. any non-array/list value) handling by extract
is somewhat undefined. Certain types just pass through while others rise a errors, for example:
results {
c: extract(123, 1); // OK, outputs c: extract(123, 1);
d: extract(#123, 1); // non_object_property_loadError: error evaluating function `extract`
c: extract('123', 1); // undefined_methodError: Object 1 has no method 'genCSS'
a: extract(name, 1); // undefined_methodError: Object n has no method 'genCSS'
// etc.
}
So my proposal is: both extract
and length
should treat a single value as an array of length 1. The rationale behind this is quite simple I think: any code working with an arbitrary number of values (as a variable(s) or a mixin argument(s)) would be able to handle both array/list and scalar input in the same uniform manner.
Here's a typical use-case example I think of:
.widget-1 {
.transition(color);
}
.widget-2 {
.transition(color, background-color, border-color);
}
.transition(@properties...) {
.loop(length(@properties));
.loop(@i) when (@i > 0) {
.loop((@i - 1));
transition+: extract(@properties, @i) 2s ease-out;
}
}
CSS output:
.widget-1 {
transition: color 2s ease-out;
}
.widget-2 {
transition: color 2s ease-out, background-color 2s ease-out, border-color 2s ease-out;
}
That's it, no need for any conditionals, specialized mixin, etc...
Thanks.