variadic concat. Close #18
This commit is contained in:
@@ -56,6 +56,7 @@ class Kiss {
|
||||
"print" => Symbol("Prelude.print"),
|
||||
"sort" => Symbol("Prelude.sort"),
|
||||
"groups" => Symbol("Prelude.groups"),
|
||||
"concat" => Symbol("Prelude.concat"),
|
||||
"pairs" => Symbol("Prelude.pairs"), // TODO test pairs
|
||||
"reversed" => Symbol("Prelude.reversed"), // TODO test reversed
|
||||
"memoize" => Symbol("Prelude.memoize"), // TODO test memoize
|
||||
|
@@ -170,6 +170,16 @@ class Prelude {
|
||||
return fullGroups;
|
||||
}
|
||||
|
||||
static function _concat(arrays:Array<Dynamic>):Array<Dynamic> {
|
||||
var arr:Array<Dynamic> = arrays[0];
|
||||
for (nextArr in arrays.slice(1)) {
|
||||
arr = arr.concat(nextArr);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static var concat:Function = Reflect.makeVarArgs(_concat);
|
||||
|
||||
public static function zip(arrays:Array<Array<Dynamic>>, extraHandling = Drop):kiss.List<kiss.List<Dynamic>> {
|
||||
var lengthsAreEqual = true;
|
||||
var lengths = [for (arr in arrays) arr.length];
|
||||
|
@@ -55,6 +55,10 @@ class BasicTestCase extends Test {
|
||||
_testCollect();
|
||||
}
|
||||
|
||||
function testConcat() {
|
||||
_testConcat();
|
||||
}
|
||||
|
||||
function testVariadicAdd() {
|
||||
Assert.equals(6, BasicTestCase.mySum);
|
||||
}
|
||||
|
@@ -109,6 +109,9 @@
|
||||
(defun myTypeCheck []
|
||||
(the Int 5))
|
||||
|
||||
(defun _testConcat []
|
||||
(Assert.equals (.toString [1 2 3 4]) (.toString (concat [1] [2 3] [4]))))
|
||||
|
||||
(defun _testGroups []
|
||||
(Assert.equals (.toString [[1 2] [3 4]]) (.toString (groups [1 2 3 4] 2)))
|
||||
(Assert.equals (.toString [[1 2 3] [4]]) (.toString (groups [1 2 3 4] 3 Keep)))
|
||||
|
@@ -22,9 +22,9 @@
|
||||
(unless (and
|
||||
(hcl.startsWith "#")
|
||||
(= hcl.length 7)
|
||||
(apply = (.concat [true]
|
||||
(for c (.split (hcl.substr 1) "")
|
||||
(<= 0 (.indexOf (.split "0123456789abcdef" "") c))))))
|
||||
(apply = (concat [true]
|
||||
(for c (.split (hcl.substr 1) "")
|
||||
(<= 0 (.indexOf (.split "0123456789abcdef" "") c))))))
|
||||
(return false)))
|
||||
(let [ecl (dictGet pp "ecl")]
|
||||
(unless (<= 0 (.indexOf (.split "amb blu brn gry grn hzl oth" " ") ecl)) (return false)))
|
||||
|
@@ -1,7 +1,7 @@
|
||||
(defun path [:kiss.List<String> hillTile x0 y0 dx dy]
|
||||
(if (>= y0 .length hillTile)
|
||||
[]
|
||||
(.concat [(.charAt (nth hillTile y0) (Math.floor (% x0 .length (nth hillTile y0))))] (path hillTile (+ x0 dx) (+ y0 dy) dx dy))))
|
||||
(concat [(.charAt (nth hillTile y0) (Math.floor (% x0 .length (nth hillTile y0))))] (path hillTile (+ x0 dx) (+ y0 dy) dx dy))))
|
||||
|
||||
(defun pathString [:kiss.List<String> hillTile x0 y0 dx dy] (.join (path hillTile x0 y0 dx dy) ""))
|
||||
|
||||
|
Reference in New Issue
Block a user