atomic-fns 0.3.3 → 0.3.5

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 (48) hide show
  1. package/README.md +18 -4
  2. package/core/collections/LRUCache.d.ts +22 -1
  3. package/core/collections/LRUCache.js +22 -1
  4. package/core/collections/LRUCache.ts +22 -1
  5. package/core/collections/SortedMap.d.ts +1 -1
  6. package/core/collections/SortedMap.js +1 -1
  7. package/core/collections/SortedMap.ts +1 -1
  8. package/core/collections/SortedSet.d.ts +6 -0
  9. package/core/collections/SortedSet.js +6 -0
  10. package/core/collections/SortedSet.ts +6 -0
  11. package/core/collections/SortedTree.d.ts +3 -3
  12. package/core/collections/SortedTree.js +3 -3
  13. package/core/collections/SortedTree.ts +3 -3
  14. package/core/collections/abc.d.ts +1 -1
  15. package/core/collections/abc.ts +1 -1
  16. package/core/collections/deque.d.ts +55 -48
  17. package/core/collections/deque.js +61 -53
  18. package/core/collections/deque.ts +63 -54
  19. package/core/collections/index.d.ts +2 -0
  20. package/core/collections/index.js +7 -5
  21. package/core/collections/index.ts +7 -5
  22. package/core/functools/index.d.ts +3 -2
  23. package/core/functools/index.ts +8 -3
  24. package/core/globals/index.d.ts +23 -4
  25. package/core/globals/index.js +29 -6
  26. package/core/globals/index.ts +40 -7
  27. package/core/i18n/date/format.d.ts +16 -0
  28. package/core/i18n/date/format.js +307 -0
  29. package/core/i18n/date/format.ts +343 -0
  30. package/core/i18n/date/index.d.ts +224 -0
  31. package/core/i18n/date/index.js +387 -0
  32. package/core/i18n/date/index.ts +471 -0
  33. package/core/i18n/date/test.html +67 -0
  34. package/core/i18n/index.d.ts +7 -0
  35. package/core/i18n/index.js +7 -0
  36. package/core/i18n/index.ts +8 -0
  37. package/core/index.d.ts +1 -0
  38. package/core/index.js +1 -0
  39. package/core/index.ts +1 -0
  40. package/core/operators/index.d.ts +1 -1
  41. package/core/operators/index.js +35 -5
  42. package/core/operators/index.ts +34 -6
  43. package/package.json +11 -11
  44. package/tests/globals.spec.ts +12 -12
  45. package/tsconfig.json +2 -1
  46. package/core/datetime/index.d.ts +0 -45
  47. package/core/datetime/index.js +0 -71
  48. package/core/datetime/index.ts +0 -128
@@ -4,36 +4,39 @@ import { eq } from '../operators/index.js';
4
4
  import { Sequence } from './abc.js';
5
5
  /**
6
6
  * Fixed capacity double-ended queue implemented as ring deque.
7
- *
8
- * @constructor
7
+ * @template T
9
8
  */
