atomic-fns 0.3.0 → 0.3.2

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.
Files changed (85) hide show
  1. package/.esdoc.json +2 -2
  2. package/README.md +48 -13
  3. package/core/collections/BTree.d.ts +229 -0
  4. package/core/collections/BTree.js +1165 -0
  5. package/core/collections/BTree.ts +1340 -0
  6. package/core/collections/Heap.d.ts +69 -0
  7. package/core/collections/Heap.js +181 -0
  8. package/core/collections/Heap.ts +189 -0
  9. package/core/collections/LRUCache.d.ts +131 -0
  10. package/core/collections/LRUCache.js +388 -0
  11. package/core/collections/LRUCache.ts +465 -0
  12. package/core/collections/SortedMap.d.ts +92 -0
  13. package/core/collections/SortedMap.js +130 -0
  14. package/core/collections/SortedMap.ts +146 -0
  15. package/core/collections/SortedSet.d.ts +63 -0
  16. package/core/collections/SortedSet.js +93 -0
  17. package/core/collections/SortedSet.ts +104 -0
  18. package/core/collections/SortedTree.d.ts +103 -0
  19. package/core/collections/SortedTree.js +141 -0
  20. package/core/collections/SortedTree.ts +160 -0
  21. package/core/collections/SplayTree.d.ts +105 -0
  22. package/core/collections/SplayTree.js +338 -0
  23. package/core/collections/SplayTree.ts +354 -0
  24. package/core/collections/abc.d.ts +152 -0
  25. package/core/collections/abc.js +39 -0
  26. package/core/collections/abc.ts +176 -0
  27. package/core/collections/deque.d.ts +110 -0
  28. package/core/collections/deque.js +285 -0
  29. package/core/collections/deque.ts +329 -0
  30. package/core/collections/frozenset.d.ts +19 -0
  31. package/core/collections/frozenset.js +33 -0
  32. package/core/collections/frozenset.ts +37 -0
  33. package/{src → core}/collections/index.d.ts +12 -161
  34. package/{src → core}/collections/index.js +13 -164
  35. package/{src → core}/collections/index.ts +13 -224
  36. package/core/collections/test.html +10 -0
  37. package/core/collections/typedArrays.d.ts +31 -0
  38. package/core/collections/typedArrays.js +143 -0
  39. package/core/collections/typedArrays.ts +163 -0
  40. package/{src → core}/datetime/index.d.ts +0 -0
  41. package/{src → core}/datetime/index.js +0 -0
  42. package/{src → core}/datetime/index.ts +0 -0
  43. package/core/datetime/test.html +0 -0
  44. package/{src → core}/functools/index.d.ts +2 -2
  45. package/{src → core}/functools/index.js +2 -2
  46. package/{src → core}/functools/index.ts +2 -2
  47. package/{src → core}/globals/index.d.ts +2 -7
  48. package/{src → core}/globals/index.js +5 -2
  49. package/{src → core}/globals/index.ts +6 -9
  50. package/{src → core}/index.d.ts +0 -0
  51. package/{src → core}/index.js +0 -0
  52. package/{src → core}/index.ts +0 -0
  53. package/{src → core}/itertools/index.d.ts +9 -7
  54. package/{src → core}/itertools/index.js +25 -9
  55. package/{src → core}/itertools/index.ts +39 -16
  56. package/{src → core}/math/index.d.ts +0 -0
  57. package/{src → core}/math/index.js +0 -0
  58. package/{src → core}/math/index.ts +0 -0
  59. package/core/operators/index.d.ts +148 -0
  60. package/core/operators/index.js +271 -0
  61. package/core/operators/index.ts +282 -0
  62. package/{src → core}/random/index.d.ts +0 -0
  63. package/{src → core}/random/index.js +0 -0
  64. package/{src → core}/random/index.ts +0 -0
  65. package/package.json +7 -4
  66. package/tests/BTree.spec.ts +143 -0
  67. package/tests/Cache.spec.ts +161 -0
  68. package/tests/Heap.spec.ts +66 -0
  69. package/tests/SortedMap.spec.ts +144 -0
  70. package/tests/SortedSet.spec.ts +84 -0
  71. package/tests/SortedTree.spec.ts +164 -0
  72. package/tests/SplayTree.spec.ts +121 -0
  73. package/tests/collections.spec.ts +1 -1
  74. package/tests/deque.spec.ts +107 -0
  75. package/tests/globals.spec.ts +2 -2
  76. package/tests/itertools.spec.ts +2 -2
  77. package/tests/math.spec.ts +1 -1
  78. package/tests/operators.spec.ts +5 -5
  79. package/tests/random.spec.ts +10 -10
  80. package/tsconfig.json +10 -10
  81. package/tsconfig.node.json +2 -2
  82. package/tsconfig.xo.json +2 -2
  83. package/src/operators/index.d.ts +0 -31
  84. package/src/operators/index.js +0 -171
  85. package/src/operators/index.ts +0 -175
