xjs-common 13.6.1 → 13.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,9 @@ var Array2;
23
23
  : (o, korv) => { o[korv] = op.vgen(korv); return o; }, {});
24
24
  }
25
25
  Array2.record = record;
26
+ /**
27
+ * sum up numbers in the array. if the array is empty, this returns `0`.
28
+ */
26
29
  function sum(array) {
27
30
  return array.map(e => u_type_1.UType.isNumber(e) ? e : Number(e)).reduce((a, b) => a + b, 0);
28
31
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UArray = void 0;
4
4
  const array2_1 = require("./array2");
5
5
  const u_1 = require("./u");
6
+ const u_type_1 = require("./u-type");
6
7
  var UArray;
7
8
  (function (UArray) {
8
9
  /**
@@ -100,4 +101,11 @@ var UArray;
100
101
  return result;
101
102
  }
102
103
  UArray.takeOut = takeOut;
104
+ async function parallelForEach(array, predicate, paraCount = 3) {
105
+ let ret = [];
106
+ for (const set of UArray.chop(array, paraCount))
107
+ ret.push(...(await Promise.all(set.map(predicate))).filter(u_type_1.UType.isDefined));
108
+ return ret;
109
+ }
110
+ UArray.parallelForEach = parallelForEach;
103
111
  })(UArray || (exports.UArray = UArray = {}));
@@ -25,5 +25,8 @@ export declare namespace Array2 {
25
25
  function record<K extends IndexSignature, V>(keyOrValues: V[], op: {
26
26
  kgen: (v: V) => K;
27
27
  }): Record<K, V>;
28
+ /**
29
+ * sum up numbers in the array. if the array is empty, this returns `0`.
30
+ */
28
31
  function sum(array: (number | `${number}`)[]): number;
29
32
  }
@@ -20,6 +20,9 @@ export var Array2;
20
20
  : (o, korv) => { o[korv] = op.vgen(korv); return o; }, {});
21
21
  }
22
22
  Array2.record = record;
23
+ /**
24
+ * sum up numbers in the array. if the array is empty, this returns `0`.
25
+ */
23
26
  function sum(array) {
24
27
  return array.map(e => UType.isNumber(e) ? e : Number(e)).reduce((a, b) => a + b, 0);
25
28
  }
@@ -47,4 +47,5 @@ export declare namespace UArray {
47
47
  function randomPick<T>(array: T[], takeout?: boolean): T;
48
48
  function shuffle<T>(array: T[]): T[];
49
49
  function takeOut<T>(array: T[], filter: (v: T, i?: number) => boolean): T[];
50
+ function parallelForEach<T, R>(array: T[], predicate: (e: T) => Promise<R>, paraCount?: number): Promise<R[]>;
50
51
  }
@@ -1,5 +1,6 @@
1
1
  import { Array2 } from "./array2";
2
2
  import { int2array } from "./u";
3
+ import { UType } from "./u-type";
3
4
  export var UArray;
4
5
  (function (UArray) {
5
6
  /**
@@ -97,4 +98,11 @@ export var UArray;
97
98
  return result;
98
99
  }
99
100
  UArray.takeOut = takeOut;
101
+ async function parallelForEach(array, predicate, paraCount = 3) {
102
+ let ret = [];
103
+ for (const set of UArray.chop(array, paraCount))
104
+ ret.push(...(await Promise.all(set.map(predicate))).filter(UType.isDefined));
105
+ return ret;
106
+ }
107
+ UArray.parallelForEach = parallelForEach;
100
108
  })(UArray || (UArray = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xjs-common",
3
- "version": "13.6.1",
3
+ "version": "13.7.0",
4
4
  "description": "library modules for typescript that bundled general-purpose implementations.",
5
5
  "repository": {
6
6
  "type": "git",