ts-data-forge 14.6.4 → 14.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +36 -6
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +26 -6
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/expect-type.d.mts +2 -70
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +1 -68
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/index.d.mts +11 -6
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +10 -6
- package/dist/functional/index.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +2 -51
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +1 -41
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts +2 -34
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +1 -34
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +2 -89
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -88
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +2 -42
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +1 -40
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/number/num.d.mts +9 -1
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -16
- package/dist/number/num.mjs.map +1 -1
- package/dist/others/index.d.mts +1 -0
- package/dist/others/index.d.mts.map +1 -1
- package/dist/others/index.mjs +1 -0
- package/dist/others/index.mjs.map +1 -1
- package/dist/others/panic-error.d.mts +9 -0
- package/dist/others/panic-error.d.mts.map +1 -0
- package/dist/others/panic-error.mjs +9 -0
- package/dist/others/panic-error.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +2 -37
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +1 -92
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/types.d.mts +1 -41
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +9 -9
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +36 -6
- package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +26 -6
- package/src/expect-type.mts +2 -78
- package/src/functional/index.mts +31 -6
- package/src/guard/has-key.mts +2 -72
- package/src/guard/is-non-null-object.mts +2 -36
- package/src/guard/is-record.mts +2 -95
- package/src/guard/key-is-in.mts +2 -49
- package/src/index.mts +2 -0
- package/src/number/num.mts +36 -28
- package/src/others/index.mts +1 -0
- package/src/others/panic-error.mts +8 -0
- package/src/others/unknown-to-string.mts +2 -111
- package/src/types.mts +4 -54
- package/dist/functional/async-result/async-result.d.mts +0 -16
- package/dist/functional/async-result/async-result.d.mts.map +0 -1
- package/dist/functional/async-result/async-result.mjs +0 -2
- package/dist/functional/async-result/async-result.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts +0 -39
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.mjs +0 -23
- package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts +0 -47
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.mjs +0 -10
- package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts +0 -53
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs +0 -15
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.d.mts +0 -35
- package/dist/functional/async-result/impl/async-result-map-err.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map-err.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.d.mts +0 -45
- package/dist/functional/async-result/impl/async-result-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts +0 -34
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +0 -37
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +0 -1
- package/dist/functional/async-result/impl/index.d.mts +0 -8
- package/dist/functional/async-result/impl/index.d.mts.map +0 -1
- package/dist/functional/async-result/impl/index.mjs +0 -8
- package/dist/functional/async-result/impl/index.mjs.map +0 -1
- package/dist/functional/async-result/impl/types.d.mts +0 -45
- package/dist/functional/async-result/impl/types.d.mts.map +0 -1
- package/dist/functional/async-result/impl/types.mjs +0 -2
- package/dist/functional/async-result/impl/types.mjs.map +0 -1
- package/dist/functional/async-result/index.d.mts +0 -2
- package/dist/functional/async-result/index.d.mts.map +0 -1
- package/dist/functional/async-result/index.mjs +0 -2
- package/dist/functional/async-result/index.mjs.map +0 -1
- package/dist/functional/match.d.mts +0 -80
- package/dist/functional/match.d.mts.map +0 -1
- package/dist/functional/match.mjs +0 -31
- package/dist/functional/match.mjs.map +0 -1
- package/dist/functional/optional/impl/index.d.mts +0 -19
- package/dist/functional/optional/impl/index.d.mts.map +0 -1
- package/dist/functional/optional/impl/index.mjs +0 -19
- package/dist/functional/optional/impl/index.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +0 -37
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +0 -22
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +0 -33
- package/dist/functional/optional/impl/optional-filter.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-filter.mjs +0 -25
- package/dist/functional/optional/impl/optional-filter.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +0 -39
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +0 -18
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +0 -27
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +0 -28
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +0 -23
- package/dist/functional/optional/impl/optional-is-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +0 -22
- package/dist/functional/optional/impl/optional-is-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +0 -21
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +0 -26
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +0 -24
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +0 -23
- package/dist/functional/optional/impl/optional-is-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-map.d.mts +0 -34
- package/dist/functional/optional/impl/optional-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-map.mjs +0 -22
- package/dist/functional/optional/impl/optional-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-match.d.mts +0 -48
- package/dist/functional/optional/impl/optional-match.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-match.mjs +0 -20
- package/dist/functional/optional/impl/optional-match.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-none.d.mts +0 -19
- package/dist/functional/optional/impl/optional-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-none.mjs +0 -19
- package/dist/functional/optional/impl/optional-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +0 -43
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +0 -16
- package/dist/functional/optional/impl/optional-or-else.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-some.d.mts +0 -22
- package/dist/functional/optional/impl/optional-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-some.mjs +0 -25
- package/dist/functional/optional/impl/optional-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +0 -37
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +0 -16
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +0 -31
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +0 -36
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +0 -32
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +0 -8
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +0 -35
- package/dist/functional/optional/impl/optional-zip.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-zip.mjs +0 -39
- package/dist/functional/optional/impl/optional-zip.mjs.map +0 -1
- package/dist/functional/optional/impl/tag.d.mts +0 -6
- package/dist/functional/optional/impl/tag.d.mts.map +0 -1
- package/dist/functional/optional/impl/tag.mjs +0 -4
- package/dist/functional/optional/impl/tag.mjs.map +0 -1
- package/dist/functional/optional/impl/types.d.mts +0 -24
- package/dist/functional/optional/impl/types.d.mts.map +0 -1
- package/dist/functional/optional/impl/types.mjs +0 -2
- package/dist/functional/optional/impl/types.mjs.map +0 -1
- package/dist/functional/optional/index.d.mts +0 -2
- package/dist/functional/optional/index.d.mts.map +0 -1
- package/dist/functional/optional/index.mjs +0 -2
- package/dist/functional/optional/index.mjs.map +0 -1
- package/dist/functional/optional/optional.d.mts +0 -16
- package/dist/functional/optional/optional.d.mts.map +0 -1
- package/dist/functional/optional/optional.mjs +0 -2
- package/dist/functional/optional/optional.mjs.map +0 -1
- package/dist/functional/pipe.d.mts +0 -102
- package/dist/functional/pipe.d.mts.map +0 -1
- package/dist/functional/pipe.mjs +0 -45
- package/dist/functional/pipe.mjs.map +0 -1
- package/dist/functional/result/impl/index.d.mts +0 -28
- package/dist/functional/result/impl/index.d.mts.map +0 -1
- package/dist/functional/result/impl/index.mjs +0 -28
- package/dist/functional/result/impl/index.mjs.map +0 -1
- package/dist/functional/result/impl/result-err.d.mts +0 -28
- package/dist/functional/result/impl/result-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-err.mjs +0 -31
- package/dist/functional/result/impl/result-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +0 -33
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +0 -23
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +0 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +0 -45
- package/dist/functional/result/impl/result-flat-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-flat-map.mjs +0 -21
- package/dist/functional/result/impl/result-flat-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-fold.d.mts +0 -50
- package/dist/functional/result/impl/result-fold.d.mts.map +0 -1
- package/dist/functional/result/impl/result-fold.mjs +0 -23
- package/dist/functional/result/impl/result-fold.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-optional.d.mts +0 -41
- package/dist/functional/result/impl/result-from-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-optional.mjs +0 -21
- package/dist/functional/result/impl/result-from-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +0 -43
- package/dist/functional/result/impl/result-from-promise.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-promise.mjs +0 -39
- package/dist/functional/result/impl/result-from-promise.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +0 -32
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +0 -46
- package/dist/functional/result/impl/result-from-throwable.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-err.d.mts +0 -23
- package/dist/functional/result/impl/result-is-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-err.mjs +0 -22
- package/dist/functional/result/impl/result-is-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +0 -23
- package/dist/functional/result/impl/result-is-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-ok.mjs +0 -22
- package/dist/functional/result/impl/result-is-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-result.d.mts +0 -22
- package/dist/functional/result/impl/result-is-result.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-result.mjs +0 -26
- package/dist/functional/result/impl/result-is-result.mjs.map +0 -1
- package/dist/functional/result/impl/result-map-err.d.mts +0 -39
- package/dist/functional/result/impl/result-map-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map-err.mjs +0 -22
- package/dist/functional/result/impl/result-map-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-map.d.mts +0 -39
- package/dist/functional/result/impl/result-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map.mjs +0 -22
- package/dist/functional/result/impl/result-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-match.d.mts +0 -47
- package/dist/functional/result/impl/result-match.d.mts.map +0 -1
- package/dist/functional/result/impl/result-match.mjs +0 -20
- package/dist/functional/result/impl/result-match.mjs.map +0 -1
- package/dist/functional/result/impl/result-ok.d.mts +0 -28
- package/dist/functional/result/impl/result-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-ok.mjs +0 -31
- package/dist/functional/result/impl/result-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-or-else.d.mts +0 -40
- package/dist/functional/result/impl/result-or-else.d.mts.map +0 -1
- package/dist/functional/result/impl/result-or-else.mjs +0 -17
- package/dist/functional/result/impl/result-or-else.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-try.d.mts +0 -51
- package/dist/functional/result/impl/result-safe-try.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-try.mjs +0 -35
- package/dist/functional/result/impl/result-safe-try.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.d.mts +0 -36
- package/dist/functional/result/impl/result-safe-unwrap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.mjs +0 -42
- package/dist/functional/result/impl/result-safe-unwrap.mjs.map +0 -1
- package/dist/functional/result/impl/result-swap.d.mts +0 -23
- package/dist/functional/result/impl/result-swap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-swap.mjs +0 -27
- package/dist/functional/result/impl/result-swap.mjs.map +0 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +0 -32
- package/dist/functional/result/impl/result-to-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-to-optional.mjs +0 -32
- package/dist/functional/result/impl/result-to-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +0 -46
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +0 -34
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +0 -26
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +0 -8
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +0 -40
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-zip.d.mts +0 -32
- package/dist/functional/result/impl/result-zip.d.mts.map +0 -1
- package/dist/functional/result/impl/result-zip.mjs +0 -37
- package/dist/functional/result/impl/result-zip.mjs.map +0 -1
- package/dist/functional/result/impl/tag.d.mts +0 -6
- package/dist/functional/result/impl/tag.d.mts.map +0 -1
- package/dist/functional/result/impl/tag.mjs +0 -4
- package/dist/functional/result/impl/tag.mjs.map +0 -1
- package/dist/functional/result/impl/types.d.mts +0 -31
- package/dist/functional/result/impl/types.d.mts.map +0 -1
- package/dist/functional/result/impl/types.mjs +0 -2
- package/dist/functional/result/impl/types.mjs.map +0 -1
- package/dist/functional/result/index.d.mts +0 -2
- package/dist/functional/result/index.d.mts.map +0 -1
- package/dist/functional/result/index.mjs +0 -2
- package/dist/functional/result/index.mjs.map +0 -1
- package/dist/functional/result/result.d.mts +0 -16
- package/dist/functional/result/result.d.mts.map +0 -1
- package/dist/functional/result/result.mjs +0 -2
- package/dist/functional/result/result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/index.d.mts +0 -29
- package/dist/functional/ternary-result/impl/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/index.mjs +0 -29
- package/dist/functional/ternary-result/impl/index.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/tag.d.mts +0 -8
- package/dist/functional/ternary-result/impl/tag.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/tag.mjs +0 -6
- package/dist/functional/ternary-result/impl/tag.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +0 -24
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +0 -39
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +0 -38
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +0 -27
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +0 -36
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +0 -32
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +0 -17
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +0 -29
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +0 -25
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +0 -10
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +0 -35
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +0 -52
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/types.d.mts +0 -26
- package/dist/functional/ternary-result/impl/types.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/types.mjs +0 -2
- package/dist/functional/ternary-result/impl/types.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts +0 -4
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +0 -13
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +0 -1
- package/dist/functional/ternary-result/index.d.mts +0 -2
- package/dist/functional/ternary-result/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/index.mjs +0 -2
- package/dist/functional/ternary-result/index.mjs.map +0 -1
- package/dist/functional/ternary-result/ternary-result.d.mts +0 -40
- package/dist/functional/ternary-result/ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/ternary-result.mjs +0 -2
- package/dist/functional/ternary-result/ternary-result.mjs.map +0 -1
- package/src/functional/async-result/async-result.mts +0 -17
- package/src/functional/async-result/impl/async-result-flat-map.mts +0 -99
- package/src/functional/async-result/impl/async-result-from-promise.mts +0 -69
- package/src/functional/async-result/impl/async-result-from-throwable.mts +0 -78
- package/src/functional/async-result/impl/async-result-map-err.mts +0 -84
- package/src/functional/async-result/impl/async-result-map.mts +0 -94
- package/src/functional/async-result/impl/async-result-unwrap-or.mts +0 -42
- package/src/functional/async-result/impl/index.mts +0 -7
- package/src/functional/async-result/impl/types.mts +0 -51
- package/src/functional/async-result/index.mts +0 -1
- package/src/functional/async-result.test.mts +0 -291
- package/src/functional/match.mts +0 -193
- package/src/functional/match.test.mts +0 -180
- package/src/functional/optional/impl/index.mts +0 -18
- package/src/functional/optional/impl/optional-expect-to-be.mts +0 -75
- package/src/functional/optional/impl/optional-filter.mts +0 -78
- package/src/functional/optional/impl/optional-flat-map.mts +0 -75
- package/src/functional/optional/impl/optional-from-nullable.mts +0 -31
- package/src/functional/optional/impl/optional-is-none.mts +0 -26
- package/src/functional/optional/impl/optional-is-optional.mts +0 -30
- package/src/functional/optional/impl/optional-is-some.mts +0 -27
- package/src/functional/optional/impl/optional-map.mts +0 -90
- package/src/functional/optional/impl/optional-match.mts +0 -108
- package/src/functional/optional/impl/optional-none.mts +0 -20
- package/src/functional/optional/impl/optional-or-else.mts +0 -83
- package/src/functional/optional/impl/optional-some.mts +0 -27
- package/src/functional/optional/impl/optional-to-nullable.mts +0 -34
- package/src/functional/optional/impl/optional-unwrap-or.mts +0 -70
- package/src/functional/optional/impl/optional-unwrap-throw.mts +0 -41
- package/src/functional/optional/impl/optional-unwrap.mts +0 -45
- package/src/functional/optional/impl/optional-zip.mts +0 -44
- package/src/functional/optional/impl/tag.mts +0 -8
- package/src/functional/optional/impl/types.mts +0 -31
- package/src/functional/optional/index.mts +0 -1
- package/src/functional/optional/optional.mts +0 -19
- package/src/functional/optional.test.mts +0 -883
- package/src/functional/pipe.mts +0 -180
- package/src/functional/pipe.test.mts +0 -155
- package/src/functional/result/impl/index.mts +0 -27
- package/src/functional/result/impl/result-err.mts +0 -33
- package/src/functional/result/impl/result-expect-to-be.mts +0 -73
- package/src/functional/result/impl/result-flat-map.mts +0 -88
- package/src/functional/result/impl/result-fold.mts +0 -102
- package/src/functional/result/impl/result-from-optional.mts +0 -80
- package/src/functional/result/impl/result-from-promise.mts +0 -51
- package/src/functional/result/impl/result-from-throwable.mts +0 -48
- package/src/functional/result/impl/result-is-err.mts +0 -26
- package/src/functional/result/impl/result-is-ok.mts +0 -26
- package/src/functional/result/impl/result-is-result.mts +0 -28
- package/src/functional/result/impl/result-map-err.mts +0 -96
- package/src/functional/result/impl/result-map.mts +0 -96
- package/src/functional/result/impl/result-match.mts +0 -108
- package/src/functional/result/impl/result-ok.mts +0 -33
- package/src/functional/result/impl/result-or-else.mts +0 -73
- package/src/functional/result/impl/result-safe-try.mts +0 -110
- package/src/functional/result/impl/result-safe-unwrap.mts +0 -50
- package/src/functional/result/impl/result-swap.mts +0 -31
- package/src/functional/result/impl/result-to-optional.mts +0 -37
- package/src/functional/result/impl/result-unwrap-err-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-err-throw.mts +0 -56
- package/src/functional/result/impl/result-unwrap-err.mts +0 -38
- package/src/functional/result/impl/result-unwrap-ok-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-ok.mts +0 -39
- package/src/functional/result/impl/result-unwrap-throw.mts +0 -46
- package/src/functional/result/impl/result-zip.mts +0 -42
- package/src/functional/result/impl/tag.mts +0 -8
- package/src/functional/result/impl/types.mts +0 -38
- package/src/functional/result/index.mts +0 -1
- package/src/functional/result/result.mts +0 -19
- package/src/functional/result.test.mts +0 -1349
- package/src/functional/ternary-result/impl/index.mts +0 -28
- package/src/functional/ternary-result/impl/tag.mts +0 -17
- package/src/functional/ternary-result/impl/ternary-result-err.mts +0 -21
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +0 -65
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +0 -112
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +0 -102
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +0 -30
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +0 -36
- package/src/functional/ternary-result/impl/ternary-result-is-err.mts +0 -24
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +0 -26
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +0 -32
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +0 -74
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +0 -79
- package/src/functional/ternary-result/impl/ternary-result-map.mts +0 -95
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +0 -22
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +0 -72
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +0 -31
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +0 -54
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +0 -42
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +0 -51
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +0 -39
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +0 -40
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +0 -28
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +0 -61
- package/src/functional/ternary-result/impl/types.mts +0 -46
- package/src/functional/ternary-result/impl/variant-name.mts +0 -18
- package/src/functional/ternary-result/index.mts +0 -1
- package/src/functional/ternary-result/ternary-result.mts +0 -50
- package/src/functional/ternary-result.test.mts +0 -310
- package/src/guard/has-key.test.mts +0 -111
- package/src/guard/is-non-null-object.test.mts +0 -109
- package/src/guard/is-record.test.mts +0 -195
- package/src/guard/key-is-in.test.mts +0 -21
- package/src/others/unknown-to-string.test.mts +0 -295
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { hasKey, isRecord } from '../../../guard/index.mjs';
|
|
2
|
-
import { type Err } from '../../../types.mjs';
|
|
3
|
-
import { type Result, type UnknownResult } from '../result.mjs';
|
|
4
|
-
import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Runs a generator body in which `yield* Result.safeUnwrap(...)` unwraps `Ok`
|
|
8
|
-
* values and short-circuits on the first `Err`, emulating Rust's `?` operator
|
|
9
|
-
* (early-return error propagation).
|
|
10
|
-
*
|
|
11
|
-
* The body must return a `Result`. If every unwrapped `Result` is `Ok`, the
|
|
12
|
-
* returned value is the body's `Result`; otherwise it is the first `Err`
|
|
13
|
-
* encountered, and the rest of the body never runs — though the generator is
|
|
14
|
-
* closed rather than dropped, so `finally` blocks and `using` disposals
|
|
15
|
-
* pending in the body still run. An exception thrown by the body is not
|
|
16
|
-
* converted to an `Err`: it propagates out of `safeTry` (as a rejected
|
|
17
|
-
* `Promise` for an async body). Use {@link Result.fromThrowable} for that.
|
|
18
|
-
*
|
|
19
|
-
* Passing an async generator (`async function*`) returns a
|
|
20
|
-
* `Promise<Result<...>>` instead, so `await` can be used inside the body.
|
|
21
|
-
* Note that `yield*` inside an `async function*` awaits what it receives, so
|
|
22
|
-
* unwrapping an `Ok` whose value is itself a `Promise` yields the awaited
|
|
23
|
-
* value there while the static type still says `Promise<...>`; keep promises
|
|
24
|
-
* out of the `Ok` side of a `Result` unwrapped in an async body.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
*
|
|
28
|
-
* ```ts
|
|
29
|
-
* const parseTwo = (a: string, b: string): Result<number, Error> =>
|
|
30
|
-
* Result.safeTry(function* () {
|
|
31
|
-
* const x = yield* Result.safeUnwrap(Num.safeParseInt(a));
|
|
32
|
-
*
|
|
33
|
-
* const y = yield* Result.safeUnwrap(Num.safeParseInt(b));
|
|
34
|
-
*
|
|
35
|
-
* return Result.ok(x + y);
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(parseTwo('1', '2'), Result.ok(3));
|
|
39
|
-
*
|
|
40
|
-
* assert.isTrue(Result.isErr(parseTwo('1', 'not a number')));
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @template Y The union of `Err` types unwrapped via
|
|
44
|
-
* {@link Result.safeUnwrap} (`never` if nothing is unwrapped).
|
|
45
|
-
* @template R2 The `Result` type returned by the body.
|
|
46
|
-
* @param body A generator function whose `yield*` expressions delegate to
|
|
47
|
-
* {@link Result.safeUnwrap} and whose return value is a `Result`.
|
|
48
|
-
* @returns The body's `Result`, or the first `Err` short-circuited out of it
|
|
49
|
-
* (wrapped in a `Promise` for an async generator body).
|
|
50
|
-
*/
|
|
51
|
-
export function safeTry<Y extends Err<unknown>, R2 extends UnknownResult>(
|
|
52
|
-
body: () => Generator<Y, R2>,
|
|
53
|
-
): Result<UnwrapOk<R2>, UnwrapErr<R2> | UnwrapErr<Y>>;
|
|
54
|
-
|
|
55
|
-
export function safeTry<Y extends Err<unknown>, R2 extends UnknownResult>(
|
|
56
|
-
body: () => AsyncGenerator<Y, R2>,
|
|
57
|
-
): Promise<Result<UnwrapOk<R2>, UnwrapErr<R2> | UnwrapErr<Y>>>;
|
|
58
|
-
|
|
59
|
-
export function safeTry(
|
|
60
|
-
body:
|
|
61
|
-
| (() => AsyncGenerator<UnknownResult, UnknownResult>)
|
|
62
|
-
| (() => Generator<UnknownResult, UnknownResult>),
|
|
63
|
-
): Promise<UnknownResult> | UnknownResult {
|
|
64
|
-
const generator = body();
|
|
65
|
-
|
|
66
|
-
// A yielded `Err` and a returned `Result` are both already the final
|
|
67
|
-
// answer, so the first step's `value` is the result in either case: the
|
|
68
|
-
// generator is closed rather than resumed after yielding.
|
|
69
|
-
const step = generator.next();
|
|
70
|
-
|
|
71
|
-
if (isSyncStep(step)) {
|
|
72
|
-
// Dropping a suspended generator would skip the `finally` blocks and
|
|
73
|
-
// `using` disposals still pending in the body; closing it runs them
|
|
74
|
-
// before the short-circuited `Err` is handed back. `isSyncGenerator` is
|
|
75
|
-
// what makes `return()` here synchronous rather than a floating promise.
|
|
76
|
-
if (step.done !== true && isSyncGenerator(generator, step)) {
|
|
77
|
-
generator.return(step.value);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return step.value;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return step.then(async (asyncStep) => {
|
|
84
|
-
if (asyncStep.done !== true) {
|
|
85
|
-
await generator.return(asyncStep.value);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return asyncStep.value;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// A sync generator's `next()` returns a plain `{ value, done }` object with
|
|
93
|
-
// own properties, while an async generator's returns a `Promise`, whose
|
|
94
|
-
// `then` lives on the prototype — so an own-key check on `done` separates the
|
|
95
|
-
// two.
|
|
96
|
-
const isSyncStep = (
|
|
97
|
-
value: unknown,
|
|
98
|
-
): value is IteratorResult<UnknownResult, UnknownResult> =>
|
|
99
|
-
isRecord(value) && hasKey(value, 'done');
|
|
100
|
-
|
|
101
|
-
// The generator-side counterpart of `isSyncStep`: a step in the sync form can
|
|
102
|
-
// only have come from a sync generator, so the step is what narrows the
|
|
103
|
-
// generator that produced it — hence the predicate reads its second argument
|
|
104
|
-
// and not its first.
|
|
105
|
-
const isSyncGenerator = (
|
|
106
|
-
_generator:
|
|
107
|
-
| AsyncGenerator<UnknownResult, UnknownResult>
|
|
108
|
-
| Generator<UnknownResult, UnknownResult>,
|
|
109
|
-
step: unknown,
|
|
110
|
-
): _generator is Generator<UnknownResult, UnknownResult> => isSyncStep(step);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type UnknownResult } from '../result.mjs';
|
|
2
|
-
import { isErr } from './result-is-err.mjs';
|
|
3
|
-
import { type NarrowToErr, type UnwrapOk } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps a `Result` inside a {@link Result.safeTry} generator body via
|
|
7
|
-
* `yield*`, emulating Rust's `?` operator.
|
|
8
|
-
*
|
|
9
|
-
* If the `Result` is `Ok`, the `yield*` expression evaluates to the contained
|
|
10
|
-
* value and execution continues. If it is `Err`, the error is yielded to
|
|
11
|
-
* {@link Result.safeTry}, which returns it immediately — the rest of the
|
|
12
|
-
* generator body never runs.
|
|
13
|
-
*
|
|
14
|
-
* This generator must only be delegated to (`yield*`) inside a
|
|
15
|
-
* {@link Result.safeTry} body; resuming it after it has yielded an `Err`
|
|
16
|
-
* throws.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* const result = Result.safeTry(function* () {
|
|
22
|
-
* const x = yield* Result.safeUnwrap(Result.ok(2));
|
|
23
|
-
*
|
|
24
|
-
* const y = yield* Result.safeUnwrap(Result.ok(3));
|
|
25
|
-
*
|
|
26
|
-
* return Result.ok(x + y);
|
|
27
|
-
* });
|
|
28
|
-
*
|
|
29
|
-
* assert.deepStrictEqual(result, Result.ok(5));
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @template R The input `UnknownResult` type.
|
|
33
|
-
* @param result The `Result` to unwrap.
|
|
34
|
-
* @returns A generator that yields the `Err` (if any) and returns the `Ok`
|
|
35
|
-
* value.
|
|
36
|
-
*/
|
|
37
|
-
export function* safeUnwrap<R extends UnknownResult>(
|
|
38
|
-
result: R,
|
|
39
|
-
): Generator<NarrowToErr<R>, UnwrapOk<R>, unknown> {
|
|
40
|
-
if (isErr(result)) {
|
|
41
|
-
yield result;
|
|
42
|
-
|
|
43
|
-
throw new Error(
|
|
44
|
-
'`safeUnwrap()` generator was resumed after yielding an `Err`; it must only be used via `yield*` inside `safeTry()`',
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
49
|
-
return result.value as UnwrapOk<R>;
|
|
50
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type Result, type UnknownResult } from '../result.mjs';
|
|
2
|
-
import { err } from './result-err.mjs';
|
|
3
|
-
import { isOk } from './result-is-ok.mjs';
|
|
4
|
-
import { ok } from './result-ok.mjs';
|
|
5
|
-
import { unwrapOk } from './result-unwrap-ok.mjs';
|
|
6
|
-
import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Swaps the success and error values of a `Result`.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* const okValue = Result.ok('value');
|
|
15
|
-
*
|
|
16
|
-
* const errValue = Result.err('error');
|
|
17
|
-
*
|
|
18
|
-
* assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));
|
|
19
|
-
*
|
|
20
|
-
* assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @template R The input `UnknownResult` type.
|
|
24
|
-
* @param result The `Result` to swap.
|
|
25
|
-
* @returns A new `Result` with success and error swapped.
|
|
26
|
-
*/
|
|
27
|
-
export const swap = <R extends UnknownResult>(
|
|
28
|
-
result: R,
|
|
29
|
-
): Result<UnwrapErr<R>, UnwrapOk<R>> =>
|
|
30
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
31
|
-
isOk(result) ? err(unwrapOk(result)) : ok(result.value as UnwrapErr<R>);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Optional } from '../../optional/index.mjs';
|
|
2
|
-
import { type UnknownResult } from '../result.mjs';
|
|
3
|
-
import { isOk } from './result-is-ok.mjs';
|
|
4
|
-
import { unwrapOk } from './result-unwrap-ok.mjs';
|
|
5
|
-
import { type UnwrapOk } from './types.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Converts a `Result` to an `Optional`.
|
|
9
|
-
*
|
|
10
|
-
* This conversion is useful when you want to discard error information and
|
|
11
|
-
* only care about whether an operation succeeded. The error information is
|
|
12
|
-
* lost in this conversion, so use it when error details are not needed.
|
|
13
|
-
*
|
|
14
|
-
* If the `Result` is `Ok`, returns `Some` with the value. If the `Result` is
|
|
15
|
-
* `Err`, returns `None`.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* const okValue = Result.ok(7);
|
|
21
|
-
*
|
|
22
|
-
* const errValue = Result.err('fail');
|
|
23
|
-
*
|
|
24
|
-
* assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));
|
|
25
|
-
*
|
|
26
|
-
* assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @template R The input `UnknownResult` type.
|
|
30
|
-
* @param result The `Result` to convert.
|
|
31
|
-
* @returns An `Optional<UnwrapOk<R>>` containing the success value or
|
|
32
|
-
* representing `None`.
|
|
33
|
-
*/
|
|
34
|
-
export const toOptional = <R extends UnknownResult>(
|
|
35
|
-
result: R,
|
|
36
|
-
): Optional<UnwrapOk<R>> =>
|
|
37
|
-
isOk(result) ? Optional.some(unwrapOk(result)) : Optional.none;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type UnknownResult } from '../result.mjs';
|
|
2
|
-
import { unwrapErr } from './result-unwrap-err.mjs';
|
|
3
|
-
import { type UnwrapErr } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps a `Result`, returning the error value or a default value if it is
|
|
7
|
-
* `Result.Ok`.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const okResult = Result.ok('success');
|
|
13
|
-
*
|
|
14
|
-
* const errResult = Result.err('failure');
|
|
15
|
-
*
|
|
16
|
-
* assert.isTrue(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
17
|
-
*
|
|
18
|
-
* assert.isTrue(Result.unwrapErrOr(errResult, 'default') === 'failure');
|
|
19
|
-
*
|
|
20
|
-
* const unwrapError = Result.unwrapErrOr('fallback error');
|
|
21
|
-
*
|
|
22
|
-
* assert.isTrue(unwrapError(Result.err('boom')) === 'boom');
|
|
23
|
-
*
|
|
24
|
-
* assert.isTrue(unwrapError(Result.ok('no error')) === 'fallback error');
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
28
|
-
* @template D The type of the default value.
|
|
29
|
-
* @param result The `Result` to unwrap.
|
|
30
|
-
* @param defaultValue The value to return if `result` is `Result.Ok`.
|
|
31
|
-
* @returns The error value if `Result.Err`, otherwise `defaultValue`.
|
|
32
|
-
*/
|
|
33
|
-
export function unwrapErrOr<R extends UnknownResult, D>(
|
|
34
|
-
result: R,
|
|
35
|
-
defaultValue: D,
|
|
36
|
-
): D | UnwrapErr<R>;
|
|
37
|
-
|
|
38
|
-
// Curried version
|
|
39
|
-
export function unwrapErrOr<D>(
|
|
40
|
-
defaultValue: D,
|
|
41
|
-
): <R extends UnknownResult>(result: R) => D | UnwrapErr<R>;
|
|
42
|
-
|
|
43
|
-
export function unwrapErrOr<R extends UnknownResult, D>(
|
|
44
|
-
...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]
|
|
45
|
-
): D | UnwrapErr<R> | ((result: R) => D | UnwrapErr<R>) {
|
|
46
|
-
switch (args.length) {
|
|
47
|
-
case 2: {
|
|
48
|
-
// Direct version: first argument is result
|
|
49
|
-
const [result, defaultValue] = args;
|
|
50
|
-
|
|
51
|
-
return unwrapErrOrImpl(result, defaultValue);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
case 1: {
|
|
55
|
-
// Curried version
|
|
56
|
-
const [defaultValue] = args;
|
|
57
|
-
|
|
58
|
-
return (result: R) => unwrapErrOrImpl(result, defaultValue);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const unwrapErrOrImpl = <R extends UnknownResult, D>(
|
|
64
|
-
result: R,
|
|
65
|
-
defaultValue: D,
|
|
66
|
-
): D | UnwrapErr<R> => unwrapErr(result) ?? defaultValue;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { unknownToString } from '../../../others/index.mjs';
|
|
2
|
-
import { match } from '../../match.mjs';
|
|
3
|
-
import { type UnknownResult } from '../result.mjs';
|
|
4
|
-
import { isErr } from './result-is-err.mjs';
|
|
5
|
-
import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Unwraps a `Result`, returning the error value. Throws an error if the
|
|
9
|
-
* `Result` is `Result.Ok`.
|
|
10
|
-
*
|
|
11
|
-
* This function is used when you expect a Result to be an error and want to
|
|
12
|
-
* extract the error value. If the Result is unexpectedly Ok, it will throw an
|
|
13
|
-
* error with information about the unexpected success value.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const errResult = Result.err(new Error('broken'));
|
|
19
|
-
*
|
|
20
|
-
* const okResult = Result.ok('value');
|
|
21
|
-
*
|
|
22
|
-
* assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
23
|
-
*
|
|
24
|
-
* assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
28
|
-
* @param result The `Result` to unwrap.
|
|
29
|
-
* @param toStr An optional function to convert the success value to a string
|
|
30
|
-
* for the error message when the Result is unexpectedly Ok. Defaults to
|
|
31
|
-
* `String`.
|
|
32
|
-
* @returns The error value if `Result.Err`.
|
|
33
|
-
* @throws {Error} Error with message "Expected Err but got Ok: {value}" if
|
|
34
|
-
* the `Result` is `Result.Ok`.
|
|
35
|
-
*/
|
|
36
|
-
export const unwrapErrThrow = <R extends UnknownResult>(
|
|
37
|
-
result: R,
|
|
38
|
-
toStr: (v: UnwrapOk<R>) => string = unknownToString,
|
|
39
|
-
): UnwrapErr<R> => {
|
|
40
|
-
if (isErr(result)) {
|
|
41
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
42
|
-
return result.value as UnwrapErr<R>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const variant = match(result.$$tag, {
|
|
46
|
-
'ts-data-forge::Result.ok': 'Ok',
|
|
47
|
-
'ts-data-forge::Result.err': 'Err',
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Expected Err but got ${variant}: ${toStr(
|
|
52
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
53
|
-
result.value as UnwrapOk<R>,
|
|
54
|
-
)}`,
|
|
55
|
-
);
|
|
56
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { type UnknownResult } from '../result.mjs';
|
|
2
|
-
import { isErr } from './result-is-err.mjs';
|
|
3
|
-
import { type UnwrapErr } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps a `Result`, returning the error value or `undefined` if it is
|
|
7
|
-
* `Result.Ok`.
|
|
8
|
-
*
|
|
9
|
-
* This provides a safe way to extract error values from Results without
|
|
10
|
-
* throwing exceptions. Useful for error handling patterns where you want to
|
|
11
|
-
* check for specific error conditions.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const okResult = Result.ok('data');
|
|
17
|
-
*
|
|
18
|
-
* const errResult = Result.err('problem');
|
|
19
|
-
*
|
|
20
|
-
* // Result.unwrapErr returns undefined for Ok results
|
|
21
|
-
*
|
|
22
|
-
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
23
|
-
* assert.isTrue(Result.unwrapErr(okResult) === undefined);
|
|
24
|
-
*
|
|
25
|
-
* // Result.unwrapErr returns the error value for Err results
|
|
26
|
-
*
|
|
27
|
-
* assert.isTrue(Result.unwrapErr(errResult) === 'problem');
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
31
|
-
* @param result The `Result` to unwrap.
|
|
32
|
-
* @returns The error value if `Result.Err`, otherwise `undefined`.
|
|
33
|
-
*/
|
|
34
|
-
export const unwrapErr = <R extends UnknownResult>(
|
|
35
|
-
result: R,
|
|
36
|
-
): UnwrapErr<R> | undefined =>
|
|
37
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
38
|
-
isErr(result) ? (result.value as UnwrapErr<R>) : undefined;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type UnknownResult } from '../result.mjs';
|
|
2
|
-
import { unwrapOk } from './result-unwrap-ok.mjs';
|
|
3
|
-
import { type UnwrapOk } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps a `Result`, returning the success value or a default value if it is
|
|
7
|
-
* `Result.Err`.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const okValue = Result.ok(10);
|
|
13
|
-
*
|
|
14
|
-
* const errValue = Result.err('fail');
|
|
15
|
-
*
|
|
16
|
-
* assert.isTrue(Result.unwrapOkOr(okValue, 0) === 10);
|
|
17
|
-
*
|
|
18
|
-
* assert.isTrue(Result.unwrapOkOr(errValue, 0) === 0);
|
|
19
|
-
*
|
|
20
|
-
* const unwrapWithDefault = Result.unwrapOkOr(5);
|
|
21
|
-
*
|
|
22
|
-
* assert.isTrue(unwrapWithDefault(Result.ok(3)) === 3);
|
|
23
|
-
*
|
|
24
|
-
* assert.isTrue(unwrapWithDefault(Result.err('no data')) === 5);
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
28
|
-
* @template D The type of the default value.
|
|
29
|
-
* @param result The `Result` to unwrap.
|
|
30
|
-
* @param defaultValue The value to return if `result` is `Result.Err`.
|
|
31
|
-
* @returns The success value if `Result.Ok`, otherwise `defaultValue`.
|
|
32
|
-
*/
|
|
33
|
-
export function unwrapOkOr<R extends UnknownResult, D>(
|
|
34
|
-
result: R,
|
|
35
|
-
defaultValue: D,
|
|
36
|
-
): D | UnwrapOk<R>;
|
|
37
|
-
|
|
38
|
-
// Curried version
|
|
39
|
-
export function unwrapOkOr<D>(
|
|
40
|
-
defaultValue: D,
|
|
41
|
-
): <R extends UnknownResult>(result: R) => D | UnwrapOk<R>;
|
|
42
|
-
|
|
43
|
-
export function unwrapOkOr<R extends UnknownResult, D>(
|
|
44
|
-
...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]
|
|
45
|
-
): D | UnwrapOk<R> | ((result: R) => D | UnwrapOk<R>) {
|
|
46
|
-
switch (args.length) {
|
|
47
|
-
case 2: {
|
|
48
|
-
// Direct version: first argument is result
|
|
49
|
-
const [result, defaultValue] = args;
|
|
50
|
-
|
|
51
|
-
return unwrapOkOrImpl(result, defaultValue);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
case 1: {
|
|
55
|
-
// Curried version
|
|
56
|
-
const [defaultValue] = args;
|
|
57
|
-
|
|
58
|
-
return (result: R) => unwrapOkOrImpl(result, defaultValue);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const unwrapOkOrImpl = <R extends UnknownResult, D>(
|
|
64
|
-
result: R,
|
|
65
|
-
defaultValue: D,
|
|
66
|
-
): D | UnwrapOk<R> => unwrapOk(result) ?? defaultValue;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Ok } from '../../../types.mjs';
|
|
2
|
-
import { type UnknownResult } from '../result.mjs';
|
|
3
|
-
import { isOk } from './result-is-ok.mjs';
|
|
4
|
-
import { type UnwrapOk } from './types.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Safely unwraps the success value, returning `undefined` for failures.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const okResult = Result.ok(42);
|
|
13
|
-
*
|
|
14
|
-
* const errResult = Result.err('oops');
|
|
15
|
-
*
|
|
16
|
-
* // Result.unwrapOk returns the value for Ok results
|
|
17
|
-
*
|
|
18
|
-
* assert.isTrue(Result.unwrapOk(okResult) === 42);
|
|
19
|
-
*
|
|
20
|
-
* // Result.unwrapOk returns undefined for Err results
|
|
21
|
-
*
|
|
22
|
-
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
23
|
-
* assert.isTrue(Result.unwrapOk(errResult) === undefined);
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export function unwrapOk<R extends Ok<unknown>>(result: R): UnwrapOk<R>;
|
|
27
|
-
|
|
28
|
-
export function unwrapOk<R extends UnknownResult>(
|
|
29
|
-
result: R,
|
|
30
|
-
): UnwrapOk<R> | undefined;
|
|
31
|
-
|
|
32
|
-
export function unwrapOk<R extends UnknownResult>(
|
|
33
|
-
result: R,
|
|
34
|
-
): UnwrapOk<R> | undefined {
|
|
35
|
-
return isOk(result)
|
|
36
|
-
? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
37
|
-
(result.value as UnwrapOk<R>)
|
|
38
|
-
: undefined;
|
|
39
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { unknownToString } from '../../../others/index.mjs';
|
|
2
|
-
import { type UnknownResult } from '../result.mjs';
|
|
3
|
-
import { isErr } from './result-is-err.mjs';
|
|
4
|
-
import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Unwraps a `Result`, returning the success value. Throws an error if the
|
|
8
|
-
* `Result` is `Result.Err`.
|
|
9
|
-
*
|
|
10
|
-
* This is useful when you're confident that a Result should contain a success
|
|
11
|
-
* value and want to treat errors as exceptional conditions. The error message
|
|
12
|
-
* will be constructed from the error value using the provided string
|
|
13
|
-
* conversion function.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const okResult = Result.ok('data');
|
|
19
|
-
*
|
|
20
|
-
* const errResult = Result.err(new Error('fail'));
|
|
21
|
-
*
|
|
22
|
-
* assert.isTrue(Result.unwrapThrow(okResult) === 'data');
|
|
23
|
-
*
|
|
24
|
-
* assert.throws(() => Result.unwrapThrow(errResult), Error, 'fail');
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
28
|
-
* @param result The `Result` to unwrap.
|
|
29
|
-
* @param toStr An optional function to convert the error value to a string
|
|
30
|
-
* for the error message. Defaults to `String`.
|
|
31
|
-
* @returns The success value if `Result.Ok`.
|
|
32
|
-
* @throws {Error} Error with the stringified error value if the `Result` is
|
|
33
|
-
* `Result.Err`.
|
|
34
|
-
*/
|
|
35
|
-
export const unwrapThrow = <R extends UnknownResult>(
|
|
36
|
-
result: R,
|
|
37
|
-
toStr: (e: UnwrapErr<R>) => string = unknownToString,
|
|
38
|
-
): UnwrapOk<R> => {
|
|
39
|
-
if (isErr(result)) {
|
|
40
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
41
|
-
throw new Error(toStr(result.value as UnwrapErr<R>));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
45
|
-
return result.value as UnwrapOk<R>;
|
|
46
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { type Result } from '../result.mjs';
|
|
2
|
-
import { isOk } from './result-is-ok.mjs';
|
|
3
|
-
import { ok } from './result-ok.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Combines two `Result` values into a single `Result` containing a tuple. If
|
|
7
|
-
* either `Result` is `Err`, returns the first `Err` encountered.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const first = Result.ok('left');
|
|
13
|
-
*
|
|
14
|
-
* const second = Result.ok(1);
|
|
15
|
-
*
|
|
16
|
-
* const expected = ['left', 1] as const;
|
|
17
|
-
*
|
|
18
|
-
* assert.deepStrictEqual(Result.zip(first, second), Result.ok(expected));
|
|
19
|
-
*
|
|
20
|
-
* assert.deepStrictEqual(
|
|
21
|
-
* Result.zip(first, Result.err('error')),
|
|
22
|
-
* Result.err('error'),
|
|
23
|
-
* );
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @template S1 The success type of the first `Result`.
|
|
27
|
-
* @template E1 The error type of the first `Result`.
|
|
28
|
-
* @template S2 The success type of the second `Result`.
|
|
29
|
-
* @template E2 The error type of the second `Result`.
|
|
30
|
-
* @param resultA The first `Result`.
|
|
31
|
-
* @param resultB The second `Result`.
|
|
32
|
-
* @returns A `Result` containing a tuple of both values, or the first `Err`.
|
|
33
|
-
*/
|
|
34
|
-
export const zip = <S1, E1, S2, E2>(
|
|
35
|
-
resultA: Result<S1, E1>,
|
|
36
|
-
resultB: Result<S2, E2>,
|
|
37
|
-
): Result<readonly [S1, S2], E1 | E2> =>
|
|
38
|
-
isOk(resultA)
|
|
39
|
-
? isOk(resultB)
|
|
40
|
-
? ok([resultA.value, resultB.value] as const)
|
|
41
|
-
: resultB
|
|
42
|
-
: resultA;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** @internal Tag identifying the Ok variant. */
|
|
2
|
-
import { type Err, type Ok } from '../../../types.mjs';
|
|
3
|
-
|
|
4
|
-
export const OkTypeTagName: Ok<unknown>['$$tag'] = 'ts-data-forge::Result.ok';
|
|
5
|
-
|
|
6
|
-
/** @internal Tag identifying the Err variant. */
|
|
7
|
-
export const ErrTypeTagName: Err<unknown>['$$tag'] =
|
|
8
|
-
'ts-data-forge::Result.err';
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { type Err, type Ok } from '../../../types.mjs';
|
|
2
|
-
import { type UnknownResult } from '../result.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Extracts the success value type `S` from a `Result.Ok<S>`. If the `Result`
|
|
6
|
-
* is `Result.Err<E>`, resolves to `never`.
|
|
7
|
-
*
|
|
8
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
9
|
-
*/
|
|
10
|
-
export type UnwrapOk<R extends UnknownResult> =
|
|
11
|
-
R extends Ok<infer S> ? S : never;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Extracts the error value type `E` from a `Result.Err<E>`. If the `Result`
|
|
15
|
-
* is `Result.Ok<S>`, resolves to `never`.
|
|
16
|
-
*
|
|
17
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
18
|
-
*/
|
|
19
|
-
export type UnwrapErr<R extends UnknownResult> =
|
|
20
|
-
R extends Err<infer E> ? E : never;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Narrows a `UnknownResult` type to `Result.Ok<S>` if it is an `Ok`. If the
|
|
24
|
-
* `Result` is `Result.Err<E>`, resolves to `never`.
|
|
25
|
-
*
|
|
26
|
-
* @template R The `UnknownResult` type to narrow.
|
|
27
|
-
*/
|
|
28
|
-
export type NarrowToOk<R extends UnknownResult> =
|
|
29
|
-
R extends Ok<unknown> ? R : never;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Narrows a `UnknownResult` type to `Result.Err<E>` if it is an `Err`. If the
|
|
33
|
-
* `Result` is `Result.Ok<S>`, resolves to `never`.
|
|
34
|
-
*
|
|
35
|
-
* @template R The `UnknownResult` type to narrow.
|
|
36
|
-
*/
|
|
37
|
-
export type NarrowToErr<R extends UnknownResult> =
|
|
38
|
-
R extends Err<unknown> ? R : never;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './result.mjs';
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type Err, type Ok } from '../../types.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a value that can either be a success (`Ok`) or an error (`Err`).
|
|
5
|
-
*
|
|
6
|
-
* @template S The type of the success value.
|
|
7
|
-
* @template E The type of the error value.
|
|
8
|
-
*/
|
|
9
|
-
export type Result<S, E> = Ok<S> | Err<E>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Base type for any `Result`, used for generic constraints. Represents a
|
|
13
|
-
* `Result` with unknown success and error types.
|
|
14
|
-
*/
|
|
15
|
-
export type UnknownResult = Ok<unknown> | Err<unknown>;
|
|
16
|
-
|
|
17
|
-
export type { Err, Ok } from '../../types.mjs';
|
|
18
|
-
|
|
19
|
-
export * as Result from './impl/index.mjs';
|