@@ -21,231 +21,24 @@ import {
21
21
  isSymbol,
22
22
  Iteratee,
23
23
  keys,
24
- NotImplementedError,
25
24
  set
26
25
  } from '../globals/index.js'
27
26
  import { enumerate } from '../itertools/index.js'
28
- import { comp, eq, id } from '../operators/index.js'
27
+ import { compare, eq, id } from '../operators/index.js'
29
28
 
30
- /**
31
- * A container type that provides contains().
32
- *
33
- *
34
- * @interface Container
35
- */
36
- export interface Container {
37
- contains: (x) => boolean
38
- }
39
-
40
- /**
41
- * These are the "rich comparison" methods, inspired by Python operators.
42
- *
43
- *
44
- * @interface Comparable
45
- */
46
- export interface Comparable {
47
- /** x < y: calls this.lt(other) reflection. */
48
- lt?: (other) => boolean
49
- /** x ≤ y: calls this.le(other) reflection. */
50
- le?: (other) => boolean
51
- /** x == y: calls this.eq(other) reflection. */
52
- eq: (other) => boolean
53
- /** x != y: calls this.ne(other) reflection. */
54
- ne: (other) => boolean
55
- /** x > y: calls this.gt(other) reflection. */
56
- gt?: (other) => boolean
57
- /** x ≥ y: calls this.ge(other) reflection. */
58
- ge?: (other) => boolean
59
- }
60
-
61
- /**
62
- * A `Collection` is an iterable {@link Container} type.
63
- * This is an abstract base class for user-defined collection types.
64
- *
65
- *
66
- * @abstract
67
- * @class Collection
68
- * @implements {Container}
69
- */
70
- export abstract class Collection implements Container {
71
- /**
72
- * Returns an iterator for the container items
73
- * @return {Iterator}
74
- */
75
- [Symbol.iterator]() {
76
- return this
77
- }
78
-
79
- /**
80
- * Implements the iterator protocol and returns the next item in the iterable.
81
- */
82
- next() {}
83
-
84
- /**
85
- * Adds a new item to the container.
86
- * @param item - The item to add to the collection.
87
- */
88
- add(item) {}
89
-
90
- /**
91
- * Checks if item is present in the container.
92
- * @param item - The item to search for in the collection.
93
- * @returns `true` when the element is found, else `false`
94
- */
95
- contains(item) {
96
- return false
97
- }
98
-
99
- /**
100
- * Returns the total number of elements in the container.
101
- */
102
- size(): number {
103
- throw new NotImplementedError()
104
- }
105
-
106
- /**
107
- * Remove the first item from the container where `item == x`
108
- * @returns `true` when the element is found and removed, else `false`
109
- */
110
- remove(x) {
111
- return false
112
- }
113
-
114
- /**
115
- * Retrieve and remove the item at index `i`.
116
- * @returns the item or undefined if not found.
117
- */
118
- pop(i) {}
119
-
120
- /**
121
- * Remove all items from the container
122
- */
123
- clear() {}
124
- }
125
-
126
- /**
127
- * Implements an iterable that allows backward iteration.
128
- * @interface Reversible
129
- */
130
- export interface Reversible<T = unknown> {
131
- reversed: () => Iterator<T>
132
- }
133
-
134
- /**
135
- * A sequence is an iterable {@link Collection} type with efficient index-based access.
136
- * @abstract
137
- * @class Sequence
138
- * @extends {Collection}
139
- * @template T
140
- */
141
- export abstract class Sequence<T> extends Collection implements Reversible<T> {
142
- /**
143
- * Return the item at the given key or index
144
- * @param {*} key
145
- * @memberof Sequence
146
- */
147
- get(key): T | undefined {
148
- throw new NotImplementedError()
149
- }
150
-
151
- /**
152
- * Set a new value at the given key or index
153
- *
154
- * @param {*} key
155
- * @param {T} val
156
- * @memberof Sequence
157
- */
158
- set(key, val: T) {
159
- throw new NotImplementedError()
160
- }
161
-
162
- /**
163
- * Deletes the given key or index, and its value.
164
- * Raises ValueError if not key is found.
165
- *
166
- * @param {*} key
167
- * @memberof Sequence
168
- */
169
- delete(key) {
170
- throw new NotImplementedError()
171
- }
172
-
173
- /**
174
- * Adds a new item to the end of the sequence.
175
- *
176
- * @param {T} x
177
- * @memberof Sequence
178
- */
179
- append(x: T) {}
180
-
181
- /**
182
- * Append all the items to the sequence.
183
- *
184
- * @param {Iterable<T>} iter
185
- * @memberof Sequence
186
- */
187
- extend(iter: Iterable<T>) {}
188
-
189
- /**
190
- * Return the index of x in the sequence, or undefined if not found.
191
- *
192
- * @param {T} item
193
- * @return {(number | undefined)}
194
- * @memberof Sequence
195
- */
196
- indexOf(item: T): number | undefined {
197
- throw new NotImplementedError()
198
- }
199
-
200
- size() {
201
- return 0
202
- }
203
-
204
- reversed(): Iterator<T> {
205
- throw new NotImplementedError()
206
- }
207
- }
208
-
209
- /**
210
- * Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
211
- *
212
- *
213
- * @class FrozenSet
214
- * @extends {Set<T>}
215
- * @template T
216
- */
217
- export class FrozenSet<T = any> extends Set<T> {
218
- constructor(iterable: Iterable<T>) {
219
- super(iterable)
220
- return this.freeze()
221
- }
222
-
223
- /** @private */
224
- add() {
225
- throw TypeError('FrozenSet cannot be modified.')
226
- return this // eslint-disable-line
227
- }
228
-
229
- /** @private */
230
- delete() {
231
- throw TypeError('FrozenSet cannot be modified.')
232
- return false // eslint-disable-line
233
- }
234
-
235
- /** @private */
236
- clear() {
237
- throw TypeError('FrozenSet cannot be modified.')
238
- return this // eslint-disable-line
239
- }
240
-
241
- /** @private */
242
- freeze() {
243
- return Object.freeze(this)
244
- }
245
- }
29
+ export * from './abc.js'
30
+ export * from './BTree.js'
31
+ export * from './deque.js'
32
+ export * from './frozenset.js'
33
+ export * from './Heap.js'
34
+ export * from './LRUCache.js'
35
+ export * from './SortedSet.js'
36
+ export * from './SortedMap.js'
37
+ export * from './SortedTree.js'
38
+ export * from './SplayTree.js'
246
39
 
