cafe-utility 17.3.1 → 18.0.0
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/index.d.ts +4 -1
- package/index.js +10 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -370,7 +370,10 @@ declare function makeAsyncQueue(concurrency?: number): {
|
|
|
370
370
|
};
|
|
371
371
|
export declare class Optional<T> {
|
|
372
372
|
value: T | null | undefined;
|
|
373
|
-
constructor(
|
|
373
|
+
private constructor();
|
|
374
|
+
static of<U>(value: U | null | undefined): Optional<U>;
|
|
375
|
+
static empty<U>(): Optional<U>;
|
|
376
|
+
map<K>(fn: (value: T) => K): Optional<K>;
|
|
374
377
|
ifPresent(fn: (value: T) => void): this;
|
|
375
378
|
orElse(fn: () => void): void;
|
|
376
379
|
}
|
package/index.js
CHANGED
|
@@ -1776,6 +1776,15 @@ class Optional {
|
|
|
1776
1776
|
constructor(t) {
|
|
1777
1777
|
this.value = t
|
|
1778
1778
|
}
|
|
1779
|
+
static of(t) {
|
|
1780
|
+
return new Optional(t)
|
|
1781
|
+
}
|
|
1782
|
+
static empty() {
|
|
1783
|
+
return new Optional(null)
|
|
1784
|
+
}
|
|
1785
|
+
map(t) {
|
|
1786
|
+
return new Optional(this.value ? t(this.value) : null)
|
|
1787
|
+
}
|
|
1779
1788
|
ifPresent(t) {
|
|
1780
1789
|
return this.value && t(this.value), this
|
|
1781
1790
|
}
|
|
@@ -1787,7 +1796,7 @@ class Optional {
|
|
|
1787
1796
|
exports.Optional = Optional
|
|
1788
1797
|
function findInstance(n, t) {
|
|
1789
1798
|
const e = n.find(r => r instanceof t)
|
|
1790
|
-
return
|
|
1799
|
+
return Optional.of(e)
|
|
1791
1800
|
}
|
|
1792
1801
|
function interleave(n, t) {
|
|
1793
1802
|
const e = [],
|