diff --git a/src/Data/Generic.js b/src/Data/Generic.js deleted file mode 100755 index e6c2d10..0000000 --- a/src/Data/Generic.js +++ /dev/null @@ -1,41 +0,0 @@ -"use strict"; - -// module Data.Generic - -exports.zipAll = function (f) { - return function (xs) { - return function (ys) { - var l = xs.length < ys.length ? xs.length : ys.length; - for (var i = 0; i < l; i++) { - if (!f(xs[i])(ys[i])) { - return false; - } - } - return true; - }; - }; -}; - -exports.zipCompare = function (f) { - return function (xs) { - return function (ys) { - var i = 0; - var xlen = xs.length; - var ylen = ys.length; - while (i < xlen && i < ylen) { - var o = f(xs[i])(ys[i]); - if (o !== 0) { - return o; - } - i++; - } - if (xlen === ylen) { - return 0; - } else if (xlen > ylen) { - return -1; - } else { - return 1; - } - }; - }; -}; diff --git a/src/Data/Generic.lua b/src/Data/Generic.lua new file mode 100755 index 0000000..f4f924c --- /dev/null +++ b/src/Data/Generic.lua @@ -0,0 +1,43 @@ +-- module Data.Generic + +local exports = {} + +exports.zipAll = function (f) + return function (xs) + return function (ys) + local l = #xs < #ys and #xs or #ys + for i=1, i<=l do + if not f(xs[i])(ys[i]) then + return false + end + end + return true + end + end +end + +exports.zipCompare = function (f) + return function (xs) + return function (ys) + local i = 1 + local xlen = #xs + local ylen = #ys + while (i <= xlen and i <= ylen) do + local o = f(xs[i])(ys[i]) + if o ~= 0 then + return o + end + i = i + 1 + end + if (xlen === ylen) then + return 0 + elseif (xlen > ylen) then + return -1 + else + return 1 + end + end + end +end + +return exports