247
40
  /**
248
- * Creates a new array with all `falsey` and empty values removed.
41
+ * Creates a new array with all falsy and empty values removed.
249
42
  * @param arr The array to compact
250
43
  * @returns A new array with the filtered values.
251
44
  * @example
@@ -942,7 +735,7 @@ uniq([2, 1, 2])
942
735
  */
943
736
  export function sortedUniq(arr, fn: string | Iteratee = id) {
944
737
  const values = uniq(arr, fn)
945
- values.sort(comp)
738
+ values.sort(compare)
946
739
  return values
947
740
  }
948
741
 
@@ -1179,8 +972,4 @@ export function remove<T>(arr: T[], func: any) {
1179
972
  }
1180
973
 
1181
974
  // TODO: binary search utils
1182
- // TODO: heap/heapify
1183
- // TODO: deque
1184
975
  // TODO: Counter
1185
- // TODO: Skip list
1186
- // TODO: BST (BTree)
@@ -0,0 +1,10 @@
1
+ <script type="module">
2
+ import { SplayTree } from 'https://unpkg.com/atomic-fns/core/collections'
3
+ let tree = new SplayTree()
4
+
5
+ for (let i = 20; i > 0; i -= 2) {
6
+ tree.set(i, i)
7
+ }
8
+
9
+ console.log(tree)
10
+ </script>
@@ -0,0 +1,31 @@
1
+ export declare function getPointerArray(size: any): Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
2
+ export declare function getSignedPointerArray(size: any): Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | Float64ArrayConstructor;
3
+ /**
4
+ * Function returning the minimal type able to represent the given number.
5
+ *
6
+ * @param {number} value - Value to test.
7
+ * @return {TypedArrayClass}
8
+ */
9
+ export declare function getNumberType(value: any): Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | Float64ArrayConstructor;
10
+ export declare function getMinimalRepresentation(array: any, getter: any): null;
11
+ /**
12
+ * Function returning whether the given value is a typed array.
13
+ *
14
+ * @param {any} value - Value to test.
15
+ * @return {boolean}
16
+ */
17
+ export declare function isTypedArray(value: any): boolean;
18
+ /**
19
+ * Function used to concat byte arrays.
20
+ *
21
+ * @param {...ByteArray}
22
+ * @return {ByteArray}
23
+ */
24
+ export declare function concat(): any;
25
+ /**
26
+ * Function used to initialize a byte array of indices.
27
+ *
28
+ * @param {number} length - Length of target.
29
+ * @return {ByteArray}
30
+ */
31
+ export declare function indices(length: any): any;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * When using an unsigned integer array to store pointers, one might want to
3
+ * choose the optimal word size in regards to the actual numbers of pointers
4
+ * to store.
5
+ *
6
+ * This helpers does just that.
7
+ *
8
+ * @param {number} size - Expected size of the array to map.
9
+ * @return {TypedArray}
10
+ */
11
+ const MAX_8BIT_INTEGER = Math.pow(2, 8) - 1;
12
+ const MAX_16BIT_INTEGER = Math.pow(2, 16) - 1;
13
+ const MAX_32BIT_INTEGER = Math.pow(2, 32) - 1;
14
+ const MAX_SIGNED_8BIT_INTEGER = Math.pow(2, 7) - 1;
15
+ const MAX_SIGNED_16BIT_INTEGER = Math.pow(2, 15) - 1;
16
+ const MAX_SIGNED_32BIT_INTEGER = Math.pow(2, 31) - 1;
17
+ export function getPointerArray(size) {
18
+ const maxIndex = size - 1;
19
+ if (maxIndex <= MAX_8BIT_INTEGER)
20
+ return Uint8Array;
21
+ if (maxIndex <= MAX_16BIT_INTEGER)
22
+ return Uint16Array;
23
+ // if (maxIndex <= MAX_32BIT_INTEGER) return Uint32Array
24
+ return Uint32Array;
25
+ }
26
+ export function getSignedPointerArray(size) {
27
+ const maxIndex = size - 1;
28
+ if (maxIndex <= MAX_SIGNED_8BIT_INTEGER)
29
+ return Int8Array;
30
+ if (maxIndex <= MAX_SIGNED_16BIT_INTEGER)
31
+ return Int16Array;
32
+ if (maxIndex <= MAX_SIGNED_32BIT_INTEGER)
33
+ return Int32Array;
34
+ return Float64Array;
35
+ }
36
+ /**
37
+ * Function returning the minimal type able to represent the given number.
38
+ *
39
+ * @param {number} value - Value to test.
40
+ * @return {TypedArrayClass}
41
+ */
42
+ export function getNumberType(value) {
43
+ // <= 32 bits itnteger?
44
+ if (value === (value | 0)) {
45
+ // Negative
46
+ if (Math.sign(value) === -1) {
47
+ if (value <= 127 && value >= -128)
48
+ return Int8Array;
49
+ if (value <= 32767 && value >= -32768)
50
+ return Int16Array;
51
+ return Int32Array;
52
+ }
53
+ else {
54
+ if (value <= 255)
55
+ return Uint8Array;
56
+ if (value <= 65535)
57
+ return Uint16Array;
58
+ return Uint32Array;
59
+ }
60
+ }
61
+ // 53 bits integer & floats
62
+ // NOTE: it's kinda hard to tell whether we could use 32bits or not...
63
+ return Float64Array;
64
+ }
65
+ /**
66
+ * Function returning the minimal type able to represent the given array
67
+ * of JavaScript numbers.
68
+ *
69
+ * @param {array} array - Array to represent.
70
+ * @param {function} getter - Optional getter.
71
+ * @return {TypedArrayClass}
72
+ */
73
+ const TYPE_PRIORITY = {
74
+ Uint8Array: 1,
75
+ Int8Array: 2,
76
+ Uint16Array: 3,
77
+ Int16Array: 4,
78
+ Uint32Array: 5,
79
+ Int32Array: 6,
80
+ Float32Array: 7,
81
+ Float64Array: 8
82
+ };
83
+ export function getMinimalRepresentation(array, getter) {
84
+ let maxType = null;
85
+ let maxPriority = 0;
86
+ let p;
87
+ let t;
88
+ let v;
89
+ let i;
90
+ let l;
91
+ for (i = 0, l = array.length; i < l; i++) {
92
+ v = getter ? getter(array[i]) : array[i];
93
+ t = exports.getNumberType(v);
94
+ p = TYPE_PRIORITY[t.name];
95
+ if (p > maxPriority) {
96
+ maxPriority = p;
97
+ maxType = t;
98
+ }
99
+ }
100
+ return maxType;
101
+ }
102
+ /**
103
+ * Function returning whether the given value is a typed array.
104
+ *
105
+ * @param {any} value - Value to test.
106
+ * @return {boolean}
107
+ */
108
+ export function isTypedArray(value) {
109
+ return ArrayBuffer.isView(value);
110
+ }
111
+ /**
112
+ * Function used to concat byte arrays.
113
+ *
114
+ * @param {...ByteArray}
115
+ * @return {ByteArray}
116
+ */
117
+ export function concat() {
118
+ let length = 0;
119
+ let i;
120
+ let o;
121
+ let l;
122
+ for (i = 0, l = arguments.length; i < l; i++)
123
+ length += arguments[i].length;
124
+ const array = new arguments[0].constructor(length);
125
+ for (i = 0, o = 0; i < l; i++) {
126
+ array.set(arguments[i], o);
127
+ o += arguments[i].length;
128
+ }
129
+ return array;
130
+ }
131
+ /**
132
+ * Function used to initialize a byte array of indices.
133
+ *
134
+ * @param {number} length - Length of target.
135
+ * @return {ByteArray}
136
+ */
137
+ export function indices(length) {
138
+ const PointerArray = exports.getPointerArray(length);
139
+ const array = new PointerArray(length);
140
+ for (let i = 0; i < length; i++)
141
+ array[i] = i;
142
+ return array;
143
+ }
@@ -0,0 +1,163 @@
1
+ /**
2
+ * When using an unsigned integer array to store pointers, one might want to
3
+ * choose the optimal word size in regards to the actual numbers of pointers
4
+ * to store.
5
+ *
6
+ * This helpers does just that.
7
+ *
8
+ * @param {number} size - Expected size of the array to map.
9
+ * @return {TypedArray}
10
+ */
11
+ const MAX_8BIT_INTEGER = Math.pow(2, 8) - 1
12
+ const MAX_16BIT_INTEGER = Math.pow(2, 16) - 1
13
+ const MAX_32BIT_INTEGER = Math.pow(2, 32) - 1
14
+
15
+ const MAX_SIGNED_8BIT_INTEGER = Math.pow(2, 7) - 1
16
+ const MAX_SIGNED_16BIT_INTEGER = Math.pow(2, 15) - 1
17
+ const MAX_SIGNED_32BIT_INTEGER = Math.pow(2, 31) - 1
18
+
19
+ export function getPointerArray(size) {
20
+ const maxIndex = size - 1
21
+
22
+ if (maxIndex <= MAX_8BIT_INTEGER) return Uint8Array
23
+
24
+ if (maxIndex <= MAX_16BIT_INTEGER) return Uint16Array
25
+
26
+ // if (maxIndex <= MAX_32BIT_INTEGER) return Uint32Array
27
+
28
+ return Uint32Array
29
+ }
30
+
31
+ export function getSignedPointerArray(size) {
32
+ const maxIndex = size - 1
33
+
34
+ if (maxIndex <= MAX_SIGNED_8BIT_INTEGER) return Int8Array
35
+
36
+ if (maxIndex <= MAX_SIGNED_16BIT_INTEGER) return Int16Array
37
+
38
+ if (maxIndex <= MAX_SIGNED_32BIT_INTEGER) return Int32Array
39
+
40
+ return Float64Array
41
+ }
42
+
43
+ /**
44
+ * Function returning the minimal type able to represent the given number.
45
+ *
46
+ * @param {number} value - Value to test.
47
+ * @return {TypedArrayClass}
48
+ */
49
+ export function getNumberType(value) {
50
+ // <= 32 bits itnteger?
51
+ if (value === (value | 0)) {
52
+ // Negative
53
+ if (Math.sign(value) === -1) {
54
+ if (value <= 127 && value >= -128) return Int8Array
55
+
56
+ if (value <= 32767 && value >= -32768) return Int16Array
57
+
58
+ return Int32Array
59
+ } else {
60
+ if (value <= 255) return Uint8Array
61
+
62
+ if (value <= 65535) return Uint16Array
63
+
64
+ return Uint32Array
65
+ }
66
+ }
67
+
68
+ // 53 bits integer & floats
69
+ // NOTE: it's kinda hard to tell whether we could use 32bits or not...
70
+ return Float64Array
71
+ }
72
+
73
+ /**
74
+ * Function returning the minimal type able to represent the given array
75
+ * of JavaScript numbers.
76
+ *
77
+ * @param {array} array - Array to represent.
78
+ * @param {function} getter - Optional getter.
79
+ * @return {TypedArrayClass}
80
+ */
81
+ const TYPE_PRIORITY = {
82
+ Uint8Array: 1,
83
+ Int8Array: 2,
84
+ Uint16Array: 3,
85
+ Int16Array: 4,
86
+ Uint32Array: 5,
87
+ Int32Array: 6,
88
+ Float32Array: 7,
89
+ Float64Array: 8
90
+ }
91
+
92
+ export function getMinimalRepresentation(array, getter) {
93
+ let maxType = null
94
+ let maxPriority = 0
95
+ let p
96
+ let t
97
+ let v
98
+ let i
99
+ let l
100
+
101
+ for (i = 0, l = array.length; i < l; i++) {
102
+ v = getter ? getter(array[i]) : array[i]
103
+ t = exports.getNumberType(v)
104
+ p = TYPE_PRIORITY[t.name]
105
+
106
+ if (p > maxPriority) {
107
+ maxPriority = p
108
+ maxType = t
109
+ }
110
+ }
111
+
112
+ return maxType
113
+ }
114
+
115
+ /**
116
+ * Function returning whether the given value is a typed array.
117
+ *
118
+ * @param {any} value - Value to test.
119
+ * @return {boolean}
120
+ */
121
+ export function isTypedArray(value) {
122
+ return ArrayBuffer.isView(value)
123
+ }
124
+
125
+ /**
126
+ * Function used to concat byte arrays.
127
+ *
128
+ * @param {...ByteArray}
129
+ * @return {ByteArray}
130
+ */
131
+ export function concat() {
132
+ let length = 0
133
+ let i
134
+ let o
135
+ let l
136
+
137
+ for (i = 0, l = arguments.length; i < l; i++) length += arguments[i].length
138
+
139
+ const array = new arguments[0].constructor(length)
140
+
141
+ for (i = 0, o = 0; i < l; i++) {
142
+ array.set(arguments[i], o)
143
+ o += arguments[i].length
144
+ }
145
+
146
+ return array
147
+ }
148
+
149
+ /**
150
+ * Function used to initialize a byte array of indices.
151
+ *
152
+ * @param {number} length - Length of target.
153
+ * @return {ByteArray}
154
+ */
155
+ export function indices(length) {
156
+ const PointerArray = exports.getPointerArray(length)
157
+
158
+ const array = new PointerArray(length)
159
+
160
+ for (let i = 0; i < length; i++) array[i] = i
161
+
162
+ return array
163
+ }
File without changes
File without changes
File without changes
File without changes
@@ -88,7 +88,7 @@ export declare function once(func: Function): (...args: any[]) => any;
88
88
  export declare type Maybe<T> = T | undefined;
