Merge pull request #170 from paulmillr/topics/iteratee

Fix naming: use “iterable” instead of “iteratee”.

Former-commit-id: 199757631f0c941898e1dcb8f5ae9f9d8c517337
This commit is contained in:
John-David Dalton
2013-01-25 19:40:13 -08:00

View File

@@ -339,8 +339,8 @@
* @returns {String} Returns the interpolated text. * @returns {String} Returns the interpolated text.
*/ */
var iteratorTemplate = template( var iteratorTemplate = template(
// the `iteratee` may be reassigned by the `top` snippet // the `iterable` may be reassigned by the `top` snippet
'var index, iteratee = <%= firstArg %>, ' + 'var index, iterable = <%= firstArg %>, ' +
// assign the `result` variable an initial value // assign the `result` variable an initial value
'result = <%= firstArg %>;\n' + 'result = <%= firstArg %>;\n' +
// exit early if the first argument is falsey // exit early if the first argument is falsey
@@ -350,13 +350,13 @@
// array-like iteration: // array-like iteration:
'<% if (arrays) { %>' + '<% if (arrays) { %>' +
'var length = iteratee.length; index = -1;\n' + 'var length = iterable.length; index = -1;\n' +
"if (<%= arrays %>) {" + "if (<%= arrays %>) {" +
// add support for accessing string characters by index if needed // add support for accessing string characters by index if needed
' <% if (noCharByIndex) { %>\n' + ' <% if (noCharByIndex) { %>\n' +
' if (isString(iteratee)) {\n' + ' if (isString(iterable)) {\n' +
" iteratee = iteratee.split('')\n" + " iterable = iterable.split('')\n" +
' }' + ' }' +
' <% } %>\n' + ' <% } %>\n' +
@@ -370,8 +370,8 @@
// object iteration: // object iteration:
// add support for iterating over `arguments` objects if needed // add support for iterating over `arguments` objects if needed
' <% } else if (nonEnumArgs) { %>\n' + ' <% } else if (nonEnumArgs) { %>\n' +
' var length = iteratee.length; index = -1;\n' + ' var length = iterable.length; index = -1;\n' +
' if (length && isArguments(iteratee)) {\n' + ' if (length && isArguments(iterable)) {\n' +
' while (++index < length) {\n' + ' while (++index < length) {\n' +
" index += '';\n" + " index += '';\n" +
' <%= loop %>\n' + ' <%= loop %>\n' +
@@ -386,14 +386,14 @@
// the the `prototype` property of functions regardless of its // the the `prototype` property of functions regardless of its
// [[Enumerable]] value. // [[Enumerable]] value.
' <% if (!hasDontEnumBug) { %>\n' + ' <% if (!hasDontEnumBug) { %>\n' +
" var skipProto = typeof iteratee == 'function' && \n" + " var skipProto = typeof iterable == 'function' && \n" +
" propertyIsEnumerable.call(iteratee, 'prototype');\n" + " propertyIsEnumerable.call(iterable, 'prototype');\n" +
' <% } %>' + ' <% } %>' +
// iterate own properties using `Object.keys` if it's fast // iterate own properties using `Object.keys` if it's fast
' <% if (isKeysFast && useHas) { %>\n' + ' <% if (isKeysFast && useHas) { %>\n' +
' var ownIndex = -1,\n' + ' var ownIndex = -1,\n' +
' ownProps = objectTypes[typeof iteratee] ? nativeKeys(iteratee) : [],\n' + ' ownProps = objectTypes[typeof iterable] ? nativeKeys(iterable) : [],\n' +
' length = ownProps.length;\n\n' + ' length = ownProps.length;\n\n' +
' while (++ownIndex < length) {\n' + ' while (++ownIndex < length) {\n' +
' index = ownProps[ownIndex];\n' + ' index = ownProps[ownIndex];\n' +
@@ -404,11 +404,11 @@
// else using a for-in loop // else using a for-in loop
' <% } else { %>\n' + ' <% } else { %>\n' +
' for (index in iteratee) {<%' + ' for (index in iterable) {<%' +
' if (!hasDontEnumBug || useHas) { %>\n if (<%' + ' if (!hasDontEnumBug || useHas) { %>\n if (<%' +
" if (!hasDontEnumBug) { %>!(skipProto && index == 'prototype')<% }" + " if (!hasDontEnumBug) { %>!(skipProto && index == 'prototype')<% }" +
' if (!hasDontEnumBug && useHas) { %> && <% }' + ' if (!hasDontEnumBug && useHas) { %> && <% }' +
' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' + ' if (useHas) { %>hasOwnProperty.call(iterable, index)<% }' +
' %>) {' + ' %>) {' +
' <% } %>\n' + ' <% } %>\n' +
' <%= loop %>;' + ' <%= loop %>;' +
@@ -421,13 +421,13 @@
// defaults to non-enumerable, Lo-Dash skips the `constructor` // defaults to non-enumerable, Lo-Dash skips the `constructor`
// property when it infers it's iterating over a `prototype` object. // property when it infers it's iterating over a `prototype` object.
' <% if (hasDontEnumBug) { %>\n\n' + ' <% if (hasDontEnumBug) { %>\n\n' +
' var ctor = iteratee.constructor;\n' + ' var ctor = iterable.constructor;\n' +
' <% for (var k = 0; k < 7; k++) { %>\n' + ' <% for (var k = 0; k < 7; k++) { %>\n' +
" index = '<%= shadowed[k] %>';\n" + " index = '<%= shadowed[k] %>';\n" +
' if (<%' + ' if (<%' +
" if (shadowed[k] == 'constructor') {" + " if (shadowed[k] == 'constructor') {" +
' %>!(ctor && ctor.prototype === iteratee) && <%' + ' %>!(ctor && ctor.prototype === iterable) && <%' +
' } %>hasOwnProperty.call(iteratee, index)) {\n' + ' } %>hasOwnProperty.call(iterable, index)) {\n' +
' <%= loop %>\n' + ' <%= loop %>\n' +
' }' + ' }' +
' <% } %>' + ' <% } %>' +
@@ -447,8 +447,8 @@
'var argsIndex = 0,\n' + 'var argsIndex = 0,\n' +
" argsLength = typeof guard == 'number' ? 2 : arguments.length;\n" + " argsLength = typeof guard == 'number' ? 2 : arguments.length;\n" +
'while (++argsIndex < argsLength) {\n' + 'while (++argsIndex < argsLength) {\n' +
' if ((iteratee = arguments[argsIndex])) {', ' if ((iterable = arguments[argsIndex])) {',
'loop': 'result[index] = iteratee[index]', 'loop': 'result[index] = iterable[index]',
'bottom': ' }\n}' 'bottom': ' }\n}'
}; };
@@ -457,7 +457,7 @@
'args': 'collection, callback, thisArg', 'args': 'collection, callback, thisArg',
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg)", 'top': "callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg)",
'arrays': "typeof length == 'number'", 'arrays': "typeof length == 'number'",
'loop': 'if (callback(iteratee[index], index, collection) === false) return result' 'loop': 'if (callback(iterable[index], index, collection) === false) return result'
}; };
/** Reusable iterator options for `forIn` and `forOwn` */ /** Reusable iterator options for `forIn` and `forOwn` */
@@ -653,7 +653,7 @@
* *
* @private * @private
* @param {Object} [options1, options2, ...] The compile options object(s). * @param {Object} [options1, options2, ...] The compile options object(s).
* arrays - A string of code to determine if the iteratee is an array or array-like. * arrays - A string of code to determine if the iterable is an array or array-like.
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop. * useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
* args - A string of comma separated arguments the iteration function will accept. * args - A string of comma separated arguments the iteration function will accept.
* top - A string of code to execute before the iteration branches. * top - A string of code to execute before the iteration branches.
@@ -672,7 +672,7 @@
'shadowed': shadowed, 'shadowed': shadowed,
// iterator options // iterator options
'arrays': 'isArray(iteratee)', 'arrays': 'isArray(iterable)',
'bottom': '', 'bottom': '',
'loop': '', 'loop': '',
'top': '', 'top': '',
@@ -2552,7 +2552,7 @@
* // => [4, 5, 2, 3, 0, 1] * // => [4, 5, 2, 3, 0, 1]
*/ */
function reduceRight(collection, callback, accumulator, thisArg) { function reduceRight(collection, callback, accumulator, thisArg) {
var iteratee = collection, var iterable = collection,
length = collection ? collection.length : 0, length = collection ? collection.length : 0,
noaccum = arguments.length < 3; noaccum = arguments.length < 3;
@@ -2560,14 +2560,14 @@
var props = keys(collection); var props = keys(collection);
length = props.length; length = props.length;
} else if (noCharByIndex && isString(collection)) { } else if (noCharByIndex && isString(collection)) {
iteratee = collection.split(''); iterable = collection.split('');
} }
callback = createCallback(callback, thisArg, indicatorObject); callback = createCallback(callback, thisArg, indicatorObject);
forEach(collection, function(value, index, collection) { forEach(collection, function(value, index, collection) {
index = props ? props[--length] : --length; index = props ? props[--length] : --length;
accumulator = noaccum accumulator = noaccum
? (noaccum = false, iteratee[index]) ? (noaccum = false, iterable[index])
: callback(accumulator, iteratee[index], index, collection); : callback(accumulator, iterable[index], index, collection);
}); });
return accumulator; return accumulator;
} }