mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add lazy invokeMap.
This commit is contained in:
@@ -14051,6 +14051,15 @@
|
||||
return this.reverse().find(predicate);
|
||||
};
|
||||
|
||||
LazyWrapper.prototype.invokeMap = rest(function(path, args) {
|
||||
if (typeof path == 'function') {
|
||||
return new LazyWrapper(this);
|
||||
}
|
||||
return this.map(function(value) {
|
||||
return baseInvokePath(value, path, args);
|
||||
});
|
||||
});
|
||||
|
||||
LazyWrapper.prototype.reject = function(predicate) {
|
||||
predicate = getIteratee(predicate, 3);
|
||||
return this.filter(function(value) {
|
||||
|
||||
21
test/test.js
21
test/test.js
@@ -7148,6 +7148,27 @@
|
||||
assert.deepEqual(_.invokeMap([object], path), [1]);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should support shortcut fusion', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
if (!isNpm) {
|
||||
var count = 0,
|
||||
method = function() { count++; return this.index; };
|
||||
|
||||
var array = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
|
||||
return { 'index': index, 'method': method };
|
||||
});
|
||||
|
||||
var actual = _(array).invokeMap('method').take(1).value();
|
||||
|
||||
assert.strictEqual(count, 1);
|
||||
assert.deepEqual(actual, [0]);
|
||||
}
|
||||
else {
|
||||
skipTest(assert, 2);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user