89
89
  export declare type Result<T, E = any> = [Maybe<T>, Maybe<E>];
90
90
  /**
91
- * Wraps a function to catch any exceptions inside and return a `go` style error-return type.
91
+ * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
92
92
  *
93
93
  * @param {Function} fun The function to wrap and catch if it throws.
94
94
  * @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
@@ -101,7 +101,7 @@ export declare function result<T = any, E = unknown>(fun: Function<T>, onFinally
101
101
  *
102
102
  * @param {Function|Promise} awaitable The function or promise to await.
103
103
  * @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
104
- * @returns {Function} A new function that awaits the `awaitable` param and returns a return type.
104
+ * @returns {Function} A new function that awaits the `awaitable` param and returns a {@link Result} type.
105
105
  * @template T,E
106
106
  */
107
107
  export declare function resultAsync<T = any, E = unknown>(awaitable: Promise<T> | Function<Promise<T>>, onFinally?: (err: E, res: T) => any): (...args: any[]) => Promise<Result<T, E>>;
@@ -171,7 +171,7 @@ export function once(func) {
171
171
  };
172
172
  }
173
173
  /**
174
- * Wraps a function to catch any exceptions inside and return a `go` style error-return type.
174
+ * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
175
175
  *
176
176
  * @param {Function} fun The function to wrap and catch if it throws.
177
177
  * @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
@@ -198,7 +198,7 @@ export function result(fun, onFinally) {
198
198
  *
199
199
  * @param {Function|Promise} awaitable The function or promise to await.
200
200
  * @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
201
- * @returns {Function} A new function that awaits the `awaitable` param and returns a return type.
201
+ * @returns {Function} A new function that awaits the `awaitable` param and returns a {@link Result} type.
202
202
  * @template T,E
203
203
  */
