Skip to content

Commit

Permalink
invokeCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekmarchi committed Dec 5, 2023
1 parent 13999c6 commit b200be5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions source/collection/invoke.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { mapArray } from '../arrays/map.js';
import { indexBy } from './indexBy';
/**
* Invokes a function on the provided property name in each object in the collection.
*
* @function invoke
* @function invokeCollection
* @category collection
* @type {Function}
* @param {Array} collection - Collection from which method will be taken.
Expand All @@ -11,10 +12,13 @@ import { mapArray } from '../arrays/map.js';
* @returns {Array} - Returns the results of the invoked method.
*
* @example
* invoke([{lucy(item, index) { return [item, index];}}, {lucy(item, index) { return [item, index];}}], 'lucy', 'EXAMPLE');
* // => [['EXAMPLE', 0], ['EXAMPLE', 1]]
* import { invokeCollection, assert } from '@universalweb/acid';
* const results = invokeCollection([{
* test(item, index) { return [item, index];}
* }], 'test', ['EXAMPLE']);
* assert(results, [['EXAMPLE', 0]]);
*/
export function invoke(collection, property, value) {
export function invokeCollection(collection, property, value) {
return mapArray(collection, (item, index) => {
return item[property](value, index);
});
Expand Down

0 comments on commit b200be5

Please sign in to comment.