atomic-fns 0.3.5 → 0.4.3

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 (109) hide show
  1. package/README.md +1 -12
  2. package/{core → dist}/collections/BTree.d.ts +6 -6
  3. package/{core → dist}/collections/BTree.js +17 -17
  4. package/{core → dist}/collections/Heap.d.ts +3 -3
  5. package/{core → dist}/collections/Heap.js +0 -0
  6. package/dist/collections/LRUCache.d.ts +80 -0
  7. package/dist/collections/LRUCache.js +126 -0
  8. package/{core → dist}/collections/SortedMap.d.ts +2 -2
  9. package/{core → dist}/collections/SortedMap.js +0 -0
  10. package/{core → dist}/collections/SortedSet.d.ts +3 -3
  11. package/{core → dist}/collections/SortedSet.js +1 -1
  12. package/{core → dist}/collections/SortedTree.d.ts +3 -3
  13. package/{core → dist}/collections/SortedTree.js +1 -1
  14. package/{core → dist}/collections/SplayTree.d.ts +5 -5
  15. package/{core → dist}/collections/SplayTree.js +0 -0
  16. package/{core → dist}/collections/abc.d.ts +0 -0
  17. package/{core → dist}/collections/abc.js +0 -0
  18. package/{core → dist}/collections/deque.d.ts +7 -7
  19. package/{core → dist}/collections/deque.js +6 -8
  20. package/{core → dist}/collections/frozenset.d.ts +0 -0
  21. package/{core → dist}/collections/frozenset.js +3 -6
  22. package/{core → dist}/collections/index.d.ts +207 -105
  23. package/{core → dist}/collections/index.js +179 -436
  24. package/{core → dist}/functools/index.d.ts +30 -16
  25. package/{core → dist}/functools/index.js +34 -12
  26. package/dist/globals/decimal.d.ts +142 -0
  27. package/dist/globals/decimal.js +371 -0
  28. package/{core → dist}/globals/index.d.ts +26 -25
  29. package/{core → dist}/globals/index.js +16 -37
  30. package/dist/i18n/currency.d.ts +24 -0
  31. package/dist/i18n/currency.js +85 -0
  32. package/dist/i18n/date/index.d.ts +204 -0
  33. package/dist/i18n/date/index.js +530 -0
  34. package/dist/i18n/date/utils.d.ts +65 -0
  35. package/dist/i18n/date/utils.js +290 -0
  36. package/dist/i18n/duration.d.ts +112 -0
  37. package/dist/i18n/duration.js +392 -0
  38. package/dist/i18n/format.d.ts +26 -0
  39. package/dist/i18n/format.js +495 -0
  40. package/{core → dist}/i18n/index.d.ts +2 -1
  41. package/{core → dist}/i18n/index.js +2 -1
  42. package/{core → dist}/index.d.ts +0 -0
  43. package/{core → dist}/index.js +0 -0
  44. package/{core → dist}/itertools/index.d.ts +74 -46
  45. package/{core → dist}/itertools/index.js +28 -56
  46. package/{core → dist}/math/index.d.ts +9 -10
  47. package/{core → dist}/math/index.js +3 -1
  48. package/{core → dist}/operators/index.d.ts +4 -4
  49. package/{core → dist}/operators/index.js +2 -8
  50. package/{core → dist}/random/index.d.ts +1 -1
  51. package/{core → dist}/random/index.js +5 -5
  52. package/package.json +28 -42
  53. package/.editorconfig +0 -12
  54. package/.esdoc.json +0 -27
  55. package/.eslintignore +0 -1
  56. package/.eslintrc.json +0 -35
  57. package/.firebaserc +0 -5
  58. package/.prettierrc +0 -19
  59. package/core/collections/BTree.ts +0 -1340
  60. package/core/collections/Heap.ts +0 -189
  61. package/core/collections/LRUCache.d.ts +0 -152
  62. package/core/collections/LRUCache.js +0 -409
  63. package/core/collections/LRUCache.ts +0 -486
  64. package/core/collections/SortedMap.ts +0 -146
  65. package/core/collections/SortedSet.ts +0 -110
  66. package/core/collections/SortedTree.ts +0 -160
  67. package/core/collections/SplayTree.ts +0 -354
  68. package/core/collections/abc.ts +0 -176
  69. package/core/collections/deque.ts +0 -338
  70. package/core/collections/frozenset.ts +0 -37
  71. package/core/collections/index.ts +0 -1024
  72. package/core/collections/test.html +0 -10
  73. package/core/collections/typedArrays.d.ts +0 -31
  74. package/core/collections/typedArrays.js +0 -143
  75. package/core/collections/typedArrays.ts +0 -163
  76. package/core/functools/index.ts +0 -260
  77. package/core/globals/index.ts +0 -481
  78. package/core/i18n/date/format.d.ts +0 -16
  79. package/core/i18n/date/format.js +0 -307
  80. package/core/i18n/date/format.ts +0 -343
  81. package/core/i18n/date/index.d.ts +0 -224
  82. package/core/i18n/date/index.js +0 -387
  83. package/core/i18n/date/index.ts +0 -471
  84. package/core/i18n/date/test.html +0 -67
  85. package/core/i18n/index.ts +0 -8
  86. package/core/index.ts +0 -8
  87. package/core/itertools/index.ts +0 -494
  88. package/core/math/index.ts +0 -152
  89. package/core/operators/index.ts +0 -310
  90. package/core/random/index.ts +0 -66
  91. package/firebase.json +0 -10
  92. package/jasmine.json +0 -14
  93. package/tests/BTree.spec.ts +0 -143
  94. package/tests/Cache.spec.ts +0 -161
  95. package/tests/Heap.spec.ts +0 -66
  96. package/tests/SortedMap.spec.ts +0 -144
  97. package/tests/SortedSet.spec.ts +0 -84
  98. package/tests/SortedTree.spec.ts +0 -164
  99. package/tests/SplayTree.spec.ts +0 -121
  100. package/tests/collections.spec.ts +0 -288
  101. package/tests/deque.spec.ts +0 -107
  102. package/tests/globals.spec.ts +0 -270
  103. package/tests/itertools.spec.ts +0 -266
  104. package/tests/math.spec.ts +0 -25
  105. package/tests/operators.spec.ts +0 -40
  106. package/tests/random.spec.ts +0 -46
  107. package/tsconfig.json +0 -126
  108. package/tsconfig.node.json +0 -18
  109. package/tsconfig.xo.json +0 -9
