Add zip().

This commit is contained in:
Natalie Weizenbaum 2016-09-22 09:40:22 -07:00 committed by Natalie Weizenbaum
parent f7fbbb075a
commit 6debf1e39a
2 changed files with 21 additions and 3 deletions

View File

@ -588,6 +588,21 @@ void defineCoreFunctions(Environment environment) {
return list.changeListContents(newList, separator: separator);
});
environment.defineFunction("zip", r"$lists...", (arguments) {
var lists = (arguments[0] as SassArgumentList)
.contents
.map((list) => list.asList)
.toList();
var i = 0;
var results = <SassList>[];
while (lists.every((list) => i != list.length)) {
results
.add(new SassList(lists.map((list) => list[i]), ListSeparator.space));
i++;
}
return new SassList(results, ListSeparator.comma);
});
// ## Introspection
environment.defineFunction("inspect", r"$value",

View File

@ -795,9 +795,12 @@ class PerformVisitor implements StatementVisitor, ExpressionVisitor<Value> {
SassArgumentList argumentList;
if (overload.restArgument != null) {
var rest = positional.length > declaredArguments.length
? positional.sublist(declaredArguments.length)
: const <Value>[];
var rest = const <Value>[];
if (positional.length > declaredArguments.length) {
rest = positional.sublist(declaredArguments.length);
positional.removeRange(declaredArguments.length, positional.length);
}
argumentList = new SassArgumentList(
rest,
named,