10
9
  export class Deque extends Sequence {
11
10
  items;
12
11
  start = 0;
13
12
  count = 0;
14
13
  capacity;
15
- ArrayClass;
16
- constructor(ArrayClass = [], capacity = 1024) {
14
+ ArrayConstructor;
15
+ /**
16
+ * Creates a new `Deque` instance of a fixed size.
17
+ * @param {Array} [arrType = []] The initial elements or array type to use (accepts any kind of typed array).
18
+ * @param {number} [capacity=1024] The fixed size of the deque. Defaults to `1024`.
19
+ */
20
+ constructor(arrType = [], capacity = 1024) {
17
21
  super();
18
22
  if (typeof capacity !== 'number' || capacity <= 0)
19
23
  throw new ValueError(`Deque capacity should be a positive integer.`);
20
- this.ArrayClass = ArrayClass.constructor;
24
+ this.ArrayConstructor = arrType.constructor;
21
25
  this.capacity = capacity;
22
- this.items = new this.ArrayClass(ArrayClass.length || this.capacity);
26
+ this.items = new this.ArrayConstructor(arrType.length || this.capacity);
23
27
  this.clear();
24
- if (ArrayClass.length) {
25
- for (const item of ArrayClass) {
28
+ if (arrType.length) {
29
+ for (const item of arrType) {
26
30
  this.append(item);
27
31
  }
28
32
  }
29
33
  }
34
+ /** Returns the total number of elements in the deque. */
30
35
  get size() {
31
36
  return this.count;
32
37
  }
33
38
  /**
34
39
  * Method used to clear the structure.
35
- *
36
- * @return {undefined}
37
40
  */
38
41
  clear() {
39
42
  // Properties
@@ -42,18 +45,16 @@ export class Deque extends Sequence {
42
45
  }
43
46
  /**
44
47
  * Alias of {@link Deque.append}
45
- *
46
- * @param {any} item - Item to append.
47
- * @return {number} - Returns the new size of the deque.
48
+ * @param {T} item Item to append.
49
+ * @returns {number} Returns the new size of the deque.
48
50
  */
49
51
  add(item) {
50
52
  return this.append(item);
51
53
  }
52
54
  /**
53
- * Method used to append a value to the deque.
54
- *
55
- * @param {any} item - Item to append.
56
- * @return {number} - Returns the new size of the deque.
55
+ * Appends a new element to the end of the deque.
56
+ * @param {T} item Item to append.
57
+ * @returns {number} Returns the new size of the deque.
57
58
  */
58
59
  append(item) {
59
60
  if (this.count === this.capacity)
@@ -63,10 +64,9 @@ export class Deque extends Sequence {
63
64
  return ++this.count;
64
65
  }
65
66
  /**
66
- * Method used to prepend a value to the deque.
67
- *
68
- * @param {any} item - Item to prepend.
69
- * @return {number} - Returns the new size of the deque.
67
+ * Appends a new element to the beginning of the deque.
68
+ * @param {T} item Item to prepend.
69
+ * @returns {number} Returns the new size of the deque.
70
70
  */
71
71
  appendleft(item) {
72
72
  if (this.count === this.capacity)
@@ -79,9 +79,8 @@ export class Deque extends Sequence {
79
79
  return ++this.count;
80
80
  }
81
81
  /**
82
- * Method used to pop the deque.
83
- *
84
- * @return {any} - Returns the popped item.
82
+ * Removes and returns the element at the end of the deque.
83
+ * @returns {?T} Returns the popped item.
85
84
  */
86
85
  pop() {
87
86
  if (this.count === 0)
@@ -92,14 +91,14 @@ export class Deque extends Sequence {
92
91
  }
93
92
  /**
94
93
  * Alias of {@link Deque.pop}
94
+ * @returns {?T} Returns the popped item.
95
95
  */
96
96
  remove() {
97
97
  return this.pop();
98
98
  }
99
99
  /**
100
- * Method used to shift the deque.
101
- *
102
- * @return {any} - Returns the shifted item.
100
+ * Removes and returns the element at the beginning of the deque.
101
+ * @returns {?T} Returns the removed deque element.
103
102
  */
104
103
  popleft() {
105
104
  if (this.count === 0)
@@ -112,9 +111,8 @@ export class Deque extends Sequence {
112
111
  return this.items[index];
113
112
  }
114
113
  /**
115
- * Method used to peek the first value of the deque.
116
- *
117
- * @return {any}
114
+ * Returns the element at the beginning of the deque.
115
+ * @returns {?T} The element if exists
118
116
  */
119
117
  first() {
120
118
  if (this.count === 0)
@@ -122,10 +120,9 @@ export class Deque extends Sequence {
122
120
  return this.items[this.start];
123
121
  }
124
122
  /**
125
- * Method used to get the desired value of the deque.
126
- *
127
- * @param {number} index
128
- * @return {any}
123
+ * Returns the element at a specified index position in the deque.
124
+ * @param {number} index The given index
125
+ * @returns {?T} The element if exists
129
126
  */
130
127
  get(index) {
131
128
  if (this.count === 0)
@@ -138,9 +135,8 @@ export class Deque extends Sequence {
138
135
  return this.items[index];
139
136
  }
140
137
  /**
141
- * Update the value at a given `index`.
142
- * @param index The given index
143
- * @param value The new value to set at `index`.
138
+ * Update the element at a given `index`.
139
+ * @param {number} index The given index
144
140
  */
145
141
  set(index, value) {
146
142
  if (index < 0)
@@ -149,6 +145,11 @@ export class Deque extends Sequence {
149
145
  throw new KeyError(`Invalid index: ${index} not in Deque.`);
150
146
  this.items[index] = value;
151
147
  }
148
+ /**
149
+ * Check if a given element is in the deque.
150
+ * @param {T} x The value to find
151
+ * @returns {boolean} `true` if the value is found
152
+ */
152
153
  contains(x) {
153
154
  for (const value of this.values()) {
154
155
  if (eq(x, value))
@@ -156,6 +157,11 @@ export class Deque extends Sequence {
156
157
  }
157
158
  return false;
158
159
  }
160
+ /**
161
+ * Returns the first element that matches the `iteratee` function.
162
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
163
+ * @returns {?T} The element if exists
164
+ */
159
165
  find(iteratee) {
160
166
  for (const [key, value] of this.entries()) {
161
167
  if (iteratee(value, key, this))
@@ -163,11 +169,8 @@ export class Deque extends Sequence {
163
169
  }
164
170
  }
165
171
  /**
166
- * Method used to iterate over the deque.
167
- *
168
- * @param {function} iteratee - Function to call for each item.
169
- * @param {object} scope - Optional scope.
170
- * @return {undefined}
172
+ * Calls `iteratee` function for every element in the deque.
173
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
171
174
  */
172
175
  forEach(iteratee) {
173
176
  const c = this.capacity;
@@ -182,20 +185,23 @@ export class Deque extends Sequence {
182
185
  i = 0;
183
186
  }
184
187
  }
188
+ /**
189
+ * Returns a new array with all the elements in reverse order.
190
+ * @returns {Array<T>} The elements reversed
191
+ */
185
192
  reversed() {
186
193
  return this.toArray().reverse();
187
194
  }
188
195
  /**
189
- * Method used to convert the deque to a JavaScript array.
190
- *
191
- * @return {array}
196
+ * Returns a new array with all the elements in the order they were added to the deque.
197
+ * @returns {Array<T>} The elements array
192
198
  */
193
199
  toArray() {
194
200
  // Optimization
195
201
  const offset = this.start + this.count;
196
202
  if (offset < this.capacity)
197
203
  return this.items.slice(this.start, offset);
198
- const array = new this.ArrayClass(this.count);
204
+ const array = new this.ArrayConstructor(this.count);
199
205
  const c = this.capacity;
200
206
  const l = this.count;
201
207
  let i = this.start;
@@ -210,9 +216,8 @@ export class Deque extends Sequence {
210
216
  return array;
211
217
  }
212
218
  /**
213
- * Method used to create an iterator over the deque's values.
214
- *
215
- * @return {Iterator}
219
+ * Returns an iterator over the deque's values.
220
+ * @returns {Iterator}
216
221
  */
217
222
  values() {
218
223
  const items = this.items;
@@ -236,13 +241,15 @@ export class Deque extends Sequence {
236
241
  };
237
242
  });
238
243
  }
244
+ /**
245
+ * Alias of {@link Deque.values}. Returns iterator of values.
246
+ */
239
247
  keys() {
240
248
  return this.values();
241
249
  }
242
250
  /**
243
- * Method used to create an iterator over the deque's entries.
244
- *
245
- * @return {Iterator}
251
+ * Creates an iterator of `[index, value]` pairs for all elements in the deque.
252
+ * @returns {Iterator}
246
253
  */
247
254
  entries() {
248
255
  const items = this.items;
@@ -271,9 +278,10 @@ export class Deque extends Sequence {
271
278
  [Symbol.for('nodejs.util.inspect.custom')]() {
272
279
  return this.inspect();
273
280
  }
281
+ // This is just for debugging in nodejs
274
282
  inspect() {
275
283
  const array = this.toArray();
276
- array.type = this.ArrayClass.name;
284
+ array.type = this.ArrayConstructor.name;
277
285
  array.capacity = this.capacity;
278
286
  // Trick so that node displays the name of the constructor
279
287
  Object.defineProperty(array, 'constructor', {
@@ -5,40 +5,44 @@ import { Sequence } from './abc.js'
5
5
 
6
6
  /**
7
7
  * Fixed capacity double-ended queue implemented as ring deque.
8
- *
9
- * @constructor
8
+ * @template T
10
9
  */
11
- export class Deque<T> extends Sequence<T> {
10
+ export class Deque<T = any> extends Sequence<T> {
12
11
  items: T[]
13
12
  start: number = 0
14
13
  count: number = 0
15
14
  capacity: number
16
- ArrayClass: any
15
+ ArrayConstructor: any
17
16
 
18
- constructor(ArrayClass = [] as T[], capacity = 1024) {
17
+ /**
18
+ * Creates a new `Deque` instance of a fixed size.
19
+ * @param {Array} [arrType = []] The initial elements or array type to use (accepts any kind of typed array).
20
+ * @param {number} [capacity=1024] The fixed size of the deque. Defaults to `1024`.
21
+ */
22
+ constructor(arrType = [] as T[], capacity = 1024) {
19
23
  super()
20
24
  if (typeof capacity !== 'number' || capacity <= 0)
21
25
  throw new ValueError(`Deque capacity should be a positive integer.`)
22
26
 
23
- this.ArrayClass = ArrayClass.constructor
27
+ this.ArrayConstructor = arrType.constructor
24
28
  this.capacity = capacity
25
- this.items = new this.ArrayClass(ArrayClass.length || this.capacity)
29
+ this.items = new this.ArrayConstructor(arrType.length || this.capacity)
26
30
  this.clear()
27
- if (ArrayClass.length) {
28
- for (const item of ArrayClass) {
31
+
32
+ if (arrType.length) {
33
+ for (const item of arrType) {
29
34
  this.append(item)
30
35
  }
31
36
  }
32
37
  }
33
38
 
39
+ /** Returns the total number of elements in the deque. */
34
40
  get size() {
35
41
  return this.count
36
42
  }
37
43
 
38
44
  /**
39
45
  * Method used to clear the structure.
40
- *
41
- * @return {undefined}
42
46
  */
43
47
  clear() {
44
48
  // Properties
@@ -48,19 +52,17 @@ export class Deque<T> extends Sequence<T> {
48
52
 
49
53
  /**
50
54
  * Alias of {@link Deque.append}
51
- *
52
- * @param {any} item - Item to append.
53
- * @return {number} - Returns the new size of the deque.
55
+ * @param {T} item Item to append.
56
+ * @returns {number} Returns the new size of the deque.
54
57
  */
55
58
  add(item) {
56
59
  return this.append(item)
57
60
  }
58
61
 
59
62
  /**
60
- * Method used to append a value to the deque.
61
- *
62
- * @param {any} item - Item to append.
63
- * @return {number} - Returns the new size of the deque.
63
+ * Appends a new element to the end of the deque.
64
+ * @param {T} item Item to append.
65
+ * @returns {number} Returns the new size of the deque.
64
66
  */
65
67
  append(item) {
66
68
  if (this.count === this.capacity) this.popleft()
@@ -73,10 +75,9 @@ export class Deque<T> extends Sequence<T> {
73
75
  }
74
76
 
75
77
  /**
76
- * Method used to prepend a value to the deque.
77
- *
78
- * @param {any} item - Item to prepend.
79
- * @return {number} - Returns the new size of the deque.
78
+ * Appends a new element to the beginning of the deque.
79
+ * @param {T} item Item to prepend.
80
+ * @returns {number} Returns the new size of the deque.
80
81
  */
81
82
  appendleft(item) {
82
83
  if (this.count === this.capacity) this.pop()
@@ -92,9 +93,8 @@ export class Deque<T> extends Sequence<T> {
92
93
  }
93
94
 
94
95
  /**
95
- * Method used to pop the deque.
96
- *
97
- * @return {any} - Returns the popped item.
96
+ * Removes and returns the element at the end of the deque.
97
+ * @returns {?T} Returns the popped item.
98
98
  */
99
99
  pop() {
100
100
  if (this.count === 0) return
@@ -108,15 +108,15 @@ export class Deque<T> extends Sequence<T> {
108
108
 
109
109
  /**
110
110
  * Alias of {@link Deque.pop}
111
+ * @returns {?T} Returns the popped item.
111
112
  */
112
113
  remove() {
113
114
  return this.pop()
114
115
  }
115
116
 
116
117
  /**
117
- * Method used to shift the deque.
118
- *
119
- * @return {any} - Returns the shifted item.
118
+ * Removes and returns the element at the beginning of the deque.
119
+ * @returns {?T} Returns the removed deque element.
120
120
  */
121
121
  popleft() {
122
122
  if (this.count === 0) return
@@ -132,9 +132,8 @@ export class Deque<T> extends Sequence<T> {
132
132
  }
133
133
 
134
134
  /**
135
- * Method used to peek the first value of the deque.
136
- *
137
- * @return {any}
135
+ * Returns the element at the beginning of the deque.
136
+ * @returns {?T} The element if exists
138
137
  */
139
138
  first() {
140
139
  if (this.count === 0) return
@@ -143,10 +142,9 @@ export class Deque<T> extends Sequence<T> {
143
142
  }
144
143
 
145
144
  /**
146
- * Method used to get the desired value of the deque.
147
- *
148
- * @param {number} index
149
- * @return {any}
145
+ * Returns the element at a specified index position in the deque.
146
+ * @param {number} index The given index
147
+ * @returns {?T} The element if exists
150
148
  */
151
149
  get(index) {
152
150
  if (this.count === 0) return
@@ -160,9 +158,8 @@ export class Deque<T> extends Sequence<T> {
160
158
  }
161
159
 
162
160
  /**
163
- * Update the value at a given `index`.
164
- * @param index The given index
165
- * @param value The new value to set at `index`.
161
+ * Update the element at a given `index`.
162
+ * @param {number} index The given index
166
163
  */
167
164
  set(index: number, value: T) {
168
165
  if (index < 0) index += this.count
@@ -170,6 +167,11 @@ export class Deque<T> extends Sequence<T> {
170
167
  this.items[index] = value
171
168
  }
172
169
 
170
+ /**
171
+ * Check if a given element is in the deque.
172
+ * @param {T} x The value to find
173
+ * @returns {boolean} `true` if the value is found
174
+ */
173
175
  contains(x) {
174
176
  for (const value of this.values()) {
175
177
  if (eq(x, value)) return true
@@ -177,6 +179,11 @@ export class Deque<T> extends Sequence<T> {
177
179
  return false
178
180
  }
179
181
 
182
+ /**
183
+ * Returns the first element that matches the `iteratee` function.
184
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
185
+ * @returns {?T} The element if exists
186
+ */
180
187
  find(iteratee: Iteratee<T>) {
181
188
  for (const [key, value] of this.entries()) {
182
189
  if (iteratee(value, key, this)) return value
@@ -184,11 +191,8 @@ export class Deque<T> extends Sequence<T> {
184
191
  }
185
192
 
186
193
  /**
187
- * Method used to iterate over the deque.
188
- *
189
- * @param {function} iteratee - Function to call for each item.
190
- * @param {object} scope - Optional scope.
191
- * @return {undefined}
194
+ * Calls `iteratee` function for every element in the deque.
195
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
192
196
  */
193
197
  forEach(iteratee) {
194
198
  const c = this.capacity
@@ -205,14 +209,17 @@ export class Deque<T> extends Sequence<T> {
205
209
  }
206
210
  }
207
211
 
212
+ /**
213
+ * Returns a new array with all the elements in reverse order.
214
+ * @returns {Array<T>} The elements reversed
215
+ */
208
216
  reversed() {
209
217
  return this.toArray().reverse()
210
218
  }
211
219
 
212
220
  /**
213
- * Method used to convert the deque to a JavaScript array.
214
- *
215
- * @return {array}
221
+ * Returns a new array with all the elements in the order they were added to the deque.
222
+ * @returns {Array<T>} The elements array
216
223
  */
217
224
  toArray() {
218
225
  // Optimization
@@ -220,7 +227,7 @@ export class Deque<T> extends Sequence<T> {
220
227
 
221
228
  if (offset < this.capacity) return this.items.slice(this.start, offset)
222
229
 
223
- const array = new this.ArrayClass(this.count)
230
+ const array = new this.ArrayConstructor(this.count)
224
231
  const c = this.capacity
225
232
  const l = this.count
226
233
  let i = this.start
@@ -238,9 +245,8 @@ export class Deque<T> extends Sequence<T> {
238
245
  }
239
246
 
240
247
  /**
241
- * Method used to create an iterator over the deque's values.
242
- *
243
- * @return {Iterator}
248
+ * Returns an iterator over the deque's values.
249
+ * @returns {Iterator}
244
250
  */
245
251
  values(): Iterable<T> {
246
252
  const items = this.items
@@ -269,14 +275,16 @@ export class Deque<T> extends Sequence<T> {
269
275
  })
270
276
  }
271
277
 
278
+ /**
279
+ * Alias of {@link Deque.values}. Returns iterator of values.
280
+ */
272
281
  keys() {
273
282
  return this.values()
274
283
  }
275
284
 
276
285
  /**
277
- * Method used to create an iterator over the deque's entries.
278
- *
279
- * @return {Iterator}
286
+ * Creates an iterator of `[index, value]` pairs for all elements in the deque.
287
+ * @returns {Iterator}
280
288
  */
281
289
  entries() {
282
290
  const items = this.items
@@ -312,10 +320,11 @@ export class Deque<T> extends Sequence<T> {
312
320
  return this.inspect()
313
321
  }
314
322
 
323
+ // This is just for debugging in nodejs
315
324
  inspect() {
316
325
  const array = this.toArray()
317
326
 
318
- array.type = this.ArrayClass.name
327
+ array.type = this.ArrayConstructor.name
319
328
  array.capacity = this.capacity
320
329
 
321
330
  // Trick so that node displays the name of the constructor
@@ -110,6 +110,8 @@ export declare function findRight(arr: any, fn: Iteratee | PropertyKey | Object)
110
110
  /**
111
111
  * Performs an efficient array insert operation in the given array. If the index or the array is invalid, it just returns the given array.
112
112
  *
113
+ * **Note:** Uses the same behavior as `Array.splice`.
114
+ *
113
115
  * @param {Array<*>} arr The given array to insert into
114
116
  * @param {number} index The index of the array insert operation.
115
117
  * @param {*} value The value to insert in the array at the given `index`.
@@ -4,7 +4,7 @@
4
4
  * @module Collections
5
5
  */
6
6
  import { partial } from '../functools/index.js';
7
- import { call, get, isArray, isArrayLike, isBool, isEmpty, isFunc, isIterable, isNull, isNumber, isObject, isString, isSymbol, keys, set } from '../globals/index.js';
7
+ import { call, get, isArray, isArrayLike, isBool, isEmpty, isFunction, isIterable, isNull, isNumber, isObject, isString, isSymbol, keys, set } from '../globals/index.js';
8
8
  import { enumerate } from '../itertools/index.js';
9
9
  import { compare, eq, id } from '../operators/index.js';
10
10
  export * from './abc.js';
@@ -81,7 +81,7 @@ filter(users, 'active')
81
81
  */
82
82
  export function filter(arr, fn = isNull) {
83
83
  if (Array.isArray(arr)) {
84
- if (isFunc(fn))
84
+ if (isFunction(fn))
85
85
  return arr.filter(fn);
86
86
  if (isNumber(fn) || isString(fn) || isSymbol(fn))
87
87
  return arr.filter((x) => get(fn, x));
@@ -117,7 +117,7 @@ find(users, 'active')
117
117
  */
118
118
  export function find(arr, fn) {
119
119
  if (Array.isArray(arr)) {
120
- if (isFunc(fn))
120
+ if (isFunction(fn))
121
121
  return arr.find(fn);
122
122
  if (isNumber(fn) || isString(fn) || isSymbol(fn))
123
123
  return arr.find((x) => x?.[fn]);
@@ -159,6 +159,8 @@ export function findRight(arr, fn) {
159
159
  /**
160
160
  * Performs an efficient array insert operation in the given array. If the index or the array is invalid, it just returns the given array.
161
161
  *
162
+ * **Note:** Uses the same behavior as `Array.splice`.
163
+ *
162
164
  * @param {Array<*>} arr The given array to insert into
163
165
  * @param {number} index The index of the array insert operation.
164
166
  * @param {*} value The value to insert in the array at the given `index`.
@@ -642,7 +644,7 @@ export function clone(value, deep = false) {
642
644
  return cloneArray(value, deep);
643
645
  }
644
646
  if (isObject(value)) {
645
- if (isFunc(value.clone)) {
647
+ if (isFunction(value.clone)) {
646
648
  return value.clone();
647
649
  }
648
650
  const copy = {};
@@ -974,7 +976,7 @@ export function remove(arr, func) {
974
976
  return arr.filter((x, i) => {
975
977
  if (isArray(func))
976
978
  return !func.includes(x);
977
- else if (isFunc(func))
979
+ else if (isFunction(func))
978
980
  return !func(x, i, arr);
979
981
  return x !== func;
980
982
  });
@@ -12,7 +12,7 @@ import {
12
12
  isArrayLike,
13
13
  isBool,
14
14
  isEmpty,
15
- isFunc,
15
+ isFunction,
16
16
  isIterable,
17
17
  isNull,
18
18
  isNumber,
@@ -114,7 +114,7 @@ filter(users, 'active')
114
114
  */
115
115
  export function filter(arr, fn: Iteratee | PropertyKey | Object = isNull) {
116
116
  if (Array.isArray(arr)) {
117
- if (isFunc(fn)) return arr.filter(fn)
117
+ if (isFunction(fn)) return arr.filter(fn)
118
118
  if (isNumber(fn) || isString(fn) || isSymbol(fn)) return arr.filter((x) => get(fn, x))
119
119
  if (isObject(fn)) return arr.filter(matches(fn))
120
120
  }
@@ -148,7 +148,7 @@ find(users, 'active')
148
148
  */
149
149
  export function find(arr, fn: Iteratee | PropertyKey | Object) {
150
150
  if (Array.isArray(arr)) {
151
- if (isFunc(fn)) return arr.find(fn)
151
+ if (isFunction(fn)) return arr.find(fn)
152
152
  if (isNumber(fn) || isString(fn) || isSymbol(fn)) return arr.find((x) => x?.[fn])
153
153
  if (isObject(fn)) return arr.find(matches(fn))
154
154
  }
@@ -183,6 +183,8 @@ export function findRight(arr, fn: Iteratee | PropertyKey | Object) {
183
183
  /**
184
184
  * Performs an efficient array insert operation in the given array. If the index or the array is invalid, it just returns the given array.
185
185
  *
186
+ * **Note:** Uses the same behavior as `Array.splice`.
187
+ *
186
188
  * @param {Array<*>} arr The given array to insert into
187
189
  * @param {number} index The index of the array insert operation.
188
190
  * @param {*} value The value to insert in the array at the given `index`.
@@ -670,7 +672,7 @@ export function clone(value, deep = false) {
670
672
  return cloneArray(value, deep)
671
673
  }
672
674
  if (isObject(value)) {
673
- if (isFunc(value.clone)) {
675
+ if (isFunction(value.clone)) {
674
676
  return value.clone()
675
677
  }
676
678
  const copy = {}
@@ -1013,7 +1015,7 @@ export function groupByMap<K = any, V = any>(
1013
1015
  export function remove<T>(arr: T[], func: any) {
1014
1016
  return arr.filter((x, i) => {
1015
1017
  if (isArray(func)) return !func.includes(x)
1016
- else if (isFunc(func)) return !func(x, i, arr)
1018
+ else if (isFunction(func)) return !func(x, i, arr)
1017
1019
  return x !== func
1018
1020
  })
1019
1021
  }
@@ -47,7 +47,7 @@ export declare const compose: (...args: any[]) => (x: any) => any;
47
47
  * @param {Function} [resolver] The function to resolve the cache key.
48
48
  * @return {Function} Returns the new memoized function.
49
49
  */
50
- export declare function memoize(func: Function, resolver?: Function): Function;
50
+ export declare function memoize<T>(func: Function<T>, resolver?: Function): Function<ReturnType<typeof func>>;
51
51
  export declare function cache(target: any, name: any, descriptor: any): any;
52
52
  /**
53
53
  * Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
@@ -84,9 +84,10 @@ single(3) // => 1
84
84
  // => `func` is invoked only once.
85
85
  ```
86
86
  */
87
- export declare function once(func: Function): (...args: any[]) => any;
87
+ export declare function once<T>(func: Function<T>): (...args: any[]) => T;
88
88
  export declare type Maybe<T> = T | undefined;
89
89
  export declare type Result<T, E = any> = [Maybe<T>, Maybe<E>];
90
+ export declare type Optional<T> = Maybe<T>;
90
91
  /**
91
92
  * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
92
93
  *