@@ -21,17 +21,17 @@ export declare function accumulate<T>(iterable: Iterable<T>, func?: typeof add,
21
21
  * @example
22
22
  ```js
23
23
  all([0])
24
- // => true
24
+ // true
25
25
 
26
26
  all([1, 2, 3])
27
- // => true
27
+ // true
28
28
 
29
29
  all([2, 4, 6] => (n) => n > 1)
30
- // => true
30
+ // true
31
31
  ```
32
32
  @see {@link any}
33
33
  */
34
- export declare const all: <T>(iterable: Iterable<T>, fn?: Predicate<T>) => boolean;
34
+ export declare const all: <T>(iterable: Iterable<T>, fn?: Predicate<T, any>) => boolean;
35
35
  /**
36
36
  * Returns true when any of the items in iterable are truthy. An optional predicate function can be used to define what truthiness means for this specific collection.
37
37
  * @param iterable
@@ -40,17 +40,17 @@ export declare const all: <T>(iterable: Iterable<T>, fn?: Predicate<T>) => boole
40
40
  * @example
41
41
  ```js
42
42
  any([0])
43
- // => false
43
+ // false
44
44
 
45
45
  any([0, 1, null, undefined])
46
- // => true
46
+ // true
47
47
 
48
48
  any([1, 4, 5] => (n) => n % 2 === 0)
49
- // => true
49
+ // true
50
50
  ```
51
51
  @see {@link all}
52
52
  */
53
- export declare const any: <T>(iterable: Iterable<T>, fn?: Predicate<T>) => boolean;
53
+ export declare const any: <T>(iterable: Iterable<T>, fn?: Predicate<T, any>) => boolean;
54
54
  export declare function chain<T>(...iterables: Array<Iterable<T>>): Generator<T, void, unknown>;
55
55
  /**
56
56
  * Checks if the `value` is in `collection`.
@@ -60,16 +60,16 @@ export declare function chain<T>(...iterables: Array<Iterable<T>>): Generator<T,
60
60
  * @example
61
61
  ```js
62
62
  contains([1, 2, 3], 1)
63
- // => true
63
+ // true
64
64
 
65
65
  contains([1, 2, 3], 1, 2)
66
- // => false
66
+ // false
67
67
 
68
68
  contains({ 'a': 1, 'b': 2 }, 1)
69
- // => true
69
+ // true
70
70
 
71
71
  contains('abcd', 'bc')
72
- // => true
72
+ // true
73
73
  ```
74
74
  *
75
75
  * @see {@link Collections.find}
@@ -81,9 +81,9 @@ export declare function contains(collection: Iterable<any>, value: any): any;
81
81
  * @param predicate A function invoked per element to check if it should be dropped.
82
82
  * @returns Elements
83
83
  */
84
- export declare function dropWhile<T>(iterable: Iterable<T>, predicate: Predicate): Generator<unknown, any, unknown>;
84
+ export declare function dropWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Generator<T, T, unknown>;
85
85
  export declare function iforEach<T>(iterable: Iterable<T>, fun: Iteratee<T>): void;
86
- export declare function IterableIterator<T = any>(next: any): Iterator<T, any, undefined> & Iterable<T>;
86
+ export declare function IterableIterator<T = any>(next: Iterator<T>['next']): Iterable<T> & Iterator<T>;
87
87
  /**
88
88
  * Yields elements like `[index, item]` from an iterable. Index starts at zero by default.
89
89
  * @template T
@@ -93,20 +93,20 @@ export declare function IterableIterator<T = any>(next: any): Iterator<T, any, u
93
93
  * @example
94
94
  ```js
95
95
  console.log([...enumerate(['hello', 'world'])])
96
- // => [[0, 'hello'], [1, 'world']]
96
+ // [[0, 'hello'], [1, 'world']]
97
97
 
98
98
  // Start with index `1`
99
99
  console.log([...enumerate(['hello', 'world'], 1)])
100
- // => [[1, 'hello'], [2, 'world']]
100
+ // [[1, 'hello'], [2, 'world']]
101
101
  ```
102
102
  */
103
- export declare function enumerate<T = any>(iterable: Iterable<T>, start?: number): Generator<(number | T)[], void, unknown>;
103
+ export declare function enumerate<T>(iterable: Iterable<T>, start?: number): Generator<[number, T], void, unknown>;
104
104
  /**
105
105
  * Returns the first element in an iterable.
106
106
  * @param iterable The iterable to inspect.
107
107
  * @returns The first element found or undefined if iterable is empty.
108
108
  */
109
- export declare function first<T>(iterable: Iterable<T>): any;
109
+ export declare function first<T>(iterable: Iterable<T>): T;
110
110
  /**
111
111
  * Creates a new generator that filters all falsy and empty values from iterable.
112
112
  * @param arr The array to compact
@@ -114,35 +114,35 @@ export declare function first<T>(iterable: Iterable<T>): any;
114
114
  * @example
115
115
  ```js
116
116
  compact([0, 1, false, 2, '', 3])
117
- // => [1, 2, 3]
117
+ // [1, 2, 3]
118
118
  ```
119
119
  */
120
120
  export declare function icompact<T>(iterable: Iterable<T>): Generator<T, void, unknown>;
121
121
  /**
122
122
  * Iterates over elements of collection, producing only those elements where predicate returns a `truthy` value.
123
123
  */
124
- export declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate): Generator<T, void, unknown>;
125
- export declare function imap<T, TReturn = any>(iterable: Iterable<T>, mapFn: (x: T) => TReturn): Generator<TReturn, void, unknown>;
124
+ export declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T, boolean>): Generator<T, void, unknown>;
125
+ export declare function imap<T, TReturn = any>(iterable: Iterable<T>, mapFn: Predicate<T, TReturn>): Generator<TReturn, void, unknown>;
126
126
  /**
127
127
  * Returns a generator flattening one level of nesting in a list of lists.
128
128
  * @param iterables The iterable to flatten
129
129
  * @example
130
130
  ```js
131
131
  [...iflatten([[0, 1], [2, 3]])]
132
- // => [0, 1, 2, 3]
132
+ // [0, 1, 2, 3]
133
133
  ```
134
134
  */
