Skip to content

Commit

Permalink
remove _slice
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Oct 21, 2016
1 parent 2dcbd5e commit 21d6a29
Show file tree
Hide file tree
Showing 30 changed files with 33 additions and 95 deletions.
3 changes: 1 addition & 2 deletions src/addIndex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _concat = require('./internal/_concat');
var _curry1 = require('./internal/_curry1');
var _slice = require('./internal/_slice');
var curryN = require('./curryN');


Expand Down Expand Up @@ -33,7 +32,7 @@ module.exports = _curry1(function addIndex(fn) {
var idx = 0;
var origFn = arguments[0];
var list = arguments[arguments.length - 1];
var args = _slice(arguments);
var args = Array.prototype.slice.call(arguments, 0);
args[0] = function() {
var result = origFn.apply(this, _concat(arguments, [idx, list]));
idx += 1;
Expand Down
3 changes: 1 addition & 2 deletions src/assocPath.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry3 = require('./internal/_curry3');
var _slice = require('./internal/_slice');
var assoc = require('./assoc');


Expand Down Expand Up @@ -33,6 +32,6 @@ module.exports = _curry3(function assocPath(path, val, obj) {
case 1:
return assoc(path[0], val, obj);
default:
return assoc(path[0], assocPath(_slice(path, 1), val, Object(obj[path[0]])), obj);
return assoc(path[0], assocPath(Array.prototype.slice.call(path, 1), val, Object(obj[path[0]])), obj);
}
});
3 changes: 1 addition & 2 deletions src/call.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var _slice = require('./internal/_slice');
var curry = require('./curry');


Expand Down Expand Up @@ -34,5 +33,5 @@ var curry = require('./curry');
* @symb R.call(f, a, b) = f(a, b)
*/
module.exports = curry(function call(fn) {
return fn.apply(this, _slice(arguments, 1));
return fn.apply(this, Array.prototype.slice.call(arguments, 1));
});
2 changes: 1 addition & 1 deletion src/constructN.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var nAry = require('./nAry');
*
* // Variadic constructor function
* var Widget = function () {
* this.children = Array.prototype.slice.call(arguments);
* this.children = Array.prototype.slice.call(arguments, 0);
* // ...
* };
* Widget.prototype = {
Expand Down
3 changes: 1 addition & 2 deletions src/dissocPath.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry2 = require('./internal/_curry2');
var _slice = require('./internal/_slice');
var assoc = require('./assoc');
var dissoc = require('./dissoc');

Expand Down Expand Up @@ -30,7 +29,7 @@ module.exports = _curry2(function dissocPath(path, obj) {
return dissoc(path[0], obj);
default:
var head = path[0];
var tail = _slice(path, 1);
var tail = Array.prototype.slice.call(path, 1);
return obj[head] == null ? obj : assoc(head, dissocPath(tail, obj[head]), obj);
}
});
3 changes: 1 addition & 2 deletions src/dropWhile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _curry2 = require('./internal/_curry2');
var _dispatchable = require('./internal/_dispatchable');
var _slice = require('./internal/_slice');
var _xdropWhile = require('./internal/_xdropWhile');


Expand Down Expand Up @@ -35,5 +34,5 @@ module.exports = _curry2(_dispatchable('dropWhile', _xdropWhile, function dropWh
while (idx < len && pred(list[idx])) {
idx += 1;
}
return _slice(list, idx);
return Array.prototype.slice.call(list, idx);
}));
3 changes: 1 addition & 2 deletions src/flip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry1 = require('./internal/_curry1');
var _slice = require('./internal/_slice');
var curry = require('./curry');


Expand All @@ -25,7 +24,7 @@ var curry = require('./curry');
*/
module.exports = _curry1(function flip(fn) {
return curry(function(a, b) {
var args = _slice(arguments);
var args = Array.prototype.slice.call(arguments, 0);
args[0] = b;
args[1] = a;
return fn.apply(this, args);
Expand Down
3 changes: 1 addition & 2 deletions src/insert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry3 = require('./internal/_curry3');
var _slice = require('./internal/_slice');


/**
Expand All @@ -22,7 +21,7 @@ var _slice = require('./internal/_slice');
*/
module.exports = _curry3(function insert(idx, elt, list) {
idx = idx < list.length && idx >= 0 ? idx : list.length;
var result = _slice(list);
var result = Array.prototype.slice.call(list, 0);
result.splice(idx, 0, elt);
return result;
});
6 changes: 3 additions & 3 deletions src/insertAll.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var _concat = require('./internal/_concat');
var _curry3 = require('./internal/_curry3');
var _slice = require('./internal/_slice');


/**
Expand All @@ -23,5 +21,7 @@ var _slice = require('./internal/_slice');
*/
module.exports = _curry3(function insertAll(idx, elts, list) {
idx = idx < list.length && idx >= 0 ? idx : list.length;
return _concat(_concat(_slice(list, 0, idx), elts), _slice(list, idx));
return [].concat(Array.prototype.slice.call(list, 0, idx),
elts,
Array.prototype.slice.call(list, idx));
});
4 changes: 1 addition & 3 deletions src/internal/_aperture.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
var _slice = require('./_slice');

module.exports = function _aperture(n, list) {
var idx = 0;
var limit = list.length - (n - 1);
var acc = new Array(limit >= 0 ? limit : 0);
while (idx < limit) {
acc[idx] = _slice(list, idx, idx + n);
acc[idx] = Array.prototype.slice.call(list, idx, idx + n);
idx += 1;
}
return acc;
Expand Down
3 changes: 0 additions & 3 deletions src/internal/_arrayOf.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/internal/_checkForMethod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _isArray = require('./_isArray');
var _slice = require('./_slice');


/**
Expand All @@ -21,6 +20,6 @@ module.exports = function _checkForMethod(methodname, fn) {
var obj = arguments[length - 1];
return (_isArray(obj) || typeof obj[methodname] !== 'function') ?
fn.apply(this, arguments) :
obj[methodname].apply(obj, _slice(arguments, 0, length - 1));
obj[methodname].apply(obj, Array.prototype.slice.call(arguments, 0, length - 1));
};
};
3 changes: 1 addition & 2 deletions src/internal/_dispatchable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _isArray = require('./_isArray');
var _isTransformer = require('./_isTransformer');
var _slice = require('./_slice');


/**
Expand All @@ -25,7 +24,7 @@ module.exports = function _dispatchable(methodname, xf, fn) {
}
var obj = arguments[length - 1];
if (!_isArray(obj)) {
var args = _slice(arguments, 0, length - 1);
var args = Array.prototype.slice.call(arguments, 0, length - 1);
if (typeof obj[methodname] === 'function') {
return obj[methodname].apply(obj, args);
}
Expand Down
4 changes: 1 addition & 3 deletions src/internal/_dropLastWhile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
var _slice = require('./_slice');

module.exports = function dropLastWhile(pred, list) {
var idx = list.length - 1;
while (idx >= 0 && pred(list[idx])) {
idx -= 1;
}
return _slice(list, 0, idx + 1);
return Array.prototype.slice.call(list, 0, idx + 1);
};
32 changes: 0 additions & 32 deletions src/internal/_slice.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/internal/_xaperture.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _concat = require('./_concat');
var _curry2 = require('./_curry2');
var _slice = require('./_slice');
var _xfBase = require('./_xfBase');


Expand Down Expand Up @@ -29,7 +28,8 @@ module.exports = (function() {
}
};
XAperture.prototype.getCopy = function() {
return _concat(_slice(this.acc, this.pos), _slice(this.acc, 0, this.pos));
return _concat(Array.prototype.slice.call(this.acc, this.pos),
Array.prototype.slice.call(this.acc, 0, this.pos));
};

return _curry2(function _xaperture(n, xf) { return new XAperture(n, xf); });
Expand Down
3 changes: 1 addition & 2 deletions src/invoker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _curry2 = require('./internal/_curry2');
var _isFunction = require('./internal/_isFunction');
var _slice = require('./internal/_slice');
var curryN = require('./curryN');
var toString = require('./toString');

Expand Down Expand Up @@ -35,7 +34,7 @@ module.exports = _curry2(function invoker(arity, method) {
return curryN(arity + 1, function() {
var target = arguments[arity];
if (target != null && _isFunction(target[method])) {
return target[method].apply(target, _slice(arguments, 0, arity));
return target[method].apply(target, Array.prototype.slice.call(arguments, 0, arity));
}
throw new TypeError(toString(target) + ' does not have a method named "' + method + '"');
});
Expand Down
3 changes: 1 addition & 2 deletions src/juxt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var _arrayOf = require('./internal/_arrayOf');
var _curry1 = require('./internal/_curry1');
var converge = require('./converge');

Expand All @@ -21,5 +20,5 @@ var converge = require('./converge');
* @symb R.juxt([f, g, h])(a, b) = [f(a, b), g(a, b), h(a, b)]
*/
module.exports = _curry1(function juxt(fns) {
return converge(_arrayOf, fns);
return converge(function() { return Array.prototype.slice.call(arguments, 0); }, fns);
});
3 changes: 1 addition & 2 deletions src/liftN.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _curry2 = require('./internal/_curry2');
var _reduce = require('./internal/_reduce');
var _slice = require('./internal/_slice');
var ap = require('./ap');
var curryN = require('./curryN');
var map = require('./map');
Expand All @@ -26,6 +25,6 @@ var map = require('./map');
module.exports = _curry2(function liftN(arity, fn) {
var lifted = curryN(arity, fn);
return curryN(arity, function() {
return _reduce(ap, map(lifted, arguments[0]), _slice(arguments, 1));
return _reduce(ap, map(lifted, arguments[0]), Array.prototype.slice.call(arguments, 1));
});
});
3 changes: 1 addition & 2 deletions src/median.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry1 = require('./internal/_curry1');
var _slice = require('./internal/_slice');
var mean = require('./mean');


Expand All @@ -26,7 +25,7 @@ module.exports = _curry1(function median(list) {
}
var width = 2 - len % 2;
var idx = (len - width) / 2;
return mean(_slice(list).sort(function(a, b) {
return mean(Array.prototype.slice.call(list, 0).sort(function(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
}).slice(idx, idx + width));
});
7 changes: 3 additions & 4 deletions src/remove.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var _concat = require('./internal/_concat');
var _curry3 = require('./internal/_curry3');
var _slice = require('./internal/_slice');


/**
Expand All @@ -23,6 +21,7 @@ var _slice = require('./internal/_slice');
* R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]
*/
module.exports = _curry3(function remove(start, count, list) {
return _concat(_slice(list, 0, Math.min(start, list.length)),
_slice(list, Math.min(list.length, start + count)));
var result = Array.prototype.slice.call(list, 0);
result.splice(start, count);
return result;
});
3 changes: 1 addition & 2 deletions src/reverse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _curry1 = require('./internal/_curry1');
var _isString = require('./internal/_isString');
var _slice = require('./internal/_slice');


/**
Expand Down Expand Up @@ -29,5 +28,5 @@ var _slice = require('./internal/_slice');
*/
module.exports = _curry1(function reverse(list) {
return _isString(list) ? list.split('').reverse().join('') :
_slice(list).reverse();
Array.prototype.slice.call(list, 0).reverse();
});
3 changes: 1 addition & 2 deletions src/sort.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry2 = require('./internal/_curry2');
var _slice = require('./internal/_slice');


/**
Expand All @@ -23,5 +22,5 @@ var _slice = require('./internal/_slice');
* R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7]
*/
module.exports = _curry2(function sort(comparator, list) {
return _slice(list).sort(comparator);
return Array.prototype.slice.call(list, 0).sort(comparator);
});
3 changes: 1 addition & 2 deletions src/sortBy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry2 = require('./internal/_curry2');
var _slice = require('./internal/_slice');


/**
Expand Down Expand Up @@ -35,7 +34,7 @@ var _slice = require('./internal/_slice');
* sortByNameCaseInsensitive(people); //=> [alice, bob, clara]
*/
module.exports = _curry2(function sortBy(fn, list) {
return _slice(list).sort(function(a, b) {
return Array.prototype.slice.call(list, 0).sort(function(a, b) {
var aa = fn(a);
var bb = fn(b);
return aa < bb ? -1 : aa > bb ? 1 : 0;
Expand Down
3 changes: 1 addition & 2 deletions src/splitWhen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry2 = require('./internal/_curry2');
var _slice = require('./internal/_slice');


/**
Expand Down Expand Up @@ -31,5 +30,5 @@ module.exports = _curry2(function splitWhen(pred, list) {
idx += 1;
}

return [prefix, _slice(list, idx)];
return [prefix, Array.prototype.slice.call(list, idx)];
});
3 changes: 1 addition & 2 deletions src/takeLastWhile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _curry2 = require('./internal/_curry2');
var _slice = require('./internal/_slice');


/**
Expand Down Expand Up @@ -29,5 +28,5 @@ module.exports = _curry2(function takeLastWhile(fn, list) {
while (idx >= 0 && fn(list[idx])) {
idx -= 1;
}
return _slice(list, idx + 1, Infinity);
return Array.prototype.slice.call(list, idx + 1);
});
3 changes: 1 addition & 2 deletions src/takeWhile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var _curry2 = require('./internal/_curry2');
var _dispatchable = require('./internal/_dispatchable');
var _slice = require('./internal/_slice');
var _xtakeWhile = require('./internal/_xtakeWhile');


Expand Down Expand Up @@ -36,5 +35,5 @@ module.exports = _curry2(_dispatchable('takeWhile', _xtakeWhile, function takeWh
while (idx < len && fn(list[idx])) {
idx += 1;
}
return _slice(list, 0, idx);
return Array.prototype.slice.call(list, 0, idx);
}));
Loading

0 comments on commit 21d6a29

Please sign in to comment.