Comparing version 0.11.2 to 0.11.3
@@ -44,13 +44,2 @@ (function (global, factory) { | ||
function _arrayEach (f, xs) { | ||
var i = 0 | ||
, len = xs.length | ||
for (; i < len; i++) { | ||
if (f(xs[i], i)) { | ||
return | ||
} | ||
} | ||
} | ||
/** | ||
@@ -62,11 +51,11 @@ * all : (a -> Boolean) -> [a] -> Boolean | ||
var all = _curry2(function all (fn, xs) { | ||
var all = true | ||
var i = 0 | ||
, len = xs.length | ||
_arrayEach(function (x) { | ||
if (fn(x)) { | ||
all = false | ||
return true | ||
for (; i < len; i++) { | ||
if (!fn(xs[i])) { | ||
return false | ||
} | ||
}, xs) | ||
return all | ||
} | ||
return true | ||
}) | ||
@@ -91,10 +80,11 @@ | ||
var any = _curry2(function any (fn, xs) { | ||
var res = false | ||
var i = 0 | ||
, len = xs.length | ||
_arrayEach(function (x) { | ||
if (fn(x)) { | ||
return (res = true) | ||
for (; i < len; i++) { | ||
if (fn(xs[i])) { | ||
return true | ||
} | ||
}, xs) | ||
return res | ||
} | ||
return false | ||
}) | ||
@@ -107,6 +97,9 @@ | ||
* | ||
* TODO(zuko): implement as conj? | ||
* TODO(zuko): how should strings be handled? | ||
* | ||
* @since v0.10.0 | ||
*/ | ||
var append = _curry2(function append (x, xs) { | ||
return _concat.call(xs, [x]) | ||
return _concat.call(xs, x) | ||
}) | ||
@@ -130,3 +123,3 @@ | ||
/** | ||
* assoc : String -> * -> {k:v} -> {k:v} | ||
* assoc : String k -> v -> {k:v} -> {k:v} | ||
* | ||
@@ -159,15 +152,12 @@ * @since v0.6.0 | ||
var cond = _curry2(function cond (conditions, x) { | ||
var _this = this | ||
, _res | ||
var i = 0 | ||
, len = conditions.length | ||
, cond | ||
_arrayEach(function (condition) { | ||
var pred = condition[0] | ||
, fn = condition[1] | ||
if (pred.apply(_this, [x])) { | ||
_res = fn.apply(_this, [x]) | ||
return true | ||
for (; i < len; i++) { | ||
cond = conditions[i] | ||
if (cond[0](x)) { | ||
return cond[1](x) | ||
} | ||
}, conditions) | ||
return _res | ||
} | ||
}) | ||
@@ -177,3 +167,3 @@ | ||
var _arraySlice = [].slice | ||
var _slice = [].slice | ||
@@ -217,3 +207,3 @@ // Credit to Ramda for this idea for creating curried functions that | ||
if (arguments.length) { | ||
newApplied = _arraySlice.call(applied) | ||
newApplied = _slice.call(applied) | ||
for (i = 0; i < arguments.length; i++) { | ||
@@ -241,8 +231,8 @@ newApplied.push(arguments[i]) | ||
, len = fns.length | ||
, y = fns[i++].apply(null, arguments) | ||
, acc = fns[i++].apply(null, arguments) | ||
for (; i < len; i++) { | ||
y = fns[i](y) | ||
acc = fns[i](acc) | ||
} | ||
return y | ||
return acc | ||
}) | ||
@@ -252,3 +242,3 @@ } | ||
/** | ||
* compose : (y -> z), ..., (g -> h), (a, b, ..., f -> g) -> (a, b, ..., f -> z) | ||
* compose : ((y -> z), ..., (g -> h), (a, b, ..., f -> g)) -> (a, b, ..., f -> z) | ||
* | ||
@@ -258,3 +248,3 @@ * @since v0.1.0 | ||
function compose () { | ||
return pipe.apply(this, _reverse.call(arguments)) | ||
return pipe.apply(null, _reverse.call(arguments)) | ||
} | ||
@@ -296,3 +286,3 @@ | ||
/** | ||
* dissoc : String -> {k:v} -> {k:v} | ||
* dissoc : String k -> {k:v} -> {k:v} | ||
* | ||
@@ -313,6 +303,2 @@ * @since v0.10.0 | ||
function _slice (xs, from, to) { | ||
return _arraySlice.call(xs, from, to) | ||
} | ||
/** | ||
@@ -324,3 +310,3 @@ * drop : Number -> Array -> Array | ||
var drop = _curry2(function drop (n, xs) { | ||
return _slice(xs, n) | ||
return _slice.call(xs, n) | ||
}) | ||
@@ -344,11 +330,15 @@ | ||
*/ | ||
var filter = _curry2(function filter (fn, xs) { | ||
var ys = [] | ||
var filter = _curry2(function filter (pred, as) { | ||
var i = 0 | ||
, len = as.length | ||
, res = [] | ||
, a | ||
_arrayEach(function (x) { | ||
if (fn(x)) { | ||
ys.push(x) | ||
while (i < len) { | ||
a = as[i++] | ||
if (pred(a)) { | ||
res[res.length] = a | ||
} | ||
}, xs) | ||
return ys | ||
} | ||
return res | ||
}) | ||
@@ -362,11 +352,12 @@ | ||
var find = _curry2(function find (pred, xs) { | ||
var y | ||
var i = 0 | ||
, len = xs.length | ||
, x | ||
_arrayEach(function (x) { | ||
for (; i < len; i++) { | ||
x = xs[i] | ||
if (pred(x)) { | ||
y = x | ||
return true | ||
return x | ||
} | ||
}, xs) | ||
return y | ||
} | ||
}) | ||
@@ -380,11 +371,31 @@ | ||
var findIndex = _curry2(function findIndex (pred, xs) { | ||
var _i = -1 | ||
var i = 0 | ||
, len = xs.length | ||
_arrayEach(function (x, i) { | ||
for (; i < len; i++) { | ||
if (pred(xs[i])) { | ||
return i | ||
} | ||
} | ||
return -1 | ||
}) | ||
/** | ||
* findLast : (a -> Boolean) -> [a] -> a | undefined | ||
* | ||
* @since v0.12.0 | ||
*/ | ||
var findLast = _curry2(function findLast (pred, xs) { | ||
var i = 0 | ||
, len = xs.length | ||
, x | ||
, res | ||
for (; i < len; i++) { | ||
x = xs[i] | ||
if (pred(x)) { | ||
_i = i | ||
return true | ||
res = x | ||
} | ||
}, xs) | ||
return _i | ||
} | ||
return res | ||
}) | ||
@@ -397,15 +408,19 @@ | ||
*/ | ||
var flatMap = _curry2(function flatMap (fn, as) { | ||
var bs = [] | ||
var flatMap = _curry2(function flatMap (fn, xs) { | ||
var i = 0 | ||
, len = xs.length | ||
, bs = [] | ||
, _i | ||
, b | ||
_arrayEach(function (a) { | ||
var x = fn(a) | ||
if (Array.isArray(x)) { | ||
_arrayEach(function (x_) { | ||
bs.push(x_) | ||
}, x) | ||
for (; i < len; i++) { | ||
b = fn(xs[i]) | ||
if (Array.isArray(b)) { | ||
for (_i = 0; _i < b.length; _i++) { | ||
bs.push(b[_i]) | ||
} | ||
} else { | ||
bs.push(x) | ||
bs.push(b) | ||
} | ||
}, as) | ||
} | ||
@@ -415,31 +430,27 @@ return bs | ||
function _reduce (fn, b, as) { | ||
_arrayEach(function (a) { | ||
b = fn(b, a) | ||
}, as) | ||
return b | ||
} | ||
/** | ||
* reduce : ((b, a) -> b) -> b -> [a] | ||
* flatten : [[a]] -> [a] | ||
* | ||
* @since v0.1.0 | ||
*/ | ||
var reduce = _curry3(_reduce) | ||
function flatten (xs) { | ||
var acc = [] | ||
, i = 0 | ||
, len = xs.length | ||
, x | ||
, xi | ||
, xlen | ||
/** | ||
* flatten : [[a]] -> [a] | ||
* | ||
* @since v0.1.0 | ||
*/ | ||
var flatten = reduce(function flatten (acc, x) { | ||
if (Array.isArray(x)) { | ||
_arrayEach(function (x_) { | ||
acc.push(x_) | ||
}, x) | ||
} else { | ||
acc.push(x) | ||
for (; i < len; i++) { | ||
x = xs[i] | ||
if (Array.isArray(x)) { | ||
for (xi = 0, xlen = x.length; xi < xlen; xi++) { | ||
acc.push(x[xi]) | ||
} | ||
} else { | ||
acc.push(x) | ||
} | ||
} | ||
return acc | ||
}, []) | ||
} | ||
@@ -451,9 +462,19 @@ /** | ||
*/ | ||
var _flattenDeep = reduce(function flattenDeep (acc, x) { | ||
return _concat.call( | ||
acc, | ||
Array.isArray(x) ? _flattenDeep(x) : x | ||
) | ||
}, []) | ||
function flattenDeep (xs) { | ||
var acc = [] | ||
, i = 0 | ||
, len = xs.length | ||
, x | ||
for (; i < len; i++) { | ||
x = xs[i] | ||
if (Array.isArray(x)) { | ||
acc = _concat.call(acc, flattenDeep(x)) | ||
} else { | ||
acc.push(x) | ||
} | ||
} | ||
return acc | ||
} | ||
/** | ||
@@ -466,3 +487,3 @@ * flip : (a -> b -> c -> ... -> z) -> (z -> ... -> c -> b -> a) | ||
return curryN(fn.length, function () { | ||
return fn.apply(this, _reverse.call(arguments)) | ||
return fn.apply(null, _reverse.call(arguments)) | ||
}) | ||
@@ -476,8 +497,28 @@ } | ||
var forEach = _curry2(function forEach (fn, xs) { | ||
_arrayEach(function (x) { | ||
fn(x) | ||
}, xs) | ||
var i = 0 | ||
, len = xs.length | ||
for (; i < len; i++) { | ||
fn(xs[i]) | ||
} | ||
}) | ||
function _reduce (fn, acc, as) { | ||
var i = 0 | ||
, len = as.length | ||
for (; i < len; i++) { | ||
acc = fn(acc, as[i]) | ||
} | ||
return acc | ||
} | ||
/** | ||
* reduce : (b, a -> b) -> b -> [a] -> b | ||
* | ||
* @since v0.1.0 | ||
*/ | ||
var reduce = _curry3(_reduce) | ||
/** | ||
* fromPairs : [[k, v]] -> {k:v} | ||
@@ -550,12 +591,12 @@ * | ||
*/ | ||
var indexOf = _curry2(function indexOf (y, xs) { | ||
var _i = -1 | ||
var indexOf = _curry2(function indexOf (a, xs) { | ||
var i = 0 | ||
, len = xs.length | ||
_arrayEach(function (x, i) { | ||
if (x === y) { | ||
_i = i | ||
return true | ||
for (; i < len; i++) { | ||
if (xs[i] === a) { | ||
return i | ||
} | ||
}, xs) | ||
return _i | ||
} | ||
return -1 | ||
}) | ||
@@ -569,3 +610,3 @@ | ||
var insert = _curry3(function insert (idx, x, xs) { | ||
var ys = _slice(xs) | ||
var ys = _slice.call(xs) | ||
@@ -605,2 +646,3 @@ ys[idx] = x | ||
/** | ||
* lens : ((k -> v), (k, v, {k:v} -> {k:v})) -> Lens k | ||
* | ||
@@ -642,9 +684,11 @@ * @param {Function} get | ||
*/ | ||
var map = _curry2(function map (fn, xs) { | ||
var ys = new Array(xs.length) | ||
var map = _curry2(function map (fn, as) { | ||
var bs = new Array(as.length) | ||
, i = 0 | ||
, len = as.length | ||
_arrayEach(function (x, i) { | ||
ys[i] = fn(x) | ||
}, xs) | ||
return ys | ||
for (; i < len; i++) { | ||
bs[i] = fn(as[i]) | ||
} | ||
return bs | ||
}) | ||
@@ -690,3 +734,3 @@ | ||
return curryN(x.length, function () { | ||
return !x.apply(this, arguments) | ||
return !x.apply(null, arguments) | ||
}) | ||
@@ -705,6 +749,8 @@ } | ||
/** | ||
* set : Lens k -> v -> {k:v} -> {k:v} | ||
* | ||
* @param {Lens} lens | ||
* @param {*} value | ||
* @param {Object|*} target | ||
* @returns {*} | ||
* @param {Object} target | ||
* @returns {Object} | ||
*/ | ||
@@ -716,2 +762,4 @@ var set = _curry3(function set (lens, value, target) { | ||
/** | ||
* over : Lens k -> (v -> *) -> {k:v} -> {k:v} | ||
* | ||
* @param {Lens} lens | ||
@@ -727,3 +775,3 @@ * @param {Function} fn | ||
/** | ||
* prop : String -> {k:v} -> v | ||
* prop : String k -> {k:v} -> v | ||
* | ||
@@ -737,3 +785,3 @@ * @since v0.1.0 | ||
/** | ||
* propEq : String -> * -> {k:v} -> Boolean | ||
* propEq : String k -> v -> {k:v} -> Boolean | ||
* | ||
@@ -803,6 +851,23 @@ * @since v0.1.0 | ||
function reverse (xs) { | ||
return _reverse.call(_slice(xs, 0)) | ||
return _reverse.call(_slice.call(xs, 0)) | ||
} | ||
/** | ||
* scan : (b, a -> b) -> b -> [a] -> [b] | ||
* | ||
* @since v0.12.0 | ||
*/ | ||
var scan = _curry3(function scan (fn, acc, as) { | ||
var i = 0 | ||
, len = as.length | ||
, bs = [acc] | ||
for (; i < len; i++) { | ||
acc = fn(acc, as[i]) | ||
bs[bs.length] = acc | ||
} | ||
return bs | ||
}) | ||
/** | ||
* sum : [Number] -> Number | ||
@@ -812,4 +877,13 @@ * | ||
*/ | ||
var sum = reduce(add, 0) | ||
function sum (xs) { | ||
var i = 0 | ||
, len = xs.length | ||
, sum = 0 | ||
for (; i < len; i++) { | ||
sum += xs[i] | ||
} | ||
return sum | ||
} | ||
/** | ||
@@ -821,3 +895,3 @@ * tail : [a] -> [a] | ||
function tail (xs) { | ||
return _slice(xs, 1) | ||
return _slice.call(xs, 1) | ||
} | ||
@@ -831,3 +905,3 @@ | ||
var take = _curry2(function take (n, xs) { | ||
return _slice(xs, 0, n) | ||
return _slice.call(xs, 0, n) | ||
}) | ||
@@ -841,11 +915,11 @@ | ||
var takeUntil = _curry2(function takeUntil (fn, xs) { | ||
var ys | ||
var i = 0 | ||
, len = xs.length | ||
_arrayEach(function (x, i) { | ||
if (fn(x)) { | ||
ys = _slice(xs, 0, i) | ||
return true | ||
for (; i < len; i++) { | ||
if (fn(xs[i])) { | ||
return _slice.call(xs, 0, i) | ||
} | ||
}, xs) | ||
return ys || _slice(xs) | ||
} | ||
return _slice.call(xs) | ||
}) | ||
@@ -887,3 +961,3 @@ | ||
/** | ||
* tap : (a -> b) -> a -> a | ||
* tap : (a -> *) -> a -> a | ||
* | ||
@@ -914,4 +988,6 @@ * @since v0.7.0 | ||
/** | ||
* view : Lens k -> {k:v} -> v | ||
* | ||
* @param {Lens} lens | ||
* @param {Object|*} target | ||
* @param {Object} target | ||
* @returns {*} | ||
@@ -926,20 +1002,29 @@ */ | ||
* | ||
* TODO(zuko): if lists are hashable, create hash to improve lookup speed | ||
* TODO(zuko): could we just use a Map? | ||
* | ||
* @since v0.7.0 | ||
*/ | ||
var without = _curry2(function without (as, bs) { | ||
var ys = [] | ||
var ys = [] | ||
, bi = 0 | ||
, aslen = as.length | ||
, bslen = bs.length | ||
, ai | ||
, b | ||
, discard | ||
_arrayEach(function (b) { | ||
var discard = false | ||
_arrayEach(function (a) { | ||
if (b === a) { | ||
return (discard = true) | ||
for (; bi < bslen; bi++) { | ||
b = bs[bi] | ||
discard = false | ||
for (ai = 0; ai < aslen; ai++) { | ||
if (b === as[ai]) { | ||
discard = true | ||
break | ||
} | ||
}, as) | ||
} | ||
if (!discard) { | ||
ys.push(b) | ||
} | ||
}, bs) | ||
} | ||
return ys | ||
@@ -998,5 +1083,6 @@ }) | ||
exports.findIndex = findIndex; | ||
exports.findLast = findLast; | ||
exports.flatMap = flatMap; | ||
exports.flatten = flatten; | ||
exports.flattenDeep = _flattenDeep; | ||
exports.flattenDeep = flattenDeep; | ||
exports.flip = flip; | ||
@@ -1032,2 +1118,3 @@ exports.forEach = forEach; | ||
exports.reverse = reverse; | ||
exports.scan = scan; | ||
exports.set = set; | ||
@@ -1034,0 +1121,0 @@ exports.sum = sum; |
{ | ||
"name": "redash", | ||
"version": "0.11.2", | ||
"version": "0.11.3", | ||
"description": "Compact library for writing performant functional JavaScript", | ||
@@ -13,3 +13,3 @@ "main": "dist/redash.js", | ||
"scripts": { | ||
"lint": "eslint src", | ||
"lint": "eslint src tests", | ||
"bundle": "rollup --format umd --name Redash -i src/redash.js -o dist/redash.js", | ||
@@ -24,16 +24,24 @@ "minify": "uglifyjs dist/redash.js --compress --mangle -o dist/redash.min.js", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"dirty-chai": "^1.2.2", | ||
"eslint": "^2.13.1", | ||
"karma": "^0.13.15", | ||
"karma": "^0.13.22", | ||
"karma-better-sinon-chai": "^0.1.1", | ||
"karma-chai": "^0.1.0", | ||
"karma-coverage": "^0.5.3", | ||
"karma-coveralls": "^1.1.2", | ||
"karma-dirty-chai": "^1.0.2", | ||
"karma-mocha": "^0.2.1", | ||
"karma-phantomjs-launcher": "^0.2.1", | ||
"karma-sinon-chai": "^1.1.0", | ||
"karma-rollup-preprocessor": "^2.0.2", | ||
"karma-sinon": "^1.0.5", | ||
"karma-spec-reporter": "0.0.22", | ||
"lodash": "^4.13.1", | ||
"mocha": "^2.3.4", | ||
"phantomjs": "^1.9.19", | ||
"ramda": "^0.21.0", | ||
"rollup": "^0.21.0", | ||
"sinon-chai": "^2.8.0", | ||
"uglify-js": "^2.6.1" | ||
} | ||
} |
22604
980
21