135
135
  export declare function iflatten<T = any>(iterables: Iterable<Iterable<T>>): Generator<T, void, unknown>;
136
136
  export declare function flatMap<T>(iterable: Iterable<T>, mapFn?: (x: T) => any): Generator<T, void, unknown>;
137
- export declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number, step?: number): Generator<number | T, number | T | undefined, unknown>;
138
- export declare function itake<T>(n: number, iterable: Iterable<T>): Generator<unknown, void, unknown>;
137
+ export declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number, step?: number): Generator<T, T, unknown>;
138
+ export declare function itake<T>(n: number, iterable: Iterable<T>): Generator<T, void, unknown>;
139
139
  /**
140
140
  * Returns an Iterator from the elements of a collection or the object keys.
141
141
  * @param obj The given collection to iterate over.
142
142
  * @returns An Iterator type.
143
143
  */
144
- export declare function iter<T>(obj: any): Iterator<T>;
145
- export declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[][];
144
+ export declare function iter<T>(obj: any): Iterator<T, T>;
145
+ export declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T, boolean>): [T[], T[]];
146
146
  /**
147
147
  * Returns a generator for a sequence of numbers in the given range, starting from `start` (default 0) to `stop` (not-inclusive) in increments of `step` (default 1).
148
148
  *
@@ -151,19 +151,19 @@ export declare function partition<T>(iterable: Iterable<T>, predicate: Predicate
151
151
  * @example
152
152
  ```js
153
153
  range(5)
154
- // => [0, 1, 2, 3, 4]
154
+ // [0, 1, 2, 3, 4]
155
155
 
156
156
  range(2, 5)
157
- // => [2, 3, 4]
157
+ // [2, 3, 4]
158
158
 
159
159
  range(0, 5, 2)
160
- // => [0, 2, 4]
160
+ // [0, 2, 4]
161
161
 
162
162
  range(5, 0, -1)
163
- // => [5, 4, 3, 2, 1]
163
+ // [5, 4, 3, 2, 1]
164
164
 
165
165
  range(-3)
166
- // => []
166
+ // []
167
167
  ```
168
168
  */
