atomic-fns 0.3.2 → 0.3.3-beta

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.
package/README.md CHANGED
@@ -52,7 +52,7 @@ You could also import any individual module directly from an html page like this
52
52
  ```html
53
53
  <script type="module">
54
54
  import {
55
- namedtuple, Deque, Heap, SortedSet, SortedMap
55
+ namedtuple, FrozenSet, SortedSet, SortedMap
56
56
  } from 'https://unpkg.com/atomic-fns/core/collections';
57
57
  // your code goes here...
58
58
  </script>
@@ -66,7 +66,7 @@ This library features a data model similar to [Python](https://docs.python.org/3
66
66
  For example in Python collections `size()` is a method while in JS its just a property. So this library uses `size` property instead of methods. Similarly, the `len` function implementation checks for both `length` and `size` since many JS objects have a `length` property.
67
67
 
68
68
  ## Special method names
69
- This library adds support for operators via object methods like:
69
+ This library adds support for operators using object methods such as:
70
70
  - `obj.eq(other)` adds custom `obj == other`.
71
71
  - `obj.lt(other)` adds custom `obj < other`.
72
72
  - `obj.lte(other)` adds custom `obj <= other`.
@@ -76,11 +76,25 @@ This library adds support for operators via object methods like:
76
76
 
77
77
  When you implement those, you can also apply operators to values like `eq(x, y), lte(x, y), compare(x, y)`, etc. to get the result of `x.<operator>(y)`.
78
78
 
79
- Some new base types introduced: `Collection, Sequence, Mapping, FrozenSet, IterableIterator`.
79
+ ## New Types
80
+
81
+ Introduces some common base interfaces and typing patterns you may have seen like `Optional`, `Result`, `Comparable`, `Iterator`, and others.
82
+
83
+ ### Sorted Containers
84
+ - [SortedSet](https://atomic-fns.dev/classes/Collections.SortedSet.html)
85
+ - [SortedMap](https://atomic-fns.dev/classes/Collections.SortedMap.html)
86
+ - [SortedTree](https://atomic-fns.dev/classes/Collections.SortedTree.html)
87
+
88
+ ### Other Containers
89
+ - [Deque](https://atomic-fns.dev/classes/Collections.Deque.html)
90
+ - [FrozenSet](https://atomic-fns.dev/classes/Collections.FrozenSet.html)
91
+ - [LRUCache](https://atomic-fns.dev/classes/Collections.LRUCache.html)
92
+
80
93
 
81
94
  ## Contributing
82
95
  If you want to contribute to the project and make it better, your help is very welcome. Contributing is also a great way to learn more about social coding on Github, new technologies and and their ecosystems and how to make constructive, helpful bug reports, feature requests and the noblest of all contributions: a good, clean pull request. You will be listed as a **Champion** on the official site as well.
83
96
 
97
+
84
98
  ## License
85
99
 
86
100
  [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)
@@ -1,7 +1,9 @@
1
1
  import { Iteratee } from '../globals/index.js';
2
2
  import { Mapping } from './abc.js';
3
3
  /**
4
- * Base append-only Cache collection.
4
+ * Base append-only Cache collection that supports adding and accessing keys in O(1).
5
+ * The collection has a fixed given size (default 1024) and when full, it evicts keys using LRU approach. This operation is also O(1).
6
+ * @template K, V
5
7
  */
6
8
  export declare class Cache<K, V = any> extends Mapping<K, V> {
7
9
  capacity: number;
@@ -13,6 +15,12 @@ export declare class Cache<K, V = any> extends Mapping<K, V> {
13
15
  protected backward: Uint8Array | Uint16Array | Uint32Array;
14
16
  protected K: K[];
15
17
  protected V: V[];
18
+ /**
19
+ * Create a new cache object of fixed size.
20
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
21
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
22
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
23
+ */
16
24
  constructor(capacity?: number, Keys?: ArrayConstructor, Values?: ArrayConstructor);
17
25
  /**
18
26
  * This is just an alias of {@link Cache.set}.
@@ -30,6 +38,9 @@ export declare class Cache<K, V = any> extends Mapping<K, V> {
30
38
  * Method used to clear the structure.
31
39
  */
32
40
  clear(): void;
41
+ /**
42
+ * Returns the number of keys in the cache.
43
+ */
33
44
  get size(): number;
34
45
  /**
35
46
  * Method used to splay a value on top.
@@ -101,10 +112,20 @@ export declare class Cache<K, V = any> extends Mapping<K, V> {
101
112
  */
102
113
  inspect(): Map<any, any>;
103
114
  }
115
+ /**
116
+ * Implements a Least Recently Used fixed-capacity cache which supports updating, removing, and accessing keys in O(1).
117
+ */
104
118
  export declare class LRUCache<K, V> extends Cache<K, V> {
105
119
  deletedSize: number;
106
120
  deleted: Uint8Array | Uint16Array | Uint32Array;
121
+ /**
122
+ * Create a new LRU cache object of fixed size.
123
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
124
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
125
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
126
+ */
107
127
  constructor(capacity?: number, Keys?: ArrayConstructor, Values?: ArrayConstructor);
128
+ /** Remove all elements in the cache. */
108
129
  clear(): void;
109
130
  /**
110
131
  * Method used to set the value for the given key in the cache.
@@ -3,7 +3,9 @@ import { IterableIterator } from '../itertools/index.js';
3
3
  import { Mapping } from './abc.js';
4
4
  import { getPointerArray } from './typedArrays.js';
5
5
  /**
6
- * Base append-only Cache collection.
6
+ * Base append-only Cache collection that supports adding and accessing keys in O(1).
7
+ * The collection has a fixed given size (default 1024) and when full, it evicts keys using LRU approach. This operation is also O(1).
8
+ * @template K, V
7
9
  */
8
10
  export class Cache extends Mapping {
9
11
  capacity;
@@ -15,6 +17,12 @@ export class Cache extends Mapping {
15
17
  backward;
16
18
  K;
17
19
  V;
20
+ /**
21
+ * Create a new cache object of fixed size.
22
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
23
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
24
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
25
+ */
18
26
  constructor(capacity = 1024, Keys = Array, Values = Array) {
19
27
  super();
20
28
  this.capacity = capacity;
@@ -53,6 +61,9 @@ export class Cache extends Mapping {
53
61
  this.tail = 0;
54
62
  this.items = new Map();
55
63
  }
64
+ /**
65
+ * Returns the number of keys in the cache.
66
+ */
56
67
  get size() {
57
68
  return this.count;
58
69
  }
@@ -264,14 +275,24 @@ export class Cache extends Mapping {
264
275
  return this.inspect();
265
276
  }
266
277
  }
278
+ /**
279
+ * Implements a Least Recently Used fixed-capacity cache which supports updating, removing, and accessing keys in O(1).
280
+ */
267
281
  export class LRUCache extends Cache {
268
282
  deletedSize = 0;
269
283
  deleted;
284
+ /**
285
+ * Create a new LRU cache object of fixed size.
286
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
287
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
288
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
289
+ */
270
290
  constructor(capacity = 1024, Keys = Array, Values = Array) {
271
291
  super(capacity, Keys, Values);
272
292
  const PointerArray = getPointerArray(capacity);
273
293
  this.deleted = new PointerArray(capacity);
274
294
  }
295
+ /** Remove all elements in the cache. */
275
296
  clear() {
276
297
  super.clear();
277
298
  this.deletedSize = 0;
@@ -4,7 +4,9 @@ import { Mapping } from './abc.js'
4
4
  import { getPointerArray } from './typedArrays.js'
5
5
 
6
6
  /**
7
- * Base append-only Cache collection.
7
+ * Base append-only Cache collection that supports adding and accessing keys in O(1).
8
+ * The collection has a fixed given size (default 1024) and when full, it evicts keys using LRU approach. This operation is also O(1).
9
+ * @template K, V
8
10
  */
9
11
  export class Cache<K, V = any> extends Mapping<K, V> {
10
12
  capacity: number
@@ -17,6 +19,12 @@ export class Cache<K, V = any> extends Mapping<K, V> {
17
19
  protected K: K[]
18
20
  protected V: V[]
19
21
 
22
+ /**
23
+ * Create a new cache object of fixed size.
24
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
25
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
26
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
27
+ */
20
28
  constructor(capacity = 1024, Keys = Array, Values = Array) {
21
29
  super()
22
30
  this.capacity = capacity
@@ -61,6 +69,9 @@ export class Cache<K, V = any> extends Mapping<K, V> {
61
69
  this.items = new Map()
62
70
  }
63
71
 
72
+ /**
73
+ * Returns the number of keys in the cache.
74
+ */
64
75
  get size() {
65
76
  return this.count
66
77
  }
@@ -315,16 +326,26 @@ export class Cache<K, V = any> extends Mapping<K, V> {
315
326
  }
316
327
  }
317
328
 
329
+ /**
330
+ * Implements a Least Recently Used fixed-capacity cache which supports updating, removing, and accessing keys in O(1).
331
+ */
318
332
  export class LRUCache<K, V> extends Cache<K, V> {
319
333
  deletedSize = 0
320
334
  deleted: Uint8Array | Uint16Array | Uint32Array
321
335
 
336
+ /**
337
+ * Create a new LRU cache object of fixed size.
338
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
339
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
340
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
341
+ */
322
342
  constructor(capacity = 1024, Keys = Array, Values = Array) {
323
343
  super(capacity, Keys, Values)
324
344
  const PointerArray = getPointerArray(capacity)
325
345
  this.deleted = new PointerArray(capacity)
326
346
  }
327
347
 
348
+ /** Remove all elements in the cache. */
328
349
  clear() {
329
350
  super.clear()
330
351
  this.deletedSize = 0
@@ -1,6 +1,6 @@
1
1
  import { Mapping } from './abc.js';
2
2
  /**
3
- * A `SortedMap` is a map that holds key value pairs in sorted orders of keys. Any primitive value (and objects that implement a `compare` or `lt` methods) can be used as keys or values.
3
+ * A `SortedMap` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
4
4
  * @see {@link Operators.compare}
5
5
  * @see {@link Operators.lt}
6
6
  * @template K, V
@@ -1,7 +1,7 @@
1
1
  import { Mapping } from './abc.js';
2
2
  import { SplayTree } from './SplayTree.js';
3
3
  /**
4
- * A `SortedMap` is a map that holds key value pairs in sorted orders of keys. Any primitive value (and objects that implement a `compare` or `lt` methods) can be used as keys or values.
4
+ * A `SortedMap` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
5
5
  * @see {@link Operators.compare}
6
6
  * @see {@link Operators.lt}
7
7
  * @template K, V
@@ -2,7 +2,7 @@ import { Mapping } from './abc.js'
2
2
  import { SplayTree } from './SplayTree.js'
3
3
 
4
4
  /**
5
- * A `SortedMap` is a map that holds key value pairs in sorted orders of keys. Any primitive value (and objects that implement a `compare` or `lt` methods) can be used as keys or values.
5
+ * A `SortedMap` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
6
6
  * @see {@link Operators.compare}
7
7
  * @see {@link Operators.lt}
8
8
  * @template K, V
@@ -1,4 +1,10 @@
1
1
  import { Collection } from './abc.js';
2
+ /**
3
+ * A `SortedSet` is a set that holds values in order. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as values.
4
+ * @see {@link Compare}
5
+ * @see {@link Ordered}
6
+ * @template K, V
7
+ */
2
8
  export declare class SortedSet<T> extends Collection {
3
9
  private readonly store;
4
10
  /**
@@ -1,5 +1,11 @@
1
1
  import { Collection } from './abc.js';
2
2
  import { SplayTree } from './SplayTree.js';
3
+ /**
4
+ * A `SortedSet` is a set that holds values in order. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as values.
5
+ * @see {@link Compare}
6
+ * @see {@link Ordered}
7
+ * @template K, V
8
+ */
3
9
  export class SortedSet extends Collection {
4
10
  store;
5
11
  /**
@@ -1,6 +1,12 @@
1
1
  import { Collection } from './abc.js'
2
2
  import { SplayTree } from './SplayTree.js'
3
3
 
4
+ /**
5
+ * A `SortedSet` is a set that holds values in order. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as values.
6
+ * @see {@link Compare}
7
+ * @see {@link Ordered}
8
+ * @template K, V
9
+ */
4
10
  export class SortedSet<T> extends Collection {
5
11
  private readonly store: SplayTree<T>
6
12
  /**
@@ -1,9 +1,9 @@
1
1
  import { Comparer } from '../operators/index.js';
2
2
  import { Mapping } from './abc.js';
3
3
  /**
4
- * A `SortedTree` is a map that holds key value pairs in sorted orders of keys. Any primitive value (and objects that implement a `compare` or `lt` methods) can be used as keys or values.
5
- * @see {@link Operators.compare}
6
- * @see {@link Operators.lt}
4
+ * A `SortedTree` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
5
+ * @see {@link Compare}
6
+ * @see {@link Ordered}
7
7
  * @template K, V
8
8
  */
9
9
  export declare class SortedTree<K, V> extends Mapping<K, V> {
@@ -1,9 +1,9 @@
1
1
  import { Mapping } from './abc.js';
2
2
  import { BTree } from './BTree.js';
3
3
  /**
4
- * A `SortedTree` is a map that holds key value pairs in sorted orders of keys. Any primitive value (and objects that implement a `compare` or `lt` methods) can be used as keys or values.
5
- * @see {@link Operators.compare}
6
- * @see {@link Operators.lt}
4
+ * A `SortedTree` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
5
+ * @see {@link Compare}
6
+ * @see {@link Ordered}
7
7
  * @template K, V
8
8
  */
9
9
  export class SortedTree extends Mapping {
@@ -3,9 +3,9 @@ import { Mapping } from './abc.js'
3
3
  import { BTree } from './BTree.js'
4
4
 
5
5
  /**
6
- * A `SortedTree` is a map that holds key value pairs in sorted orders of keys. Any primitive value (and objects that implement a `compare` or `lt` methods) can be used as keys or values.
7
- * @see {@link Operators.compare}
8
- * @see {@link Operators.lt}
6
+ * A `SortedTree` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
7
+ * @see {@link Compare}
8
+ * @see {@link Ordered}
9
9
  * @template K, V
10
10
  */
11
11
  export class SortedTree<K, V> extends Mapping<K, V> {
@@ -107,6 +107,17 @@ findRight([1, 2, 3, 4], (n) => n % 2 === 1)
107
107
  * @see {@link find}
108
108
  */
109
109
  export declare function findRight(arr: any, fn: Iteratee | PropertyKey | Object): any;
110
+ /**
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
+ *
113
+ * **Note:** Uses the same behavior as `Array.splice`.
114
+ *
115
+ * @param {Array<*>} arr The given array to insert into
116
+ * @param {number} index The index of the array insert operation.
117
+ * @param {*} value The value to insert in the array at the given `index`.
118
+ * @returns {Array<*>} The given array.
119
+ */
120
+ export declare function insert(arr: any[], index: number, value: any): any[];
110
121
  /**
111
122
  * Creates a function that performs a partial deep comparison between a given object and `shape`, returning `true` if the given object has equivalent property values, else `false`.
112
123
  * @example
@@ -501,7 +512,7 @@ export declare function union(...args: Array<Iterable<any>>): Generator<unknown,
501
512
  *
502
513
  * @param arr The collection to iterate over.
503
514
  * @param [func=id] The iteratee to transform keys.
504
- * @returns Returns the composed aggregate object.
515
+ * @returns Returns the aggregated object.
505
516
  *
506
517
  * @example
507
518
  ```js