204
204
  export function resultAsync(awaitable, onFinally) {
@@ -204,7 +204,7 @@ export type Maybe<T> = T | undefined
204
204
  export type Result<T, E = any> = [Maybe<T>, Maybe<E>]
205
205
 
206
206
  /**
207
- * Wraps a function to catch any exceptions inside and return a `go` style error-return type.
207
+ * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
208
208
  *
209
209
  * @param {Function} fun The function to wrap and catch if it throws.
210
210
  * @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
@@ -233,7 +233,7 @@ export function result<T = any, E = unknown>(
233
233
  *
234
234
  * @param {Function|Promise} awaitable The function or promise to await.
235
235
  * @param {?function(err: E, res: T): *} [onFinally] Optional callback that will be called on the `finally` clause if given.
236
- * @returns {Function} A new function that awaits the `awaitable` param and returns a return type.
236
+ * @returns {Function} A new function that awaits the `awaitable` param and returns a {@link Result} type.
237
237
  * @template T,E
238
238
  */
239
239
  export function resultAsync<T = any, E = unknown>(
@@ -3,11 +3,6 @@
3
3
  *
4
4
  * @module Globals
5
5
  */
6
- /** Describes a function used to compare two values.
7
- *
8
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description Array.sort()}
9
- */
10
- export declare type Comp = (x: any, y: any) => -1 | 0 | 1;
11
6
  /** This is just a noop function. */
12
7
  export declare const _: () => void;
13
8
  /**
@@ -27,7 +22,7 @@ export declare type Function<T = any> = (...args: any) => T;
27
22
  * @see {@link Collections.sortedUniq}
28
23
  * @see {@link Collections.groupBy}
29
24
  */
30
- export declare type Iteratee<T = any> = (value: T, key?: any, arr?: any) => any;
25
+ export declare type Iteratee<T = any, K = any> = (value: T, key?: K, arr?: any) => any;
31
26
  export declare type Predicate<T = any> = (value: T) => any;
32
27
  /** A function that always returns `true`. */
33
28
  export declare const True: () => boolean;
@@ -130,7 +125,7 @@ export declare const isGenerator: (x: any) => x is Generator<unknown, any, unkno
130
125
  export declare const isNull: (x: any) => x is null | undefined;
131
126
  /** Check if value is not `null` or `undefined`. */
132
127
  export declare const notNull: (x: any) => boolean;
133
- /** Returns `true` for objects without length or falsey values. */
128
+ /** Returns `true` for objects without length or falsy values. */
134
129
  export declare const isEmpty: (x: any) => boolean;
135
130
  /** Check if value is a `Symbol` type */
136
131
  export declare const isSymbol: (x: any) => x is symbol;