169
169
  export declare function range(...args: number[]): Generator<number, void, unknown>;
@@ -176,7 +176,7 @@ export declare function range(...args: number[]): Generator<number, void, unknow
176
176
  * @example
177
177
  ```js
178
178
  reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)
179
- // => 15
179
+ // 15
180
180
  ```
181
181
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce Array.reduce()}
182
182
  */
@@ -187,23 +187,51 @@ export declare function reduce<T>(iterable: Iterable<T>, reducer: (prev: T, valu
187
187
  * @returns A new array with the elements reversed.
188
188
  */
189
189
  export declare function reversed<T>(iterable: Iterable<T>): T[];
190
- export declare function sorted(args: any[]): any[];
191
- export declare function sorted(args: any[], reverse: boolean): any[];
192
- export declare function sorted(args: any[], reverse: boolean, comp: Comparer): any[];
193
- export declare function sorted(args: any[], key: Function): any[];
194
- export declare function sorted(args: any[], key: Function, reverse: boolean): any[];
195
- export declare function sort(args: any[]): any[];
196
- export declare function sort(args: any[], reverse: boolean): any[];
197
- export declare function sort(args: any[], compareFn: Comparer): any[];
198
- export declare function sort(args: any[], reverse: boolean, compareFn: Comparer): any[];
199
- export declare function take<T>(n: number, iterable: Iterable<T>): unknown[];
190
+ /**
191
+ * Creates a new sorted list from the elements in the array. This can be called many ways:
192
+ * - sorted([...], true) => reverse order
193
+ * - sorted([...], fn = (x) => any) => using a key fn
194
+ * - sorted([...], fn = (x) => any, true) => reverse order using key
195
+ * - sorted([...], false, (x, y) => number) => using custom compare
196
+ * - sorted([...], fn = (x) => any, true, (x, y) => number) => custom key, reverse and compare
197
+ *
198
+ * If `args` is an Object, returns the sorted keys.
199
+ *
200
+ *
201
+ * @param {(Array | Object)} args
202
+ * @param {(boolean | Function)} [key]
203
+ * @param {(boolean | Comparer)} [reverse]
204
+ * @param {Comparer} [compareFn]
205
+ * @return
206
+ */
207
+ export declare function sorted<T>(args: T[]): T[];
208
+ export declare function sorted<T>(args: T[], reverse: boolean): T[];
209
+ export declare function sorted<T>(args: T[], reverse: boolean, comp: Comparer): T[];
210
+ export declare function sorted<T>(args: T[], key: Function): T[];
211
+ export declare function sorted<T>(args: T[], key: Function, reverse: boolean): T[];
212
+ /**
213
+ * Sort `args` in place. Can be called like this:
214
+ * - sort([...], true) => reverse order
215
+ * - sort([...], (x, y) => number) => using custom compare
216
+ * - sort([...], true, (x, y) => number) => reverse and using custom compare
217
+ *
218
+ * @param {any[]} args
219
+ * @param {(boolean | Comparer)} [reverse]
220
+ * @param {Comparer} [compareFn]
221
+ * @return
222
+ */
223
+ export declare function sort<T>(args: T[]): T[];
224
+ export declare function sort<T>(args: T[], reverse: boolean): T[];
225
+ export declare function sort<T>(args: T[], compareFn: Comparer): T[];
226
+ export declare function sort<T>(args: T[], reverse: boolean, compareFn: Comparer): T[];
227
+ export declare function take<T>(n: number, iterable: Iterable<T>): T[];
200
228
  /**
201
229
  * Returns a generator that takes elements from the iterable as long as the predicate is `true`.
202
230
  * @param iterable The iterable to inspect.
203
231
  * @param predicate A function invoked per element to check if it should be taken.
204
232
  * @returns Elements
205
233
  */
206
- export declare function takeWhile<T>(iterable: Iterable<T>, predicate: Predicate): Generator<T, void, unknown>;
234
+ export declare function takeWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Generator<T, void, unknown>;
207
235
  /** Returns a generator that calls `fn(index)` for each index < n */
208
236
  /**
209
237
  * Returns a generator that produces `fn(index)` for each `index < n`.
@@ -219,9 +247,9 @@ export declare function times(n: number, fn: (index: number) => any): Generator<
219
247
  ```js
220
248
  for item of zip([1, 2, 3], ['sugar', 'spice', 'nice'])
221
249
  console.log(item)
222
- // => [1, 'sugar']
223
- // => [2, 'spice']
224
- // => [3, 'nice']
250
+ // [1, 'sugar']
251
+ // [2, 'spice']
252
+ // [3, 'nice']
225
253
  ```
226
254
  */
227
255
  export declare function zip(...args: Array<Iterable<any>>): Generator<any[], void, unknown>;
@@ -34,13 +34,13 @@ export function* accumulate(iterable, func = add, initial) {
34
34
  * @example
35
35
  ```js
36
36
  all([0])
37
- // => true
37
+ // true
38
38
 
39
39
  all([1, 2, 3])
40
- // => true
40
+ // true
41
41
 
42
42
  all([2, 4, 6] => (n) => n > 1)
43
- // => true
43
+ // true
44
44
  ```
45
45
  @see {@link any}
46
46
  */
@@ -59,13 +59,13 @@ export const all = (iterable, fn = bool) => {
59
59
  * @example
60
60
  ```js
61
61
  any([0])
62
- // => false
62
+ // false
63
63
 
64
64
  any([0, 1, null, undefined])
65
- // => true
65
+ // true
66
66
 
67
67
  any([1, 4, 5] => (n) => n % 2 === 0)
68
- // => true
68
+ // true
69
69
  ```
70
70
  @see {@link all}
71
71
  */
@@ -87,16 +87,16 @@ export function chain(...iterables) {
87
87
  * @example
88
88
  ```js
89
89
  contains([1, 2, 3], 1)
90
- // => true
90
+ // true
91
91
 
92
92
  contains([1, 2, 3], 1, 2)
93
- // => false
93
+ // false
94
94
 
95
95
  contains({ 'a': 1, 'b': 2 }, 1)
96
- // => true
96
+ // true
97
97
 
98
98
  contains('abcd', 'bc')
99
- // => true
99
+ // true
100
100
  ```
101
101
  *
102
102
  * @see {@link Collections.find}
@@ -109,7 +109,6 @@ export function contains(collection, value) {
109
109
  return includes;
110
110
  return any(collection, (x) => eq(value, x));
111
111
  }
112
- const compKey = (compare, key) => (x, y) => compare(key(x), key(y));
113
112
  /**
114
113
  * Returns a generator that drops elements from the iterable as long as the predicate is `true`; afterwards, returns every remaining element. Note, the generator does not produce any output until the predicate first becomes `false`.
115
114
  * @param iterable The iterable to inspect.
@@ -142,13 +141,12 @@ export function iforEach(iterable, fun) {
142
141
  }
143
142
  }
144
143
  export function IterableIterator(next) {
145
- const it = {
144
+ return {
146
145
  next,
147
146
  [Symbol.iterator]() {
148
147
  return this;
149
148
  }
150
149
  };
151
- return it;
152
150
  }
153
151
  /**
154
152
  * Yields elements like `[index, item]` from an iterable. Index starts at zero by default.
@@ -159,11 +157,11 @@ export function IterableIterator(next) {
159
157
  * @example
160
158
  ```js
161
159
  console.log([...enumerate(['hello', 'world'])])
162
- // => [[0, 'hello'], [1, 'world']]
160
+ // [[0, 'hello'], [1, 'world']]
163
161
 
164
162
  // Start with index `1`
165
163
  console.log([...enumerate(['hello', 'world'], 1)])
166
- // => [[1, 'hello'], [2, 'world']]
164
+ // [[1, 'hello'], [2, 'world']]
167
165
  ```
168
166
  */
169
167
  export function* enumerate(iterable, start = 0) {
@@ -187,7 +185,7 @@ export function first(iterable) {
187
185
  * @example
188
186
  ```js
189
187
  compact([0, 1, false, 2, '', 3])
190
- // => [1, 2, 3]
188
+ // [1, 2, 3]
191
189
  ```
192
190
  */
193
191
  export function* icompact(iterable) {
@@ -216,7 +214,7 @@ export function* imap(iterable, mapFn) {
216
214
  * @example
217
215
  ```js
218
216
  [...iflatten([[0, 1], [2, 3]])]
219
- // => [0, 1, 2, 3]
217
+ // [0, 1, 2, 3]
220
218
  ```
221
219
  */
222
220
  export function* iflatten(iterables) {
@@ -287,19 +285,19 @@ export function partition(iterable, predicate) {
287
285
  * @example
288
286
  ```js
289
287
  range(5)
290
- // => [0, 1, 2, 3, 4]
288
+ // [0, 1, 2, 3, 4]
291
289
 
292
290
  range(2, 5)
293
- // => [2, 3, 4]
291
+ // [2, 3, 4]
294
292
 
295
293
  range(0, 5, 2)
296
- // => [0, 2, 4]
294
+ // [0, 2, 4]
297
295
 
298
296
  range(5, 0, -1)
299
- // => [5, 4, 3, 2, 1]
297
+ // [5, 4, 3, 2, 1]
300
298
 
301
299
  range(-3)
302
- // => []
300
+ // []
303
301
  ```
304
302
  */
305
303
  export function* range(...args) {
@@ -333,7 +331,7 @@ export function* range(...args) {
333
331
  * @example
334
332
  ```js
335
333
  reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0)
336
- // => 15
334
+ // 15
337
335
  ```
338
336
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce Array.reduce()}
339
337
  */
@@ -353,26 +351,11 @@ export function reduce(iterable, reducer, initial) {
353
351
  export function reversed(iterable) {
354
352
  return Array.from(iterable).reverse();
355
353
  }
356
- /**
357
- * Creates a new sorted list from the elements in the array. This can be called many ways:
358
- * - sorted([...], true) => reverse order
359
- * - sorted([...], fn = (x) => any) => using a key fn
360
- * - sorted([...], fn = (x) => any, true) => reverse order using key
361
- * - sorted([...], false, (x, y) => number) => using custom compare
362
- * - sorted([...], fn = (x) => any, true, (x, y) => number) => custom key, reverse and compare
363
- *
364
- * If `args` is an Object, returns the sorted keys.
365
- *
366
- *
367
- * @param {(Array | Object)} args
368
- * @param {(boolean | Function)} [key]
369
- * @param {(boolean | Comparer)} [reverse]
370
- * @param {Comparer} [compareFn]
371
- * @return
372
- */
354
+ const compKey = (compare, key) => (x, y) => compare(key(x), key(y));
373
355
  export function sorted(args, key, reverse, compareFn) {
374
- if (isObject(args))
356
+ if (isObject(args)) {
375
357
  args = Object.keys(args);
358
+ }
376
359
  if (typeof key === 'boolean') {
377
360
  if (typeof reverse === 'function') {
378
361
  compareFn = reverse;
@@ -390,24 +373,13 @@ export function sorted(args, key, reverse, compareFn) {
390
373
  copy.reverse();
391
374
  return copy;
392
375
  }
393
- /**
394
- * Sort `args` in place. Can be called like this:
395
- * - sort([...], true) => reverse order
396
- * - sort([...], (x, y) => number) => using custom compare
397
- * - sort([...], true, (x, y) => number) => reverse and using custom compare
398
- *
399
- * @param {any[]} args
400
- * @param {(boolean | Comparer)} [reverse]
401
- * @param {Comparer} [compareFn]
402
- * @return
403
- */
404
376
  export function sort(args, reverse, compareFn) {
405
377
  if (typeof reverse === 'function') {
406
378
  compareFn = reverse;
407
379
  reverse = false;
408
380
  }
409
381
  args.sort(compareFn || compare);
410
- if (reverse === true)
382
+ if (reverse)
411
383
  args.reverse();
412
384
  return args;
413
385
  }
@@ -445,9 +417,9 @@ export function* times(n, fn) {
445
417
  ```js
446
418
  for item of zip([1, 2, 3], ['sugar', 'spice', 'nice'])
447
419
  console.log(item)
448
- // => [1, 'sugar']
449
- // => [2, 'spice']
450
- // => [3, 'nice']
420
+ // [1, 'sugar']
421
+ // [2, 'spice']
422
+ // [3, 'nice']
451
423
  ```
452
424
  */
453
425
  export function* zip(...args) {
@@ -43,7 +43,7 @@ export declare const ceil: (x: number) => number;
43
43
  * @param y
44
44
  * @returns
45
45
  */
46
- export declare function divmod(x: number, y: number): number[];
46
+ export declare function divmod(x: number, y: number): [number, number];
47
47
  export declare function log2(x: any): number;
48
48
  export declare function logBase(x: any, y: any): number;
49
49
  /**
@@ -66,18 +66,18 @@ export declare function max<T>(iterable: Iterable<T>, key?: Predicate<T>): T;
66
66
  * Computes the mean of the values in `iterable` and accepts an optional `key` function which is invoked for each element to generate the values to be averaged.
67
67
  * @param {Array<number>|Iterable<T>} iterable
68
68
  * @param {Function} [key] Optional iteratee invoked per element.
69
- * @returns Returns the mean value or `false` if no elements.
69
+ * @returns Returns the mean value or `NaN` if no elements.
70
70
  * @template T
71
71
  * @example
72
72
  ```js
73
73
  let objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]
74
74
 
75
75
  mean(objects, (o) => o.n)
76
- // => 5
76
+ // 5
77
77
  ```
78
78
  */
79
- export declare function mean(iterable: number[]): false | number;
80
- export declare function mean<T>(iterable: Iterable<T>, key?: Predicate<T>): false | number;
79
+ export declare function mean(iterable: number[]): number;
80
+ export declare function mean<T>(iterable: Iterable<T>, key?: Predicate<T>): number;
81
81
  /**
82
82
  * Sums `initial` and the items of an iterable and returns the total.
83
83
  * @param args The elements to add to `initial`.
@@ -86,12 +86,11 @@ export declare function mean<T>(iterable: Iterable<T>, key?: Predicate<T>): fals
86
86
  * @example
87
87
  ```js
88
88
  sum([1, 2, 3, 4])
89
- // => 10
89
+ // 10
90
90
 
91
91
  sum([1, 2, 3, 4], 5)
92
- // => 15
92
+ // 15
93
93
  ```
94
94
  */
95
- export declare function sum(iterable: number[]): number;
96
- export declare function sum<T>(iterable: Iterable<T>, key?: Predicate<T>): T;
97
- export declare function sum<T>(iterable: Iterable<T>, key?: Predicate<T>): T;
95
+ export declare function sum(args: number[]): number;
96
+ export declare function sum<T>(args: Iterable<T>, key?: Predicate<T>): number;
@@ -81,7 +81,9 @@ export function mean(iterable, key = id) {
81
81
  total += key(value);
82
82
  count++;
83
83
  }
84
- return count !== 0 && total / count;
84
+ if (count !== 0)
85
+ return total / count;
86
+ return Number.NaN;
85
87
  }
86
88
  export function sum(args, key = id) {
87
89
  let initial = 0;
@@ -35,8 +35,8 @@ export declare type Comparer<T = any> = (x: T, y: T) => number;
35
35
  * @param {*} y Other value to compare
36
36
  * @returns {number} The comparison result
37
37
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
38
- * @see {@link eq}
39
- * @see {@link lt}
38
+ * @see {@link Operators.eq}
39
+ * @see {@link Operators.lt}
40
40
  */
41
41
  export declare function compare(x: any, y: any): number;
42
42
  /**
@@ -72,7 +72,7 @@ export declare function lte(x: any, y: any): boolean;
72
72
  * @param {*} y
73
73
  * @returns {boolean} `true` if `x` is strictly greater than `y` or `false` otherwise.
74
74
  */
75
- export declare function gt(x: any, y: any): any;
75
+ export declare function gt(x: any, y: any): boolean;
76
76
  /**
77
77
  * Compares two values to check if `x >= y`. If `x` is an object with a `gte` method, it returns `x.gte(y)`, also checks `x.eq(y)` and `x.gt(y)`.
78
78
  * Otherwise it returns the result of `x >= y`.
@@ -145,4 +145,4 @@ export declare function shallowEqual(obj: any, other: any): boolean;
145
145
  * @param other
146
146
  * @returns `true` if the objects are considered equal.
147
147
  */
148
- export declare function deepEqual(obj: any, other: any, checker?: typeof eq, seen?: WeakSet<object>): boolean;
148
+ export declare function deepEqual(obj: any, other: any, checker?: Function, seen?: any): boolean;
@@ -36,8 +36,8 @@ export const isinstance = (x, y) => x instanceof y;
36
36
  * @param {*} y Other value to compare
37
37
  * @returns {number} The comparison result
38
38
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
39
- * @see {@link eq}
40
- * @see {@link lt}
39
+ * @see {@link Operators.eq}
40
+ * @see {@link Operators.lt}
41
41
  */
42
42
  export function compare(x, y) {
43
43
  if (x === y || eq(x, y))
@@ -231,12 +231,6 @@ export function shallowEqual(obj, other) {
231
231
  }
232
232
  return false;
233
233
  }
234
- /**
235
- * Performs a recursive comparison of two objects or arrays to check if they have the same keys, length and values. Unlike {@link shallowEqual} this method compares nested values also.
236
- * @param obj
237
- * @param other
238
- * @returns `true` if the objects are considered equal.
239
- */
240
234
  export function deepEqual(obj, other, checker = eq, seen = new WeakSet()) {
241
235
  if (checker(obj, other))
242
236
  return true;
@@ -22,7 +22,7 @@ export declare const randomInt: (min?: number, max?: number) => number;
22
22
  * @returns {T}
23
23
  * @template T
24
24
  */
25
- export declare const choice: <T>(arr: T[]) => T | undefined;
25
+ export declare function choice<T>(arr: T[]): T;
26
26
  /**
27
27
  * Returns a random sample of size k from a list of items.
28
28
  * @param {Array} arr
@@ -23,11 +23,11 @@ export const randomInt = (min = 0, max = 1) => Math.round(random(min, max));
23
23
  * @returns {T}
24
24
  * @template T
25
25
  */
26
- export const choice = (arr) => {
27
- if (!arr || !arr.length)
26
+ export function choice(arr) {
27
+ if (!arr?.length)
28
28
  return;
29
29
  return arr[randomInt(0, arr.length - 1)];
30
- };
30
+ }
31
31
  /**
32
32
  * Returns a random sample of size k from a list of items.
33
33
  * @param {Array} arr
@@ -36,7 +36,7 @@ export const choice = (arr) => {
36
36
  * @template T
37
37
  */
38
38
  export function sample(arr, size) {
39
- if (!arr || !arr.length || arr.length < size)
39
+ if (!arr?.length || arr.length < size)
40
40
  return [];
41
41
  return shuffle(arr.slice()).slice(-size);
42
42
  }
@@ -49,7 +49,7 @@ export function sample(arr, size) {
49
49
  * @template T
50
50
  */
51
51
  export function shuffle(arr, size) {
52
- if (!arr || !arr.length)
52
+ if (!arr?.length)
53
53
  return arr;
54
54
  if (isObject(arr))
55
55
  arr = Object.values(arr);