From 6debf1e39ab902eeabf4ca806ef1168a5185ffe7 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 22 Sep 2016 09:40:22 -0700 Subject: [PATCH] Add zip(). --- lib/src/functions.dart | 15 +++++++++++++++ lib/src/visitor/perform.dart | 9 ++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/src/functions.dart b/lib/src/functions.dart index 076f1341..33b4d140 100644 --- a/lib/src/functions.dart +++ b/lib/src/functions.dart @@ -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 = []; + 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", diff --git a/lib/src/visitor/perform.dart b/lib/src/visitor/perform.dart index f4535260..22d6b547 100644 --- a/lib/src/visitor/perform.dart +++ b/lib/src/visitor/perform.dart @@ -795,9 +795,12 @@ class PerformVisitor implements StatementVisitor, ExpressionVisitor { SassArgumentList argumentList; if (overload.restArgument != null) { - var rest = positional.length > declaredArguments.length - ? positional.sublist(declaredArguments.length) - : const []; + var rest = const []; + if (positional.length > declaredArguments.length) { + rest = positional.sublist(declaredArguments.length); + positional.removeRange(declaredArguments.length, positional.length); + } + argumentList = new SassArgumentList( rest, named,