ts-data-forge 14.6.3 → 14.7.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/README.md +2 -1
- package/dist/array/impl/array-utils-modification.mjs +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +2 -2
- 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/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 +6 -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/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,34 +0,0 @@
|
|
|
1
|
-
import { type TernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* Combines two `TernaryResult`s, prioritising Err over Warn over Ok.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* const okPair = TernaryResult.zip(
|
|
9
|
-
* TernaryResult.ok('left'),
|
|
10
|
-
* TernaryResult.ok(1),
|
|
11
|
-
* );
|
|
12
|
-
*
|
|
13
|
-
* const warnPair = TernaryResult.zip(
|
|
14
|
-
* TernaryResult.warn('left', 'warn'),
|
|
15
|
-
* TernaryResult.ok(1),
|
|
16
|
-
* );
|
|
17
|
-
*
|
|
18
|
-
* const errPair = TernaryResult.zip(
|
|
19
|
-
* TernaryResult.ok('left'),
|
|
20
|
-
* TernaryResult.err('err'),
|
|
21
|
-
* );
|
|
22
|
-
*
|
|
23
|
-
* assert.deepStrictEqual(okPair, TernaryResult.ok(['left', 1] as const));
|
|
24
|
-
*
|
|
25
|
-
* assert.deepStrictEqual(
|
|
26
|
-
* warnPair,
|
|
27
|
-
* TernaryResult.warn(['left', 1] as const, 'warn'),
|
|
28
|
-
* );
|
|
29
|
-
*
|
|
30
|
-
* assert.deepStrictEqual(errPair, TernaryResult.err('err'));
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare const zip: <S1, W1, E1, S2, W2, E2>(resultA: TernaryResult<S1, E1, W1>, resultB: TernaryResult<S2, E2, W2>) => TernaryResult<readonly [S1, S2], E1 | E2, W1 | W2>;
|
|
34
|
-
//# sourceMappingURL=ternary-result-zip.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result-zip.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-zip.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAM3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,GAAG,GAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,WAC/B,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,WACzB,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,KACjC,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAoBnD,CAAC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { isErr } from './ternary-result-is-err.mjs';
|
|
2
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
3
|
-
import { ok } from './ternary-result-ok.mjs';
|
|
4
|
-
import { warn } from './ternary-result-warn.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export const zip = (resultA, resultB) => {
|
|
37
|
-
if (isErr(resultA)) {
|
|
38
|
-
return resultA;
|
|
39
|
-
}
|
|
40
|
-
if (isErr(resultB)) {
|
|
41
|
-
return resultB;
|
|
42
|
-
}
|
|
43
|
-
const pair = [resultA.value, resultB.value];
|
|
44
|
-
if (isWarn(resultA)) {
|
|
45
|
-
return warn(pair, resultA.warning);
|
|
46
|
-
}
|
|
47
|
-
if (isWarn(resultB)) {
|
|
48
|
-
return warn(pair, resultB.warning);
|
|
49
|
-
}
|
|
50
|
-
return ok(pair);
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=ternary-result-zip.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result-zip.mjs","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-zip.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,OAAkC,EAClC,OAAkC,EACkB,EAAE;IACtD,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAU,CAAC;IAErD,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type TernaryErr, type TernaryOk, type TernaryWarn, type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* Extracts the success value type `S` from a `TernaryResult.Ok<S>`.
|
|
4
|
-
*/
|
|
5
|
-
export type UnwrapOk<R extends UnknownTernaryResult> = R extends TernaryOk<infer S> ? S : R extends TernaryWarn<infer S, unknown> ? S : never;
|
|
6
|
-
/**
|
|
7
|
-
* Extracts the warning value type `W` from a `TernaryResult.Warn<W>`.
|
|
8
|
-
*/
|
|
9
|
-
export type UnwrapWarn<R extends UnknownTernaryResult> = R extends TernaryWarn<unknown, infer E> ? E : never;
|
|
10
|
-
/**
|
|
11
|
-
* Extracts the error value type `E` from a `TernaryResult.Err<E>`.
|
|
12
|
-
*/
|
|
13
|
-
export type UnwrapErr<R extends UnknownTernaryResult> = R extends TernaryErr<infer E> ? E : never;
|
|
14
|
-
/**
|
|
15
|
-
* Narrows the provided `UnknownTernaryResult` to its Ok variant.
|
|
16
|
-
*/
|
|
17
|
-
export type NarrowToOk<R extends UnknownTernaryResult> = R extends TernaryOk<unknown> ? R : never;
|
|
18
|
-
/**
|
|
19
|
-
* Narrows the provided `UnknownTernaryResult` to its Warn variant.
|
|
20
|
-
*/
|
|
21
|
-
export type NarrowToWarn<R extends UnknownTernaryResult> = R extends TernaryWarn<unknown, unknown> ? R : never;
|
|
22
|
-
/**
|
|
23
|
-
* Narrows the provided `UnknownTernaryResult` to its Err variant.
|
|
24
|
-
*/
|
|
25
|
-
export type NarrowToErr<R extends UnknownTernaryResult> = R extends TernaryErr<unknown> ? R : never;
|
|
26
|
-
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/types.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,oBAAoB,IACjD,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,GACxB,CAAC,GACD,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GACrC,CAAC,GACD,KAAK,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,oBAAoB,IACnD,CAAC,SAAS,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,oBAAoB,IAClD,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,oBAAoB,IACnD,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,oBAAoB,IACrD,CAAC,SAAS,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,oBAAoB,IACpD,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/types.mts"],"names":[],"mappings":""}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
/** @internal Returns the human readable variant label for the given tag. */
|
|
3
|
-
export declare const variantName: (tag: UnknownTernaryResult['$$tag']) => 'Ok' | 'Warn' | 'Err';
|
|
4
|
-
//# sourceMappingURL=variant-name.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"variant-name.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/variant-name.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAGlE,4EAA4E;AAC5E,eAAO,MAAM,WAAW,QACjB,oBAAoB,CAAC,OAAO,CAAC,KACjC,IAAI,GAAG,MAAM,GAAG,KAWlB,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ErrTypeTagName, OkTypeTagName, WarnTypeTagName } from './tag.mjs';
|
|
2
|
-
|
|
3
|
-
export const variantName = (tag) => {
|
|
4
|
-
switch (tag) {
|
|
5
|
-
case OkTypeTagName:
|
|
6
|
-
return 'Ok';
|
|
7
|
-
case WarnTypeTagName:
|
|
8
|
-
return 'Warn';
|
|
9
|
-
case ErrTypeTagName:
|
|
10
|
-
return 'Err';
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=variant-name.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"variant-name.mjs","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/variant-name.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE3E,4EAA4E;AAC5E,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAkC,EACX,EAAE;IACzB,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,aAAa;YAChB,OAAO,IAAI,CAAC;QAEd,KAAK,eAAe;YAClB,OAAO,MAAM,CAAC;QAEhB,KAAK,cAAc;YACjB,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/functional/ternary-result/index.mts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/functional/ternary-result/index.mts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a `TernaryResult` that is a success, containing a value.
|
|
3
|
-
*/
|
|
4
|
-
export type TernaryOk<S> = Readonly<{
|
|
5
|
-
/** @internal Discriminant property for the 'Ok' type. */
|
|
6
|
-
$$tag: 'ts-data-forge::Result.ok';
|
|
7
|
-
/** The success value. */
|
|
8
|
-
value: S;
|
|
9
|
-
}>;
|
|
10
|
-
/**
|
|
11
|
-
* Represents a `TernaryResult` that contains a success value and an attached
|
|
12
|
-
* warning.
|
|
13
|
-
*/
|
|
14
|
-
export type TernaryWarn<S, W> = Readonly<{
|
|
15
|
-
/** @internal Discriminant property for the 'Warn' type. */
|
|
16
|
-
$$tag: 'ts-data-forge::Result.warn';
|
|
17
|
-
/** The success value. */
|
|
18
|
-
value: S;
|
|
19
|
-
/** The warning value. */
|
|
20
|
-
warning: W;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Represents a `TernaryResult` that is an error, containing an error value.
|
|
24
|
-
*/
|
|
25
|
-
export type TernaryErr<E> = Readonly<{
|
|
26
|
-
/** @internal Discriminant property for the 'Err' type. */
|
|
27
|
-
$$tag: 'ts-data-forge::Result.err';
|
|
28
|
-
/** The error value. */
|
|
29
|
-
value: E;
|
|
30
|
-
}>;
|
|
31
|
-
/**
|
|
32
|
-
* Represents a value that can be `Ok`, `Warn`, or `Err`.
|
|
33
|
-
*/
|
|
34
|
-
export type TernaryResult<S, E, W = E> = TernaryOk<S> | TernaryWarn<S, W> | TernaryErr<E>;
|
|
35
|
-
/**
|
|
36
|
-
* Base type for any `TernaryResult`, used for generic constraints.
|
|
37
|
-
*/
|
|
38
|
-
export type UnknownTernaryResult = TernaryOk<unknown> | TernaryWarn<unknown, unknown> | TernaryErr<unknown>;
|
|
39
|
-
export * as TernaryResult from './impl/index.mjs';
|
|
40
|
-
//# sourceMappingURL=ternary-result.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result.d.mts","sourceRoot":"","sources":["../../../src/functional/ternary-result/ternary-result.mts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,QAAQ,CAAC;IAClC,yDAAyD;IACzD,KAAK,EAAE,0BAA0B,CAAC;IAElC,yBAAyB;IACzB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC;IACvC,2DAA2D;IAC3D,KAAK,EAAE,4BAA4B,CAAC;IAEpC,yBAAyB;IACzB,KAAK,EAAE,CAAC,CAAC;IAET,yBAAyB;IACzB,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,QAAQ,CAAC;IACnC,0DAA0D;IAC1D,KAAK,EAAE,2BAA2B,CAAC;IAEnC,uBAAuB;IACvB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IACnC,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC9B,SAAS,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AAE3E,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result.mjs","sourceRoot":"","sources":["../../../src/functional/ternary-result/ternary-result.mts"],"names":[],"mappings":"AAiDA,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type Result } from '../result/index.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an asynchronous computation that can either succeed (`Ok`) or
|
|
5
|
-
* fail (`Err`) — a `Promise` that resolves to a `Result<S, E>`.
|
|
6
|
-
*
|
|
7
|
-
* Unlike a raw `Promise`, an `AsyncResult` never rejects for expected
|
|
8
|
-
* failures: errors are carried in the `Err` channel with a concrete type `E`,
|
|
9
|
-
* so they can be handled with the same combinators as a synchronous
|
|
10
|
-
* `Result`.
|
|
11
|
-
*
|
|
12
|
-
* @template S The type of the success value.
|
|
13
|
-
* @template E The type of the error value.
|
|
14
|
-
*/
|
|
15
|
-
export type AsyncResult<S, E> = Promise<Result<S, E>>;
|
|
16
|
-
|
|
17
|
-
export * as AsyncResult from './impl/index.mjs';
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Result, type UnknownResult } from '../../result/index.mjs';
|
|
2
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
3
|
-
import {
|
|
4
|
-
type UnknownAsyncResult,
|
|
5
|
-
type UnwrapErr,
|
|
6
|
-
type UnwrapOk,
|
|
7
|
-
} from './types.mjs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Applies a function that returns an `AsyncResult` or a `Result` to the
|
|
11
|
-
* success value of an `AsyncResult`. If the input resolves to `Err`, the
|
|
12
|
-
* original `Err` is passed through and the function is not called. This is
|
|
13
|
-
* the monadic bind operation for `AsyncResult`.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const parseNumber = (input: string): Result<number, string> => {
|
|
19
|
-
* const num = Number.parseInt(input, 10);
|
|
20
|
-
*
|
|
21
|
-
* return Number.isNaN(num) ? Result.err('not a number') : Result.ok(num);
|
|
22
|
-
* };
|
|
23
|
-
*
|
|
24
|
-
* const input = AsyncResult.fromPromise(
|
|
25
|
-
* Promise.resolve('42'),
|
|
26
|
-
* () => 'failed',
|
|
27
|
-
* );
|
|
28
|
-
*
|
|
29
|
-
* const parsed = await AsyncResult.flatMap(input, parseNumber);
|
|
30
|
-
*
|
|
31
|
-
* assert.deepStrictEqual(parsed, Result.ok(42));
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @template S The type of the success value of the input.
|
|
35
|
-
* @template E The type of the error value of the input.
|
|
36
|
-
* @template R2 The `AsyncResult` or `Result` type returned by the function.
|
|
37
|
-
* @param asyncResult The `AsyncResult` to flat map.
|
|
38
|
-
* @param flatMapFn The function to apply that returns an `AsyncResult` or a
|
|
39
|
-
* `Result`.
|
|
40
|
-
* @returns The result of applying the function, or the original `Err`.
|
|
41
|
-
*/
|
|
42
|
-
export function flatMap<S, E, R2 extends UnknownAsyncResult | UnknownResult>(
|
|
43
|
-
asyncResult: AsyncResult<S, E>,
|
|
44
|
-
flatMapFn: (value: S) => R2,
|
|
45
|
-
): AsyncResult<UnwrapOk<R2>, E | UnwrapErr<R2>>;
|
|
46
|
-
|
|
47
|
-
// Curried version
|
|
48
|
-
//
|
|
49
|
-
// The function's return type is captured as a whole (`R2`) and unwrapped with
|
|
50
|
-
// `UnwrapOk` / `UnwrapErr`, instead of being written as
|
|
51
|
-
// `AsyncResult<S2, E2> | Result<S2, E2>` with separate `S2` / `E2` type
|
|
52
|
-
// parameters. With the union form, inference for `E2` collects a candidate
|
|
53
|
-
// from matching `Ok<S2>` against `Err<E2>` (both have a `value` property), so
|
|
54
|
-
// `E2` ends up as the success type and the call fails to type-check even for
|
|
55
|
-
// a function annotated as returning `Result<S2, E2>`.
|
|
56
|
-
export function flatMap<S, R2 extends UnknownAsyncResult | UnknownResult>(
|
|
57
|
-
flatMapFn: (value: S) => R2,
|
|
58
|
-
): <E>(
|
|
59
|
-
asyncResult: AsyncResult<S, E>,
|
|
60
|
-
) => AsyncResult<UnwrapOk<R2>, E | UnwrapErr<R2>>;
|
|
61
|
-
|
|
62
|
-
export function flatMap<S, E, R2 extends UnknownAsyncResult | UnknownResult>(
|
|
63
|
-
...args:
|
|
64
|
-
| readonly [asyncResult: AsyncResult<S, E>, flatMapFn: (value: S) => R2]
|
|
65
|
-
| readonly [flatMapFn: (value: S) => R2]
|
|
66
|
-
):
|
|
67
|
-
| AsyncResult<UnwrapOk<R2>, E | UnwrapErr<R2>>
|
|
68
|
-
| ((
|
|
69
|
-
asyncResult: AsyncResult<S, E>,
|
|
70
|
-
) => AsyncResult<UnwrapOk<R2>, E | UnwrapErr<R2>>) {
|
|
71
|
-
switch (args.length) {
|
|
72
|
-
case 2: {
|
|
73
|
-
// Direct version: first argument is asyncResult
|
|
74
|
-
const [asyncResult, flatMapFn] = args;
|
|
75
|
-
|
|
76
|
-
return flatMapImpl(asyncResult, flatMapFn);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
case 1: {
|
|
80
|
-
// Curried version
|
|
81
|
-
const [flatMapFn] = args;
|
|
82
|
-
|
|
83
|
-
return (asyncResult: AsyncResult<S, E>) =>
|
|
84
|
-
flatMapImpl(asyncResult, flatMapFn);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const flatMapImpl = async <S, E, R2 extends UnknownAsyncResult | UnknownResult>(
|
|
90
|
-
asyncResult: AsyncResult<S, E>,
|
|
91
|
-
flatMapFn: (value: S) => R2,
|
|
92
|
-
): AsyncResult<UnwrapOk<R2>, E | UnwrapErr<R2>> => {
|
|
93
|
-
const result = await asyncResult;
|
|
94
|
-
|
|
95
|
-
return Result.isErr(result)
|
|
96
|
-
? result
|
|
97
|
-
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
98
|
-
((await flatMapFn(result.value)) as Result<UnwrapOk<R2>, UnwrapErr<R2>>);
|
|
99
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../result/index.mjs';
|
|
2
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Converts a `Promise` into an `AsyncResult`. If the input Promise resolves,
|
|
6
|
-
* the `AsyncResult` resolves to `Ok` with the resolved value. If the input
|
|
7
|
-
* Promise rejects, the rejection reason is passed through `mapError` and the
|
|
8
|
-
* `AsyncResult` resolves to `Err` with the mapped error.
|
|
9
|
-
*
|
|
10
|
-
* Passing `mapError` is what gives the error channel a concrete type `E`.
|
|
11
|
-
* Omitting it carries the rejection reason through untouched, leaving the
|
|
12
|
-
* error channel as `unknown` — the same contract as `Result.fromPromise`.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* const resolved = await AsyncResult.fromPromise(
|
|
18
|
-
* Promise.resolve('ok'),
|
|
19
|
-
* (error) => `failed: ${String(error)}`,
|
|
20
|
-
* );
|
|
21
|
-
*
|
|
22
|
-
* const rejected = await AsyncResult.fromPromise(
|
|
23
|
-
* Promise.reject(new Error('boom')),
|
|
24
|
-
* (error) => (isError(error) ? error.message : 'unknown'),
|
|
25
|
-
* );
|
|
26
|
-
*
|
|
27
|
-
* assert.deepStrictEqual(resolved, Result.ok('ok'));
|
|
28
|
-
*
|
|
29
|
-
* assert.deepStrictEqual(rejected, Result.err('boom'));
|
|
30
|
-
*
|
|
31
|
-
* // Without `mapError`, the rejection reason is carried as-is.
|
|
32
|
-
* const untyped = await AsyncResult.fromPromise(
|
|
33
|
-
* Promise.reject(new Error('boom')),
|
|
34
|
-
* );
|
|
35
|
-
*
|
|
36
|
-
* assert.isTrue(Result.isErr(untyped));
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @template S The type of the success value.
|
|
40
|
-
* @template E The type of the error value.
|
|
41
|
-
* @param promise The Promise to convert.
|
|
42
|
-
* @param mapError The function applied to the rejection reason to produce the
|
|
43
|
-
* error value. Omit it to carry the rejection reason as `unknown`.
|
|
44
|
-
* @returns An `AsyncResult<S, E>` that never rejects for the input Promise's
|
|
45
|
-
* failure.
|
|
46
|
-
*/
|
|
47
|
-
export function fromPromise<S>(promise: Promise<S>): AsyncResult<S, unknown>;
|
|
48
|
-
|
|
49
|
-
export function fromPromise<S, E>(
|
|
50
|
-
promise: Promise<S>,
|
|
51
|
-
mapError: (error: unknown) => E,
|
|
52
|
-
): AsyncResult<S, E>;
|
|
53
|
-
|
|
54
|
-
export function fromPromise<S, E>(
|
|
55
|
-
promise: Promise<S>,
|
|
56
|
-
mapError?: (error: unknown) => E,
|
|
57
|
-
): AsyncResult<S, E> | AsyncResult<S, unknown> {
|
|
58
|
-
return mapError === undefined
|
|
59
|
-
? fromPromiseImpl(promise, (error: unknown) => error)
|
|
60
|
-
: fromPromiseImpl(promise, mapError);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const fromPromiseImpl = <S, E>(
|
|
64
|
-
promise: Promise<S>,
|
|
65
|
-
mapError: (error: unknown) => E,
|
|
66
|
-
): AsyncResult<S, E> =>
|
|
67
|
-
promise
|
|
68
|
-
.then((value) => Result.ok(value))
|
|
69
|
-
.catch((error: unknown) => Result.err(mapError(error)));
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../result/index.mjs';
|
|
2
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a function returning a `Promise` in an `AsyncResult`. Both a
|
|
6
|
-
* synchronous `throw` while calling `fn` and an asynchronous rejection of the
|
|
7
|
-
* returned Promise are caught, passed through `mapError`, and carried as
|
|
8
|
-
* `Err`.
|
|
9
|
-
*
|
|
10
|
-
* Passing `mapError` is what gives the error channel a concrete type `E`.
|
|
11
|
-
* Omitting it carries the thrown value through untouched, leaving the error
|
|
12
|
-
* channel as `unknown`.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* const success = await AsyncResult.fromThrowable(
|
|
18
|
-
* () => Promise.resolve(2),
|
|
19
|
-
* (error) => `failed: ${String(error)}`,
|
|
20
|
-
* );
|
|
21
|
-
*
|
|
22
|
-
* const failure = await AsyncResult.fromThrowable(
|
|
23
|
-
* (): Promise<number> => {
|
|
24
|
-
* throw new Error('boom');
|
|
25
|
-
* },
|
|
26
|
-
* (error) => (isError(error) ? error.message : 'unknown'),
|
|
27
|
-
* );
|
|
28
|
-
*
|
|
29
|
-
* assert.deepStrictEqual(success, Result.ok(2));
|
|
30
|
-
*
|
|
31
|
-
* assert.deepStrictEqual(failure, Result.err('boom'));
|
|
32
|
-
*
|
|
33
|
-
* // Without `mapError`, the thrown value is carried as-is.
|
|
34
|
-
* const untyped = await AsyncResult.fromThrowable(
|
|
35
|
-
* (): Promise<number> => {
|
|
36
|
-
* throw new Error('boom');
|
|
37
|
-
* },
|
|
38
|
-
* );
|
|
39
|
-
*
|
|
40
|
-
* assert.isTrue(Result.isErr(untyped));
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @template S The type of the success value.
|
|
44
|
-
* @template E The type of the error value.
|
|
45
|
-
* @param fn The function to execute; it may throw synchronously or return a
|
|
46
|
-
* rejecting Promise.
|
|
47
|
-
* @param mapError The function applied to the thrown value or rejection
|
|
48
|
-
* reason to produce the error value. Omit it to carry the thrown value as
|
|
49
|
-
* `unknown`.
|
|
50
|
-
* @returns An `AsyncResult<S, E>` containing either the resolved value or the
|
|
51
|
-
* mapped error.
|
|
52
|
-
*/
|
|
53
|
-
export function fromThrowable<S>(fn: () => Promise<S>): AsyncResult<S, unknown>;
|
|
54
|
-
|
|
55
|
-
export function fromThrowable<S, E>(
|
|
56
|
-
fn: () => Promise<S>,
|
|
57
|
-
mapError: (error: unknown) => E,
|
|
58
|
-
): AsyncResult<S, E>;
|
|
59
|
-
|
|
60
|
-
export function fromThrowable<S, E>(
|
|
61
|
-
fn: () => Promise<S>,
|
|
62
|
-
mapError?: (error: unknown) => E,
|
|
63
|
-
): AsyncResult<S, E> | AsyncResult<S, unknown> {
|
|
64
|
-
return mapError === undefined
|
|
65
|
-
? fromThrowableImpl(fn, (error: unknown) => error)
|
|
66
|
-
: fromThrowableImpl(fn, mapError);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const fromThrowableImpl = async <S, E>(
|
|
70
|
-
fn: () => Promise<S>,
|
|
71
|
-
mapError: (error: unknown) => E,
|
|
72
|
-
): AsyncResult<S, E> => {
|
|
73
|
-
try {
|
|
74
|
-
return Result.ok(await fn());
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return Result.err(mapError(error));
|
|
77
|
-
}
|
|
78
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../result/index.mjs';
|
|
2
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Maps an `AsyncResult<S, E>` to `AsyncResult<S, E2>` by applying a function
|
|
6
|
-
* to the error value. The mapping function may be synchronous or return a
|
|
7
|
-
* `Promise`; both are handled transparently. If the `AsyncResult` resolves to
|
|
8
|
-
* `Ok`, the original `Ok` is passed through and the function is not called.
|
|
9
|
-
*
|
|
10
|
-
* If `mapFn` throws or returns a rejecting Promise, the rejection propagates
|
|
11
|
-
* as-is — it is **not** caught and converted into an `Err`.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const errValue = AsyncResult.fromPromise(
|
|
17
|
-
* Promise.reject(new Error('boom')),
|
|
18
|
-
* () => 'failure',
|
|
19
|
-
* );
|
|
20
|
-
*
|
|
21
|
-
* const uppercased = await AsyncResult.mapErr(errValue, (error) =>
|
|
22
|
-
* error.toUpperCase(),
|
|
23
|
-
* );
|
|
24
|
-
*
|
|
25
|
-
* assert.deepStrictEqual(uppercased, Result.err('FAILURE'));
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @template S The type of the success value.
|
|
29
|
-
* @template E The type of the error value of the input.
|
|
30
|
-
* @template E2 The type of the error value returned by the mapping function.
|
|
31
|
-
* @param asyncResult The `AsyncResult` to map.
|
|
32
|
-
* @param mapFn The function to apply to the error value if present.
|
|
33
|
-
* @returns A new `AsyncResult<S, E2>`.
|
|
34
|
-
*/
|
|
35
|
-
export function mapErr<S, E, E2>(
|
|
36
|
-
asyncResult: AsyncResult<S, E>,
|
|
37
|
-
mapFn: (error: E) => E2 | Promise<E2>,
|
|
38
|
-
): AsyncResult<S, E2>;
|
|
39
|
-
|
|
40
|
-
// Curried version
|
|
41
|
-
//
|
|
42
|
-
// Unlike `Result.mapErr`, the returned function can simply be generic over
|
|
43
|
-
// `S`: an `AsyncResult` is a `Promise`, not a discriminated union, so there
|
|
44
|
-
// is no literal-narrowing problem that would require the whole-result
|
|
45
|
-
// generic trick used by the synchronous combinators.
|
|
46
|
-
export function mapErr<E, E2>(
|
|
47
|
-
mapFn: (error: E) => E2 | Promise<E2>,
|
|
48
|
-
): <S>(asyncResult: AsyncResult<S, E>) => AsyncResult<S, E2>;
|
|
49
|
-
|
|
50
|
-
export function mapErr<S, E, E2>(
|
|
51
|
-
...args:
|
|
52
|
-
| readonly [
|
|
53
|
-
asyncResult: AsyncResult<S, E>,
|
|
54
|
-
mapFn: (error: E) => E2 | Promise<E2>,
|
|
55
|
-
]
|
|
56
|
-
| readonly [mapFn: (error: E) => E2 | Promise<E2>]
|
|
57
|
-
):
|
|
58
|
-
| AsyncResult<S, E2>
|
|
59
|
-
| ((asyncResult: AsyncResult<S, E>) => AsyncResult<S, E2>) {
|
|
60
|
-
switch (args.length) {
|
|
61
|
-
case 2: {
|
|
62
|
-
// Direct version: first argument is asyncResult
|
|
63
|
-
const [asyncResult, mapFn] = args;
|
|
64
|
-
|
|
65
|
-
return mapErrImpl(asyncResult, mapFn);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
case 1: {
|
|
69
|
-
// Curried version: first argument is mapping function
|
|
70
|
-
const [mapFn] = args;
|
|
71
|
-
|
|
72
|
-
return (asyncResult: AsyncResult<S, E>) => mapErrImpl(asyncResult, mapFn);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const mapErrImpl = async <S, E, E2>(
|
|
78
|
-
asyncResult: AsyncResult<S, E>,
|
|
79
|
-
mapFn: (error: E) => E2 | Promise<E2>,
|
|
80
|
-
): AsyncResult<S, E2> => {
|
|
81
|
-
const result = await asyncResult;
|
|
82
|
-
|
|
83
|
-
return Result.isOk(result) ? result : Result.err(await mapFn(result.value));
|
|
84
|
-
};
|