ts-data-forge 4.0.0 → 4.1.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/dist/entry-point.mjs +2 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functional/index.d.mts +1 -0
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +2 -0
- package/dist/functional/index.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/index.d.mts +29 -0
- package/dist/functional/ternary-result/impl/index.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/index.mjs +28 -0
- package/dist/functional/ternary-result/impl/index.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/tag.d.mts +7 -0
- package/dist/functional/ternary-result/impl/tag.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/tag.mjs +9 -0
- package/dist/functional/ternary-result/impl/tag.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +14 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +41 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +27 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +20 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +33 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +20 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +28 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +35 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +16 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +19 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +16 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +25 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +13 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +19 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +32 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +48 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/types.d.mts +25 -0
- package/dist/functional/ternary-result/impl/types.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/types.mjs +2 -0
- package/dist/functional/ternary-result/impl/types.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/variant-name.d.mts +3 -0
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/variant-name.mjs +16 -0
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -0
- package/dist/functional/ternary-result/index.d.mts +2 -0
- package/dist/functional/ternary-result/index.d.mts.map +1 -0
- package/dist/functional/ternary-result/index.mjs +3 -0
- package/dist/functional/ternary-result/index.mjs.map +1 -0
- package/dist/globals.d.mts +55 -2
- package/package.json +1 -1
- package/src/functional/index.mts +1 -0
- package/src/functional/ternary-result/impl/index.mts +28 -0
- package/src/functional/ternary-result/impl/tag.mts +11 -0
- package/src/functional/ternary-result/impl/ternary-result-err.mts +18 -0
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +53 -0
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +95 -0
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +93 -0
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +27 -0
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +31 -0
- package/src/functional/ternary-result/impl/ternary-result-is-err.mts +23 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +24 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +27 -0
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +24 -0
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +64 -0
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +66 -0
- package/src/functional/ternary-result/impl/ternary-result-map.mts +81 -0
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +20 -0
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +66 -0
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +25 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +40 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +22 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +32 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +42 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +38 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +22 -0
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +23 -0
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +53 -0
- package/src/functional/ternary-result/impl/types.mts +39 -0
- package/src/functional/ternary-result/impl/variant-name.mts +17 -0
- package/src/functional/ternary-result/index.mts +1 -0
- package/src/functional/ternary-result.test.mts +198 -0
- package/src/globals.d.mts +55 -2
package/dist/entry-point.mjs
CHANGED
|
@@ -6,6 +6,8 @@ export { index$1 as Optional };
|
|
|
6
6
|
export { pipe } from './functional/pipe.mjs';
|
|
7
7
|
import * as index$2 from './functional/result/impl/index.mjs';
|
|
8
8
|
export { index$2 as Result };
|
|
9
|
+
import * as index$3 from './functional/ternary-result/impl/index.mjs';
|
|
10
|
+
export { index$3 as TernaryResult };
|
|
9
11
|
export { IMapMapped } from './collections/imap-mapped.mjs';
|
|
10
12
|
export { IMap } from './collections/imap.mjs';
|
|
11
13
|
export { ISetMapped } from './collections/iset-mapped.mjs';
|
package/dist/entry-point.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/functional/index.mts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/functional/index.mts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC"}
|
|
@@ -4,4 +4,6 @@ export { index as Optional };
|
|
|
4
4
|
export { pipe } from './pipe.mjs';
|
|
5
5
|
import * as index$1 from './result/impl/index.mjs';
|
|
6
6
|
export { index$1 as Result };
|
|
7
|
+
import * as index$2 from './ternary-result/impl/index.mjs';
|
|
8
|
+
export { index$2 as TernaryResult };
|
|
7
9
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from './ternary-result-err.mjs';
|
|
2
|
+
export * from './ternary-result-expect-to-be.mjs';
|
|
3
|
+
export * from './ternary-result-flat-map.mjs';
|
|
4
|
+
export * from './ternary-result-fold.mjs';
|
|
5
|
+
export * from './ternary-result-from-promise.mjs';
|
|
6
|
+
export * from './ternary-result-from-throwable.mjs';
|
|
7
|
+
export * from './ternary-result-is-err.mjs';
|
|
8
|
+
export * from './ternary-result-is-ok.mjs';
|
|
9
|
+
export * from './ternary-result-is-ternary-result.mjs';
|
|
10
|
+
export * from './ternary-result-is-warn.mjs';
|
|
11
|
+
export * from './ternary-result-map-err.mjs';
|
|
12
|
+
export * from './ternary-result-map-warn.mjs';
|
|
13
|
+
export * from './ternary-result-map.mjs';
|
|
14
|
+
export * from './ternary-result-ok.mjs';
|
|
15
|
+
export * from './ternary-result-or-else.mjs';
|
|
16
|
+
export * from './ternary-result-to-optional.mjs';
|
|
17
|
+
export * from './ternary-result-unwrap-err-or.mjs';
|
|
18
|
+
export * from './ternary-result-unwrap-err-throw.mjs';
|
|
19
|
+
export * from './ternary-result-unwrap-err.mjs';
|
|
20
|
+
export * from './ternary-result-unwrap-ok-or.mjs';
|
|
21
|
+
export * from './ternary-result-unwrap-ok.mjs';
|
|
22
|
+
export * from './ternary-result-unwrap-throw.mjs';
|
|
23
|
+
export * from './ternary-result-unwrap-warn-or.mjs';
|
|
24
|
+
export * from './ternary-result-unwrap-warn-throw.mjs';
|
|
25
|
+
export * from './ternary-result-unwrap-warn.mjs';
|
|
26
|
+
export * from './ternary-result-warn.mjs';
|
|
27
|
+
export * from './ternary-result-zip.mjs';
|
|
28
|
+
export * from './types.mjs';
|
|
29
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/index.mts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { err } from './ternary-result-err.mjs';
|
|
2
|
+
export { expectToBe } from './ternary-result-expect-to-be.mjs';
|
|
3
|
+
export { flatMap } from './ternary-result-flat-map.mjs';
|
|
4
|
+
export { fold } from './ternary-result-fold.mjs';
|
|
5
|
+
export { fromPromise } from './ternary-result-from-promise.mjs';
|
|
6
|
+
export { fromThrowable } from './ternary-result-from-throwable.mjs';
|
|
7
|
+
export { isErr } from './ternary-result-is-err.mjs';
|
|
8
|
+
export { isOk } from './ternary-result-is-ok.mjs';
|
|
9
|
+
export { isTernaryResult } from './ternary-result-is-ternary-result.mjs';
|
|
10
|
+
export { isWarn } from './ternary-result-is-warn.mjs';
|
|
11
|
+
export { mapErr } from './ternary-result-map-err.mjs';
|
|
12
|
+
export { mapWarn } from './ternary-result-map-warn.mjs';
|
|
13
|
+
export { map } from './ternary-result-map.mjs';
|
|
14
|
+
export { ok } from './ternary-result-ok.mjs';
|
|
15
|
+
export { orElse } from './ternary-result-or-else.mjs';
|
|
16
|
+
export { toOptional } from './ternary-result-to-optional.mjs';
|
|
17
|
+
export { unwrapErrOr } from './ternary-result-unwrap-err-or.mjs';
|
|
18
|
+
export { unwrapErrThrow } from './ternary-result-unwrap-err-throw.mjs';
|
|
19
|
+
export { unwrapErr } from './ternary-result-unwrap-err.mjs';
|
|
20
|
+
export { unwrapOkOr } from './ternary-result-unwrap-ok-or.mjs';
|
|
21
|
+
export { unwrapOk } from './ternary-result-unwrap-ok.mjs';
|
|
22
|
+
export { unwrapThrow } from './ternary-result-unwrap-throw.mjs';
|
|
23
|
+
export { unwrapWarnOr } from './ternary-result-unwrap-warn-or.mjs';
|
|
24
|
+
export { unwrapWarnThrow } from './ternary-result-unwrap-warn-throw.mjs';
|
|
25
|
+
export { unwrapWarn } from './ternary-result-unwrap-warn.mjs';
|
|
26
|
+
export { warn } from './ternary-result-warn.mjs';
|
|
27
|
+
export { zip } from './ternary-result-zip.mjs';
|
|
28
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** @internal Tag identifying the Ok variant. */
|
|
2
|
+
export declare const OkTypeTagName: TernaryOk<unknown>['$$tag'];
|
|
3
|
+
/** @internal Tag identifying the Warn variant. */
|
|
4
|
+
export declare const WarnTypeTagName: TernaryWarn<unknown, unknown>['$$tag'];
|
|
5
|
+
/** @internal Tag identifying the Err variant. */
|
|
6
|
+
export declare const ErrTypeTagName: TernaryErr<unknown>['$$tag'];
|
|
7
|
+
//# sourceMappingURL=tag.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/tag.mts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAC1B,CAAC;AAE7B,kDAAkD;AAClD,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,OAAO,CACrC,CAAC;AAE/B,iDAAiD;AACjD,eAAO,MAAM,cAAc,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAC3B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @internal Tag identifying the Ok variant. */
|
|
2
|
+
const OkTypeTagName = 'ts-data-forge::Result.ok';
|
|
3
|
+
/** @internal Tag identifying the Warn variant. */
|
|
4
|
+
const WarnTypeTagName = 'ts-data-forge::Result.warn';
|
|
5
|
+
/** @internal Tag identifying the Err variant. */
|
|
6
|
+
const ErrTypeTagName = 'ts-data-forge::Result.err';
|
|
7
|
+
|
|
8
|
+
export { ErrTypeTagName, OkTypeTagName, WarnTypeTagName };
|
|
9
|
+
//# sourceMappingURL=tag.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.mjs","sources":["../../../../src/functional/ternary-result/impl/tag.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACO,MAAM,aAAa,GACxB;AAEF;AACO,MAAM,eAAe,GAC1B;AAEF;AACO,MAAM,cAAc,GACzB;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a `TernaryResult.Err` containing the provided error value.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const failure = TernaryResult.err(new Error('missing data'));
|
|
8
|
+
*
|
|
9
|
+
* assert.strictEqual(failure.$$tag, 'ts-data-forge::Result.err');
|
|
10
|
+
* assert.ok(TernaryResult.isErr(failure));
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const err: <E>(value: E) => TernaryErr<E>;
|
|
14
|
+
//# sourceMappingURL=ternary-result-err.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-err.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,EAAG,OAAO,CAAC,KAAG,UAAU,CAAC,CAAC,CAG7C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ErrTypeTagName } from './tag.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a `TernaryResult.Err` containing the provided error value.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const failure = TernaryResult.err(new Error('missing data'));
|
|
10
|
+
*
|
|
11
|
+
* assert.strictEqual(failure.$$tag, 'ts-data-forge::Result.err');
|
|
12
|
+
* assert.ok(TernaryResult.isErr(failure));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
const err = (value) => ({
|
|
16
|
+
$$tag: ErrTypeTagName,
|
|
17
|
+
value,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export { err };
|
|
21
|
+
//# sourceMappingURL=ternary-result-err.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-err.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-err.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;AAWG;MACU,GAAG,GAAG,CAAK,KAAQ,MAAqB;AACnD,IAAA,KAAK,EAAE,cAAc;IACrB,KAAK;AACN,CAAA;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type UnwrapOk } from './types.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Unwraps the Ok value or throws with the provided message.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const okValue = TernaryResult.ok('ready');
|
|
9
|
+
*
|
|
10
|
+
* assert.strictEqual(TernaryResult.expectToBe(okValue, 'missing'), 'ready');
|
|
11
|
+
* const expectResult = TernaryResult.expectToBe<string>('needs value');
|
|
12
|
+
*
|
|
13
|
+
* assert.throws(() => expectResult(TernaryResult.err('oops')), /needs value/u);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function expectToBe<R extends UnknownTernaryResult>(result: R, message: string): UnwrapOk<R>;
|
|
17
|
+
export declare function expectToBe<S>(message: string): <W, E>(result: TernaryResult<S, E, W>) => S;
|
|
18
|
+
//# sourceMappingURL=ternary-result-expect-to-be.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-expect-to-be.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-expect-to-be.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,oBAAoB,EACvD,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,MAAM,GACd,QAAQ,CAAC,CAAC,CAAC,CAAC;AAGf,wBAAgB,UAAU,CAAC,CAAC,EAC1B,OAAO,EAAE,MAAM,GACd,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isOk } from './ternary-result-is-ok.mjs';
|
|
2
|
+
import { unwrapOk } from './ternary-result-unwrap-ok.mjs';
|
|
3
|
+
|
|
4
|
+
function expectToBe(...args) {
|
|
5
|
+
switch (args.length) {
|
|
6
|
+
case 2: {
|
|
7
|
+
const [result, message] = args;
|
|
8
|
+
return expectImpl(result, message);
|
|
9
|
+
}
|
|
10
|
+
case 1: {
|
|
11
|
+
const [message] = args;
|
|
12
|
+
return (result) => expectImpl(result, message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const expectImpl = (result, message) => {
|
|
17
|
+
if (isOk(result)) {
|
|
18
|
+
return unwrapOk(result);
|
|
19
|
+
}
|
|
20
|
+
throw new Error(message);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { expectToBe };
|
|
24
|
+
//# sourceMappingURL=ternary-result-expect-to-be.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-expect-to-be.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-expect-to-be.mts"],"sourcesContent":[null],"names":[],"mappings":";;;AA4BM,SAAU,UAAU,CACxB,GAAG,IAAwE,EAAA;AAE3E,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;AAC9B,YAAA,OAAO,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;QACpC;QACA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI;YACtB,OAAO,CAAC,MAAS,KAAK,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;QACnD;;AAEJ;AAEA,MAAM,UAAU,GAAG,CACjB,MAAS,EACT,OAAe,KACA;AACf,IAAA,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE;AAChB,QAAA,OAAO,QAAQ,CAAC,MAAM,CAAC;IACzB;AAEA,IAAA,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC;AAC1B,CAAC;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Applies a function returning a `TernaryResult` to the Ok variant.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const parse = (value: string): TernaryResult<number, string, string> =>
|
|
9
|
+
* Number.isNaN(Number(value))
|
|
10
|
+
* ? TernaryResult.err('NaN')
|
|
11
|
+
* : TernaryResult.ok(Number(value));
|
|
12
|
+
*
|
|
13
|
+
* const doubled = TernaryResult.flatMap(TernaryResult.ok('3'), (text) =>
|
|
14
|
+
* TernaryResult.map(parse(text), (num) => num * 2),
|
|
15
|
+
* );
|
|
16
|
+
* const warnPassthrough = TernaryResult.flatMap(
|
|
17
|
+
* TernaryResult.warn('3', 'retry'),
|
|
18
|
+
* parse,
|
|
19
|
+
* );
|
|
20
|
+
* const errPassthrough = TernaryResult.flatMap(TernaryResult.err('oops'), parse);
|
|
21
|
+
*
|
|
22
|
+
* assert.deepStrictEqual(doubled, TernaryResult.ok(6));
|
|
23
|
+
* assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(3, 'retry'));
|
|
24
|
+
* assert.deepStrictEqual(errPassthrough, TernaryResult.err('oops'));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function flatMap<R extends UnknownTernaryResult, S2, W2, E2>(result: R, flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>): TernaryResult<S2, E2 | UnwrapErr<R>, W2 | UnwrapWarn<R>>;
|
|
28
|
+
export declare function flatMap<S, S2, W2, E2>(flatMapFn: (value: S) => TernaryResult<S2, E2, W2>): <W, E>(result: TernaryResult<S, E, W>) => TernaryResult<S2, E | E2, W | W2>;
|
|
29
|
+
//# sourceMappingURL=ternary-result-flat-map.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-flat-map.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-flat-map.mts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,oBAAoB,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAChE,MAAM,EAAE,CAAC,EACT,SAAS,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAC3D,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAG5D,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EACnC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GACjD,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isOk } from './ternary-result-is-ok.mjs';
|
|
2
|
+
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
3
|
+
import { warn } from './ternary-result-warn.mjs';
|
|
4
|
+
|
|
5
|
+
function flatMap(...args) {
|
|
6
|
+
switch (args.length) {
|
|
7
|
+
case 2: {
|
|
8
|
+
const [result, flatMapFn] = args;
|
|
9
|
+
return flatMapImpl(result, flatMapFn);
|
|
10
|
+
}
|
|
11
|
+
case 1: {
|
|
12
|
+
const [flatMapFn] = args;
|
|
13
|
+
return (result) => flatMapImpl(result, flatMapFn);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const flatMapImpl = (result, flatMapFn) => {
|
|
18
|
+
if (isOk(result)) {
|
|
19
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
20
|
+
return flatMapFn(result.value);
|
|
21
|
+
}
|
|
22
|
+
if (isWarn(result)) {
|
|
23
|
+
const next = flatMapFn(
|
|
24
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
|
+
result.value);
|
|
26
|
+
if (isOk(next)) {
|
|
27
|
+
return warn(next.value,
|
|
28
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
29
|
+
result.warning);
|
|
30
|
+
}
|
|
31
|
+
if (isWarn(next)) {
|
|
32
|
+
return warn(next.value, next.warning);
|
|
33
|
+
}
|
|
34
|
+
return next;
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { flatMap };
|
|
41
|
+
//# sourceMappingURL=ternary-result-flat-map.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-flat-map.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-flat-map.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAwCM,SAAU,OAAO,CACrB,GAAG,IAKwE,EAAA;AAI3E,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAI;AAChC,YAAA,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC;QACvC;QACA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI;YACxB,OAAO,CAAC,MAAS,KAAK,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC;QACtD;;AAEJ;AAEA,MAAM,WAAW,GAAG,CAClB,MAAS,EACT,SAA4D,KACA;AAC5D,IAAA,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE;;AAEhB,QAAA,OAAO,SAAS,CAAC,MAAM,CAAC,KAAoB,CAAC;IAC/C;AAEA,IAAA,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE;QAClB,MAAM,IAAI,GAAG,SAAS;;QAEpB,MAAM,CAAC,KAAoB,CAC5B;AAED,QAAA,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE;AACd,YAAA,OAAO,IAAI,CACT,IAAI,CAAC,KAAK;;YAEV,MAAM,CAAC,OAAwB,CAChC;QACH;AAEA,QAAA,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE;YAChB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAoC,CAAC;QACpE;AAEA,QAAA,OAAO,IAAI;IACb;;AAGA,IAAA,OAAO,MAAuC;AAChD,CAAC;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Applies the provided mapper based on the current variant.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const okFold = TernaryResult.fold(
|
|
9
|
+
* TernaryResult.ok(2),
|
|
10
|
+
* (value) => value * 2,
|
|
11
|
+
* (warn: string) => warn.length,
|
|
12
|
+
* (error: string) => error.toUpperCase(),
|
|
13
|
+
* );
|
|
14
|
+
* const warnFold = TernaryResult.fold(
|
|
15
|
+
* TernaryResult.warn(2, 'spike'),
|
|
16
|
+
* (value: number) => value,
|
|
17
|
+
* (warn: string) => warn.toUpperCase(),
|
|
18
|
+
* (error: string) => error,
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* assert.deepStrictEqual(okFold, TernaryResult.ok(4));
|
|
22
|
+
* assert.deepStrictEqual(warnFold, TernaryResult.warn(2, 'SPIKE'));
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function fold<R extends UnknownTernaryResult, S2, W2, E2>(result: R, mapOk: (value: UnwrapOk<R>) => S2, mapWarn: (value: UnwrapWarn<R>) => W2, mapErr: (error: UnwrapErr<R>) => E2): TernaryResult<S2, E2, W2>;
|
|
26
|
+
export declare function fold<S, W, E, S2, W2, E2>(mapOk: (value: S) => S2, mapWarn: (value: W) => W2, mapErr: (error: E) => E2): (result: TernaryResult<S, E, W>) => TernaryResult<S2, E2, W2>;
|
|
27
|
+
//# sourceMappingURL=ternary-result-fold.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-fold.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-fold.mts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,oBAAoB,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAC7D,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,EACjC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,EACrC,MAAM,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,GAClC,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAG7B,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EACtC,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EACvB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EACzB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,GACvB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { err } from './ternary-result-err.mjs';
|
|
2
|
+
import { isOk } from './ternary-result-is-ok.mjs';
|
|
3
|
+
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
4
|
+
import { ok } from './ternary-result-ok.mjs';
|
|
5
|
+
import { warn } from './ternary-result-warn.mjs';
|
|
6
|
+
|
|
7
|
+
function fold(...args) {
|
|
8
|
+
switch (args.length) {
|
|
9
|
+
case 4: {
|
|
10
|
+
const [result, mapOk, mapWarn, mapErr] = args;
|
|
11
|
+
return foldImpl(result, mapOk, mapWarn, mapErr);
|
|
12
|
+
}
|
|
13
|
+
case 3: {
|
|
14
|
+
const [mapOk, mapWarn, mapErr] = args;
|
|
15
|
+
return (result) => foldImpl(result, mapOk, mapWarn, mapErr);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const foldImpl = (result, mapOk, mapWarnFn, mapErrFn) => {
|
|
20
|
+
if (isOk(result)) {
|
|
21
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
22
|
+
return ok(mapOk(result.value));
|
|
23
|
+
}
|
|
24
|
+
if (isWarn(result)) {
|
|
25
|
+
return warn(
|
|
26
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
27
|
+
mapOk(result.value),
|
|
28
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
29
|
+
mapWarnFn(result.warning));
|
|
30
|
+
}
|
|
31
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
32
|
+
return err(mapErrFn(result.value));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { fold };
|
|
36
|
+
//# sourceMappingURL=ternary-result-fold.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-fold.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-fold.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AA4CM,SAAU,IAAI,CAClB,GAAG,IAWE,EAAA;AAEL,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,IAAI;YAC7C,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC;QACjD;QACA,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,IAAI;AACrC,YAAA,OAAO,CAAC,MAAS,KAAK,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC;QAChE;;AAEJ;AAEA,MAAM,QAAQ,GAAG,CACf,MAAS,EACT,KAAiC,EACjC,SAAyC,EACzC,QAAqC,KACR;AAC7B,IAAA,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE;;QAEhB,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAoB,CAAC,CAAC;IAC/C;AAEA,IAAA,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE;AAClB,QAAA,OAAO,IAAI;;AAET,QAAA,KAAK,CAAC,MAAM,CAAC,KAAoB,CAAC;;AAElC,QAAA,SAAS,CAAC,MAAM,CAAC,OAAwB,CAAC,CAC3C;IACH;;IAGA,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAqB,CAAC,CAAC;AACpD,CAAC;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @internal Utility type extracting the resolved value from a Promise. */
|
|
2
|
+
type UnwrapPromise<P extends Promise<unknown>> = P extends Promise<infer V> ? V : never;
|
|
3
|
+
/**
|
|
4
|
+
* Converts a Promise into a Promise that resolves to a `TernaryResult`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const resolved = await TernaryResult.fromPromise(Promise.resolve('ok'));
|
|
10
|
+
* const rejected = await TernaryResult.fromPromise(
|
|
11
|
+
* Promise.reject(new Error('fail')),
|
|
12
|
+
* );
|
|
13
|
+
*
|
|
14
|
+
* assert.deepStrictEqual(resolved, TernaryResult.ok('ok'));
|
|
15
|
+
* assert.ok(TernaryResult.isErr(rejected));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const fromPromise: <P extends Promise<unknown>>(promise: P) => Promise<TernaryResult<UnwrapPromise<P>, unknown, never>>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=ternary-result-from-promise.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-from-promise.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-from-promise.mts"],"names":[],"mappings":"AAGA,2EAA2E;AAC3E,KAAK,aAAa,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,IAC3C,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEzC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,EACpD,SAAS,CAAC,KACT,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAEoB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { err } from './ternary-result-err.mjs';
|
|
2
|
+
import { ok } from './ternary-result-ok.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Promise into a Promise that resolves to a `TernaryResult`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const resolved = await TernaryResult.fromPromise(Promise.resolve('ok'));
|
|
11
|
+
* const rejected = await TernaryResult.fromPromise(
|
|
12
|
+
* Promise.reject(new Error('fail')),
|
|
13
|
+
* );
|
|
14
|
+
*
|
|
15
|
+
* assert.deepStrictEqual(resolved, TernaryResult.ok('ok'));
|
|
16
|
+
* assert.ok(TernaryResult.isErr(rejected));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const fromPromise = (promise) =>
|
|
20
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
21
|
+
promise.then((value) => ok(value)).catch(err);
|
|
22
|
+
|
|
23
|
+
export { fromPromise };
|
|
24
|
+
//# sourceMappingURL=ternary-result-from-promise.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-from-promise.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-from-promise.mts"],"sourcesContent":[null],"names":[],"mappings":";;;AAOA;;;;;;;;;;;;;;AAcG;AACI,MAAM,WAAW,GAAG,CACzB,OAAU;AAEV;AACA,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK,CAAgC,CAAC,CAAC,KAAK,CAAC,GAAG;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a potentially-throwing function in a `TernaryResult`.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const success = TernaryResult.fromThrowable(() => 1 + 1);
|
|
8
|
+
* const failure = TernaryResult.fromThrowable(() => {
|
|
9
|
+
* throw new Error('boom');
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* assert.deepStrictEqual(success, TernaryResult.ok(2));
|
|
13
|
+
* assert.ok(TernaryResult.isErr(failure));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const fromThrowable: <T>(fn: () => T) => TernaryResult<T, Error, never>;
|
|
17
|
+
//# sourceMappingURL=ternary-result-from-throwable.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-from-throwable.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-from-throwable.mts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,IAAI,MAAM,CAAC,KACV,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAS/B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { unknownToString } from '../../../others/unknown-to-string.mjs';
|
|
2
|
+
import { err } from './ternary-result-err.mjs';
|
|
3
|
+
import { ok } from './ternary-result-ok.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a potentially-throwing function in a `TernaryResult`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const success = TernaryResult.fromThrowable(() => 1 + 1);
|
|
12
|
+
* const failure = TernaryResult.fromThrowable(() => {
|
|
13
|
+
* throw new Error('boom');
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* assert.deepStrictEqual(success, TernaryResult.ok(2));
|
|
17
|
+
* assert.ok(TernaryResult.isErr(failure));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
const fromThrowable = (fn) => {
|
|
21
|
+
try {
|
|
22
|
+
return ok(fn());
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (Error.isError(error)) {
|
|
26
|
+
return err(error);
|
|
27
|
+
}
|
|
28
|
+
return err(new Error(unknownToString(error)));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { fromThrowable };
|
|
33
|
+
//# sourceMappingURL=ternary-result-from-throwable.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-from-throwable.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-from-throwable.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;AAcG;AACI,MAAM,aAAa,GAAG,CAC3B,EAAW,KACuB;AAClC,IAAA,IAAI;AACF,QAAA,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;IACjB;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACxB,YAAA,OAAO,GAAG,CAAC,KAAK,CAAC;QACnB;QACA,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/C;AACF;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type NarrowToErr } from './types.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for the Err variant.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const maybeErr = TernaryResult.err('boom') as TernaryResult<
|
|
9
|
+
* number,
|
|
10
|
+
* string,
|
|
11
|
+
* string
|
|
12
|
+
* >;
|
|
13
|
+
*
|
|
14
|
+
* if (TernaryResult.isErr(maybeErr)) {
|
|
15
|
+
* assert.strictEqual(maybeErr.value, 'boom');
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const isErr: <R extends UnknownTernaryResult>(result: R) => result is NarrowToErr<R>;
|
|
20
|
+
//# sourceMappingURL=ternary-result-is-err.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-is-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-is-err.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,oBAAoB,EAClD,QAAQ,CAAC,KACR,MAAM,IAAI,WAAW,CAAC,CAAC,CAAoC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ErrTypeTagName } from './tag.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type guard for the Err variant.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const maybeErr = TernaryResult.err('boom') as TernaryResult<
|
|
10
|
+
* number,
|
|
11
|
+
* string,
|
|
12
|
+
* string
|
|
13
|
+
* >;
|
|
14
|
+
*
|
|
15
|
+
* if (TernaryResult.isErr(maybeErr)) {
|
|
16
|
+
* assert.strictEqual(maybeErr.value, 'boom');
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
const isErr = (result) => result.$$tag === ErrTypeTagName;
|
|
21
|
+
|
|
22
|
+
export { isErr };
|
|
23
|
+
//# sourceMappingURL=ternary-result-is-err.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-is-err.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-is-err.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;;;;;;;;;;;AAgBG;AACI,MAAM,KAAK,GAAG,CACnB,MAAS,KACoB,MAAM,CAAC,KAAK,KAAK;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type NarrowToOk } from './types.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for the Ok variant.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const maybeNumber = TernaryResult.ok(42) as TernaryResult<
|
|
9
|
+
* number,
|
|
10
|
+
* string,
|
|
11
|
+
* string
|
|
12
|
+
* >;
|
|
13
|
+
*
|
|
14
|
+
* if (TernaryResult.isOk(maybeNumber)) {
|
|
15
|
+
* const value: number = maybeNumber.value;
|
|
16
|
+
* assert.strictEqual(value, 42);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const isOk: <R extends UnknownTernaryResult>(result: R) => result is NarrowToOk<R>;
|
|
21
|
+
//# sourceMappingURL=ternary-result-is-ok.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-is-ok.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-is-ok.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,oBAAoB,EACjD,QAAQ,CAAC,KACR,MAAM,IAAI,UAAU,CAAC,CAAC,CAAmC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OkTypeTagName } from './tag.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type guard for the Ok variant.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const maybeNumber = TernaryResult.ok(42) as TernaryResult<
|
|
10
|
+
* number,
|
|
11
|
+
* string,
|
|
12
|
+
* string
|
|
13
|
+
* >;
|
|
14
|
+
*
|
|
15
|
+
* if (TernaryResult.isOk(maybeNumber)) {
|
|
16
|
+
* const value: number = maybeNumber.value;
|
|
17
|
+
* assert.strictEqual(value, 42);
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const isOk = (result) => result.$$tag === OkTypeTagName;
|
|
22
|
+
|
|
23
|
+
export { isOk };
|
|
24
|
+
//# sourceMappingURL=ternary-result-is-ok.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternary-result-is-ok.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-is-ok.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;;;;;;;;;;;;AAiBG;AACI,MAAM,IAAI,GAAG,CAClB,MAAS,KACmB,MAAM,CAAC,KAAK,KAAK;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the provided value is a {@link TernaryResult}.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const okValue = TernaryResult.ok('done');
|
|
8
|
+
* const warnValue = TernaryResult.warn('done', 'retry later');
|
|
9
|
+
* const notResult = { $$tag: 'ts-data-forge::Result.ok' };
|
|
10
|
+
*
|
|
11
|
+
* assert.ok(TernaryResult.isTernaryResult(okValue));
|
|
12
|
+
* assert.ok(TernaryResult.isTernaryResult(warnValue));
|
|
13
|
+
* assert.ok(!TernaryResult.isTernaryResult(notResult));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const isTernaryResult: (maybeResult: unknown) => maybeResult is UnknownTernaryResult;
|
|
17
|
+
//# sourceMappingURL=ternary-result-is-ternary-result.d.mts.map
|