Skip to content

Commit

Permalink
map.series index
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericHeem authored and richytong committed Dec 15, 2023
1 parent 666f087 commit daec8ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions _internal/arrayMapSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const objectSet = require('./objectSet')
* arrayMapSeriesAsync<
* T any,
* array Array<T>,
* mapper T=>Promise|any,
* mapper (T,index)=>Promise|any,
* result Array,
* index number,
* >(array, mapper, result Array, index) -> Promise|result
Expand All @@ -27,7 +27,7 @@ const arrayMapSeriesAsync = async function (
) {
const arrayLength = array.length
while (++index < arrayLength) {
const resultItem = mapper(array[index])
const resultItem = mapper(array[index], index)
result[index] = isPromise(resultItem) ? await resultItem : resultItem
}
return result
Expand All @@ -41,7 +41,7 @@ const arrayMapSeriesAsync = async function (
* arrayMapSeries<
* T any,
* array Array<T>,
* mapper T=>Promise|any,
* mapper (T,index)=>Promise|any,
* >(array, mapper) -> mappedInSeries Promise|Array
* ```
*
Expand All @@ -54,7 +54,7 @@ const arrayMapSeries = function (array, mapper) {
let index = -1

while (++index < arrayLength) {
const resultItem = mapper(array[index])
const resultItem = mapper(array[index], index)
if (isPromise(resultItem)) {
return resultItem.then(funcConcat(
curry3(objectSet, result, index, __),
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,13 @@ describe('rubico', () => {
[1, 4, 9, 16, 25],
)
})
it('map.series index', async () => {
const square = (_number, index) => index
assert.deepEqual(
map.series(square)([1, 2, 4]),
[0, 1, 2],
)
})
})
it('syncly maps into array of functions', async () => {
const arr = []
Expand Down

0 comments on commit daec8ad

Please sign in to comment.