@@ -514,6 +525,25 @@ groupBy(['one', 'two', 'three'], 'length')
514
525
  ```
515
526
  */
516
527
  export declare function groupBy(arr: Iterable<any> | Object, func?: Iteratee | PropertyKey): Object;
528
+ /**
529
+ * Similar to {@link groupBy} but it returns a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map} object with the results.
530
+ *
531
+ * @param arr The collection to iterate over.
532
+ * @param {Function | PropertyKey} [func=id] The iteratee to transform keys.
533
+ * @returns {Map} Returns the aggregated map object.
534
+ * @template K, V
535
+ *
536
+ * @example
537
+ ```js
538
+ groupByMap([6.1, 4.2, 6.3], Math.floor)
539
+ // => Map { 4: [4.2], 6: [6.1, 6.3] }
540
+
541
+ // The `property` iteratee shorthand.
542
+ groupByMap(['one', 'two', 'three'], 'length')
543
+ // => Map { 3: ['one', 'two'], 5: ['three'] }
544
+ ```
545
+ */
546
+ export declare function groupByMap<K = any, V = any>(arr: Iterable<any> | Object, func?: Iteratee | PropertyKey): Map<K, V[]>;
517
547
  /**
518
548
  * Removes all elements from array that `func` returns truthy for and returns an array of the removed elements.
519
549
  * @param arr The array to remove from.
@@ -156,6 +156,22 @@ export function findRight(arr, fn) {
156
156
  }
157
157
  }
158
158
  }
159
+ /**
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
+ *
162
+ * **Note:** Uses the same behavior as `Array.splice`.
163
+ *
164
+ * @param {Array<*>} arr The given array to insert into
165
+ * @param {number} index The index of the array insert operation.
166
+ * @param {*} value The value to insert in the array at the given `index`.
167
+ * @returns {Array<*>} The given array.
168
+ */
169
+ export function insert(arr, index, value) {
170
+ if (!arr || arr.length <= index || index < 0)
171
+ return arr;
172
+ arr.splice(index, 0, value);
173
+ return arr;
174
+ }
159
175
  /**
160
176
  * Creates a function that performs a partial deep comparison between a given object and `shape`, returning `true` if the given object has equivalent property values, else `false`.
161
177
  * @example
@@ -898,7 +914,7 @@ export function* union(...args) {
898
914
  *
899
915
  * @param arr The collection to iterate over.
900
916
  * @param [func=id] The iteratee to transform keys.
901
- * @returns Returns the composed aggregate object.
917
+ * @returns Returns the aggregated object.
902
918
  *
903
919
  * @example
904
920
  ```js
