ts-data-forge 3.3.1 → 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/array/impl/array-utils-element-access.d.mts +3 -4
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +8 -8
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +8 -9
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +9 -7
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +0 -1
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +6 -6
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +2 -4
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/collections/imap-mapped.d.mts +0 -1
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +7 -6
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +0 -1
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +11 -9
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/queue.d.mts +0 -1
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +4 -4
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +0 -1
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +4 -4
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.d.mts +1 -0
- package/dist/entry-point.d.mts.map +1 -1
- package/dist/entry-point.mjs +8 -4
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functional/index.d.mts +3 -2
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +6 -2
- package/dist/functional/index.mjs.map +1 -1
- package/dist/functional/optional/impl/index.d.mts +18 -0
- package/dist/functional/optional/impl/index.d.mts.map +1 -0
- package/dist/functional/optional/impl/index.mjs +17 -0
- package/dist/functional/optional/impl/index.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +29 -0
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +25 -0
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-filter.d.mts +29 -0
- package/dist/functional/optional/impl/optional-filter.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-filter.mjs +28 -0
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-flat-map.d.mts +33 -0
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-flat-map.mjs +21 -0
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +24 -0
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-from-nullable.mjs +29 -0
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-is-none.d.mts +22 -0
- package/dist/functional/optional/impl/optional-is-none.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-is-none.mjs +25 -0
- package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-is-optional.d.mts +18 -0
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-is-optional.mjs +27 -0
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-is-some.d.mts +22 -0
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-is-some.mjs +25 -0
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-map.d.mts +31 -0
- package/dist/functional/optional/impl/optional-map.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-map.mjs +25 -0
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-none.d.mts +16 -0
- package/dist/functional/optional/impl/optional-none.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-none.mjs +20 -0
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-or-else.d.mts +35 -0
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-or-else.mjs +19 -0
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-some.d.mts +19 -0
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-some.mjs +26 -0
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +27 -0
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-to-nullable.mjs +31 -0
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +33 -0
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +19 -0
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +29 -0
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +38 -0
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-unwrap.d.mts +28 -0
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-unwrap.mjs +11 -0
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -0
- package/dist/functional/optional/impl/optional-zip.d.mts +31 -0
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -0
- package/dist/functional/optional/impl/optional-zip.mjs +39 -0
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -0
- package/dist/functional/optional/impl/tag.d.mts +5 -0
- package/dist/functional/optional/impl/tag.d.mts.map +1 -0
- package/dist/functional/optional/impl/tag.mjs +7 -0
- package/dist/functional/optional/impl/tag.mjs.map +1 -0
- package/dist/functional/optional/impl/types.d.mts +22 -0
- package/dist/functional/optional/impl/types.d.mts.map +1 -0
- package/dist/functional/optional/impl/types.mjs +2 -0
- package/dist/functional/optional/impl/types.mjs.map +1 -0
- package/dist/functional/optional/index.d.mts +2 -0
- package/dist/functional/optional/index.d.mts.map +1 -0
- package/dist/functional/optional/index.mjs +3 -0
- package/dist/functional/optional/index.mjs.map +1 -0
- package/dist/functional/pipe.d.mts +4 -4
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs +4 -3
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result/impl/index.d.mts +24 -0
- package/dist/functional/result/impl/index.d.mts.map +1 -0
- package/dist/functional/result/impl/index.mjs +23 -0
- package/dist/functional/result/impl/index.mjs.map +1 -0
- package/dist/functional/result/impl/result-err.d.mts +25 -0
- package/dist/functional/result/impl/result-err.d.mts.map +1 -0
- package/dist/functional/result/impl/result-err.mjs +32 -0
- package/dist/functional/result/impl/result-err.mjs.map +1 -0
- package/dist/functional/result/impl/result-expect-to-be.d.mts +27 -0
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +1 -0
- package/dist/functional/result/impl/result-expect-to-be.mjs +26 -0
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -0
- package/dist/functional/result/impl/result-flat-map.d.mts +39 -0
- package/dist/functional/result/impl/result-flat-map.d.mts.map +1 -0
- package/dist/functional/result/impl/result-flat-map.mjs +24 -0
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -0
- package/dist/functional/result/impl/result-fold.d.mts +45 -0
- package/dist/functional/result/impl/result-fold.d.mts.map +1 -0
- package/dist/functional/result/impl/result-fold.mjs +26 -0
- package/dist/functional/result/impl/result-fold.mjs.map +1 -0
- package/dist/functional/result/impl/result-from-promise.d.mts +32 -0
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -0
- package/dist/functional/result/impl/result-from-promise.mjs +32 -0
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -0
- package/dist/functional/result/impl/result-from-throwable.d.mts +29 -0
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -0
- package/dist/functional/result/impl/result-from-throwable.mjs +46 -0
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -0
- package/dist/functional/result/impl/result-is-err.d.mts +20 -0
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -0
- package/dist/functional/result/impl/result-is-err.mjs +23 -0
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -0
- package/dist/functional/result/impl/result-is-ok.d.mts +20 -0
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -0
- package/dist/functional/result/impl/result-is-ok.mjs +23 -0
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -0
- package/dist/functional/result/impl/result-is-result.d.mts +17 -0
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -0
- package/dist/functional/result/impl/result-is-result.mjs +26 -0
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -0
- package/dist/functional/result/impl/result-map-err.d.mts +33 -0
- package/dist/functional/result/impl/result-map-err.d.mts.map +1 -0
- package/dist/functional/result/impl/result-map-err.mjs +25 -0
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -0
- package/dist/functional/result/impl/result-map.d.mts +34 -0
- package/dist/functional/result/impl/result-map.d.mts.map +1 -0
- package/dist/functional/result/impl/result-map.mjs +25 -0
- package/dist/functional/result/impl/result-map.mjs.map +1 -0
- package/dist/functional/result/impl/result-ok.d.mts +25 -0
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -0
- package/dist/functional/result/impl/result-ok.mjs +32 -0
- package/dist/functional/result/impl/result-ok.mjs.map +1 -0
- package/dist/functional/result/impl/result-or-else.d.mts +32 -0
- package/dist/functional/result/impl/result-or-else.d.mts.map +1 -0
- package/dist/functional/result/impl/result-or-else.mjs +20 -0
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -0
- package/dist/functional/result/impl/result-swap.d.mts +20 -0
- package/dist/functional/result/impl/result-swap.d.mts.map +1 -0
- package/dist/functional/result/impl/result-swap.mjs +28 -0
- package/dist/functional/result/impl/result-swap.mjs.map +1 -0
- package/dist/functional/result/impl/result-to-optional.d.mts +28 -0
- package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -0
- package/dist/functional/result/impl/result-to-optional.mjs +34 -0
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -0
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +29 -0
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +1 -0
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +20 -0
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +30 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +47 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -0
- package/dist/functional/result/impl/result-unwrap-err.d.mts +31 -0
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -0
- package/dist/functional/result/impl/result-unwrap-err.mjs +36 -0
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -0
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +29 -0
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +1 -0
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +20 -0
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -0
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +23 -0
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +1 -0
- package/dist/functional/result/impl/result-unwrap-ok.mjs +11 -0
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -0
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +30 -0
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -0
- package/dist/functional/result/impl/result-unwrap-throw.mjs +41 -0
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -0
- package/dist/functional/result/impl/result-zip.d.mts +29 -0
- package/dist/functional/result/impl/result-zip.d.mts.map +1 -0
- package/dist/functional/result/impl/result-zip.mjs +38 -0
- package/dist/functional/result/impl/result-zip.mjs.map +1 -0
- package/dist/functional/result/impl/tag.d.mts +5 -0
- package/dist/functional/result/impl/tag.d.mts.map +1 -0
- package/dist/functional/result/impl/tag.mjs +7 -0
- package/dist/functional/result/impl/tag.mjs.map +1 -0
- package/dist/functional/result/impl/types.d.mts +29 -0
- package/dist/functional/result/impl/types.d.mts.map +1 -0
- package/dist/functional/result/impl/types.mjs +2 -0
- package/dist/functional/result/impl/types.mjs.map +1 -0
- package/dist/functional/result/index.d.mts +2 -0
- package/dist/functional/result/index.d.mts.map +1 -0
- package/dist/functional/result/index.mjs +3 -0
- package/dist/functional/result/index.mjs.map +1 -0
- 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 +136 -0
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +1 -1
- package/dist/json/json.d.mts +0 -1
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +8 -8
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +1 -1
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.mjs +1 -1
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.mjs +1 -1
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.mjs +1 -1
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +1 -1
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +1 -1
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +1 -1
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +1 -1
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +1 -1
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +1 -1
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +1 -1
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.mjs +1 -1
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.mjs +1 -1
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.mjs +1 -1
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.mjs +1 -1
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.mjs +1 -1
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs +0 -2
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/promise/promise.d.mts +0 -1
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +2 -3
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +27 -21
- package/src/array/impl/array-utils-element-access.mts +6 -6
- package/src/array/impl/array-utils-element-access.test.mts +6 -6
- package/src/array/impl/array-utils-reducing-value.mts +8 -24
- package/src/array/impl/array-utils-reducing-value.test.mts +8 -8
- package/src/array/impl/array-utils-slice-clamped.test.mts +1 -1
- package/src/entry-point.mts +1 -0
- package/src/functional/index.mts +3 -2
- package/src/functional/optional/impl/index.mts +17 -0
- package/src/functional/optional/impl/optional-expect-to-be.mts +65 -0
- package/src/functional/optional/impl/optional-filter.mts +71 -0
- package/src/functional/optional/impl/optional-flat-map.mts +67 -0
- package/src/functional/optional/impl/optional-from-nullable.mts +28 -0
- package/src/functional/optional/impl/optional-is-none.mts +25 -0
- package/src/functional/optional/impl/optional-is-optional.mts +27 -0
- package/src/functional/optional/impl/optional-is-some.mts +25 -0
- package/src/functional/optional/impl/optional-map.mts +69 -0
- package/src/functional/optional/impl/optional-none.mts +17 -0
- package/src/functional/optional/impl/optional-or-else.mts +73 -0
- package/src/functional/optional/impl/optional-some.mts +23 -0
- package/src/functional/optional/impl/optional-to-nullable.mts +31 -0
- package/src/functional/optional/impl/optional-unwrap-or.mts +64 -0
- package/src/functional/optional/impl/optional-unwrap-throw.mts +39 -0
- package/src/functional/optional/impl/optional-unwrap.mts +41 -0
- package/src/functional/optional/impl/optional-zip.mts +40 -0
- package/src/functional/optional/impl/tag.mts +6 -0
- package/src/functional/optional/impl/types.mts +28 -0
- package/src/functional/optional/index.mts +1 -0
- package/src/functional/optional.test.mts +7 -8
- package/src/functional/pipe.mts +5 -5
- package/src/functional/pipe.test.mts +1 -1
- package/src/functional/result/impl/index.mts +23 -0
- package/src/functional/result/impl/result-err.mts +29 -0
- package/src/functional/result/impl/result-expect-to-be.mts +63 -0
- package/src/functional/result/impl/result-flat-map.mts +79 -0
- package/src/functional/result/impl/result-fold.mts +95 -0
- package/src/functional/result/impl/result-from-promise.mts +39 -0
- package/src/functional/result/impl/result-from-throwable.mts +42 -0
- package/src/functional/result/impl/result-is-err.mts +23 -0
- package/src/functional/result/impl/result-is-ok.mts +23 -0
- package/src/functional/result/impl/result-is-result.mts +23 -0
- package/src/functional/result/impl/result-map-err.mts +72 -0
- package/src/functional/result/impl/result-map.mts +73 -0
- package/src/functional/result/impl/result-ok.mts +29 -0
- package/src/functional/result/impl/result-or-else.mts +63 -0
- package/src/functional/result/impl/result-swap.mts +28 -0
- package/src/functional/result/impl/result-to-optional.mts +34 -0
- package/src/functional/result/impl/result-unwrap-err-or.mts +60 -0
- package/src/functional/result/impl/result-unwrap-err-throw.mts +53 -0
- package/src/functional/result/impl/result-unwrap-err.mts +36 -0
- package/src/functional/result/impl/result-unwrap-ok-or.mts +60 -0
- package/src/functional/result/impl/result-unwrap-ok.mts +35 -0
- package/src/functional/result/impl/result-unwrap-throw.mts +43 -0
- package/src/functional/result/impl/result-zip.mts +39 -0
- package/src/functional/result/impl/tag.mts +6 -0
- package/src/functional/result/impl/types.mts +35 -0
- package/src/functional/result/index.mts +1 -0
- package/src/functional/result.test.mts +5 -4
- 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 +136 -0
- package/src/guard/is-non-empty-string.test.mts +1 -1
- package/src/guard/is-non-null-object.test.mts +3 -3
- package/src/guard/is-primitive.test.mts +3 -3
- package/src/guard/is-type.test.mts +3 -3
- package/src/index.mts +0 -1
- package/src/number/branded-types/finite-number.mts +7 -7
- package/src/number/branded-types/int.mts +7 -7
- package/src/number/branded-types/int16.mts +9 -9
- package/src/number/branded-types/int32.mts +9 -9
- package/src/number/branded-types/non-negative-finite-number.mts +8 -8
- package/src/number/branded-types/non-negative-int16.mts +9 -9
- package/src/number/branded-types/non-negative-int32.mts +9 -9
- package/src/number/branded-types/non-zero-finite-number.mts +7 -7
- package/src/number/branded-types/non-zero-int.mts +7 -7
- package/src/number/branded-types/non-zero-int16.mts +9 -9
- package/src/number/branded-types/non-zero-int32.mts +9 -9
- package/src/number/branded-types/non-zero-safe-int.mts +9 -9
- package/src/number/branded-types/non-zero-uint16.mts +9 -9
- package/src/number/branded-types/non-zero-uint32.mts +9 -9
- package/src/number/branded-types/positive-finite-number.mts +8 -8
- package/src/number/branded-types/positive-int.mts +8 -8
- package/src/number/branded-types/positive-int16.mts +9 -9
- package/src/number/branded-types/positive-int32.mts +9 -9
- package/src/number/branded-types/positive-safe-int.mts +9 -9
- package/src/number/branded-types/positive-uint16.mts +9 -9
- package/src/number/branded-types/positive-uint32.mts +9 -9
- package/src/number/branded-types/safe-int.mts +9 -9
- package/src/number/branded-types/safe-uint.mts +9 -9
- package/src/number/branded-types/uint.mts +8 -8
- package/src/number/branded-types/uint16.mts +9 -9
- package/src/number/branded-types/uint32.mts +9 -9
- package/src/number/enum/int8.mts +3 -3
- package/src/number/enum/int8.test.mts +9 -9
- package/src/number/enum/uint8.mts +3 -3
- package/src/number/enum/uint8.test.mts +8 -8
- package/dist/functional/optional.d.mts +0 -482
- package/dist/functional/optional.d.mts.map +0 -1
- package/dist/functional/optional.mjs +0 -328
- package/dist/functional/optional.mjs.map +0 -1
- package/dist/functional/result.d.mts +0 -712
- package/dist/functional/result.d.mts.map +0 -1
- package/dist/functional/result.mjs +0 -539
- package/dist/functional/result.mjs.map +0 -1
- package/src/functional/optional.mts +0 -713
- package/src/functional/result.mts +0 -1087
|
@@ -1,712 +0,0 @@
|
|
|
1
|
-
import { Optional } from './optional.mjs';
|
|
2
|
-
/** @internal String literal tag to identify the 'Ok' variant of Result. */
|
|
3
|
-
declare const OkTypeTagName = "ts-data-forge::Result.ok";
|
|
4
|
-
/** @internal String literal tag to identify the 'Err' variant of Result. */
|
|
5
|
-
declare const ErrTypeTagName = "ts-data-forge::Result.err";
|
|
6
|
-
/**
|
|
7
|
-
* @template S The type of the success value.
|
|
8
|
-
* @internal
|
|
9
|
-
* Represents the 'Ok' variant of a Result, containing a success value.
|
|
10
|
-
*/
|
|
11
|
-
type Ok_<S> = Readonly<{
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
* Discriminant property for the 'Ok' type.
|
|
15
|
-
*/
|
|
16
|
-
$$tag: typeof OkTypeTagName;
|
|
17
|
-
/** The success value. */
|
|
18
|
-
value: S;
|
|
19
|
-
}>;
|
|
20
|
-
/**
|
|
21
|
-
* @template E The type of the error value.
|
|
22
|
-
* @internal
|
|
23
|
-
* Represents the 'Err' variant of a Result, containing an error value.
|
|
24
|
-
*/
|
|
25
|
-
type Err_<E> = Readonly<{
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
* Discriminant property for the 'Err' type.
|
|
29
|
-
*/
|
|
30
|
-
$$tag: typeof ErrTypeTagName;
|
|
31
|
-
/** The error value. */
|
|
32
|
-
value: E;
|
|
33
|
-
}>;
|
|
34
|
-
/**
|
|
35
|
-
* Represents a value that can either be a success (`Ok`) or an error (`Err`).
|
|
36
|
-
*
|
|
37
|
-
* @template S The type of the success value.
|
|
38
|
-
* @template E The type of the error value.
|
|
39
|
-
*/
|
|
40
|
-
export type Result<S, E> = Ok_<S> | Err_<E>;
|
|
41
|
-
/**
|
|
42
|
-
* Namespace for the `Result` type and related functions. Provides utilities to
|
|
43
|
-
* handle operations that can succeed or fail.
|
|
44
|
-
*/
|
|
45
|
-
export declare namespace Result {
|
|
46
|
-
/**
|
|
47
|
-
* Checks if the given value is a `Result`.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
*
|
|
51
|
-
* ```ts
|
|
52
|
-
* const okValue = Result.ok('success');
|
|
53
|
-
* const errValue = Result.err(new Error('failure'));
|
|
54
|
-
* const notResult = { $$tag: 'ts-data-forge::Result.ok' };
|
|
55
|
-
*
|
|
56
|
-
* assert.ok(Result.isResult(okValue));
|
|
57
|
-
* assert.ok(Result.isResult(errValue));
|
|
58
|
-
* assert.notOk(Result.isResult(notResult));
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @param maybeOptional The value to check.
|
|
62
|
-
* @returns `true` if the value is a `Result`, otherwise `false`.
|
|
63
|
-
*/
|
|
64
|
-
export const isResult: (maybeOptional: unknown) => maybeOptional is Result<unknown, unknown>;
|
|
65
|
-
/**
|
|
66
|
-
* Represents a `Result` that is a success, containing a value.
|
|
67
|
-
*
|
|
68
|
-
* @template S The type of the success value.
|
|
69
|
-
*/
|
|
70
|
-
export type Ok<S> = Ok_<S>;
|
|
71
|
-
/**
|
|
72
|
-
* Represents a `Result` that is an error, containing an error value.
|
|
73
|
-
*
|
|
74
|
-
* @template E The type of the error value.
|
|
75
|
-
*/
|
|
76
|
-
export type Err<E> = Err_<E>;
|
|
77
|
-
/**
|
|
78
|
-
* Base type for any `Result`, used for generic constraints. Represents a
|
|
79
|
-
* `Result` with unknown success and error types.
|
|
80
|
-
*/
|
|
81
|
-
export type Base = Result<unknown, unknown>;
|
|
82
|
-
/**
|
|
83
|
-
* Extracts the success value type `S` from a `Result.Ok<S>`. If the `Result`
|
|
84
|
-
* is `Result.Err<E>`, resolves to `never`.
|
|
85
|
-
*
|
|
86
|
-
* @template R The `Result.Base` type to unwrap.
|
|
87
|
-
*/
|
|
88
|
-
export type UnwrapOk<R extends Base> = R extends Ok<infer S> ? S : never;
|
|
89
|
-
/**
|
|
90
|
-
* Extracts the error value type `E` from a `Result.Err<E>`. If the `Result`
|
|
91
|
-
* is `Result.Ok<S>`, resolves to `never`.
|
|
92
|
-
*
|
|
93
|
-
* @template R The `Result.Base` type to unwrap.
|
|
94
|
-
*/
|
|
95
|
-
export type UnwrapErr<R extends Base> = R extends Err<infer E> ? E : never;
|
|
96
|
-
/**
|
|
97
|
-
* Narrows a `Result.Base` type to `Result.Ok<S>` if it is an `Ok`. If the
|
|
98
|
-
* `Result` is `Result.Err<E>`, resolves to `never`.
|
|
99
|
-
*
|
|
100
|
-
* @template R The `Result.Base` type to narrow.
|
|
101
|
-
*/
|
|
102
|
-
export type NarrowToOk<R extends Base> = R extends Err<unknown> ? never : R;
|
|
103
|
-
/**
|
|
104
|
-
* Narrows a `Result.Base` type to `Result.Err<E>` if it is an `Err`. If the
|
|
105
|
-
* `Result` is `Result.Ok<S>`, resolves to `never`.
|
|
106
|
-
*
|
|
107
|
-
* @template R The `Result.Base` type to narrow.
|
|
108
|
-
*/
|
|
109
|
-
export type NarrowToErr<R extends Base> = R extends Ok<unknown> ? never : R;
|
|
110
|
-
/**
|
|
111
|
-
* Creates a `Result.Ok` containing the given success value.
|
|
112
|
-
*
|
|
113
|
-
* Use this constructor when an operation succeeds and you want to wrap the
|
|
114
|
-
* successful result in a Result type for consistent error handling.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
*
|
|
118
|
-
* ```ts
|
|
119
|
-
* const success = Result.ok({ id: 1 });
|
|
120
|
-
* const failure = Result.err(new Error('missing data'));
|
|
121
|
-
*
|
|
122
|
-
* assert.deepStrictEqual(success, {
|
|
123
|
-
* $$tag: 'ts-data-forge::Result.ok',
|
|
124
|
-
* value: { id: 1 },
|
|
125
|
-
* });
|
|
126
|
-
* assert.ok(Result.isErr(failure));
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* @template S The type of the success value.
|
|
130
|
-
* @param value The success value.
|
|
131
|
-
* @returns A `Result.Ok<S>` containing the value.
|
|
132
|
-
*/
|
|
133
|
-
export const ok: <S>(value: S) => Ok<S>;
|
|
134
|
-
/**
|
|
135
|
-
* Creates a `Result.Err` containing the given error value.
|
|
136
|
-
*
|
|
137
|
-
* Use this constructor when an operation fails and you want to wrap the error
|
|
138
|
-
* information in a Result type for consistent error handling.
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
*
|
|
142
|
-
* ```ts
|
|
143
|
-
* const success = Result.ok({ id: 1 });
|
|
144
|
-
* const failure = Result.err(new Error('missing data'));
|
|
145
|
-
*
|
|
146
|
-
* assert.deepStrictEqual(success, {
|
|
147
|
-
* $$tag: 'ts-data-forge::Result.ok',
|
|
148
|
-
* value: { id: 1 },
|
|
149
|
-
* });
|
|
150
|
-
* assert.ok(Result.isErr(failure));
|
|
151
|
-
* ```
|
|
152
|
-
*
|
|
153
|
-
* @template E The type of the error value.
|
|
154
|
-
* @param value The error value.
|
|
155
|
-
* @returns A `Result.Err<E>` containing the value.
|
|
156
|
-
*/
|
|
157
|
-
export const err: <E>(value: E) => Err<E>;
|
|
158
|
-
/**
|
|
159
|
-
* Checks if a `Result` is `Result.Ok`. Acts as a type guard, narrowing the
|
|
160
|
-
* type to the success variant.
|
|
161
|
-
*
|
|
162
|
-
* This function is essential for type-safe Result handling, allowing
|
|
163
|
-
* TypeScript to understand that subsequent operations will work with the
|
|
164
|
-
* success value rather than the error value.
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
*
|
|
168
|
-
* ```ts
|
|
169
|
-
* const operation = Result.ok(3);
|
|
170
|
-
* const failure = Result.err('error');
|
|
171
|
-
*
|
|
172
|
-
* if (Result.isOk(operation)) {
|
|
173
|
-
* const value: number = operation.value;
|
|
174
|
-
* assert(value === 3);
|
|
175
|
-
* }
|
|
176
|
-
*
|
|
177
|
-
* assert.ok(Result.isErr(failure));
|
|
178
|
-
* ```
|
|
179
|
-
*
|
|
180
|
-
* @template R The `Result.Base` type to check.
|
|
181
|
-
* @param result The `Result` to check.
|
|
182
|
-
* @returns `true` if the `Result` is `Result.Ok`, otherwise `false`.
|
|
183
|
-
*/
|
|
184
|
-
export const isOk: <R extends Base>(result: R) => result is NarrowToOk<R>;
|
|
185
|
-
/**
|
|
186
|
-
* Checks if a `Result` is `Result.Err`. Acts as a type guard, narrowing the
|
|
187
|
-
* type to the error variant.
|
|
188
|
-
*
|
|
189
|
-
* This function is essential for type-safe Result handling, allowing
|
|
190
|
-
* TypeScript to understand that subsequent operations will work with the
|
|
191
|
-
* error value rather than the success value.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
*
|
|
195
|
-
* ```ts
|
|
196
|
-
* const operation = Result.ok(3);
|
|
197
|
-
* const failure = Result.err('error');
|
|
198
|
-
*
|
|
199
|
-
* if (Result.isOk(operation)) {
|
|
200
|
-
* const value: number = operation.value;
|
|
201
|
-
* assert(value === 3);
|
|
202
|
-
* }
|
|
203
|
-
*
|
|
204
|
-
* assert.ok(Result.isErr(failure));
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* @template R The `Result.Base` type to check.
|
|
208
|
-
* @param result The `Result` to check.
|
|
209
|
-
* @returns `true` if the `Result` is `Result.Err`, otherwise `false`.
|
|
210
|
-
*/
|
|
211
|
-
export const isErr: <R extends Base>(result: R) => result is NarrowToErr<R>;
|
|
212
|
-
/**
|
|
213
|
-
* Unwraps a `Result`, returning the success value. Throws an error if the
|
|
214
|
-
* `Result` is `Result.Err`.
|
|
215
|
-
*
|
|
216
|
-
* This is useful when you're confident that a Result should contain a success
|
|
217
|
-
* value and want to treat errors as exceptional conditions. The error message
|
|
218
|
-
* will be constructed from the error value using the provided string
|
|
219
|
-
* conversion function.
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
*
|
|
223
|
-
* ```ts
|
|
224
|
-
* const okResult = Result.ok('data');
|
|
225
|
-
* const errResult = Result.err(new Error('fail'));
|
|
226
|
-
*
|
|
227
|
-
* assert(Result.unwrapThrow(okResult) === 'data');
|
|
228
|
-
* assert.throws(() => Result.unwrapThrow(errResult), /fail/u);
|
|
229
|
-
* ```
|
|
230
|
-
*
|
|
231
|
-
* @template R The `Result.Base` type to unwrap.
|
|
232
|
-
* @param result The `Result` to unwrap.
|
|
233
|
-
* @param toStr An optional function to convert the error value to a string
|
|
234
|
-
* for the error message. Defaults to `String`.
|
|
235
|
-
* @returns The success value if `Result.Ok`.
|
|
236
|
-
* @throws {Error} Error with the stringified error value if the `Result` is
|
|
237
|
-
* `Result.Err`.
|
|
238
|
-
*/
|
|
239
|
-
export const unwrapThrow: <R extends Base>(result: R, toStr?: (e: UnwrapErr<R>) => string) => UnwrapOk<R>;
|
|
240
|
-
/**
|
|
241
|
-
* Unwraps a `Result`, returning the success value or `undefined` if it's an
|
|
242
|
-
* error.
|
|
243
|
-
*
|
|
244
|
-
* This function provides a safe way to extract success values from Results
|
|
245
|
-
* without throwing exceptions. It has overloaded behavior based on the type:
|
|
246
|
-
*
|
|
247
|
-
* - For `Result.Ok<T>`: Always returns `T` (guaranteed by type system)
|
|
248
|
-
* - For general `Result<T, E>`: Returns `T | undefined`
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
*
|
|
252
|
-
* ```ts
|
|
253
|
-
* const okResult = Result.ok(42);
|
|
254
|
-
* const errResult = Result.err('oops');
|
|
255
|
-
*
|
|
256
|
-
* // Result.unwrapOk returns the value for Ok results
|
|
257
|
-
*
|
|
258
|
-
* assert(Result.unwrapOk(okResult) === 42);
|
|
259
|
-
*
|
|
260
|
-
* // Result.unwrapOk returns undefined for Err results
|
|
261
|
-
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
262
|
-
* assert(Result.unwrapOk(errResult) === undefined);
|
|
263
|
-
* ```
|
|
264
|
-
*
|
|
265
|
-
* @template R The `Result.Base` type to unwrap.
|
|
266
|
-
* @param result The `Result` to unwrap.
|
|
267
|
-
* @returns The success value if `Result.Ok`, otherwise `undefined`.
|
|
268
|
-
*/
|
|
269
|
-
export function unwrapOk<R extends Ok<unknown>>(result: R): UnwrapOk<R>;
|
|
270
|
-
export function unwrapOk<R extends Base>(result: R): UnwrapOk<R> | undefined;
|
|
271
|
-
/**
|
|
272
|
-
* Unwraps a `Result`, returning the success value or a default value if it is
|
|
273
|
-
* `Result.Err`.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
*
|
|
277
|
-
* ```ts
|
|
278
|
-
* const okValue = Result.ok(10);
|
|
279
|
-
* const errValue = Result.err('fail');
|
|
280
|
-
*
|
|
281
|
-
* assert(Result.unwrapOkOr(okValue, 0) === 10);
|
|
282
|
-
* assert(Result.unwrapOkOr(errValue, 0) === 0);
|
|
283
|
-
*
|
|
284
|
-
* const unwrapWithDefault = Result.unwrapOkOr(5);
|
|
285
|
-
*
|
|
286
|
-
* assert(unwrapWithDefault(Result.ok(3)) === 3);
|
|
287
|
-
* assert(unwrapWithDefault(Result.err('no data')) === 5);
|
|
288
|
-
* ```
|
|
289
|
-
*
|
|
290
|
-
* @template R The `Result.Base` type to unwrap.
|
|
291
|
-
* @template D The type of the default value.
|
|
292
|
-
* @param result The `Result` to unwrap.
|
|
293
|
-
* @param defaultValue The value to return if `result` is `Result.Err`.
|
|
294
|
-
* @returns The success value if `Result.Ok`, otherwise `defaultValue`.
|
|
295
|
-
*/
|
|
296
|
-
export function unwrapOkOr<R extends Base, D>(result: R, defaultValue: D): D | UnwrapOk<R>;
|
|
297
|
-
export function unwrapOkOr<S, D>(defaultValue: D): <E>(result: Result<S, E>) => D | S;
|
|
298
|
-
/**
|
|
299
|
-
* Unwraps a `Result`, returning the error value. Throws an error if the
|
|
300
|
-
* `Result` is `Result.Ok`.
|
|
301
|
-
*
|
|
302
|
-
* This function is used when you expect a Result to be an error and want to
|
|
303
|
-
* extract the error value. If the Result is unexpectedly Ok, it will throw an
|
|
304
|
-
* error with information about the unexpected success value.
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
*
|
|
308
|
-
* ```ts
|
|
309
|
-
* const errResult = Result.err(new Error('broken'));
|
|
310
|
-
* const okResult = Result.ok('value');
|
|
311
|
-
*
|
|
312
|
-
* assert(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
313
|
-
* assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
|
|
314
|
-
* ```
|
|
315
|
-
*
|
|
316
|
-
* @template R The `Result.Base` type to unwrap.
|
|
317
|
-
* @param result The `Result` to unwrap.
|
|
318
|
-
* @param toStr An optional function to convert the success value to a string
|
|
319
|
-
* for the error message when the Result is unexpectedly Ok. Defaults to
|
|
320
|
-
* `String`.
|
|
321
|
-
* @returns The error value if `Result.Err`.
|
|
322
|
-
* @throws {Error} Error with message "Expected Err but got Ok: {value}" if
|
|
323
|
-
* the `Result` is `Result.Ok`.
|
|
324
|
-
*/
|
|
325
|
-
export const unwrapErrThrow: <R extends Base>(result: R, toStr?: (v: UnwrapOk<R>) => string) => UnwrapErr<R>;
|
|
326
|
-
/**
|
|
327
|
-
* Unwraps a `Result`, returning the error value or `undefined` if it is
|
|
328
|
-
* `Result.Ok`.
|
|
329
|
-
*
|
|
330
|
-
* This provides a safe way to extract error values from Results without
|
|
331
|
-
* throwing exceptions. Useful for error handling patterns where you want to
|
|
332
|
-
* check for specific error conditions.
|
|
333
|
-
*
|
|
334
|
-
* @example
|
|
335
|
-
*
|
|
336
|
-
* ```ts
|
|
337
|
-
* const okResult = Result.ok('data');
|
|
338
|
-
* const errResult = Result.err('problem');
|
|
339
|
-
*
|
|
340
|
-
* // Result.unwrapErr returns undefined for Ok results
|
|
341
|
-
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
342
|
-
* assert(Result.unwrapErr(okResult) === undefined);
|
|
343
|
-
*
|
|
344
|
-
* // Result.unwrapErr returns the error value for Err results
|
|
345
|
-
*
|
|
346
|
-
* assert(Result.unwrapErr(errResult) === 'problem');
|
|
347
|
-
* ```
|
|
348
|
-
*
|
|
349
|
-
* @template R The `Result.Base` type to unwrap.
|
|
350
|
-
* @param result The `Result` to unwrap.
|
|
351
|
-
* @returns The error value if `Result.Err`, otherwise `undefined`.
|
|
352
|
-
*/
|
|
353
|
-
export const unwrapErr: <R extends Base>(result: R) => UnwrapErr<R> | undefined;
|
|
354
|
-
/**
|
|
355
|
-
* Unwraps a `Result`, returning the error value or a default value if it is
|
|
356
|
-
* `Result.Ok`.
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
*
|
|
360
|
-
* ```ts
|
|
361
|
-
* const okResult = Result.ok('success');
|
|
362
|
-
* const errResult = Result.err('failure');
|
|
363
|
-
*
|
|
364
|
-
* assert(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
365
|
-
* assert(Result.unwrapErrOr(errResult, 'default') === 'failure');
|
|
366
|
-
*
|
|
367
|
-
* const unwrapError = Result.unwrapErrOr('fallback error');
|
|
368
|
-
*
|
|
369
|
-
* assert(unwrapError(Result.err('boom')) === 'boom');
|
|
370
|
-
* assert(unwrapError(Result.ok('no error')) === 'fallback error');
|
|
371
|
-
* ```
|
|
372
|
-
*
|
|
373
|
-
* @template R The `Result.Base` type to unwrap.
|
|
374
|
-
* @template D The type of the default value.
|
|
375
|
-
* @param result The `Result` to unwrap.
|
|
376
|
-
* @param defaultValue The value to return if `result` is `Result.Ok`.
|
|
377
|
-
* @returns The error value if `Result.Err`, otherwise `defaultValue`.
|
|
378
|
-
*/
|
|
379
|
-
export function unwrapErrOr<R extends Base, D>(result: R, defaultValue: D): D | UnwrapErr<R>;
|
|
380
|
-
export function unwrapErrOr<E, D>(defaultValue: D): <S>(result: Result<S, E>) => D | E;
|
|
381
|
-
/**
|
|
382
|
-
* Maps a `Result<S, E>` to `Result<S2, E>` by applying a function to the
|
|
383
|
-
* success value. If the `Result` is `Result.Err`, returns the original
|
|
384
|
-
* `Err`.
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
*
|
|
388
|
-
* ```ts
|
|
389
|
-
* const okNumber = Result.ok(5);
|
|
390
|
-
* const errMessage = Result.err('error');
|
|
391
|
-
*
|
|
392
|
-
* const doubled = Result.map(okNumber, (value) => value * 2);
|
|
393
|
-
* const untouchedError = Result.map(errMessage, (value: number) => value * 2);
|
|
394
|
-
*
|
|
395
|
-
* assert.deepStrictEqual(doubled, Result.ok(10));
|
|
396
|
-
* assert.deepStrictEqual(untouchedError, errMessage);
|
|
397
|
-
*
|
|
398
|
-
* const mapToLength = Result.map((text: string) => text.length);
|
|
399
|
-
*
|
|
400
|
-
* assert.deepStrictEqual(mapToLength(Result.ok('abc')), Result.ok(3));
|
|
401
|
-
* assert.deepStrictEqual(mapToLength(Result.err('bad')), Result.err('bad'));
|
|
402
|
-
* ```
|
|
403
|
-
*
|
|
404
|
-
* @template R The input `Result.Base` type.
|
|
405
|
-
* @template S2 The type of the success value returned by the mapping
|
|
406
|
-
* function.
|
|
407
|
-
* @param result The `Result` to map.
|
|
408
|
-
* @param mapFn The function to apply to the success value if present.
|
|
409
|
-
* @returns A new `Result<S2, UnwrapErr<R>>`.
|
|
410
|
-
*/
|
|
411
|
-
export function map<R extends Base, S2>(result: R, mapFn: (value: UnwrapOk<R>) => S2): Result<S2, UnwrapErr<R>>;
|
|
412
|
-
export function map<S, S2>(mapFn: (value: S) => S2): <E>(result: Result<S, E>) => Result<S2, E>;
|
|
413
|
-
/**
|
|
414
|
-
* Maps a `Result<S, E>` to `Result<S, E2>` by applying a function to the
|
|
415
|
-
* error value. If the `Result` is `Result.Ok`, returns the original `Ok`.
|
|
416
|
-
*
|
|
417
|
-
* @example
|
|
418
|
-
*
|
|
419
|
-
* ```ts
|
|
420
|
-
* const okValue = Result.ok(3) as Result<number, string>;
|
|
421
|
-
* const errValue = Result.err('missing');
|
|
422
|
-
*
|
|
423
|
-
* const untouchedOk = Result.mapErr(okValue, (error) => error.toUpperCase());
|
|
424
|
-
* const uppercasedErr = Result.mapErr(errValue, (error) => error.toUpperCase());
|
|
425
|
-
*
|
|
426
|
-
* assert.deepStrictEqual(untouchedOk, Result.ok(3));
|
|
427
|
-
* assert.deepStrictEqual(uppercasedErr, Result.err('MISSING'));
|
|
428
|
-
*
|
|
429
|
-
* const mapError = Result.mapErr((error: Readonly<Error>) => error.message);
|
|
430
|
-
*
|
|
431
|
-
* const wrapped = mapError(Result.err(new Error('boom')));
|
|
432
|
-
*
|
|
433
|
-
* assert.deepStrictEqual(wrapped, Result.err('boom'));
|
|
434
|
-
* ```
|
|
435
|
-
*
|
|
436
|
-
* @template R The input `Result.Base` type.
|
|
437
|
-
* @template E2 The type of the error value returned by the mapping function.
|
|
438
|
-
* @param result The `Result` to map.
|
|
439
|
-
* @param mapFn The function to apply to the error value if present.
|
|
440
|
-
* @returns A new `Result<UnwrapOk<R>, E2>`.
|
|
441
|
-
*/
|
|
442
|
-
export function mapErr<R extends Base, E2>(result: R, mapFn: (error: UnwrapErr<R>) => E2): Result<UnwrapOk<R>, E2>;
|
|
443
|
-
export function mapErr<E, E2>(mapFn: (error: E) => E2): <S>(result: Result<S, E>) => Result<S, E2>;
|
|
444
|
-
/**
|
|
445
|
-
* Applies one of two functions depending on whether the `Result` is `Ok` or
|
|
446
|
-
* `Err`.
|
|
447
|
-
*
|
|
448
|
-
* @example
|
|
449
|
-
*
|
|
450
|
-
* ```ts
|
|
451
|
-
* const okValue = Result.ok(2);
|
|
452
|
-
* const errValue = Result.err('bad');
|
|
453
|
-
*
|
|
454
|
-
* const foldedOk = Result.fold(
|
|
455
|
-
* okValue,
|
|
456
|
-
* (value) => value * 2,
|
|
457
|
-
* (error) => error,
|
|
458
|
-
* );
|
|
459
|
-
* const foldedErr = Result.fold(
|
|
460
|
-
* errValue,
|
|
461
|
-
* (value: number) => value * 2,
|
|
462
|
-
* (error) => error.toUpperCase(),
|
|
463
|
-
* );
|
|
464
|
-
*
|
|
465
|
-
* assert.deepStrictEqual(foldedOk, Result.ok(4));
|
|
466
|
-
* assert.deepStrictEqual(foldedErr, Result.err('BAD'));
|
|
467
|
-
*
|
|
468
|
-
* const foldNumbers = Result.fold(
|
|
469
|
-
* (value: number) => value * 3,
|
|
470
|
-
* (error: string) => error.length,
|
|
471
|
-
* );
|
|
472
|
-
*
|
|
473
|
-
* assert.deepStrictEqual(foldNumbers(Result.ok(3)), Result.ok(9));
|
|
474
|
-
* assert.deepStrictEqual(foldNumbers(Result.err('oops')), Result.err(4));
|
|
475
|
-
* ```
|
|
476
|
-
*
|
|
477
|
-
* @template R The input `Result.Base` type.
|
|
478
|
-
* @template S2 The type of the success value returned by `mapFn`.
|
|
479
|
-
* @template E2 The type of the error value returned by `mapErrFn`.
|
|
480
|
-
* @param result The `Result` to fold.
|
|
481
|
-
* @param mapFn The function to apply if `result` is `Ok`.
|
|
482
|
-
* @param mapErrFn The function to apply if `result` is `Err`.
|
|
483
|
-
* @returns A new `Result<S2, E2>` based on the applied function.
|
|
484
|
-
*/
|
|
485
|
-
export function fold<R extends Base, S2, E2>(result: R, mapFn: (value: UnwrapOk<R>) => S2, mapErrFn: (error: UnwrapErr<R>) => E2): Result<S2, E2>;
|
|
486
|
-
export function fold<S, E, S2, E2>(mapFn: (value: S) => S2, mapErrFn: (error: E) => E2): (result: Result<S, E>) => Result<S2, E2>;
|
|
487
|
-
/**
|
|
488
|
-
* Applies a function that returns a `Result` to the success value of a
|
|
489
|
-
* `Result`. If the input is `Err`, returns the original `Err`. This is the
|
|
490
|
-
* monadic bind operation for `Result`.
|
|
491
|
-
*
|
|
492
|
-
* @example
|
|
493
|
-
*
|
|
494
|
-
* ```ts
|
|
495
|
-
* const parseNumber = (input: string): Result<number, string> => {
|
|
496
|
-
* const num = Number.parseInt(input, 10);
|
|
497
|
-
* return Number.isNaN(num) ? Result.err('not a number') : Result.ok(num);
|
|
498
|
-
* };
|
|
499
|
-
*
|
|
500
|
-
* const parsed = Result.flatMap(Result.ok('42'), parseNumber);
|
|
501
|
-
* const failure = Result.flatMap(Result.ok('abc'), parseNumber);
|
|
502
|
-
* const passthrough = Result.flatMap(Result.err('fail'), parseNumber);
|
|
503
|
-
*
|
|
504
|
-
* assert.deepStrictEqual(parsed, Result.ok(42));
|
|
505
|
-
* assert.deepStrictEqual(failure, Result.err('not a number'));
|
|
506
|
-
* assert.deepStrictEqual(passthrough, Result.err('fail'));
|
|
507
|
-
*
|
|
508
|
-
* const parseThenDouble = Result.flatMap((input: string) =>
|
|
509
|
-
* Result.map(parseNumber(input), (value) => value * 2),
|
|
510
|
-
* );
|
|
511
|
-
*
|
|
512
|
-
* assert.deepStrictEqual(parseThenDouble(Result.ok('10')), Result.ok(20));
|
|
513
|
-
* ```
|
|
514
|
-
*
|
|
515
|
-
* @template R The input `Result.Base` type.
|
|
516
|
-
* @template S2 The success type of the `Result` returned by the function.
|
|
517
|
-
* @template E2 The error type of the `Result` returned by the function.
|
|
518
|
-
* @param result The `Result` to flat map.
|
|
519
|
-
* @param flatMapFn The function to apply that returns a `Result`.
|
|
520
|
-
* @returns The result of applying the function, or the original `Err`.
|
|
521
|
-
*/
|
|
522
|
-
export function flatMap<R extends Base, S2, E2>(result: R, flatMapFn: (value: UnwrapOk<R>) => Result<S2, E2>): Result<S2, E2 | UnwrapErr<R>>;
|
|
523
|
-
export function flatMap<S, S2, E2>(flatMapFn: (value: S) => Result<S2, E2>): <E>(result: Result<S, E>) => Result<S2, E | E2>;
|
|
524
|
-
/**
|
|
525
|
-
* Unwraps a `Result`, returning the success value or throwing an error with
|
|
526
|
-
* the provided message.
|
|
527
|
-
*
|
|
528
|
-
* @example
|
|
529
|
-
*
|
|
530
|
-
* ```ts
|
|
531
|
-
* const okValue = Result.ok('data');
|
|
532
|
-
*
|
|
533
|
-
* assert(Result.expectToBe(okValue, 'should have value') === 'data');
|
|
534
|
-
*
|
|
535
|
-
* const expectResult = Result.expectToBe<string>('missing result');
|
|
536
|
-
*
|
|
537
|
-
* assert.throws(() => expectResult(Result.err('boom')), /missing result/u);
|
|
538
|
-
* assert(expectResult(Result.ok('value')) === 'value');
|
|
539
|
-
* ```
|
|
540
|
-
*
|
|
541
|
-
* @template R The `Result.Base` type to unwrap.
|
|
542
|
-
* @param result The `Result` to unwrap.
|
|
543
|
-
* @param message The error message to throw if the `Result` is `Result.Err`.
|
|
544
|
-
* @returns The success value if `Result.Ok`.
|
|
545
|
-
* @throws Error with the provided message if the `Result` is `Result.Err`.
|
|
546
|
-
*/
|
|
547
|
-
export function expectToBe<R extends Base>(result: R, message: string): UnwrapOk<R>;
|
|
548
|
-
export function expectToBe<S>(message: string): <E>(result: Result<S, E>) => S;
|
|
549
|
-
/**
|
|
550
|
-
* @template P The Promise type.
|
|
551
|
-
* @internal
|
|
552
|
-
* Utility type to extract the resolved value type from a Promise.
|
|
553
|
-
*/
|
|
554
|
-
type UnwrapPromise<P extends Promise<unknown>> = P extends Promise<infer V> ? V : never;
|
|
555
|
-
/**
|
|
556
|
-
* Converts a Promise into a Promise that resolves to a `Result`. If the input
|
|
557
|
-
* Promise resolves, the `Result` will be `Ok` with the resolved value. If the
|
|
558
|
-
* input Promise rejects, the `Result` will be `Err` with the rejection
|
|
559
|
-
* reason.
|
|
560
|
-
*
|
|
561
|
-
* @example
|
|
562
|
-
*
|
|
563
|
-
* ```ts
|
|
564
|
-
* const successPromise = Result.fromPromise(Promise.resolve('ok'));
|
|
565
|
-
* const failurePromise = Result.fromPromise(Promise.reject(new Error('fail')));
|
|
566
|
-
*
|
|
567
|
-
* const resolved = await successPromise;
|
|
568
|
-
* const rejected = await failurePromise;
|
|
569
|
-
*
|
|
570
|
-
* assert.deepStrictEqual(resolved, Result.ok('ok'));
|
|
571
|
-
* assert.ok(Result.isErr(rejected));
|
|
572
|
-
* ```
|
|
573
|
-
*
|
|
574
|
-
* @template P The type of the input Promise.
|
|
575
|
-
* @param promise The Promise to convert.
|
|
576
|
-
* @returns A Promise that resolves to `Result<UnwrapPromise<P>, unknown>`.
|
|
577
|
-
*/
|
|
578
|
-
export const fromPromise: <P extends Promise<unknown>>(promise: P) => Promise<Result<UnwrapPromise<P>, unknown>>;
|
|
579
|
-
/**
|
|
580
|
-
* Wraps a function that may throw an exception in a `Result`.
|
|
581
|
-
*
|
|
582
|
-
* This is a fundamental utility for converting traditional exception-based
|
|
583
|
-
* error handling into Result-based error handling. Any thrown value is
|
|
584
|
-
* converted to an Error object for consistent error handling.
|
|
585
|
-
*
|
|
586
|
-
* If the function executes successfully, returns `Result.Ok` with the result.
|
|
587
|
-
* If the function throws, returns `Result.Err` with the caught error.
|
|
588
|
-
*
|
|
589
|
-
* @example
|
|
590
|
-
*
|
|
591
|
-
* ```ts
|
|
592
|
-
* const success = Result.fromThrowable(() => 1 + 1);
|
|
593
|
-
* const failure = Result.fromThrowable(() => {
|
|
594
|
-
* throw new Error('boom');
|
|
595
|
-
* });
|
|
596
|
-
*
|
|
597
|
-
* assert.deepStrictEqual(success, Result.ok(2));
|
|
598
|
-
* assert.ok(Result.isErr(failure));
|
|
599
|
-
* ```
|
|
600
|
-
*
|
|
601
|
-
* @template T The return type of the function.
|
|
602
|
-
* @param fn The function to execute that may throw.
|
|
603
|
-
* @returns A `Result<T, Error>` containing either the successful result or
|
|
604
|
-
* the caught error.
|
|
605
|
-
*/
|
|
606
|
-
export const fromThrowable: <T>(fn: () => T) => Result<T, Error>;
|
|
607
|
-
/**
|
|
608
|
-
* Swaps the success and error values of a `Result`.
|
|
609
|
-
*
|
|
610
|
-
* @example
|
|
611
|
-
*
|
|
612
|
-
* ```ts
|
|
613
|
-
* const okValue = Result.ok('value');
|
|
614
|
-
* const errValue = Result.err('error');
|
|
615
|
-
*
|
|
616
|
-
* assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));
|
|
617
|
-
* assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));
|
|
618
|
-
* ```
|
|
619
|
-
*
|
|
620
|
-
* @template R The input `Result.Base` type.
|
|
621
|
-
* @param result The `Result` to swap.
|
|
622
|
-
* @returns A new `Result` with success and error swapped.
|
|
623
|
-
*/
|
|
624
|
-
export const swap: <R extends Base>(result: R) => Result<UnwrapErr<R>, UnwrapOk<R>>;
|
|
625
|
-
/**
|
|
626
|
-
* Converts a `Result` to an `Optional`.
|
|
627
|
-
*
|
|
628
|
-
* This conversion is useful when you want to discard error information and
|
|
629
|
-
* only care about whether an operation succeeded. The error information is
|
|
630
|
-
* lost in this conversion, so use it when error details are not needed.
|
|
631
|
-
*
|
|
632
|
-
* If the `Result` is `Ok`, returns `Some` with the value. If the `Result` is
|
|
633
|
-
* `Err`, returns `None`.
|
|
634
|
-
*
|
|
635
|
-
* @example
|
|
636
|
-
*
|
|
637
|
-
* ```ts
|
|
638
|
-
* const okValue = Result.ok(7);
|
|
639
|
-
* const errValue = Result.err('fail');
|
|
640
|
-
*
|
|
641
|
-
* assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));
|
|
642
|
-
* assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);
|
|
643
|
-
* ```
|
|
644
|
-
*
|
|
645
|
-
* @template R The input `Result.Base` type.
|
|
646
|
-
* @param result The `Result` to convert.
|
|
647
|
-
* @returns An `Optional<UnwrapOk<R>>` containing the success value or
|
|
648
|
-
* representing `None`.
|
|
649
|
-
*/
|
|
650
|
-
export const toOptional: <R extends Base>(result: R) => Optional<UnwrapOk<R>>;
|
|
651
|
-
/**
|
|
652
|
-
* Returns the `Result` if it is `Ok`, otherwise returns the alternative.
|
|
653
|
-
*
|
|
654
|
-
* @example
|
|
655
|
-
*
|
|
656
|
-
* ```ts
|
|
657
|
-
* const primary = Result.ok('primary');
|
|
658
|
-
* const fallback = Result.ok('fallback');
|
|
659
|
-
* const failure = Result.err('failure');
|
|
660
|
-
*
|
|
661
|
-
* assert.deepStrictEqual(Result.orElse(primary, fallback), primary);
|
|
662
|
-
* assert.deepStrictEqual(Result.orElse(failure, fallback), fallback);
|
|
663
|
-
*
|
|
664
|
-
* const orElseFallback = Result.orElse(Result.ok('default'));
|
|
665
|
-
*
|
|
666
|
-
* assert.deepStrictEqual(
|
|
667
|
-
* orElseFallback(Result.err('missing')),
|
|
668
|
-
* Result.ok('default'),
|
|
669
|
-
* );
|
|
670
|
-
* assert.deepStrictEqual(orElseFallback(Result.ok('value')), Result.ok('value'));
|
|
671
|
-
* ```
|
|
672
|
-
*
|
|
673
|
-
* @template R The input `Result.Base` type.
|
|
674
|
-
* @param result The `Result` to check.
|
|
675
|
-
* @param alternative The alternative `Result` to return if the first is
|
|
676
|
-
* `Err`.
|
|
677
|
-
* @returns The first `Result` if `Ok`, otherwise the alternative.
|
|
678
|
-
*/
|
|
679
|
-
export function orElse<R extends Base, R2 extends Base>(result: R, alternative: R2): NarrowToOk<R> | R2;
|
|
680
|
-
export function orElse<S, E, S2, E2>(alternative: Result<S2, E2>): (result: Result<S, E>) => Result<S, E> | Result<S2, E2>;
|
|
681
|
-
/**
|
|
682
|
-
* Combines two `Result` values into a single `Result` containing a tuple. If
|
|
683
|
-
* either `Result` is `Err`, returns the first `Err` encountered.
|
|
684
|
-
*
|
|
685
|
-
* @example
|
|
686
|
-
*
|
|
687
|
-
* ```ts
|
|
688
|
-
* const first = Result.ok('left');
|
|
689
|
-
* const second = Result.ok(1);
|
|
690
|
-
*
|
|
691
|
-
* const expected: readonly [string, number] = ['left', 1];
|
|
692
|
-
*
|
|
693
|
-
* assert.deepStrictEqual(Result.zip(first, second), Result.ok(expected));
|
|
694
|
-
* assert.deepStrictEqual(
|
|
695
|
-
* Result.zip(first, Result.err('error')),
|
|
696
|
-
* Result.err('error'),
|
|
697
|
-
* );
|
|
698
|
-
* ```
|
|
699
|
-
*
|
|
700
|
-
* @template S1 The success type of the first `Result`.
|
|
701
|
-
* @template E1 The error type of the first `Result`.
|
|
702
|
-
* @template S2 The success type of the second `Result`.
|
|
703
|
-
* @template E2 The error type of the second `Result`.
|
|
704
|
-
* @param resultA The first `Result`.
|
|
705
|
-
* @param resultB The second `Result`.
|
|
706
|
-
* @returns A `Result` containing a tuple of both values, or the first `Err`.
|
|
707
|
-
*/
|
|
708
|
-
export const zip: <S1, E1, S2, E2>(resultA: Result<S1, E1>, resultB: Result<S2, E2>) => Result<readonly [S1, S2], E1 | E2>;
|
|
709
|
-
export {};
|
|
710
|
-
}
|
|
711
|
-
export {};
|
|
712
|
-
//# sourceMappingURL=result.d.mts.map
|