(collect) macro
This commit is contained in:
@@ -535,6 +535,12 @@ class Macros {
|
||||
]));
|
||||
};
|
||||
|
||||
macros["collect"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
wholeExp.checkNumArgs(1, 1, "(collect [iterator or iterable])");
|
||||
var b = wholeExp.expBuilder();
|
||||
b.call(b.symbol("for"), [b.symbol("elem"), exps[0], b.symbol("elem")]);
|
||||
}
|
||||
|
||||
return macros;
|
||||
}
|
||||
|
||||
|
@@ -51,6 +51,10 @@ class BasicTestCase extends Test {
|
||||
Assert.equals(3, BasicTestCase.myArrayLast);
|
||||
}
|
||||
|
||||
function testCollect() {
|
||||
_testCollect();
|
||||
}
|
||||
|
||||
function testVariadicAdd() {
|
||||
Assert.equals(6, BasicTestCase.mySum);
|
||||
}
|
||||
|
@@ -27,6 +27,10 @@
|
||||
// Array access is via nth
|
||||
(defvar myArrayLast (nth myArray -1))
|
||||
|
||||
// (collect) turns iterators to arrays
|
||||
(defun _testCollect []
|
||||
(Assert.equals "[0,1,2]" (Std.string (collect (range 3)))))
|
||||
|
||||
// Variadic math uses haxe's Lambda.fold under the hood
|
||||
(defvar mySum (+ 1 2 3))
|
||||
|
||||
|
Reference in New Issue
Block a user