ts-data-forge 14.6.4 → 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/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 +5 -5
- 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,95 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TernaryErr,
|
|
3
|
-
type TernaryResult,
|
|
4
|
-
type UnknownTernaryResult,
|
|
5
|
-
} from '../ternary-result.mjs';
|
|
6
|
-
import { isOk } from './ternary-result-is-ok.mjs';
|
|
7
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
8
|
-
import { ok } from './ternary-result-ok.mjs';
|
|
9
|
-
import { warn } from './ternary-result-warn.mjs';
|
|
10
|
-
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Maps the Ok variant while leaving Warn/Err untouched.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const okNumber = TernaryResult.ok(5);
|
|
19
|
-
*
|
|
20
|
-
* const warnValue = TernaryResult.warn(5, 'slow');
|
|
21
|
-
*
|
|
22
|
-
* const errValue = TernaryResult.err('bad');
|
|
23
|
-
*
|
|
24
|
-
* const doubled = TernaryResult.map(okNumber, (value) => value * 2);
|
|
25
|
-
*
|
|
26
|
-
* const warnPassthrough = TernaryResult.map(
|
|
27
|
-
* warnValue,
|
|
28
|
-
* (value: number) => value * 2,
|
|
29
|
-
* );
|
|
30
|
-
*
|
|
31
|
-
* const errPassthrough = TernaryResult.map(
|
|
32
|
-
* errValue,
|
|
33
|
-
* (value: number) => value * 2,
|
|
34
|
-
* );
|
|
35
|
-
*
|
|
36
|
-
* assert.deepStrictEqual(doubled, TernaryResult.ok(10));
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(10, 'slow'));
|
|
39
|
-
*
|
|
40
|
-
* assert.deepStrictEqual(errPassthrough, errValue);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export function map<R extends UnknownTernaryResult, S2>(
|
|
44
|
-
result: R,
|
|
45
|
-
mapFn: (value: UnwrapOk<R>) => S2,
|
|
46
|
-
): TernaryResult<S2, UnwrapErr<R>, UnwrapWarn<R>>;
|
|
47
|
-
|
|
48
|
-
// Curried version
|
|
49
|
-
export function map<S, S2>(
|
|
50
|
-
mapFn: (value: S) => S2,
|
|
51
|
-
): <W, E>(result: TernaryResult<S, E, W>) => TernaryResult<S2, E, W>;
|
|
52
|
-
|
|
53
|
-
export function map<R extends UnknownTernaryResult, S2>(
|
|
54
|
-
...args:
|
|
55
|
-
| readonly [result: R, mapFn: (value: UnwrapOk<R>) => S2]
|
|
56
|
-
| readonly [mapFn: (value: UnwrapOk<R>) => S2]
|
|
57
|
-
):
|
|
58
|
-
| TernaryResult<S2, UnwrapErr<R>, UnwrapWarn<R>>
|
|
59
|
-
| ((result: R) => TernaryResult<S2, UnwrapErr<R>, UnwrapWarn<R>>) {
|
|
60
|
-
switch (args.length) {
|
|
61
|
-
case 2: {
|
|
62
|
-
const [result, mapFn] = args;
|
|
63
|
-
|
|
64
|
-
return mapImpl(result, mapFn);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
case 1: {
|
|
68
|
-
const [mapFn] = args;
|
|
69
|
-
|
|
70
|
-
return (result: R) => mapImpl(result, mapFn);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const mapImpl = <R extends UnknownTernaryResult, S2>(
|
|
76
|
-
result: R,
|
|
77
|
-
mapFn: (value: UnwrapOk<R>) => S2,
|
|
78
|
-
): TernaryResult<S2, UnwrapErr<R>, UnwrapWarn<R>> => {
|
|
79
|
-
if (isOk(result)) {
|
|
80
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
81
|
-
return ok(mapFn(result.value as UnwrapOk<R>));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (isWarn(result)) {
|
|
85
|
-
return warn(
|
|
86
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
87
|
-
mapFn(result.value as UnwrapOk<R>),
|
|
88
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
89
|
-
result.warning as UnwrapWarn<R>,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
94
|
-
return result as TernaryErr<UnwrapErr<R>>;
|
|
95
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type TernaryOk } from '../ternary-result.mjs';
|
|
2
|
-
import { OkTypeTagName } from './tag.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a `TernaryResult.Ok` containing the provided value.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* const success = TernaryResult.ok({ id: 1 });
|
|
11
|
-
*
|
|
12
|
-
* assert.deepStrictEqual(success, {
|
|
13
|
-
* $$tag: 'ts-data-forge::Result.ok',
|
|
14
|
-
* value: { id: 1 },
|
|
15
|
-
* });
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export const ok = <const S,>(value: S): TernaryOk<S> =>
|
|
19
|
-
({
|
|
20
|
-
$$tag: OkTypeTagName,
|
|
21
|
-
value,
|
|
22
|
-
}) as const;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { isOk } from './ternary-result-is-ok.mjs';
|
|
3
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
4
|
-
import { type NarrowToOk, type NarrowToWarn } from './types.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns the original result if it is Ok, otherwise the provided fallback.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const fallback = TernaryResult.ok('fallback');
|
|
13
|
-
*
|
|
14
|
-
* assert.deepStrictEqual(
|
|
15
|
-
* TernaryResult.orElse(TernaryResult.ok('value'), fallback),
|
|
16
|
-
* TernaryResult.ok('value'),
|
|
17
|
-
* );
|
|
18
|
-
*
|
|
19
|
-
* assert.deepStrictEqual(
|
|
20
|
-
* TernaryResult.orElse(TernaryResult.warn('value', 'warn'), fallback),
|
|
21
|
-
* TernaryResult.warn('value', 'warn'),
|
|
22
|
-
* );
|
|
23
|
-
*
|
|
24
|
-
* assert.deepStrictEqual(
|
|
25
|
-
* TernaryResult.orElse(TernaryResult.err('err'), fallback),
|
|
26
|
-
* fallback,
|
|
27
|
-
* );
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function orElse<
|
|
31
|
-
R extends UnknownTernaryResult,
|
|
32
|
-
R2 extends UnknownTernaryResult,
|
|
33
|
-
>(result: R, alternative: R2): NarrowToOk<R> | NarrowToWarn<R> | R2;
|
|
34
|
-
|
|
35
|
-
// Curried version
|
|
36
|
-
export function orElse<R2 extends UnknownTernaryResult>(
|
|
37
|
-
alternative: R2,
|
|
38
|
-
): <R extends UnknownTernaryResult>(
|
|
39
|
-
result: R,
|
|
40
|
-
) => NarrowToOk<R> | NarrowToWarn<R> | R2;
|
|
41
|
-
|
|
42
|
-
export function orElse<
|
|
43
|
-
R extends UnknownTernaryResult,
|
|
44
|
-
R2 extends UnknownTernaryResult,
|
|
45
|
-
>(
|
|
46
|
-
...args: readonly [result: R, alternative: R2] | readonly [alternative: R2]
|
|
47
|
-
):
|
|
48
|
-
| (NarrowToOk<R> | NarrowToWarn<R> | R2)
|
|
49
|
-
| ((result: R) => NarrowToOk<R> | NarrowToWarn<R> | R2) {
|
|
50
|
-
switch (args.length) {
|
|
51
|
-
case 2: {
|
|
52
|
-
const [result, alternative] = args;
|
|
53
|
-
|
|
54
|
-
return orElseImpl(result, alternative);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
case 1: {
|
|
58
|
-
const [alternative] = args;
|
|
59
|
-
|
|
60
|
-
return (result: R) => orElseImpl(result, alternative);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const orElseImpl = <
|
|
66
|
-
R extends UnknownTernaryResult,
|
|
67
|
-
R2 extends UnknownTernaryResult,
|
|
68
|
-
>(
|
|
69
|
-
result: R,
|
|
70
|
-
alternative: R2,
|
|
71
|
-
): NarrowToOk<R> | NarrowToWarn<R> | R2 =>
|
|
72
|
-
isOk(result) || isWarn(result) ? result : alternative;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Optional } from '../../optional/index.mjs';
|
|
2
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
3
|
-
import { isOk } from './ternary-result-is-ok.mjs';
|
|
4
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
5
|
-
import { type UnwrapOk } from './types.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Converts a `TernaryResult` into an `Optional` by keeping only Ok values.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const okValue = TernaryResult.ok(7);
|
|
14
|
-
*
|
|
15
|
-
* const warnValue = TernaryResult.warn(7, 'warn');
|
|
16
|
-
*
|
|
17
|
-
* assert.deepStrictEqual(TernaryResult.toOptional(okValue), Optional.some(7));
|
|
18
|
-
*
|
|
19
|
-
* assert.deepStrictEqual(
|
|
20
|
-
* TernaryResult.toOptional(warnValue),
|
|
21
|
-
* Optional.some(7),
|
|
22
|
-
* );
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export const toOptional = <R extends UnknownTernaryResult>(
|
|
26
|
-
result: R,
|
|
27
|
-
): Optional<UnwrapOk<R>> =>
|
|
28
|
-
isOk(result) || isWarn(result)
|
|
29
|
-
? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
30
|
-
Optional.some(result.value as UnwrapOk<R>)
|
|
31
|
-
: Optional.none;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { unwrapErr } from './ternary-result-unwrap-err.mjs';
|
|
3
|
-
import { type UnwrapErr } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the Err value or the provided default.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const okValue = TernaryResult.ok('value');
|
|
12
|
-
*
|
|
13
|
-
* assert.strictEqual(
|
|
14
|
-
* TernaryResult.unwrapErrOr(okValue, 'default'),
|
|
15
|
-
* 'default',
|
|
16
|
-
* );
|
|
17
|
-
*
|
|
18
|
-
* const unwrapErr = TernaryResult.unwrapErrOr('fallback error');
|
|
19
|
-
*
|
|
20
|
-
* assert.strictEqual(unwrapErr(TernaryResult.err('boom')), 'boom');
|
|
21
|
-
*
|
|
22
|
-
* assert.strictEqual(
|
|
23
|
-
* unwrapErr(TernaryResult.warn('value', 'warn')),
|
|
24
|
-
* 'fallback error',
|
|
25
|
-
* );
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export function unwrapErrOr<R extends UnknownTernaryResult, D>(
|
|
29
|
-
result: R,
|
|
30
|
-
defaultValue: D,
|
|
31
|
-
): D | UnwrapErr<R>;
|
|
32
|
-
|
|
33
|
-
// Curried version
|
|
34
|
-
export function unwrapErrOr<D>(
|
|
35
|
-
defaultValue: D,
|
|
36
|
-
): <R extends UnknownTernaryResult>(result: R) => D | UnwrapErr<R>;
|
|
37
|
-
|
|
38
|
-
export function unwrapErrOr<R extends UnknownTernaryResult, D>(
|
|
39
|
-
...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]
|
|
40
|
-
): D | UnwrapErr<R> | ((result: R) => D | UnwrapErr<R>) {
|
|
41
|
-
switch (args.length) {
|
|
42
|
-
case 2: {
|
|
43
|
-
const [result, defaultValue] = args;
|
|
44
|
-
|
|
45
|
-
return unwrapErr(result) ?? defaultValue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
case 1: {
|
|
49
|
-
const [defaultValue] = args;
|
|
50
|
-
|
|
51
|
-
return (result: R) => unwrapErr(result) ?? defaultValue;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { unknownToString } from '../../../others/index.mjs';
|
|
2
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
3
|
-
import { isErr } from './ternary-result-is-err.mjs';
|
|
4
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
5
|
-
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
6
|
-
import { variantName } from './variant-name.mjs';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns the Err value or throws if the result is not Err.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* const errValue = TernaryResult.err('boom');
|
|
15
|
-
*
|
|
16
|
-
* assert.strictEqual(TernaryResult.unwrapErrThrow(errValue), 'boom');
|
|
17
|
-
*
|
|
18
|
-
* assert.throws(
|
|
19
|
-
* () => TernaryResult.unwrapErrThrow(TernaryResult.ok('value')),
|
|
20
|
-
* /Expected Err/u,
|
|
21
|
-
* );
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const unwrapErrThrow = <R extends UnknownTernaryResult>(
|
|
25
|
-
result: R,
|
|
26
|
-
toStr: (value: UnwrapOk<R> | UnwrapWarn<R>) => string = unknownToString,
|
|
27
|
-
): UnwrapErr<R> => {
|
|
28
|
-
if (isErr(result)) {
|
|
29
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
30
|
-
return result.value as UnwrapErr<R>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const variant = variantName(result.$$tag);
|
|
34
|
-
|
|
35
|
-
const payload = isWarn(result)
|
|
36
|
-
? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
37
|
-
(result.warning as UnwrapWarn<R> as UnwrapOk<R> | UnwrapWarn<R>)
|
|
38
|
-
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
39
|
-
(result.value as UnwrapOk<R> as UnwrapOk<R> | UnwrapWarn<R>);
|
|
40
|
-
|
|
41
|
-
throw new Error(`Expected Err but got ${variant}: ${toStr(payload)}`);
|
|
42
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { isErr } from './ternary-result-is-err.mjs';
|
|
3
|
-
import { type UnwrapErr } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Safely unwraps the Err value.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const errValue = TernaryResult.err('fail');
|
|
12
|
-
*
|
|
13
|
-
* const okValue = TernaryResult.ok('value');
|
|
14
|
-
*
|
|
15
|
-
* assert.strictEqual(TernaryResult.unwrapErr(errValue), 'fail');
|
|
16
|
-
*
|
|
17
|
-
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
18
|
-
* assert.strictEqual(TernaryResult.unwrapErr(okValue), undefined);
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const unwrapErr = <R extends UnknownTernaryResult>(
|
|
22
|
-
result: R,
|
|
23
|
-
): UnwrapErr<R> | undefined =>
|
|
24
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
|
-
isErr(result) ? (result.value as UnwrapErr<R>) : undefined;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { unwrapOk } from './ternary-result-unwrap-ok.mjs';
|
|
3
|
-
import { type UnwrapOk } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the Ok value or the provided default.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const errValue = TernaryResult.err('err');
|
|
12
|
-
*
|
|
13
|
-
* assert.strictEqual(TernaryResult.unwrapOkOr(errValue, 0), 0);
|
|
14
|
-
*
|
|
15
|
-
* const unwrapWithDefault = TernaryResult.unwrapOkOr('fallback');
|
|
16
|
-
*
|
|
17
|
-
* assert.strictEqual(unwrapWithDefault(TernaryResult.ok(5)), 5);
|
|
18
|
-
*
|
|
19
|
-
* assert.strictEqual(
|
|
20
|
-
* unwrapWithDefault(TernaryResult.warn('warn-value', 'warn')),
|
|
21
|
-
* 'warn-value',
|
|
22
|
-
* );
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function unwrapOkOr<R extends UnknownTernaryResult, D>(
|
|
26
|
-
result: R,
|
|
27
|
-
defaultValue: D,
|
|
28
|
-
): D | UnwrapOk<R>;
|
|
29
|
-
|
|
30
|
-
// Curried version
|
|
31
|
-
export function unwrapOkOr<D>(
|
|
32
|
-
defaultValue: D,
|
|
33
|
-
): <R extends UnknownTernaryResult>(result: R) => D | UnwrapOk<R>;
|
|
34
|
-
|
|
35
|
-
export function unwrapOkOr<R extends UnknownTernaryResult, D>(
|
|
36
|
-
...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]
|
|
37
|
-
): D | UnwrapOk<R> | ((result: R) => D | UnwrapOk<R>) {
|
|
38
|
-
switch (args.length) {
|
|
39
|
-
case 2: {
|
|
40
|
-
const [result, defaultValue] = args;
|
|
41
|
-
|
|
42
|
-
return unwrapOk(result) ?? defaultValue;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
case 1: {
|
|
46
|
-
const [defaultValue] = args;
|
|
47
|
-
|
|
48
|
-
return (result: R) => unwrapOk(result) ?? defaultValue;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TernaryOk,
|
|
3
|
-
type UnknownTernaryResult,
|
|
4
|
-
} from '../ternary-result.mjs';
|
|
5
|
-
import { isOk } from './ternary-result-is-ok.mjs';
|
|
6
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
7
|
-
import { type UnwrapOk } from './types.mjs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Safely unwraps the Ok value.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const okValue = TernaryResult.ok(3);
|
|
16
|
-
*
|
|
17
|
-
* const warnValue = TernaryResult.warn(4, 'warn');
|
|
18
|
-
*
|
|
19
|
-
* assert.strictEqual(TernaryResult.unwrapOk(okValue), 3);
|
|
20
|
-
*
|
|
21
|
-
* assert.strictEqual(TernaryResult.unwrapOk(warnValue), 4);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function unwrapOk<R extends TernaryOk<unknown>>(result: R): UnwrapOk<R>;
|
|
25
|
-
|
|
26
|
-
export function unwrapOk<R extends UnknownTernaryResult>(
|
|
27
|
-
result: R,
|
|
28
|
-
): UnwrapOk<R> | undefined;
|
|
29
|
-
|
|
30
|
-
export function unwrapOk<R extends UnknownTernaryResult>(
|
|
31
|
-
result: R,
|
|
32
|
-
): UnwrapOk<R> | undefined {
|
|
33
|
-
if (isOk(result) || isWarn(result)) {
|
|
34
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
35
|
-
return result.value as UnwrapOk<R>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { unknownToString } from '../../../others/index.mjs';
|
|
2
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
3
|
-
import { isErr } from './ternary-result-is-err.mjs';
|
|
4
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
5
|
-
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns the Ok value or throws if the result is Warn or Err.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const okValue = TernaryResult.ok('ready');
|
|
14
|
-
*
|
|
15
|
-
* assert.strictEqual(TernaryResult.unwrapThrow(okValue), 'ready');
|
|
16
|
-
*
|
|
17
|
-
* const throwTest = (): void => {
|
|
18
|
-
* TernaryResult.unwrapThrow(TernaryResult.warn('warn', 'warned'));
|
|
19
|
-
* };
|
|
20
|
-
*
|
|
21
|
-
* assert.throws(throwTest, /Expected Ok/u);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const unwrapThrow = <R extends UnknownTernaryResult>(
|
|
25
|
-
result: R,
|
|
26
|
-
toStr: (value: UnwrapWarn<R> | UnwrapErr<R>) => string = unknownToString,
|
|
27
|
-
): UnwrapOk<R> => {
|
|
28
|
-
if (isErr(result)) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
`Expected Ok but got Err: ${toStr(
|
|
31
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
32
|
-
result.value as UnwrapErr<R>,
|
|
33
|
-
)}`,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (isWarn(result)) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`Expected Ok but got Warn: ${toStr(
|
|
40
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
41
|
-
result.warning as UnwrapWarn<R>,
|
|
42
|
-
)}`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
47
|
-
return result.value as UnwrapOk<R>;
|
|
48
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { unwrapWarn } from './ternary-result-unwrap-warn.mjs';
|
|
3
|
-
import { type UnwrapWarn } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the Warn value or the provided default.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const okValue = TernaryResult.ok('value');
|
|
12
|
-
*
|
|
13
|
-
* assert.strictEqual(TernaryResult.unwrapWarnOr(okValue, 'warn'), 'warn');
|
|
14
|
-
*
|
|
15
|
-
* const unwrapWarn = TernaryResult.unwrapWarnOr('fallback warn');
|
|
16
|
-
*
|
|
17
|
-
* assert.strictEqual(unwrapWarn(TernaryResult.warn('value', 'slow')), 'slow');
|
|
18
|
-
*
|
|
19
|
-
* assert.strictEqual(unwrapWarn(TernaryResult.err('err')), 'fallback warn');
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export function unwrapWarnOr<R extends UnknownTernaryResult, D>(
|
|
23
|
-
result: R,
|
|
24
|
-
defaultValue: D,
|
|
25
|
-
): D | UnwrapWarn<R>;
|
|
26
|
-
|
|
27
|
-
// Curried version
|
|
28
|
-
export function unwrapWarnOr<D>(
|
|
29
|
-
defaultValue: D,
|
|
30
|
-
): <R extends UnknownTernaryResult>(result: R) => D | UnwrapWarn<R>;
|
|
31
|
-
|
|
32
|
-
export function unwrapWarnOr<R extends UnknownTernaryResult, D>(
|
|
33
|
-
...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]
|
|
34
|
-
): D | UnwrapWarn<R> | ((result: R) => D | UnwrapWarn<R>) {
|
|
35
|
-
switch (args.length) {
|
|
36
|
-
case 2: {
|
|
37
|
-
const [result, defaultValue] = args;
|
|
38
|
-
|
|
39
|
-
return unwrapWarn(result) ?? defaultValue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
case 1: {
|
|
43
|
-
const [defaultValue] = args;
|
|
44
|
-
|
|
45
|
-
return (result: R) => unwrapWarn(result) ?? defaultValue;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { unknownToString } from '../../../others/index.mjs';
|
|
2
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
3
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
4
|
-
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
5
|
-
import { variantName } from './variant-name.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns the Warn value or throws if the result is not Warn.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const warnValue = TernaryResult.warn('pending', 'check logs');
|
|
14
|
-
*
|
|
15
|
-
* assert.strictEqual(TernaryResult.unwrapWarnThrow(warnValue), 'check logs');
|
|
16
|
-
*
|
|
17
|
-
* assert.throws(
|
|
18
|
-
* () => TernaryResult.unwrapWarnThrow(TernaryResult.err('err')),
|
|
19
|
-
* /Expected Warn/u,
|
|
20
|
-
* );
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export const unwrapWarnThrow = <R extends UnknownTernaryResult>(
|
|
24
|
-
result: R,
|
|
25
|
-
toStr: (value: UnwrapOk<R> | UnwrapErr<R>) => string = unknownToString,
|
|
26
|
-
): UnwrapWarn<R> => {
|
|
27
|
-
if (isWarn(result)) {
|
|
28
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
29
|
-
return result.warning as UnwrapWarn<R>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const variant = variantName(result.$$tag);
|
|
33
|
-
|
|
34
|
-
throw new Error(
|
|
35
|
-
`Expected Warn but got ${variant}: ${toStr(
|
|
36
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
37
|
-
result.value as UnwrapOk<R> | UnwrapErr<R>,
|
|
38
|
-
)}`,
|
|
39
|
-
);
|
|
40
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
3
|
-
import { type UnwrapWarn } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Safely unwraps the Warn value.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const warnValue = TernaryResult.warn('ok', 'careful');
|
|
12
|
-
*
|
|
13
|
-
* const okValue = TernaryResult.ok('ok');
|
|
14
|
-
*
|
|
15
|
-
* assert.strictEqual(TernaryResult.unwrapWarn(warnValue), 'careful');
|
|
16
|
-
*
|
|
17
|
-
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
18
|
-
* assert.strictEqual(TernaryResult.unwrapWarn(okValue), undefined);
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const unwrapWarn = <R extends UnknownTernaryResult>(
|
|
22
|
-
result: R,
|
|
23
|
-
): UnwrapWarn<R> | undefined =>
|
|
24
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
|
-
isWarn(result) ? (result.warning as UnwrapWarn<R>) : undefined;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type TernaryWarn } from '../ternary-result.mjs';
|
|
2
|
-
import { WarnTypeTagName } from './tag.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a `TernaryResult.Warn` containing the provided success value and
|
|
6
|
-
* warning.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const caution = TernaryResult.warn({ id: 1 }, 'Needs review');
|
|
12
|
-
*
|
|
13
|
-
* assert.deepStrictEqual(caution, {
|
|
14
|
-
* $$tag: 'ts-data-forge::Result.warn',
|
|
15
|
-
* value: { id: 1 },
|
|
16
|
-
* warning: 'Needs review',
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export const warn = <const S, const W>(
|
|
21
|
-
value: S,
|
|
22
|
-
warning: W,
|
|
23
|
-
): TernaryWarn<S, W> =>
|
|
24
|
-
({
|
|
25
|
-
$$tag: WarnTypeTagName,
|
|
26
|
-
value,
|
|
27
|
-
warning,
|
|
28
|
-
}) as const;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { type TernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { isErr } from './ternary-result-is-err.mjs';
|
|
3
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
4
|
-
import { ok } from './ternary-result-ok.mjs';
|
|
5
|
-
import { warn } from './ternary-result-warn.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Combines two `TernaryResult`s, prioritising Err over Warn over Ok.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const okPair = TernaryResult.zip(
|
|
14
|
-
* TernaryResult.ok('left'),
|
|
15
|
-
* TernaryResult.ok(1),
|
|
16
|
-
* );
|
|
17
|
-
*
|
|
18
|
-
* const warnPair = TernaryResult.zip(
|
|
19
|
-
* TernaryResult.warn('left', 'warn'),
|
|
20
|
-
* TernaryResult.ok(1),
|
|
21
|
-
* );
|
|
22
|
-
*
|
|
23
|
-
* const errPair = TernaryResult.zip(
|
|
24
|
-
* TernaryResult.ok('left'),
|
|
25
|
-
* TernaryResult.err('err'),
|
|
26
|
-
* );
|
|
27
|
-
*
|
|
28
|
-
* assert.deepStrictEqual(okPair, TernaryResult.ok(['left', 1] as const));
|
|
29
|
-
*
|
|
30
|
-
* assert.deepStrictEqual(
|
|
31
|
-
* warnPair,
|
|
32
|
-
* TernaryResult.warn(['left', 1] as const, 'warn'),
|
|
33
|
-
* );
|
|
34
|
-
*
|
|
35
|
-
* assert.deepStrictEqual(errPair, TernaryResult.err('err'));
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export const zip = <S1, W1, E1, S2, W2, E2>(
|
|
39
|
-
resultA: TernaryResult<S1, E1, W1>,
|
|
40
|
-
resultB: TernaryResult<S2, E2, W2>,
|
|
41
|
-
): TernaryResult<readonly [S1, S2], E1 | E2, W1 | W2> => {
|
|
42
|
-
if (isErr(resultA)) {
|
|
43
|
-
return resultA;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (isErr(resultB)) {
|
|
47
|
-
return resultB;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const pair = [resultA.value, resultB.value] as const;
|
|
51
|
-
|
|
52
|
-
if (isWarn(resultA)) {
|
|
53
|
-
return warn(pair, resultA.warning);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (isWarn(resultB)) {
|
|
57
|
-
return warn(pair, resultB.warning);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return ok(pair);
|
|
61
|
-
};
|