diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef62c587..47f12cc9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,15 @@
+10.3.4
+
+- Fix wrong typing for `R.sortByDescending` - [Issue #797](https://github.com/selfrefactor/rambda/issues/797)
+
+- Improve `R.mapParallelAsync` typings to allow optional `batchSize` parameter.
+
+- Change order of inputs in `R.mapPropObject`
+
+- Change REPL links in documentation
+
+- Remove `jsr.json`
+
10.3.3
- Fix wrong typing for `R.reject` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
diff --git a/README.md b/README.md
index eebbe342..927e5c96 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ const result = pipe(
//=> [6, 8]
```
-You can test this example in Rambda's REPL
+You can test this example in Rambda's REPL
* [API](#api)
* [Changelog](#-changelog)
@@ -183,7 +183,7 @@ const result = R.pipe(
// => { a: 1, b: 'foo', c: 3 }
```
-Try this R.addProp example in Rambda REPL
+Try this R.addProp example in Rambda REPL
@@ -278,7 +278,7 @@ const result = R.pipe(
// => [{a: 1, b: 2, c: '3'}, {a: 3, b: 4, c: '7'}]
```
-Try this R.addPropToObjects example in Rambda REPL
+Try this R.addPropToObjects example in Rambda REPL
@@ -393,7 +393,7 @@ const result = R.pipe(
) // => true
```
-Try this R.all example in Rambda REPL
+Try this R.all example in Rambda REPL
@@ -491,7 +491,7 @@ const result = R.pipe(
) // => [[1, 2, 3, 4]]
```
-Try this R.allPass example in Rambda REPL
+Try this R.allPass example in Rambda REPL
@@ -591,7 +591,7 @@ R.any(predicate)(list)
// => true
```
-Try this R.any example in Rambda REPL
+Try this R.any example in Rambda REPL
@@ -688,7 +688,7 @@ const result = fn(input)
// => true
```
-Try this R.anyPass example in Rambda REPL
+Try this R.anyPass example in Rambda REPL
@@ -838,7 +838,7 @@ const result = R.append('foo')(['bar', 'baz'])
// => ['bar', 'baz', 'foo']
```
-Try this R.append example in Rambda REPL
+Try this R.append example in Rambda REPL
@@ -930,7 +930,7 @@ const result = R.pipe(
// => [{a: 0}, {a: 1}, {a: 2}]
```
-Try this R.ascend example in Rambda REPL
+Try this R.ascend example in Rambda REPL
@@ -1136,7 +1136,7 @@ const result = condition(input)
// => true
```
-Try this R.checkObjectWithSpec example in Rambda REPL
+Try this R.checkObjectWithSpec example in Rambda REPL
@@ -1272,7 +1272,7 @@ const result = R.pipe(
// => { a: ['a', 'b', 'c'], b: [1, 2, 3], c: { a: 1, b: 2, c: 0, f: false } }
```
-Try this R.compact example in Rambda REPL
+Try this R.compact example in Rambda REPL
@@ -1392,7 +1392,7 @@ const result = [
] => [ true, false ]
```
-Try this R.complement example in Rambda REPL
+Try this R.complement example in Rambda REPL
@@ -1473,7 +1473,7 @@ R.concat([1, 2])([3, 4]) // => [1, 2, 3, 4]
R.concat('foo')('bar') // => 'foobar'
```
-Try this R.concat example in Rambda REPL
+Try this R.concat example in Rambda REPL
@@ -1592,7 +1592,7 @@ const result = R.count(x => x.a !== undefined)(list)
// => 2
```
-Try this R.count example in Rambda REPL
+Try this R.count example in Rambda REPL
@@ -1683,7 +1683,7 @@ const expected = { a: 2, b: 2, c: 2 }
// => `result` is equal to `expected`
```
-Try this R.countBy example in Rambda REPL
+Try this R.countBy example in Rambda REPL
@@ -1781,7 +1781,7 @@ const result = R.createObjectFromKeys(
// => {a: 'a-0', b: 'b-1', c: 'c-2'}
```
-Try this R.createObjectFromKeys example in Rambda REPL
+Try this R.createObjectFromKeys example in Rambda REPL
@@ -1857,7 +1857,7 @@ R.defaultTo('foo'))(undefined) // => 'foo'
R.defaultTo('foo')('') // => 'foo'
```
-Try this R.defaultTo example in Rambda REPL
+Try this R.defaultTo example in Rambda REPL
@@ -1956,7 +1956,7 @@ const result = R.pipe(
// => [{a: 2}, {a: 1}, {a: 0}]
```
-Try this R.descend example in Rambda REPL
+Try this R.descend example in Rambda REPL
@@ -2002,7 +2002,7 @@ It returns `howMany` items dropped from beginning of list.
R.drop(2)(['foo', 'bar', 'baz']) // => ['baz']
```
-Try this R.drop example in Rambda REPL
+Try this R.drop example in Rambda REPL
@@ -2135,7 +2135,7 @@ const result = dropLastWhile(predicate)(list);
// => [1, 2]
```
-Try this R.dropLastWhile example in Rambda REPL
+Try this R.dropLastWhile example in Rambda REPL
@@ -2219,7 +2219,7 @@ const result = R.dropRepeatsBy(
// => [1, 2, 3]
```
-Try this R.dropRepeatsBy example in Rambda REPL
+Try this R.dropRepeatsBy example in Rambda REPL
@@ -2247,7 +2247,7 @@ const result = R.dropRepeatsWith(R.prop('a'))(list)
// => [{a:1,b:2}, {a:2, b:4}]
```
-Try this R.dropRepeatsWith example in Rambda REPL
+Try this R.dropRepeatsWith example in Rambda REPL
@@ -2275,7 +2275,7 @@ const result = R.dropWhile(predicate)(list)
// => [3, 4]
```
-Try this R.dropWhile example in Rambda REPL
+Try this R.dropWhile example in Rambda REPL
@@ -2394,7 +2394,7 @@ const result = R.duplicateBy(x => x, list)
// => [{a:1}]
```
-Try this R.duplicateBy example in Rambda REPL
+Try this R.duplicateBy example in Rambda REPL
@@ -2462,7 +2462,7 @@ const result = R.eqBy(Math.abs, 5)(-5)
// => true
```
-Try this R.eqBy example in Rambda REPL
+Try this R.eqBy example in Rambda REPL
@@ -2531,7 +2531,7 @@ const result = R.eqProps('a', obj1)(obj2)
// => true
```
-Try this R.eqProps example in Rambda REPL
+Try this R.eqProps example in Rambda REPL
@@ -2630,7 +2630,7 @@ R.equals(
) // => true
```
-Try this R.equals example in Rambda REPL
+Try this R.equals example in Rambda REPL
@@ -3122,7 +3122,7 @@ const result = R.pipe(
// => result is { foo: 3, baz: 'baz' }
```
-Try this R.evolve example in Rambda REPL
+Try this R.evolve example in Rambda REPL
@@ -3228,7 +3228,7 @@ const result = [
// => [true, true ]
```
-Try this R.excludes example in Rambda REPL
+Try this R.excludes example in Rambda REPL
@@ -3321,7 +3321,7 @@ const result = R.filter(predicate)(list)
// => [2, 3]
```
-Try this R.filter example in Rambda REPL
+Try this R.filter example in Rambda REPL
@@ -3583,7 +3583,7 @@ const result = R.filterObject(
// => {a: 1, c: 3}
```
-Try this R.filterObject example in Rambda REPL
+Try this R.filterObject example in Rambda REPL
@@ -3691,7 +3691,7 @@ const result = R.find(predicate)(list)
// => {foo: 1}
```
-Try this R.find example in Rambda REPL
+Try this R.find example in Rambda REPL
@@ -3795,7 +3795,7 @@ const result = R.findIndex(predicate)(list)
// => 1
```
-Try this R.findIndex example in Rambda REPL
+Try this R.findIndex example in Rambda REPL
@@ -3890,7 +3890,7 @@ const result = R.findLast(predicate)(list)
// => {foo: 1}
```
-Try this R.findLast example in Rambda REPL
+Try this R.findLast example in Rambda REPL
@@ -3945,7 +3945,7 @@ const result = R.findLastIndex(predicate)(list)
// => 1
```
-Try this R.findLastIndex example in Rambda REPL
+Try this R.findLastIndex example in Rambda REPL
@@ -4034,7 +4034,7 @@ const result = R.findNth(predicate, 2)(list)
// => {foo: 2}
```
-Try this R.findNth example in Rambda REPL
+Try this R.findNth example in Rambda REPL
@@ -4112,7 +4112,7 @@ const result = R.flatMap(duplicate)(list)
// => [ 1, 1, 2, 2, 3, 3 ]
```
-Try this R.flatMap example in Rambda REPL
+Try this R.flatMap example in Rambda REPL
@@ -4233,7 +4233,7 @@ const result = R.flatten([
// => [ 1, 2, 3, 30, 300, 4 ]
```
-Try this R.flatten example in Rambda REPL
+Try this R.flatten example in Rambda REPL
@@ -4331,7 +4331,7 @@ const result = R.flattenObject(
// => [3, 1, 2] or [2, 3, 1] or ...
```
-Try this R.flattenObject example in Rambda REPL
+Try this R.flattenObject example in Rambda REPL
@@ -4555,7 +4555,7 @@ const result = R.groupBy(groupFn, list)
// => { '1': ['a', 'b'], '2': ['aa', 'bb'] }
```
-Try this R.groupBy example in Rambda REPL
+Try this R.groupBy example in Rambda REPL
@@ -4672,7 +4672,7 @@ const result = [
// => [1, 'f']
```
-Try this R.head example in Rambda REPL
+Try this R.head example in Rambda REPL
@@ -4795,7 +4795,7 @@ const result = [
// => [true, true ]
```
-Try this R.includes example in Rambda REPL
+Try this R.includes example in Rambda REPL
@@ -4927,7 +4927,7 @@ const result = R.indexBy(
// => {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
```
-Try this R.indexBy example in Rambda REPL
+Try this R.indexBy example in Rambda REPL
@@ -5029,7 +5029,7 @@ const result = [
// => [0, 1]
```
-Try this R.indexOf example in Rambda REPL
+Try this R.indexOf example in Rambda REPL
@@ -5129,7 +5129,7 @@ const result = [
// => [[1, 2], 'fo']
```
-Try this R.init example in Rambda REPL
+Try this R.init example in Rambda REPL
@@ -5235,7 +5235,7 @@ const result = R.innerJoin(predicate, list1)(list2)
// => [4, 5]
```
-Try this R.innerJoin example in Rambda REPL
+Try this R.innerJoin example in Rambda REPL
@@ -5357,7 +5357,7 @@ const expected = 'foo is BAR even 1 more'
// => `result` is equal to `expected`
```
-Try this R.interpolate example in Rambda REPL
+Try this R.interpolate example in Rambda REPL
@@ -5466,7 +5466,7 @@ const result = R.intersection(listA)(listB)
// => [{ id : 3 }, { id : 4 }]
```
-Try this R.intersection example in Rambda REPL
+Try this R.intersection example in Rambda REPL
@@ -5561,7 +5561,7 @@ const result = R.intersperse(separator)(list)
// => [0, 10, 1, 10, 2, 10, 3]
```
-Try this R.intersperse example in Rambda REPL
+Try this R.intersperse example in Rambda REPL
@@ -5656,7 +5656,7 @@ It returns a string of all `list` instances joined with a `glue`.
R.join('-', [1, 2, 3]) // => '1-2-3'
```
-Try this R.join example in Rambda REPL
+Try this R.join example in Rambda REPL
@@ -5721,7 +5721,7 @@ const result = [
// => [3, 'o']
```
-Try this R.last example in Rambda REPL
+Try this R.last example in Rambda REPL
@@ -5800,7 +5800,7 @@ const result = [
// => [4, -1]
```
-Try this R.lastIndexOf example in Rambda REPL
+Try this R.lastIndexOf example in Rambda REPL
@@ -5903,7 +5903,7 @@ const result = R.map(fn)(iterable),
// => [2, 4]
```
-Try this R.map example in Rambda REPL
+Try this R.map example in Rambda REPL
@@ -6022,7 +6022,7 @@ const result = await R.mapAsync(fn)([1, 2, 3])
// `result` resolves after 3 seconds to `[2, 3, 4]`
```
-Try this R.mapAsync example in Rambda REPL
+Try this R.mapAsync example in Rambda REPL
@@ -6166,7 +6166,7 @@ const result = R.mapKeys(
// => { A1: 1, B2: 2 }
```
-Try this R.mapKeys example in Rambda REPL
+Try this R.mapKeys example in Rambda REPL
@@ -6257,7 +6257,7 @@ const result = R.mapObject(fn)(obj)
// => {a: 'a-1', b: 'b-2'}
```
-Try this R.mapObject example in Rambda REPL
+Try this R.mapObject example in Rambda REPL
@@ -6493,22 +6493,22 @@ it('R.mapObjectAsync', async () => {
```typescript
mapParallelAsync(
- fn: (value: T[number], index: number) => Promise,
+ fn: (value: T[number]) => Promise,
+ batchSize?: number,
): (data: T) => Promise>
```
Wrapper around `Promise.all` for asynchronous mapping with `fn` over members of `list`.
+There is optional `batchSize` parameter to allow parallel execution to run in batches. In this case, the whole batch must complete before the next batch starts.
All TypeScript definitions
```typescript
-mapParallelAsync(
- fn: (value: T[number], index: number) => Promise,
-): (data: T) => Promise>;
mapParallelAsync(
fn: (value: T[number]) => Promise,
+ batchSize?: number,
): (data: T) => Promise>;
```
@@ -6519,8 +6519,18 @@ mapParallelAsync(
R.mapParallelAsync source
```javascript
-export function mapParallelAsync(fn) {
- return async list => Promise.all(list.map((x, i) => fn(x, i)))
+export function mapParallelAsync(fn, batchSize){
+ if(!batchSize) return async list => Promise.all(list.map(fn))
+
+ return async list => {
+ const result = []
+ for(let i = 0; i < list.length; i += batchSize){
+ const batch = list.slice(i, i + batchSize)
+ const batchResult = await Promise.all(batch.map((x, j) => fn(x, i + j)))
+ result.push(...batchResult)
+ }
+ return result
+ }
}
```
@@ -6556,6 +6566,17 @@ test('pipeAsync', async () => {
)
expect(result).toEqual([ 2,3,4 ])
})
+
+test('with batchSize', async () => {
+ const fn = async (x, i) => {
+ await delay(100)
+ return `${x}:${i}`
+ }
+ const result = await mapParallelAsync(fn, 2)([1, 2, 3, 4, 5])
+ expect(result).toEqual(
+ ['1:0', '2:1', '3:2', '4:3', '5:4']
+ )
+})
```
@@ -6566,46 +6587,53 @@ test('pipeAsync', async () => {
```typescript
-mapPropObject(
- valueMapper: (
- value: T[K] extends ReadonlyArray ? ElementType : never,
- data: T[K],
- ) => Value,
- prop: K,
+mapPropObject(
+ prop: K,
+ valueMapper: (
+ listItem: T[K] extends ReadonlyArray ? ElementType : never,
+ list: T[K] extends ReadonlyArray ? T[K] : never,
+ ) => Value,
): (data: T) => T[K] extends ReadonlyArray
- ? MergeTypes & { [P in K]: Value[] }>
- : never
+ ? MergeTypes & { [P in K]: Value[] }>
+ : never
```
-It maps over a property of object that is a list.
+Convenience method, when one needs to maps over a object property that is a list.
```javascript
const result = pipe(
{ a: [1,2,3], b: 'foo' },
- mapPropObject(x => {
- x // $ExpectType { a: number; b: string; }
+ mapPropObject('a',x => {
return {
a: x,
flag: x > 2,
}
- }, 'a'),
+ }),
)
// => { a: [{ a: 1, flag: false },{ a: 2, flag: false }, { a: 3, flag: true }], b: 'foo' }
```
-Try this R.mapPropObject example in Rambda REPL
+Try this R.mapPropObject example in Rambda REPL
All TypeScript definitions
```typescript
-mapPropObject(
+mapPropObject(
+ prop: K,
+ valueMapper: (
+ listItem: T[K] extends ReadonlyArray ? ElementType : never,
+ list: T[K] extends ReadonlyArray ? T[K] : never,
+ ) => Value,
+): (data: T) => T[K] extends ReadonlyArray
+ ? MergeTypes & { [P in K]: Value[] }>
+ : never;
+mapPropObject(
+ prop: K,
valueMapper: (
- value: T[K] extends ReadonlyArray ? ElementType : never,
- data: T[K],
+ listItem: T[K] extends ReadonlyArray ? ElementType : never,
) => Value,
- prop: K,
): (data: T) => T[K] extends ReadonlyArray
? MergeTypes & { [P in K]: Value[] }>
: never;
@@ -6664,24 +6692,52 @@ it('happy', () => {
TypeScript test
```typescript
-import { mapPropObject, pipe } from 'rambda'
+import { map, mapPropObject, pipe } from 'rambda'
describe('R.mapPropObject', () => {
it('iterable with one arguments', () => {
const result = pipe(
{ a: [1,2,3], b: 'foo' },
- mapPropObject(x => {
+ mapPropObject('a', x => {
x // $ExpectType number
return {
a: x,
flag: x > 2,
}
- }, 'a'),
+ }),
)
result.a // $ExpectType { a: number; flag: boolean; }[]
result.b // $ExpectType string
})
+
+ it('iterable with two arguments', () => {
+ const result = pipe(
+ { a: [1,2,3], b: 'foo' },
+ mapPropObject('a', (x, list) => {
+ x // $ExpectType number
+ list // $ExpectType number[]
+ return list.length
+ }),
+ )
+ result.a // $ExpectType number[]
+ result.b // $ExpectType string
+ })
+
+ it('more complex example', () => {
+ const result = pipe(
+ [{a:[true, false, true], b: 'foo'}],
+ map(
+ mapPropObject( 'a',(a) => {
+ a // $ExpectType boolean
+ return {a, b: 2}
+ })
+ )
+ )
+
+ result[0].a[0].a // $ExpectType boolean
+ result[0].a[0].b // $ExpectType number
+ })
})
```
@@ -6706,7 +6762,7 @@ const result = [
// => [[], ['ba', 'na', 'na']]
```
-Try this R.match example in Rambda REPL
+Try this R.match example in Rambda REPL
@@ -6792,7 +6848,7 @@ const compareFn = Math.abs
R.maxBy(compareFn, 5, -7) // => -7
```
-Try this R.maxBy example in Rambda REPL
+Try this R.maxBy example in Rambda REPL
@@ -6975,7 +7031,7 @@ const compareFn = Math.abs
R.minBy(compareFn, -5, 2) // => -5
```
-Try this R.minBy example in Rambda REPL
+Try this R.minBy example in Rambda REPL
@@ -7032,7 +7088,7 @@ const result = R.pipe(
) // => [1, 3, 3]
```
-Try this R.modifyItemAtIndex example in Rambda REPL
+Try this R.modifyItemAtIndex example in Rambda REPL
@@ -7113,7 +7169,7 @@ const result = R.modifyPath('a.b.c', x=> x+1, {a:{b: {c:1}}})
// => {a:{b: {c:2}}}
```
-Try this R.modifyPath example in Rambda REPL
+Try this R.modifyPath example in Rambda REPL
@@ -7256,7 +7312,7 @@ const result = R.modifyProp('age', x => x + 1)(person)
// => {name: 'foo', age: 21}
```
-Try this R.modifyProp example in Rambda REPL
+Try this R.modifyProp example in Rambda REPL
@@ -7379,7 +7435,7 @@ const result = R.none(predicate)(arr)
// => true
```
-Try this R.none example in Rambda REPL
+Try this R.none example in Rambda REPL
@@ -7475,7 +7531,7 @@ const result = objectIncludes(specification)(input)
// => true
```
-Try this R.objectIncludes example in Rambda REPL
+Try this R.objectIncludes example in Rambda REPL
@@ -7599,7 +7655,7 @@ const result = R.objOf('foo')('bar')
// => {foo: 'bar'}
```
-Try this R.objOf example in Rambda REPL
+Try this R.objOf example in Rambda REPL
@@ -7685,7 +7741,7 @@ const result = [
// => [{b: 2}, {b: 2}]
```
-Try this R.omit example in Rambda REPL
+Try this R.omit example in Rambda REPL
@@ -7827,7 +7883,7 @@ const expected = [[3], [1, 2]]
// `result` is equal to `expected`
```
-Try this R.partition example in Rambda REPL
+Try this R.partition example in Rambda REPL
@@ -7952,7 +8008,7 @@ const expected = [{c: 3}, {a: 1, b: 2}]
// `result` is equal to `expected`
```
-Try this R.partitionObject example in Rambda REPL
+Try this R.partitionObject example in Rambda REPL
@@ -8096,7 +8152,7 @@ const result = [
// => [1, 1, undefined]
```
-Try this R.path example in Rambda REPL
+Try this R.path example in Rambda REPL
@@ -8252,7 +8308,7 @@ const result = R.pathSatisfies(
// => true
```
-Try this R.pathSatisfies example in Rambda REPL
+Try this R.pathSatisfies example in Rambda REPL
@@ -8372,7 +8428,7 @@ const result = R.permutations(
// => [[1, 2], [2, 1]]
```
-Try this R.permutations example in Rambda REPL
+Try this R.permutations example in Rambda REPL
@@ -8475,7 +8531,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.pick example in Rambda REPL
+Try this R.pick example in Rambda REPL
@@ -8614,7 +8670,7 @@ const result = R.pipe(
// => [20, 30]
```
-Try this R.pipe example in Rambda REPL
+Try this R.pipe example in Rambda REPL
@@ -8967,7 +9023,7 @@ const result = await R.pipeAsync(
// `result` resolves to `RAMBDAX_DELAY104`
```
-Try this R.pipeAsync example in Rambda REPL
+Try this R.pipeAsync example in Rambda REPL
@@ -9083,7 +9139,7 @@ const result = R.pluck(property)(list)
// => [1, 2]
```
-Try this R.pluck example in Rambda REPL
+Try this R.pluck example in Rambda REPL
@@ -9189,7 +9245,7 @@ const result = R.prepend('foo', ['bar', 'baz'])
// => ['foo', 'bar', 'baz']
```
-Try this R.prepend example in Rambda REPL
+Try this R.prepend example in Rambda REPL
@@ -9253,7 +9309,7 @@ const result = [
// => [100, undefined]
```
-Try this R.prop example in Rambda REPL
+Try this R.prop example in Rambda REPL
@@ -9327,7 +9383,7 @@ const result = [
// => [true, false]
```
-Try this R.propEq example in Rambda REPL
+Try this R.propEq example in Rambda REPL
@@ -9413,7 +9469,7 @@ const result = [
// => [1, 'DEFAULT_VALUE']
```
-Try this R.propOr example in Rambda REPL
+Try this R.propOr example in Rambda REPL
@@ -9501,7 +9557,7 @@ const result = R.propSatisfies(predicate, property, obj)
// => true
```
-Try this R.propSatisfies example in Rambda REPL
+Try this R.propSatisfies example in Rambda REPL
@@ -9588,7 +9644,7 @@ If `start` is greater than `end`, then the result will be in descending order.
// => [[0, 1, 2, 3, 4], [5, 4, 3, 2, 1]]
```
-Try this R.range example in Rambda REPL
+Try this R.range example in Rambda REPL
@@ -9695,7 +9751,7 @@ const result = R.reduce(reducer, initialValue, list)
// => 60
```
-Try this R.reduce example in Rambda REPL
+Try this R.reduce example in Rambda REPL
@@ -9816,7 +9872,7 @@ const result = [
// => [[1], {a: 1}]
```
-Try this R.reject example in Rambda REPL
+Try this R.reject example in Rambda REPL
@@ -9969,7 +10025,7 @@ const result = R.rejectObject(
// => {b: 2}
```
-Try this R.rejectObject example in Rambda REPL
+Try this R.rejectObject example in Rambda REPL
@@ -10075,7 +10131,7 @@ const result = [
// => ['f|1|o', 'f|1||1|']
```
-Try this R.replace example in Rambda REPL
+Try this R.replace example in Rambda REPL
@@ -10158,7 +10214,7 @@ const result = [
// => 'f|1||1|'
```
-Try this R.replaceAll example in Rambda REPL
+Try this R.replaceAll example in Rambda REPL
@@ -10250,7 +10306,7 @@ const result = R.shuffle(
// => [3, 1, 2] or [2, 3, 1] or ...
```
-Try this R.shuffle example in Rambda REPL
+Try this R.shuffle example in Rambda REPL
@@ -10335,7 +10391,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sort example in Rambda REPL
+Try this R.sort example in Rambda REPL
@@ -10442,7 +10498,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sortBy example in Rambda REPL
+Try this R.sortBy example in Rambda REPL
@@ -10542,7 +10598,7 @@ describe('R.sortBy', () => {
```typescript
-sortByDescending(sortFn: (a: T, b: T) => number): (list: T[]) => T[]
+sortByDescending(sortFn: (x: T) => Ord): (list: T[]) => T[]
```
```javascript
@@ -10562,14 +10618,14 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sortByDescending example in Rambda REPL
+Try this R.sortByDescending example in Rambda REPL
All TypeScript definitions
```typescript
-sortByDescending(sortFn: (a: T, b: T) => number): (list: T[]) => T[];
+sortByDescending(sortFn: (x: T) => Ord): (list: T[]) => T[];
```
@@ -10588,6 +10644,24 @@ export function sortByDescending(sortFn) {
+
+
+Tests
+
+```javascript
+import { sortByDescending } from './sortByDescending.js'
+import { path } from './path.js'
+
+const list = [{ a: { b: 3 } }, { a: { b: 1 } }, { a: { b: 2 } }]
+const sorted = [{ a: { b: 3 } }, { a: { b: 2 } }, { a: { b: 1 } }]
+
+test('happy', () => {
+ expect(sortByDescending(path('a.b'))(list)).toEqual(sorted)
+})
+```
+
+
+
[](#sortByDescending)
### sortByPath
@@ -10616,7 +10690,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sortByPath example in Rambda REPL
+Try this R.sortByPath example in Rambda REPL
@@ -10737,7 +10811,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sortByPathDescending example in Rambda REPL
+Try this R.sortByPathDescending example in Rambda REPL
@@ -10816,7 +10890,7 @@ const result = R.sortObject(predicate)({a:1, b: 4, c: 2})
// => {b: 4, c: 2, a: 1}
```
-Try this R.sortObject example in Rambda REPL
+Try this R.sortObject example in Rambda REPL
@@ -10963,7 +11037,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sortWith example in Rambda REPL
+Try this R.sortWith example in Rambda REPL
@@ -11188,7 +11262,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.splitEvery example in Rambda REPL
+Try this R.splitEvery example in Rambda REPL
@@ -11279,7 +11353,7 @@ const result = R.symmetricDifference(x)(y)
// => [ 1, 2, 5, 6 ]
```
-Try this R.symmetricDifference example in Rambda REPL
+Try this R.symmetricDifference example in Rambda REPL
@@ -11376,7 +11450,7 @@ const result = [
// => [[2, 3], 'oo']
```
-Try this R.tail example in Rambda REPL
+Try this R.tail example in Rambda REPL
@@ -11475,7 +11549,7 @@ const result = [
// => [[1, 2], 'fo']
```
-Try this R.take example in Rambda REPL
+Try this R.take example in Rambda REPL
@@ -11568,7 +11642,7 @@ const result = [
// => [[2, 3], 'ar']
```
-Try this R.takeLast example in Rambda REPL
+Try this R.takeLast example in Rambda REPL
@@ -11656,7 +11730,7 @@ const result = R.takeLastWhile(x => x > 2)([1, 2, 3, 4])
// => [3, 4]
```
-Try this R.takeLastWhile example in Rambda REPL
+Try this R.takeLastWhile example in Rambda REPL
@@ -11745,7 +11819,7 @@ const result = R.takeWhile(predicate)(list)
// => [1, 2]
```
-Try this R.takeWhile example in Rambda REPL
+Try this R.takeWhile example in Rambda REPL
@@ -11855,7 +11929,7 @@ const result = R.pipe(
// => `2` and `3` will be logged
```
-Try this R.tap example in Rambda REPL
+Try this R.tap example in Rambda REPL
@@ -11899,7 +11973,7 @@ R.test(/^f/)('foo')
// => true
```
-Try this R.test example in Rambda REPL
+Try this R.test example in Rambda REPL
@@ -11977,7 +12051,7 @@ const result = R.transformPropObject(fn, 'a')(obj)
// => {a: false, b: 2}
```
-Try this R.transformPropObject example in Rambda REPL
+Try this R.transformPropObject example in Rambda REPL
@@ -12038,7 +12112,7 @@ const result = [
// => [false, 'bar']
```
-Try this R.tryCatch example in Rambda REPL
+Try this R.tryCatch example in Rambda REPL
@@ -12169,7 +12243,7 @@ const delay = ms => new Promise(resolve => {
R.type(delay) // => 'Promise'
```
-Try this R.type example in Rambda REPL
+Try this R.type example in Rambda REPL
@@ -12419,7 +12493,7 @@ const result = R.union([1,2,3])([3,4,5]);
// => [1, 2, 3, 4, 5]
```
-Try this R.union example in Rambda REPL
+Try this R.union example in Rambda REPL
@@ -12528,7 +12602,7 @@ R.uniq(list)
// => [1, {a: 1}, {a: 2}]
```
-Try this R.uniq example in Rambda REPL
+Try this R.uniq example in Rambda REPL
@@ -12635,7 +12709,7 @@ const result = R.uniqBy(x => x)(list)
// => [{a:1}, {a:2}]
```
-Try this R.uniqBy example in Rambda REPL
+Try this R.uniqBy example in Rambda REPL
@@ -12741,7 +12815,7 @@ const result = R.uniqWith(predicate)(list)
// => `result` is equal to `expected`
```
-Try this R.uniqWith example in Rambda REPL
+Try this R.uniqWith example in Rambda REPL
@@ -12892,7 +12966,7 @@ const result = [
// => [11, 5]
```
-Try this R.unless example in Rambda REPL
+Try this R.unless example in Rambda REPL
@@ -13007,7 +13081,7 @@ const expected = [{a:1, b:2}, {a:1, b:3}]
// => `result` is equal to `expected`
```
-Try this R.unwind example in Rambda REPL
+Try this R.unwind example in Rambda REPL
@@ -13116,7 +13190,7 @@ const result = R.update(index, newValue)(list)
// => [1, 2, 88, 4, 5]
```
-Try this R.update example in Rambda REPL
+Try this R.update example in Rambda REPL
@@ -13217,7 +13291,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.when example in Rambda REPL
+Try this R.when example in Rambda REPL
@@ -13335,7 +13409,7 @@ R.zip([...x, 3])(['A', 'B'])
// => [[1, 'A'], [2, 'B']]
```
-Try this R.zip example in Rambda REPL
+Try this R.zip example in Rambda REPL
@@ -13453,7 +13527,7 @@ const result = R.zipWith((x, y) => x + y, list1)(list2)
// => [110, 220]
```
-Try this R.zipWith example in Rambda REPL
+Try this R.zipWith example in Rambda REPL
@@ -13542,6 +13616,14 @@ describe('R.zipWith', () => {
## ❯ CHANGELOG
+10.3.4
+
+- Fix wrong typing for `R.sortByDescending` - [Issue #797](https://github.com/selfrefactor/rambda/issues/797)
+
+- Improve `R.mapParallelAsync` typings to allow optional `batchSize` parameter.
+
+- Change order of inputs in `R.mapPropObject`
+
10.3.3
- Fix wrong typing for `R.reject` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
diff --git a/deno.json b/deno.json
index 0efb4ed4..8a8cddbf 100644
--- a/deno.json
+++ b/deno.json
@@ -1,6 +1,6 @@
{
"name": "@rambda/rambda",
- "version": "10.3.3",
+ "version": "10.3.4",
"exports": "./mod.ts",
"imports": {
"rambda": "./mod.ts"
diff --git a/dist/rambda.cjs b/dist/rambda.cjs
index f353c2aa..1cf98995 100644
--- a/dist/rambda.cjs
+++ b/dist/rambda.cjs
@@ -1044,8 +1044,18 @@ function mapObjectAsync(fn) {
}
}
-function mapParallelAsync(fn) {
- return async list => Promise.all(list.map((x, i) => fn(x, i)))
+function mapParallelAsync(fn, batchSize){
+ if(!batchSize) return async list => Promise.all(list.map(fn))
+
+ return async list => {
+ const result = [];
+ for(let i = 0; i < list.length; i += batchSize){
+ const batch = list.slice(i, i + batchSize);
+ const batchResult = await Promise.all(batch.map((x, j) => fn(x, i + j)));
+ result.push(...batchResult);
+ }
+ return result
+ }
}
function mapPropObject(fn, prop) {
diff --git a/dist/rambda.js b/dist/rambda.js
index 8bb98b3a..cb7bccb9 100644
--- a/dist/rambda.js
+++ b/dist/rambda.js
@@ -1042,8 +1042,18 @@ function mapObjectAsync(fn) {
}
}
-function mapParallelAsync(fn) {
- return async list => Promise.all(list.map((x, i) => fn(x, i)))
+function mapParallelAsync(fn, batchSize){
+ if(!batchSize) return async list => Promise.all(list.map(fn))
+
+ return async list => {
+ const result = [];
+ for(let i = 0; i < list.length; i += batchSize){
+ const batch = list.slice(i, i + batchSize);
+ const batchResult = await Promise.all(batch.map((x, j) => fn(x, i + j)));
+ result.push(...batchResult);
+ }
+ return result
+ }
}
function mapPropObject(fn, prop) {
diff --git a/dist/rambda.umd.js b/dist/rambda.umd.js
index 0d35ec22..777dc450 100644
--- a/dist/rambda.umd.js
+++ b/dist/rambda.umd.js
@@ -1048,8 +1048,18 @@
}
}
- function mapParallelAsync(fn) {
- return async list => Promise.all(list.map((x, i) => fn(x, i)))
+ function mapParallelAsync(fn, batchSize){
+ if(!batchSize) return async list => Promise.all(list.map(fn))
+
+ return async list => {
+ const result = [];
+ for(let i = 0; i < list.length; i += batchSize){
+ const batch = list.slice(i, i + batchSize);
+ const batchResult = await Promise.all(batch.map((x, j) => fn(x, i + j)));
+ result.push(...batchResult);
+ }
+ return result
+ }
}
function mapPropObject(fn, prop) {
diff --git a/docs/README.md b/docs/README.md
index eebbe342..927e5c96 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -21,7 +21,7 @@ const result = pipe(
//=> [6, 8]
```
-You can test this example in Rambda's REPL
+You can test this example in Rambda's REPL
* [API](#api)
* [Changelog](#-changelog)
@@ -183,7 +183,7 @@ const result = R.pipe(
// => { a: 1, b: 'foo', c: 3 }
```
-Try this R.addProp example in Rambda REPL
+Try this R.addProp example in Rambda REPL
@@ -278,7 +278,7 @@ const result = R.pipe(
// => [{a: 1, b: 2, c: '3'}, {a: 3, b: 4, c: '7'}]
```
-Try this R.addPropToObjects example in Rambda REPL
+Try this R.addPropToObjects example in Rambda REPL
@@ -393,7 +393,7 @@ const result = R.pipe(
) // => true
```
-Try this R.all example in Rambda REPL
+Try this R.all example in Rambda REPL
@@ -491,7 +491,7 @@ const result = R.pipe(
) // => [[1, 2, 3, 4]]
```
-Try this R.allPass example in Rambda REPL
+Try this R.allPass example in Rambda REPL
@@ -591,7 +591,7 @@ R.any(predicate)(list)
// => true
```
-Try this R.any example in Rambda REPL
+Try this R.any example in Rambda REPL
@@ -688,7 +688,7 @@ const result = fn(input)
// => true
```
-Try this R.anyPass example in Rambda REPL
+Try this R.anyPass example in Rambda REPL
@@ -838,7 +838,7 @@ const result = R.append('foo')(['bar', 'baz'])
// => ['bar', 'baz', 'foo']
```
-Try this R.append example in Rambda REPL
+Try this R.append example in Rambda REPL
@@ -930,7 +930,7 @@ const result = R.pipe(
// => [{a: 0}, {a: 1}, {a: 2}]
```
-Try this R.ascend example in Rambda REPL
+Try this R.ascend example in Rambda REPL
@@ -1136,7 +1136,7 @@ const result = condition(input)
// => true
```
-Try this R.checkObjectWithSpec example in Rambda REPL
+Try this R.checkObjectWithSpec example in Rambda REPL
@@ -1272,7 +1272,7 @@ const result = R.pipe(
// => { a: ['a', 'b', 'c'], b: [1, 2, 3], c: { a: 1, b: 2, c: 0, f: false } }
```
-Try this R.compact example in Rambda REPL
+Try this R.compact example in Rambda REPL
@@ -1392,7 +1392,7 @@ const result = [
] => [ true, false ]
```
-Try this R.complement example in Rambda REPL
+Try this R.complement example in Rambda REPL
@@ -1473,7 +1473,7 @@ R.concat([1, 2])([3, 4]) // => [1, 2, 3, 4]
R.concat('foo')('bar') // => 'foobar'
```
-Try this R.concat example in Rambda REPL
+Try this R.concat example in Rambda REPL
@@ -1592,7 +1592,7 @@ const result = R.count(x => x.a !== undefined)(list)
// => 2
```
-Try this R.count example in Rambda REPL
+Try this R.count example in Rambda REPL
@@ -1683,7 +1683,7 @@ const expected = { a: 2, b: 2, c: 2 }
// => `result` is equal to `expected`
```
-Try this R.countBy example in Rambda REPL
+Try this R.countBy example in Rambda REPL
@@ -1781,7 +1781,7 @@ const result = R.createObjectFromKeys(
// => {a: 'a-0', b: 'b-1', c: 'c-2'}
```
-Try this R.createObjectFromKeys example in Rambda REPL
+Try this R.createObjectFromKeys example in Rambda REPL
@@ -1857,7 +1857,7 @@ R.defaultTo('foo'))(undefined) // => 'foo'
R.defaultTo('foo')('') // => 'foo'
```
-Try this R.defaultTo example in Rambda REPL
+Try this R.defaultTo example in Rambda REPL
@@ -1956,7 +1956,7 @@ const result = R.pipe(
// => [{a: 2}, {a: 1}, {a: 0}]
```
-Try this R.descend example in Rambda REPL
+Try this R.descend example in Rambda REPL
@@ -2002,7 +2002,7 @@ It returns `howMany` items dropped from beginning of list.
R.drop(2)(['foo', 'bar', 'baz']) // => ['baz']
```
-Try this R.drop example in Rambda REPL
+Try this R.drop example in Rambda REPL
@@ -2135,7 +2135,7 @@ const result = dropLastWhile(predicate)(list);
// => [1, 2]
```
-Try this R.dropLastWhile example in Rambda REPL
+Try this R.dropLastWhile example in Rambda REPL
@@ -2219,7 +2219,7 @@ const result = R.dropRepeatsBy(
// => [1, 2, 3]
```
-Try this R.dropRepeatsBy example in Rambda REPL
+Try this R.dropRepeatsBy example in Rambda REPL
@@ -2247,7 +2247,7 @@ const result = R.dropRepeatsWith(R.prop('a'))(list)
// => [{a:1,b:2}, {a:2, b:4}]
```
-Try this R.dropRepeatsWith example in Rambda REPL
+Try this R.dropRepeatsWith example in Rambda REPL
@@ -2275,7 +2275,7 @@ const result = R.dropWhile(predicate)(list)
// => [3, 4]
```
-Try this R.dropWhile example in Rambda REPL
+Try this R.dropWhile example in Rambda REPL
@@ -2394,7 +2394,7 @@ const result = R.duplicateBy(x => x, list)
// => [{a:1}]
```
-Try this R.duplicateBy example in Rambda REPL
+Try this R.duplicateBy example in Rambda REPL
@@ -2462,7 +2462,7 @@ const result = R.eqBy(Math.abs, 5)(-5)
// => true
```
-Try this R.eqBy example in Rambda REPL
+Try this R.eqBy example in Rambda REPL
@@ -2531,7 +2531,7 @@ const result = R.eqProps('a', obj1)(obj2)
// => true
```
-Try this R.eqProps example in Rambda REPL
+Try this R.eqProps example in Rambda REPL
@@ -2630,7 +2630,7 @@ R.equals(
) // => true
```
-Try this R.equals example in Rambda REPL
+Try this R.equals example in Rambda REPL
@@ -3122,7 +3122,7 @@ const result = R.pipe(
// => result is { foo: 3, baz: 'baz' }
```
-Try this R.evolve example in Rambda REPL
+Try this R.evolve example in Rambda REPL
@@ -3228,7 +3228,7 @@ const result = [
// => [true, true ]
```
-Try this R.excludes example in Rambda REPL
+Try this R.excludes example in Rambda REPL
@@ -3321,7 +3321,7 @@ const result = R.filter(predicate)(list)
// => [2, 3]
```
-Try this R.filter example in Rambda REPL
+Try this R.filter example in Rambda REPL
@@ -3583,7 +3583,7 @@ const result = R.filterObject(
// => {a: 1, c: 3}
```
-Try this R.filterObject example in Rambda REPL
+Try this R.filterObject example in Rambda REPL
@@ -3691,7 +3691,7 @@ const result = R.find(predicate)(list)
// => {foo: 1}
```
-Try this R.find example in Rambda REPL
+Try this R.find example in Rambda REPL
@@ -3795,7 +3795,7 @@ const result = R.findIndex(predicate)(list)
// => 1
```
-Try this R.findIndex example in Rambda REPL
+Try this R.findIndex example in Rambda REPL
@@ -3890,7 +3890,7 @@ const result = R.findLast(predicate)(list)
// => {foo: 1}
```
-Try this R.findLast example in Rambda REPL
+Try this R.findLast example in Rambda REPL
@@ -3945,7 +3945,7 @@ const result = R.findLastIndex(predicate)(list)
// => 1
```
-Try this R.findLastIndex example in Rambda REPL
+Try this R.findLastIndex example in Rambda REPL
@@ -4034,7 +4034,7 @@ const result = R.findNth(predicate, 2)(list)
// => {foo: 2}
```
-Try this R.findNth example in Rambda REPL
+Try this R.findNth example in Rambda REPL
@@ -4112,7 +4112,7 @@ const result = R.flatMap(duplicate)(list)
// => [ 1, 1, 2, 2, 3, 3 ]
```
-Try this R.flatMap example in Rambda REPL
+Try this R.flatMap example in Rambda REPL
@@ -4233,7 +4233,7 @@ const result = R.flatten([
// => [ 1, 2, 3, 30, 300, 4 ]
```
-Try this R.flatten example in Rambda REPL
+Try this R.flatten example in Rambda REPL
@@ -4331,7 +4331,7 @@ const result = R.flattenObject(
// => [3, 1, 2] or [2, 3, 1] or ...
```
-Try this R.flattenObject example in Rambda REPL
+Try this R.flattenObject example in Rambda REPL
@@ -4555,7 +4555,7 @@ const result = R.groupBy(groupFn, list)
// => { '1': ['a', 'b'], '2': ['aa', 'bb'] }
```
-Try this R.groupBy example in Rambda REPL
+Try this R.groupBy example in Rambda REPL
@@ -4672,7 +4672,7 @@ const result = [
// => [1, 'f']
```
-Try this R.head example in Rambda REPL
+Try this R.head example in Rambda REPL
@@ -4795,7 +4795,7 @@ const result = [
// => [true, true ]
```
-Try this R.includes example in Rambda REPL
+Try this R.includes example in Rambda REPL
@@ -4927,7 +4927,7 @@ const result = R.indexBy(
// => {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
```
-Try this R.indexBy example in Rambda REPL
+Try this R.indexBy example in Rambda REPL
@@ -5029,7 +5029,7 @@ const result = [
// => [0, 1]
```
-Try this R.indexOf example in Rambda REPL
+Try this R.indexOf example in Rambda REPL
@@ -5129,7 +5129,7 @@ const result = [
// => [[1, 2], 'fo']
```
-Try this R.init example in Rambda REPL
+Try this R.init example in Rambda REPL
@@ -5235,7 +5235,7 @@ const result = R.innerJoin(predicate, list1)(list2)
// => [4, 5]
```
-Try this R.innerJoin example in Rambda REPL
+Try this R.innerJoin example in Rambda REPL
@@ -5357,7 +5357,7 @@ const expected = 'foo is BAR even 1 more'
// => `result` is equal to `expected`
```
-Try this R.interpolate example in Rambda REPL
+Try this R.interpolate example in Rambda REPL
@@ -5466,7 +5466,7 @@ const result = R.intersection(listA)(listB)
// => [{ id : 3 }, { id : 4 }]
```
-Try this R.intersection example in Rambda REPL
+Try this R.intersection example in Rambda REPL
@@ -5561,7 +5561,7 @@ const result = R.intersperse(separator)(list)
// => [0, 10, 1, 10, 2, 10, 3]
```
-Try this R.intersperse example in Rambda REPL
+Try this R.intersperse example in Rambda REPL
@@ -5656,7 +5656,7 @@ It returns a string of all `list` instances joined with a `glue`.
R.join('-', [1, 2, 3]) // => '1-2-3'
```
-Try this R.join example in Rambda REPL
+Try this R.join example in Rambda REPL
@@ -5721,7 +5721,7 @@ const result = [
// => [3, 'o']
```
-Try this R.last example in Rambda REPL
+Try this R.last example in Rambda REPL
@@ -5800,7 +5800,7 @@ const result = [
// => [4, -1]
```
-Try this R.lastIndexOf example in Rambda REPL
+Try this R.lastIndexOf example in Rambda REPL
@@ -5903,7 +5903,7 @@ const result = R.map(fn)(iterable),
// => [2, 4]
```
-Try this R.map example in Rambda REPL
+Try this R.map example in Rambda REPL
@@ -6022,7 +6022,7 @@ const result = await R.mapAsync(fn)([1, 2, 3])
// `result` resolves after 3 seconds to `[2, 3, 4]`
```
-Try this R.mapAsync example in Rambda REPL
+Try this R.mapAsync example in Rambda REPL
@@ -6166,7 +6166,7 @@ const result = R.mapKeys(
// => { A1: 1, B2: 2 }
```
-Try this R.mapKeys example in Rambda REPL
+Try this R.mapKeys example in Rambda REPL
@@ -6257,7 +6257,7 @@ const result = R.mapObject(fn)(obj)
// => {a: 'a-1', b: 'b-2'}
```
-Try this R.mapObject example in Rambda REPL
+Try this R.mapObject example in Rambda REPL
@@ -6493,22 +6493,22 @@ it('R.mapObjectAsync', async () => {
```typescript
mapParallelAsync(
- fn: (value: T[number], index: number) => Promise,
+ fn: (value: T[number]) => Promise,
+ batchSize?: number,
): (data: T) => Promise>
```
Wrapper around `Promise.all` for asynchronous mapping with `fn` over members of `list`.
+There is optional `batchSize` parameter to allow parallel execution to run in batches. In this case, the whole batch must complete before the next batch starts.
All TypeScript definitions
```typescript
-mapParallelAsync(
- fn: (value: T[number], index: number) => Promise,
-): (data: T) => Promise>;
mapParallelAsync(
fn: (value: T[number]) => Promise,
+ batchSize?: number,
): (data: T) => Promise>;
```
@@ -6519,8 +6519,18 @@ mapParallelAsync(
R.mapParallelAsync source
```javascript
-export function mapParallelAsync(fn) {
- return async list => Promise.all(list.map((x, i) => fn(x, i)))
+export function mapParallelAsync(fn, batchSize){
+ if(!batchSize) return async list => Promise.all(list.map(fn))
+
+ return async list => {
+ const result = []
+ for(let i = 0; i < list.length; i += batchSize){
+ const batch = list.slice(i, i + batchSize)
+ const batchResult = await Promise.all(batch.map((x, j) => fn(x, i + j)))
+ result.push(...batchResult)
+ }
+ return result
+ }
}
```
@@ -6556,6 +6566,17 @@ test('pipeAsync', async () => {
)
expect(result).toEqual([ 2,3,4 ])
})
+
+test('with batchSize', async () => {
+ const fn = async (x, i) => {
+ await delay(100)
+ return `${x}:${i}`
+ }
+ const result = await mapParallelAsync(fn, 2)([1, 2, 3, 4, 5])
+ expect(result).toEqual(
+ ['1:0', '2:1', '3:2', '4:3', '5:4']
+ )
+})
```
@@ -6566,46 +6587,53 @@ test('pipeAsync', async () => {
```typescript
-mapPropObject(
- valueMapper: (
- value: T[K] extends ReadonlyArray ? ElementType : never,
- data: T[K],
- ) => Value,
- prop: K,
+mapPropObject(
+ prop: K,
+ valueMapper: (
+ listItem: T[K] extends ReadonlyArray ? ElementType : never,
+ list: T[K] extends ReadonlyArray ? T[K] : never,
+ ) => Value,
): (data: T) => T[K] extends ReadonlyArray
- ? MergeTypes & { [P in K]: Value[] }>
- : never
+ ? MergeTypes & { [P in K]: Value[] }>
+ : never
```
-It maps over a property of object that is a list.
+Convenience method, when one needs to maps over a object property that is a list.
```javascript
const result = pipe(
{ a: [1,2,3], b: 'foo' },
- mapPropObject(x => {
- x // $ExpectType { a: number; b: string; }
+ mapPropObject('a',x => {
return {
a: x,
flag: x > 2,
}
- }, 'a'),
+ }),
)
// => { a: [{ a: 1, flag: false },{ a: 2, flag: false }, { a: 3, flag: true }], b: 'foo' }
```
-Try this R.mapPropObject example in Rambda REPL
+Try this R.mapPropObject example in Rambda REPL
All TypeScript definitions
```typescript
-mapPropObject(
+mapPropObject(
+ prop: K,
+ valueMapper: (
+ listItem: T[K] extends ReadonlyArray ? ElementType : never,
+ list: T[K] extends ReadonlyArray ? T[K] : never,
+ ) => Value,
+): (data: T) => T[K] extends ReadonlyArray
+ ? MergeTypes & { [P in K]: Value[] }>
+ : never;
+mapPropObject(
+ prop: K,
valueMapper: (
- value: T[K] extends ReadonlyArray ? ElementType : never,
- data: T[K],
+ listItem: T[K] extends ReadonlyArray ? ElementType : never,
) => Value,
- prop: K,
): (data: T) => T[K] extends ReadonlyArray
? MergeTypes & { [P in K]: Value[] }>
: never;
@@ -6664,24 +6692,52 @@ it('happy', () => {
TypeScript test
```typescript
-import { mapPropObject, pipe } from 'rambda'
+import { map, mapPropObject, pipe } from 'rambda'
describe('R.mapPropObject', () => {
it('iterable with one arguments', () => {
const result = pipe(
{ a: [1,2,3], b: 'foo' },
- mapPropObject(x => {
+ mapPropObject('a', x => {
x // $ExpectType number
return {
a: x,
flag: x > 2,
}
- }, 'a'),
+ }),
)
result.a // $ExpectType { a: number; flag: boolean; }[]
result.b // $ExpectType string
})
+
+ it('iterable with two arguments', () => {
+ const result = pipe(
+ { a: [1,2,3], b: 'foo' },
+ mapPropObject('a', (x, list) => {
+ x // $ExpectType number
+ list // $ExpectType number[]
+ return list.length
+ }),
+ )
+ result.a // $ExpectType number[]
+ result.b // $ExpectType string
+ })
+
+ it('more complex example', () => {
+ const result = pipe(
+ [{a:[true, false, true], b: 'foo'}],
+ map(
+ mapPropObject( 'a',(a) => {
+ a // $ExpectType boolean
+ return {a, b: 2}
+ })
+ )
+ )
+
+ result[0].a[0].a // $ExpectType boolean
+ result[0].a[0].b // $ExpectType number
+ })
})
```
@@ -6706,7 +6762,7 @@ const result = [
// => [[], ['ba', 'na', 'na']]
```
-Try this R.match example in Rambda REPL
+Try this R.match example in Rambda REPL
@@ -6792,7 +6848,7 @@ const compareFn = Math.abs
R.maxBy(compareFn, 5, -7) // => -7
```
-Try this R.maxBy example in Rambda REPL
+Try this R.maxBy example in Rambda REPL
@@ -6975,7 +7031,7 @@ const compareFn = Math.abs
R.minBy(compareFn, -5, 2) // => -5
```
-Try this R.minBy example in Rambda REPL
+Try this R.minBy example in Rambda REPL
@@ -7032,7 +7088,7 @@ const result = R.pipe(
) // => [1, 3, 3]
```
-Try this R.modifyItemAtIndex example in Rambda REPL
+Try this R.modifyItemAtIndex example in Rambda REPL
@@ -7113,7 +7169,7 @@ const result = R.modifyPath('a.b.c', x=> x+1, {a:{b: {c:1}}})
// => {a:{b: {c:2}}}
```
-Try this R.modifyPath example in Rambda REPL
+Try this R.modifyPath example in Rambda REPL
@@ -7256,7 +7312,7 @@ const result = R.modifyProp('age', x => x + 1)(person)
// => {name: 'foo', age: 21}
```
-Try this R.modifyProp example in Rambda REPL
+Try this R.modifyProp example in Rambda REPL
@@ -7379,7 +7435,7 @@ const result = R.none(predicate)(arr)
// => true
```
-Try this R.none example in Rambda REPL
+Try this R.none example in Rambda REPL
@@ -7475,7 +7531,7 @@ const result = objectIncludes(specification)(input)
// => true
```
-Try this R.objectIncludes example in Rambda REPL
+Try this R.objectIncludes example in Rambda REPL
@@ -7599,7 +7655,7 @@ const result = R.objOf('foo')('bar')
// => {foo: 'bar'}
```
-Try this R.objOf example in Rambda REPL
+Try this R.objOf example in Rambda REPL
@@ -7685,7 +7741,7 @@ const result = [
// => [{b: 2}, {b: 2}]
```
-Try this R.omit example in Rambda REPL
+Try this R.omit example in Rambda REPL
@@ -7827,7 +7883,7 @@ const expected = [[3], [1, 2]]
// `result` is equal to `expected`
```
-Try this R.partition example in Rambda REPL
+Try this R.partition example in Rambda REPL
@@ -7952,7 +8008,7 @@ const expected = [{c: 3}, {a: 1, b: 2}]
// `result` is equal to `expected`
```
-Try this R.partitionObject example in Rambda REPL
+Try this R.partitionObject example in Rambda REPL
@@ -8096,7 +8152,7 @@ const result = [
// => [1, 1, undefined]
```
-Try this R.path example in Rambda REPL
+Try this R.path example in Rambda REPL
@@ -8252,7 +8308,7 @@ const result = R.pathSatisfies(
// => true
```
-Try this R.pathSatisfies example in Rambda REPL
+Try this R.pathSatisfies example in Rambda REPL
@@ -8372,7 +8428,7 @@ const result = R.permutations(
// => [[1, 2], [2, 1]]
```
-Try this R.permutations example in Rambda REPL
+Try this R.permutations example in Rambda REPL
@@ -8475,7 +8531,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.pick example in Rambda REPL
+Try this R.pick example in Rambda REPL
@@ -8614,7 +8670,7 @@ const result = R.pipe(
// => [20, 30]
```
-Try this R.pipe example in Rambda REPL
+Try this R.pipe example in Rambda REPL
@@ -8967,7 +9023,7 @@ const result = await R.pipeAsync(
// `result` resolves to `RAMBDAX_DELAY104`
```
-Try this R.pipeAsync example in Rambda REPL
+Try this R.pipeAsync example in Rambda REPL
@@ -9083,7 +9139,7 @@ const result = R.pluck(property)(list)
// => [1, 2]
```
-Try this R.pluck example in Rambda REPL
+Try this R.pluck example in Rambda REPL
@@ -9189,7 +9245,7 @@ const result = R.prepend('foo', ['bar', 'baz'])
// => ['foo', 'bar', 'baz']
```
-Try this R.prepend example in Rambda REPL
+Try this R.prepend example in Rambda REPL
@@ -9253,7 +9309,7 @@ const result = [
// => [100, undefined]
```
-Try this R.prop example in Rambda REPL
+Try this R.prop example in Rambda REPL
@@ -9327,7 +9383,7 @@ const result = [
// => [true, false]
```
-Try this R.propEq example in Rambda REPL
+Try this R.propEq example in Rambda REPL
@@ -9413,7 +9469,7 @@ const result = [
// => [1, 'DEFAULT_VALUE']
```
-Try this R.propOr example in Rambda REPL
+Try this R.propOr example in Rambda REPL
@@ -9501,7 +9557,7 @@ const result = R.propSatisfies(predicate, property, obj)
// => true
```
-Try this R.propSatisfies example in Rambda REPL
+Try this R.propSatisfies example in Rambda REPL
@@ -9588,7 +9644,7 @@ If `start` is greater than `end`, then the result will be in descending order.
// => [[0, 1, 2, 3, 4], [5, 4, 3, 2, 1]]
```
-Try this R.range example in Rambda REPL
+Try this R.range example in Rambda REPL
@@ -9695,7 +9751,7 @@ const result = R.reduce(reducer, initialValue, list)
// => 60
```
-Try this R.reduce example in Rambda REPL
+Try this R.reduce example in Rambda REPL
@@ -9816,7 +9872,7 @@ const result = [
// => [[1], {a: 1}]
```
-Try this R.reject example in Rambda REPL
+Try this R.reject example in Rambda REPL
@@ -9969,7 +10025,7 @@ const result = R.rejectObject(
// => {b: 2}
```
-Try this R.rejectObject example in Rambda REPL
+Try this R.rejectObject example in Rambda REPL
@@ -10075,7 +10131,7 @@ const result = [
// => ['f|1|o', 'f|1||1|']
```
-Try this R.replace example in Rambda REPL
+Try this R.replace example in Rambda REPL
@@ -10158,7 +10214,7 @@ const result = [
// => 'f|1||1|'
```
-Try this R.replaceAll example in Rambda REPL
+Try this R.replaceAll example in Rambda REPL
@@ -10250,7 +10306,7 @@ const result = R.shuffle(
// => [3, 1, 2] or [2, 3, 1] or ...
```
-Try this R.shuffle example in Rambda REPL
+Try this R.shuffle example in Rambda REPL
@@ -10335,7 +10391,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sort example in Rambda REPL
+Try this R.sort example in Rambda REPL
@@ -10442,7 +10498,7 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this R.sortBy example in Rambda REPL
+Try this R.sortBy example in Rambda REPL
@@ -10542,7 +10598,7 @@ describe('R.sortBy', () => {
```typescript
-sortByDescending(sortFn: (a: T, b: T) => number): (list: T[]) => T[]
+sortByDescending(sortFn: (x: T) => Ord): (list: T[]) => T[]
```
```javascript
@@ -10562,14 +10618,14 @@ const expected = [
// => `result` is equal to `expected`
```
-Try this