@@ -921,6 +937,35 @@ export function groupBy(arr, func = id) {
921
937
  });
922
938
  return results;
923
939
  }
940
+ /**
941
+ * Similar to {@link groupBy} but it returns a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map} object with the results.
942
+ *
943
+ * @param arr The collection to iterate over.
944
+ * @param {Function | PropertyKey} [func=id] The iteratee to transform keys.
945
+ * @returns {Map} Returns the aggregated map object.
946
+ * @template K, V
947
+ *
948
+ * @example
949
+ ```js
950
+ groupByMap([6.1, 4.2, 6.3], Math.floor)
951
+ // => Map { 4: [4.2], 6: [6.1, 6.3] }
952
+
953
+ // The `property` iteratee shorthand.
954
+ groupByMap(['one', 'two', 'three'], 'length')
955
+ // => Map { 3: ['one', 'two'], 5: ['three'] }
956
+ ```
957
+ */
958
+ export function groupByMap(arr, func = id) {
959
+ const results = new Map();
960
+ const useKey = typeof func === 'function' ? func : partial(get, func);
961
+ forEach(arr, (value) => {
962
+ const groupKey = useKey(value);
963
+ const values = results.get(groupKey) || [];
964
+ values.push(value);
965
+ results.set(groupKey, values);
966
+ });
967
+ return results;
968
+ }
924
969
  /**
925
970
  * Removes all elements from array that `func` returns truthy for and returns an array of the removed elements.
926
971
  * @param arr The array to remove from.
@@ -180,6 +180,22 @@ export function findRight(arr, fn: Iteratee | PropertyKey | Object) {
180
180
  }
181
181
  }
182
182
 
183
+ /**
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
+ *
186
+ * **Note:** Uses the same behavior as `Array.splice`.
187
+ *
188
+ * @param {Array<*>} arr The given array to insert into
189
+ * @param {number} index The index of the array insert operation.
190
+ * @param {*} value The value to insert in the array at the given `index`.
191
+ * @returns {Array<*>} The given array.
192
+ */
193
+ export function insert(arr: any[], index: number, value) {
194
+ if (!arr || arr.length <= index || index < 0) return arr
195
+ arr.splice(index, 0, value)
196
+ return arr
197
+ }
198
+
183
199
  /**
184
200
  * Creates a function that performs a partial deep comparison between a given object and `shape`, returning `true` if the given object has equivalent property values, else `false`.
185
201
  * @example
@@ -933,7 +949,7 @@ export function* union(...args: Array<Iterable<any>>) {
933
949
  *
934
950
  * @param arr The collection to iterate over.
935
951
  * @param [func=id] The iteratee to transform keys.
936
- * @returns Returns the composed aggregate object.
952
+ * @returns Returns the aggregated object.
937
953
  *
938
954
  * @example
939
955
  ```js
@@ -957,6 +973,39 @@ export function groupBy(arr: Iterable<any> | Object, func: Iteratee | PropertyKe
957
973
  return results
958
974
  }
959
975
 
976
+ /**
977
+ * Similar to {@link groupBy} but it returns a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map} object with the results.
978
+ *
979
+ * @param arr The collection to iterate over.
980
+ * @param {Function | PropertyKey} [func=id] The iteratee to transform keys.
981
+ * @returns {Map} Returns the aggregated map object.
982
+ * @template K, V
983
+ *
984
+ * @example
985
+ ```js
986
+ groupByMap([6.1, 4.2, 6.3], Math.floor)
987
+ // => Map { 4: [4.2], 6: [6.1, 6.3] }
988
+
989
+ // The `property` iteratee shorthand.
990
+ groupByMap(['one', 'two', 'three'], 'length')
991
+ // => Map { 3: ['one', 'two'], 5: ['three'] }
992
+ ```
993
+ */
994
+ export function groupByMap<K = any, V = any>(
995
+ arr: Iterable<any> | Object,
996
+ func: Iteratee | PropertyKey = id
997
+ ): Map<K, V[]> {
998
+ const results = new Map<K, V[]>()
999
+ const useKey = typeof func === 'function' ? func : partial(get, func)
1000
+ forEach(arr, (value: V) => {
1001
+ const groupKey = useKey(value)
1002
+ const values = results.get(groupKey) || []
1003
+ values.push(value)
1004
+ results.set(groupKey, values)
1005
+ })
1006
+ return results
1007
+ }
1008
+
960
1009
  /**
961
1010
  * Removes all elements from array that `func` returns truthy for and returns an array of the removed elements.
962
1011
  * @param arr The array to remove from.
package/core/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './collections/index.js';
2
- export * from './datetime/index.js';
3
2
  export * from './functools/index.js';
4
3
  export * from './globals/index.js';
5
4
  export * from './itertools/index.js';
package/core/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './collections/index.js';
2
- export * from './datetime/index.js';
3
2
  export * from './functools/index.js';
4
3
  export * from './globals/index.js';
5
4
  export * from './itertools/index.js';
package/core/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './collections/index.js'
2
- export * from './datetime/index.js'
3
2
  export * from './functools/index.js'
4
3
  export * from './globals/index.js'
5
4
  export * from './itertools/index.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "atomic-fns",
3
3
  "description": "Like Lodash, but for ESNext and with types. Stop shipping code built for browsers from 2015.",
4
- "version": "0.3.2",
4
+ "version": "0.3.3-beta",
5
5
  "main": "core/index.js",
6
6
  "type": "module",
7
7
  "types": "core/index.d.ts",
@@ -1,6 +0,0 @@
1
- /**
2
- * This module includes classes and functions to work with Date types.
3
- *
4
- * @module Date
5
- */
6
- export declare const now: number;
@@ -1,6 +0,0 @@
1
- /**
2
- * This module includes classes and functions to work with Date types.
3
- *
4
- * @module Date
5
- */
6
- export const now = new Date().getTime();
@@ -1,7 +0,0 @@
1
- /**
2
- * This module includes classes and functions to work with Date types.
3
- *
4
- * @module Date
5
- */
6
-
7
- export const now = new Date().getTime()
File without changes