@zelgadis87/utils-core 5.5.0-beta.0 → 5.5.0-beta.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.
package/.rollup/index.cjs CHANGED
@@ -285,6 +285,12 @@ class Optional {
285
285
  }
286
286
  }
287
287
  orElse = this.orElseReturn.bind(this);
288
+ orElseReturnNull() {
289
+ return this.isPresent() ? this.get() : null;
290
+ }
291
+ orElseReturnUndefined() {
292
+ return this.isPresent() ? this.get() : undefined;
293
+ }
288
294
  orElseProduce(newValueProducer) {
289
295
  if (this.isPresent()) {
290
296
  return this.get();
@@ -1694,7 +1700,7 @@ class LazyAsync {
1694
1700
  */
1695
1701
  class LazyDictionary {
1696
1702
  _generator;
1697
- _dictionary = {};
1703
+ _map = new Map();
1698
1704
  constructor(_generator) {
1699
1705
  this._generator = _generator;
1700
1706
  }
@@ -1710,13 +1716,14 @@ class LazyDictionary {
1710
1716
  * The generator is invoked at most once per key.
1711
1717
  * @param key - The key to look up or generate.
1712
1718
  * @returns The value associated with `key`.
1713
- */ getOrCreate(key) {
1714
- if (key in this._dictionary) {
1715
- return this._dictionary[key];
1719
+ */
1720
+ getOrCreate(key) {
1721
+ if (!this._map.has(key)) {
1722
+ const value = this._generator(key);
1723
+ this._map.set(key, value);
1724
+ return value;
1716
1725
  }
1717
- const value = this._generator(key);
1718
- this._dictionary[key] = value;
1719
- return value;
1726
+ return this._map.get(key);
1720
1727
  }
1721
1728
  /**
1722
1729
  * Returns the cached value for `key`, or throws if the key has not been generated yet.
@@ -1727,8 +1734,8 @@ class LazyDictionary {
1727
1734
  * @returns The value associated with `key`.
1728
1735
  */
1729
1736
  getOrThrow(key, errorMessage) {
1730
- if (key in this._dictionary) {
1731
- return this._dictionary[key];
1737
+ if (this._map.has(key)) {
1738
+ return this._map.get(key);
1732
1739
  }
1733
1740
  throw new Error(errorMessage);
1734
1741
  }
@@ -1737,7 +1744,7 @@ class LazyDictionary {
1737
1744
  * @param key - The key to check.
1738
1745
  */
1739
1746
  hasKey(key) {
1740
- return key in this._dictionary;
1747
+ return this._map.has(key);
1741
1748
  }
1742
1749
  /**
1743
1750
  * Returns all key-value pairs that have been generated so far.
@@ -1745,7 +1752,7 @@ class LazyDictionary {
1745
1752
  * @returns An array of `[key, value]` tuples.
1746
1753
  */
1747
1754
  getEntries() {
1748
- return Object.entries(this._dictionary);
1755
+ return [...this._map.entries()];
1749
1756
  }
1750
1757
  }
1751
1758