ts-data-forge 14.6.4 → 14.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +36 -6
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +26 -6
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/expect-type.d.mts +2 -70
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +1 -68
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/index.d.mts +11 -6
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +10 -6
- package/dist/functional/index.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +2 -51
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +1 -41
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts +2 -34
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +1 -34
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +2 -89
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -88
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +2 -42
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +1 -40
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/number/num.d.mts +9 -1
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -16
- package/dist/number/num.mjs.map +1 -1
- package/dist/others/index.d.mts +1 -0
- package/dist/others/index.d.mts.map +1 -1
- package/dist/others/index.mjs +1 -0
- package/dist/others/index.mjs.map +1 -1
- package/dist/others/panic-error.d.mts +9 -0
- package/dist/others/panic-error.d.mts.map +1 -0
- package/dist/others/panic-error.mjs +9 -0
- package/dist/others/panic-error.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +2 -37
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +1 -92
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/types.d.mts +1 -41
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +9 -9
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +36 -6
- package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +26 -6
- package/src/expect-type.mts +2 -78
- package/src/functional/index.mts +31 -6
- package/src/guard/has-key.mts +2 -72
- package/src/guard/is-non-null-object.mts +2 -36
- package/src/guard/is-record.mts +2 -95
- package/src/guard/key-is-in.mts +2 -49
- package/src/index.mts +2 -0
- package/src/number/num.mts +36 -28
- package/src/others/index.mts +1 -0
- package/src/others/panic-error.mts +8 -0
- package/src/others/unknown-to-string.mts +2 -111
- package/src/types.mts +4 -54
- package/dist/functional/async-result/async-result.d.mts +0 -16
- package/dist/functional/async-result/async-result.d.mts.map +0 -1
- package/dist/functional/async-result/async-result.mjs +0 -2
- package/dist/functional/async-result/async-result.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts +0 -39
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.mjs +0 -23
- package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts +0 -47
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.mjs +0 -10
- package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts +0 -53
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs +0 -15
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.d.mts +0 -35
- package/dist/functional/async-result/impl/async-result-map-err.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map-err.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.d.mts +0 -45
- package/dist/functional/async-result/impl/async-result-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts +0 -34
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +0 -37
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +0 -1
- package/dist/functional/async-result/impl/index.d.mts +0 -8
- package/dist/functional/async-result/impl/index.d.mts.map +0 -1
- package/dist/functional/async-result/impl/index.mjs +0 -8
- package/dist/functional/async-result/impl/index.mjs.map +0 -1
- package/dist/functional/async-result/impl/types.d.mts +0 -45
- package/dist/functional/async-result/impl/types.d.mts.map +0 -1
- package/dist/functional/async-result/impl/types.mjs +0 -2
- package/dist/functional/async-result/impl/types.mjs.map +0 -1
- package/dist/functional/async-result/index.d.mts +0 -2
- package/dist/functional/async-result/index.d.mts.map +0 -1
- package/dist/functional/async-result/index.mjs +0 -2
- package/dist/functional/async-result/index.mjs.map +0 -1
- package/dist/functional/match.d.mts +0 -80
- package/dist/functional/match.d.mts.map +0 -1
- package/dist/functional/match.mjs +0 -31
- package/dist/functional/match.mjs.map +0 -1
- package/dist/functional/optional/impl/index.d.mts +0 -19
- package/dist/functional/optional/impl/index.d.mts.map +0 -1
- package/dist/functional/optional/impl/index.mjs +0 -19
- package/dist/functional/optional/impl/index.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +0 -37
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +0 -22
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +0 -33
- package/dist/functional/optional/impl/optional-filter.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-filter.mjs +0 -25
- package/dist/functional/optional/impl/optional-filter.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +0 -39
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +0 -18
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +0 -27
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +0 -28
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +0 -23
- package/dist/functional/optional/impl/optional-is-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +0 -22
- package/dist/functional/optional/impl/optional-is-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +0 -21
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +0 -26
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +0 -24
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +0 -23
- package/dist/functional/optional/impl/optional-is-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-map.d.mts +0 -34
- package/dist/functional/optional/impl/optional-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-map.mjs +0 -22
- package/dist/functional/optional/impl/optional-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-match.d.mts +0 -48
- package/dist/functional/optional/impl/optional-match.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-match.mjs +0 -20
- package/dist/functional/optional/impl/optional-match.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-none.d.mts +0 -19
- package/dist/functional/optional/impl/optional-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-none.mjs +0 -19
- package/dist/functional/optional/impl/optional-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +0 -43
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +0 -16
- package/dist/functional/optional/impl/optional-or-else.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-some.d.mts +0 -22
- package/dist/functional/optional/impl/optional-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-some.mjs +0 -25
- package/dist/functional/optional/impl/optional-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +0 -37
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +0 -16
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +0 -31
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +0 -36
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +0 -32
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +0 -8
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +0 -35
- package/dist/functional/optional/impl/optional-zip.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-zip.mjs +0 -39
- package/dist/functional/optional/impl/optional-zip.mjs.map +0 -1
- package/dist/functional/optional/impl/tag.d.mts +0 -6
- package/dist/functional/optional/impl/tag.d.mts.map +0 -1
- package/dist/functional/optional/impl/tag.mjs +0 -4
- package/dist/functional/optional/impl/tag.mjs.map +0 -1
- package/dist/functional/optional/impl/types.d.mts +0 -24
- package/dist/functional/optional/impl/types.d.mts.map +0 -1
- package/dist/functional/optional/impl/types.mjs +0 -2
- package/dist/functional/optional/impl/types.mjs.map +0 -1
- package/dist/functional/optional/index.d.mts +0 -2
- package/dist/functional/optional/index.d.mts.map +0 -1
- package/dist/functional/optional/index.mjs +0 -2
- package/dist/functional/optional/index.mjs.map +0 -1
- package/dist/functional/optional/optional.d.mts +0 -16
- package/dist/functional/optional/optional.d.mts.map +0 -1
- package/dist/functional/optional/optional.mjs +0 -2
- package/dist/functional/optional/optional.mjs.map +0 -1
- package/dist/functional/pipe.d.mts +0 -102
- package/dist/functional/pipe.d.mts.map +0 -1
- package/dist/functional/pipe.mjs +0 -45
- package/dist/functional/pipe.mjs.map +0 -1
- package/dist/functional/result/impl/index.d.mts +0 -28
- package/dist/functional/result/impl/index.d.mts.map +0 -1
- package/dist/functional/result/impl/index.mjs +0 -28
- package/dist/functional/result/impl/index.mjs.map +0 -1
- package/dist/functional/result/impl/result-err.d.mts +0 -28
- package/dist/functional/result/impl/result-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-err.mjs +0 -31
- package/dist/functional/result/impl/result-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +0 -33
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +0 -23
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +0 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +0 -45
- package/dist/functional/result/impl/result-flat-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-flat-map.mjs +0 -21
- package/dist/functional/result/impl/result-flat-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-fold.d.mts +0 -50
- package/dist/functional/result/impl/result-fold.d.mts.map +0 -1
- package/dist/functional/result/impl/result-fold.mjs +0 -23
- package/dist/functional/result/impl/result-fold.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-optional.d.mts +0 -41
- package/dist/functional/result/impl/result-from-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-optional.mjs +0 -21
- package/dist/functional/result/impl/result-from-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +0 -43
- package/dist/functional/result/impl/result-from-promise.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-promise.mjs +0 -39
- package/dist/functional/result/impl/result-from-promise.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +0 -32
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +0 -46
- package/dist/functional/result/impl/result-from-throwable.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-err.d.mts +0 -23
- package/dist/functional/result/impl/result-is-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-err.mjs +0 -22
- package/dist/functional/result/impl/result-is-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +0 -23
- package/dist/functional/result/impl/result-is-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-ok.mjs +0 -22
- package/dist/functional/result/impl/result-is-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-result.d.mts +0 -22
- package/dist/functional/result/impl/result-is-result.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-result.mjs +0 -26
- package/dist/functional/result/impl/result-is-result.mjs.map +0 -1
- package/dist/functional/result/impl/result-map-err.d.mts +0 -39
- package/dist/functional/result/impl/result-map-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map-err.mjs +0 -22
- package/dist/functional/result/impl/result-map-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-map.d.mts +0 -39
- package/dist/functional/result/impl/result-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map.mjs +0 -22
- package/dist/functional/result/impl/result-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-match.d.mts +0 -47
- package/dist/functional/result/impl/result-match.d.mts.map +0 -1
- package/dist/functional/result/impl/result-match.mjs +0 -20
- package/dist/functional/result/impl/result-match.mjs.map +0 -1
- package/dist/functional/result/impl/result-ok.d.mts +0 -28
- package/dist/functional/result/impl/result-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-ok.mjs +0 -31
- package/dist/functional/result/impl/result-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-or-else.d.mts +0 -40
- package/dist/functional/result/impl/result-or-else.d.mts.map +0 -1
- package/dist/functional/result/impl/result-or-else.mjs +0 -17
- package/dist/functional/result/impl/result-or-else.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-try.d.mts +0 -51
- package/dist/functional/result/impl/result-safe-try.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-try.mjs +0 -35
- package/dist/functional/result/impl/result-safe-try.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.d.mts +0 -36
- package/dist/functional/result/impl/result-safe-unwrap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.mjs +0 -42
- package/dist/functional/result/impl/result-safe-unwrap.mjs.map +0 -1
- package/dist/functional/result/impl/result-swap.d.mts +0 -23
- package/dist/functional/result/impl/result-swap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-swap.mjs +0 -27
- package/dist/functional/result/impl/result-swap.mjs.map +0 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +0 -32
- package/dist/functional/result/impl/result-to-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-to-optional.mjs +0 -32
- package/dist/functional/result/impl/result-to-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +0 -46
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +0 -34
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +0 -26
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +0 -8
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +0 -40
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-zip.d.mts +0 -32
- package/dist/functional/result/impl/result-zip.d.mts.map +0 -1
- package/dist/functional/result/impl/result-zip.mjs +0 -37
- package/dist/functional/result/impl/result-zip.mjs.map +0 -1
- package/dist/functional/result/impl/tag.d.mts +0 -6
- package/dist/functional/result/impl/tag.d.mts.map +0 -1
- package/dist/functional/result/impl/tag.mjs +0 -4
- package/dist/functional/result/impl/tag.mjs.map +0 -1
- package/dist/functional/result/impl/types.d.mts +0 -31
- package/dist/functional/result/impl/types.d.mts.map +0 -1
- package/dist/functional/result/impl/types.mjs +0 -2
- package/dist/functional/result/impl/types.mjs.map +0 -1
- package/dist/functional/result/index.d.mts +0 -2
- package/dist/functional/result/index.d.mts.map +0 -1
- package/dist/functional/result/index.mjs +0 -2
- package/dist/functional/result/index.mjs.map +0 -1
- package/dist/functional/result/result.d.mts +0 -16
- package/dist/functional/result/result.d.mts.map +0 -1
- package/dist/functional/result/result.mjs +0 -2
- package/dist/functional/result/result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/index.d.mts +0 -29
- package/dist/functional/ternary-result/impl/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/index.mjs +0 -29
- package/dist/functional/ternary-result/impl/index.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/tag.d.mts +0 -8
- package/dist/functional/ternary-result/impl/tag.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/tag.mjs +0 -6
- package/dist/functional/ternary-result/impl/tag.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +0 -24
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +0 -39
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +0 -38
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +0 -27
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +0 -36
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +0 -32
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +0 -17
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +0 -29
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +0 -25
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +0 -10
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +0 -35
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +0 -52
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/types.d.mts +0 -26
- package/dist/functional/ternary-result/impl/types.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/types.mjs +0 -2
- package/dist/functional/ternary-result/impl/types.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts +0 -4
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +0 -13
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +0 -1
- package/dist/functional/ternary-result/index.d.mts +0 -2
- package/dist/functional/ternary-result/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/index.mjs +0 -2
- package/dist/functional/ternary-result/index.mjs.map +0 -1
- package/dist/functional/ternary-result/ternary-result.d.mts +0 -40
- package/dist/functional/ternary-result/ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/ternary-result.mjs +0 -2
- package/dist/functional/ternary-result/ternary-result.mjs.map +0 -1
- package/src/functional/async-result/async-result.mts +0 -17
- package/src/functional/async-result/impl/async-result-flat-map.mts +0 -99
- package/src/functional/async-result/impl/async-result-from-promise.mts +0 -69
- package/src/functional/async-result/impl/async-result-from-throwable.mts +0 -78
- package/src/functional/async-result/impl/async-result-map-err.mts +0 -84
- package/src/functional/async-result/impl/async-result-map.mts +0 -94
- package/src/functional/async-result/impl/async-result-unwrap-or.mts +0 -42
- package/src/functional/async-result/impl/index.mts +0 -7
- package/src/functional/async-result/impl/types.mts +0 -51
- package/src/functional/async-result/index.mts +0 -1
- package/src/functional/async-result.test.mts +0 -291
- package/src/functional/match.mts +0 -193
- package/src/functional/match.test.mts +0 -180
- package/src/functional/optional/impl/index.mts +0 -18
- package/src/functional/optional/impl/optional-expect-to-be.mts +0 -75
- package/src/functional/optional/impl/optional-filter.mts +0 -78
- package/src/functional/optional/impl/optional-flat-map.mts +0 -75
- package/src/functional/optional/impl/optional-from-nullable.mts +0 -31
- package/src/functional/optional/impl/optional-is-none.mts +0 -26
- package/src/functional/optional/impl/optional-is-optional.mts +0 -30
- package/src/functional/optional/impl/optional-is-some.mts +0 -27
- package/src/functional/optional/impl/optional-map.mts +0 -90
- package/src/functional/optional/impl/optional-match.mts +0 -108
- package/src/functional/optional/impl/optional-none.mts +0 -20
- package/src/functional/optional/impl/optional-or-else.mts +0 -83
- package/src/functional/optional/impl/optional-some.mts +0 -27
- package/src/functional/optional/impl/optional-to-nullable.mts +0 -34
- package/src/functional/optional/impl/optional-unwrap-or.mts +0 -70
- package/src/functional/optional/impl/optional-unwrap-throw.mts +0 -41
- package/src/functional/optional/impl/optional-unwrap.mts +0 -45
- package/src/functional/optional/impl/optional-zip.mts +0 -44
- package/src/functional/optional/impl/tag.mts +0 -8
- package/src/functional/optional/impl/types.mts +0 -31
- package/src/functional/optional/index.mts +0 -1
- package/src/functional/optional/optional.mts +0 -19
- package/src/functional/optional.test.mts +0 -883
- package/src/functional/pipe.mts +0 -180
- package/src/functional/pipe.test.mts +0 -155
- package/src/functional/result/impl/index.mts +0 -27
- package/src/functional/result/impl/result-err.mts +0 -33
- package/src/functional/result/impl/result-expect-to-be.mts +0 -73
- package/src/functional/result/impl/result-flat-map.mts +0 -88
- package/src/functional/result/impl/result-fold.mts +0 -102
- package/src/functional/result/impl/result-from-optional.mts +0 -80
- package/src/functional/result/impl/result-from-promise.mts +0 -51
- package/src/functional/result/impl/result-from-throwable.mts +0 -48
- package/src/functional/result/impl/result-is-err.mts +0 -26
- package/src/functional/result/impl/result-is-ok.mts +0 -26
- package/src/functional/result/impl/result-is-result.mts +0 -28
- package/src/functional/result/impl/result-map-err.mts +0 -96
- package/src/functional/result/impl/result-map.mts +0 -96
- package/src/functional/result/impl/result-match.mts +0 -108
- package/src/functional/result/impl/result-ok.mts +0 -33
- package/src/functional/result/impl/result-or-else.mts +0 -73
- package/src/functional/result/impl/result-safe-try.mts +0 -110
- package/src/functional/result/impl/result-safe-unwrap.mts +0 -50
- package/src/functional/result/impl/result-swap.mts +0 -31
- package/src/functional/result/impl/result-to-optional.mts +0 -37
- package/src/functional/result/impl/result-unwrap-err-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-err-throw.mts +0 -56
- package/src/functional/result/impl/result-unwrap-err.mts +0 -38
- package/src/functional/result/impl/result-unwrap-ok-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-ok.mts +0 -39
- package/src/functional/result/impl/result-unwrap-throw.mts +0 -46
- package/src/functional/result/impl/result-zip.mts +0 -42
- package/src/functional/result/impl/tag.mts +0 -8
- package/src/functional/result/impl/types.mts +0 -38
- package/src/functional/result/index.mts +0 -1
- package/src/functional/result/result.mts +0 -19
- package/src/functional/result.test.mts +0 -1349
- package/src/functional/ternary-result/impl/index.mts +0 -28
- package/src/functional/ternary-result/impl/tag.mts +0 -17
- package/src/functional/ternary-result/impl/ternary-result-err.mts +0 -21
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +0 -65
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +0 -112
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +0 -102
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +0 -30
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +0 -36
- package/src/functional/ternary-result/impl/ternary-result-is-err.mts +0 -24
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +0 -26
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +0 -32
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +0 -74
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +0 -79
- package/src/functional/ternary-result/impl/ternary-result-map.mts +0 -95
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +0 -22
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +0 -72
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +0 -31
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +0 -54
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +0 -42
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +0 -51
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +0 -39
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +0 -40
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +0 -28
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +0 -61
- package/src/functional/ternary-result/impl/types.mts +0 -46
- package/src/functional/ternary-result/impl/variant-name.mts +0 -18
- package/src/functional/ternary-result/index.mts +0 -1
- package/src/functional/ternary-result/ternary-result.mts +0 -50
- package/src/functional/ternary-result.test.mts +0 -310
- package/src/guard/has-key.test.mts +0 -111
- package/src/guard/is-non-null-object.test.mts +0 -109
- package/src/guard/is-record.test.mts +0 -195
- package/src/guard/key-is-in.test.mts +0 -21
- package/src/others/unknown-to-string.test.mts +0 -295
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export * from './ternary-result-err.mjs';
|
|
2
|
-
export * from './ternary-result-expect-to-be.mjs';
|
|
3
|
-
export * from './ternary-result-flat-map.mjs';
|
|
4
|
-
export * from './ternary-result-fold.mjs';
|
|
5
|
-
export * from './ternary-result-from-promise.mjs';
|
|
6
|
-
export * from './ternary-result-from-throwable.mjs';
|
|
7
|
-
export * from './ternary-result-is-err.mjs';
|
|
8
|
-
export * from './ternary-result-is-ok.mjs';
|
|
9
|
-
export * from './ternary-result-is-ternary-result.mjs';
|
|
10
|
-
export * from './ternary-result-is-warn.mjs';
|
|
11
|
-
export * from './ternary-result-map-err.mjs';
|
|
12
|
-
export * from './ternary-result-map-warn.mjs';
|
|
13
|
-
export * from './ternary-result-map.mjs';
|
|
14
|
-
export * from './ternary-result-ok.mjs';
|
|
15
|
-
export * from './ternary-result-or-else.mjs';
|
|
16
|
-
export * from './ternary-result-to-optional.mjs';
|
|
17
|
-
export * from './ternary-result-unwrap-err-or.mjs';
|
|
18
|
-
export * from './ternary-result-unwrap-err-throw.mjs';
|
|
19
|
-
export * from './ternary-result-unwrap-err.mjs';
|
|
20
|
-
export * from './ternary-result-unwrap-ok-or.mjs';
|
|
21
|
-
export * from './ternary-result-unwrap-ok.mjs';
|
|
22
|
-
export * from './ternary-result-unwrap-throw.mjs';
|
|
23
|
-
export * from './ternary-result-unwrap-warn-or.mjs';
|
|
24
|
-
export * from './ternary-result-unwrap-warn-throw.mjs';
|
|
25
|
-
export * from './ternary-result-unwrap-warn.mjs';
|
|
26
|
-
export * from './ternary-result-warn.mjs';
|
|
27
|
-
export * from './ternary-result-zip.mjs';
|
|
28
|
-
export * from './types.mjs';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** @internal Tag identifying the Ok variant. */
|
|
2
|
-
import {
|
|
3
|
-
type TernaryErr,
|
|
4
|
-
type TernaryOk,
|
|
5
|
-
type TernaryWarn,
|
|
6
|
-
} from '../ternary-result.mjs';
|
|
7
|
-
|
|
8
|
-
export const OkTypeTagName: TernaryOk<unknown>['$$tag'] =
|
|
9
|
-
'ts-data-forge::Result.ok';
|
|
10
|
-
|
|
11
|
-
/** @internal Tag identifying the Warn variant. */
|
|
12
|
-
export const WarnTypeTagName: TernaryWarn<unknown, unknown>['$$tag'] =
|
|
13
|
-
'ts-data-forge::Result.warn';
|
|
14
|
-
|
|
15
|
-
/** @internal Tag identifying the Err variant. */
|
|
16
|
-
export const ErrTypeTagName: TernaryErr<unknown>['$$tag'] =
|
|
17
|
-
'ts-data-forge::Result.err';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type TernaryErr } from '../ternary-result.mjs';
|
|
2
|
-
import { ErrTypeTagName } from './tag.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a `TernaryResult.Err` containing the provided error value.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* const failure = TernaryResult.err(new Error('missing data'));
|
|
11
|
-
*
|
|
12
|
-
* assert.strictEqual(failure.$$tag, 'ts-data-forge::Result.err');
|
|
13
|
-
*
|
|
14
|
-
* assert.isTrue(TernaryResult.isErr(failure));
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export const err = <const E,>(value: E): TernaryErr<E> =>
|
|
18
|
-
({
|
|
19
|
-
$$tag: ErrTypeTagName,
|
|
20
|
-
value,
|
|
21
|
-
}) as const;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TernaryResult,
|
|
3
|
-
type UnknownTernaryResult,
|
|
4
|
-
} from '../ternary-result.mjs';
|
|
5
|
-
import { isOk } from './ternary-result-is-ok.mjs';
|
|
6
|
-
import { unwrapOk } from './ternary-result-unwrap-ok.mjs';
|
|
7
|
-
import { type UnwrapOk } from './types.mjs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Unwraps the Ok value or throws with the provided message.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const okValue = TernaryResult.ok('ready');
|
|
16
|
-
*
|
|
17
|
-
* assert.strictEqual(TernaryResult.expectToBe(okValue, 'missing'), 'ready');
|
|
18
|
-
*
|
|
19
|
-
* const expectResult = TernaryResult.expectToBe('needs value');
|
|
20
|
-
*
|
|
21
|
-
* const throwTest = (): void => {
|
|
22
|
-
* expectResult(TernaryResult.err('oops'));
|
|
23
|
-
* };
|
|
24
|
-
*
|
|
25
|
-
* assert.throws(throwTest, /needs value/u);
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export function expectToBe<R extends UnknownTernaryResult>(
|
|
29
|
-
result: R,
|
|
30
|
-
message: string,
|
|
31
|
-
): UnwrapOk<R>;
|
|
32
|
-
|
|
33
|
-
// Curried version
|
|
34
|
-
export function expectToBe(
|
|
35
|
-
message: string,
|
|
36
|
-
): <S, W, E>(result: TernaryResult<S, E, W>) => S;
|
|
37
|
-
|
|
38
|
-
export function expectToBe<R extends UnknownTernaryResult>(
|
|
39
|
-
...args: readonly [result: R, message: string] | readonly [message: string]
|
|
40
|
-
): UnwrapOk<R> | ((result: R) => UnwrapOk<R>) {
|
|
41
|
-
switch (args.length) {
|
|
42
|
-
case 2: {
|
|
43
|
-
const [result, message] = args;
|
|
44
|
-
|
|
45
|
-
return expectImpl(result, message);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
case 1: {
|
|
49
|
-
const [message] = args;
|
|
50
|
-
|
|
51
|
-
return (result: R) => expectImpl(result, message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const expectImpl = <R extends UnknownTernaryResult>(
|
|
57
|
-
result: R,
|
|
58
|
-
message: string,
|
|
59
|
-
): UnwrapOk<R> => {
|
|
60
|
-
if (isOk(result)) {
|
|
61
|
-
return unwrapOk(result);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
throw new Error(message);
|
|
65
|
-
};
|
|
@@ -1,112 +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 { warn } from './ternary-result-warn.mjs';
|
|
9
|
-
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Applies a function returning a `TernaryResult` to the Ok variant.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* const parse = (value: string): TernaryResult<number, string, string> =>
|
|
18
|
-
* pipe(Num.safeParseFloat(value)).map((result) =>
|
|
19
|
-
* Result.isErr(result)
|
|
20
|
-
* ? TernaryResult.err('NaN')
|
|
21
|
-
* : TernaryResult.ok(result.value),
|
|
22
|
-
* ).value;
|
|
23
|
-
*
|
|
24
|
-
* const doubled = TernaryResult.flatMap(TernaryResult.ok('3'), (text) =>
|
|
25
|
-
* TernaryResult.map(parse(text), (num) => num * 2),
|
|
26
|
-
* );
|
|
27
|
-
*
|
|
28
|
-
* const warnPassthrough = TernaryResult.flatMap(
|
|
29
|
-
* TernaryResult.warn('3', 'retry'),
|
|
30
|
-
* parse,
|
|
31
|
-
* );
|
|
32
|
-
*
|
|
33
|
-
* const errPassthrough = TernaryResult.flatMap(
|
|
34
|
-
* TernaryResult.err('oops'),
|
|
35
|
-
* parse,
|
|
36
|
-
* );
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(doubled, TernaryResult.ok(6));
|
|
39
|
-
*
|
|
40
|
-
* assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(3, 'retry'));
|
|
41
|
-
*
|
|
42
|
-
* assert.deepStrictEqual(errPassthrough, TernaryResult.err('oops'));
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export function flatMap<R extends UnknownTernaryResult, S2, W2, E2>(
|
|
46
|
-
result: R,
|
|
47
|
-
flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>,
|
|
48
|
-
): TernaryResult<S2, E2 | UnwrapErr<R>, W2 | UnwrapWarn<R>>;
|
|
49
|
-
|
|
50
|
-
// Curried version
|
|
51
|
-
export function flatMap<S, S2, W2, E2>(
|
|
52
|
-
flatMapFn: (value: S) => TernaryResult<S2, E2, W2>,
|
|
53
|
-
): <W, E>(result: TernaryResult<S, E, W>) => TernaryResult<S2, E | E2, W | W2>;
|
|
54
|
-
|
|
55
|
-
export function flatMap<R extends UnknownTernaryResult, S2, W2, E2>(
|
|
56
|
-
...args:
|
|
57
|
-
| readonly [
|
|
58
|
-
result: R,
|
|
59
|
-
flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>,
|
|
60
|
-
]
|
|
61
|
-
| readonly [flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>]
|
|
62
|
-
):
|
|
63
|
-
| TernaryResult<S2, E2 | UnwrapErr<R>, W2 | UnwrapWarn<R>>
|
|
64
|
-
| ((result: R) => TernaryResult<S2, UnwrapErr<R> | E2, UnwrapWarn<R> | W2>) {
|
|
65
|
-
switch (args.length) {
|
|
66
|
-
case 2: {
|
|
67
|
-
const [result, flatMapFn] = args;
|
|
68
|
-
|
|
69
|
-
return flatMapImpl(result, flatMapFn);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
case 1: {
|
|
73
|
-
const [flatMapFn] = args;
|
|
74
|
-
|
|
75
|
-
return (result: R) => flatMapImpl(result, flatMapFn);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const flatMapImpl = <R extends UnknownTernaryResult, S2, W2, E2>(
|
|
81
|
-
result: R,
|
|
82
|
-
flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>,
|
|
83
|
-
): TernaryResult<S2, E2 | UnwrapErr<R>, W2 | UnwrapWarn<R>> => {
|
|
84
|
-
if (isOk(result)) {
|
|
85
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
86
|
-
return flatMapFn(result.value as UnwrapOk<R>);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (isWarn(result)) {
|
|
90
|
-
const next = flatMapFn(
|
|
91
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
92
|
-
result.value as UnwrapOk<R>,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
if (isOk(next)) {
|
|
96
|
-
return warn(
|
|
97
|
-
next.value,
|
|
98
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
99
|
-
result.warning as UnwrapWarn<R>,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (isWarn(next)) {
|
|
104
|
-
return warn(next.value, next.warning satisfies W2 | UnwrapWarn<R>);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return next;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
111
|
-
return result as TernaryErr<E2 | UnwrapErr<R>>;
|
|
112
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TernaryResult,
|
|
3
|
-
type UnknownTernaryResult,
|
|
4
|
-
} from '../ternary-result.mjs';
|
|
5
|
-
import { err } from './ternary-result-err.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
|
-
* Applies the provided mapper based on the current variant.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const okFold = TernaryResult.fold(
|
|
19
|
-
* TernaryResult.ok(2),
|
|
20
|
-
* (value) => value * 2,
|
|
21
|
-
* (warn: string) => warn.length,
|
|
22
|
-
* (error: string) => error.toUpperCase(),
|
|
23
|
-
* );
|
|
24
|
-
*
|
|
25
|
-
* const warnFold = TernaryResult.fold(
|
|
26
|
-
* TernaryResult.warn(2, 'spike'),
|
|
27
|
-
* (value: number) => value,
|
|
28
|
-
* (warn: string) => warn.toUpperCase(),
|
|
29
|
-
* (error: string) => error,
|
|
30
|
-
* );
|
|
31
|
-
*
|
|
32
|
-
* assert.deepStrictEqual(okFold, TernaryResult.ok(4));
|
|
33
|
-
*
|
|
34
|
-
* assert.deepStrictEqual(warnFold, TernaryResult.warn(2, 'SPIKE'));
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export function fold<R extends UnknownTernaryResult, S2, W2, E2>(
|
|
38
|
-
result: R,
|
|
39
|
-
mapOk: (value: UnwrapOk<R>) => S2,
|
|
40
|
-
mapWarn: (value: UnwrapWarn<R>) => W2,
|
|
41
|
-
mapErr: (error: UnwrapErr<R>) => E2,
|
|
42
|
-
): TernaryResult<S2, E2, W2>;
|
|
43
|
-
|
|
44
|
-
// Curried version
|
|
45
|
-
export function fold<S, W, E, S2, W2, E2>(
|
|
46
|
-
mapOk: (value: S) => S2,
|
|
47
|
-
mapWarn: (value: W) => W2,
|
|
48
|
-
mapErr: (error: E) => E2,
|
|
49
|
-
): (result: TernaryResult<S, E, W>) => TernaryResult<S2, E2, W2>;
|
|
50
|
-
|
|
51
|
-
export function fold<R extends UnknownTernaryResult, S2, W2, E2>(
|
|
52
|
-
...args:
|
|
53
|
-
| readonly [
|
|
54
|
-
result: R,
|
|
55
|
-
mapOk: (value: UnwrapOk<R>) => S2,
|
|
56
|
-
mapWarn: (value: UnwrapWarn<R>) => W2,
|
|
57
|
-
mapErr: (error: UnwrapErr<R>) => E2,
|
|
58
|
-
]
|
|
59
|
-
| readonly [
|
|
60
|
-
mapOk: (value: UnwrapOk<R>) => S2,
|
|
61
|
-
mapWarn: (value: UnwrapWarn<R>) => W2,
|
|
62
|
-
mapErr: (error: UnwrapErr<R>) => E2,
|
|
63
|
-
]
|
|
64
|
-
): TernaryResult<S2, E2, W2> | ((result: R) => TernaryResult<S2, E2, W2>) {
|
|
65
|
-
switch (args.length) {
|
|
66
|
-
case 4: {
|
|
67
|
-
const [result, mapOk, mapWarn, mapErr] = args;
|
|
68
|
-
|
|
69
|
-
return foldImpl(result, mapOk, mapWarn, mapErr);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
case 3: {
|
|
73
|
-
const [mapOk, mapWarn, mapErr] = args;
|
|
74
|
-
|
|
75
|
-
return (result: R) => foldImpl(result, mapOk, mapWarn, mapErr);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const foldImpl = <R extends UnknownTernaryResult, S2, W2, E2>(
|
|
81
|
-
result: R,
|
|
82
|
-
mapOk: (value: UnwrapOk<R>) => S2,
|
|
83
|
-
mapWarnFn: (warning: UnwrapWarn<R>) => W2,
|
|
84
|
-
mapErrFn: (error: UnwrapErr<R>) => E2,
|
|
85
|
-
): TernaryResult<S2, E2, W2> => {
|
|
86
|
-
if (isOk(result)) {
|
|
87
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
88
|
-
return ok(mapOk(result.value as UnwrapOk<R>));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (isWarn(result)) {
|
|
92
|
-
return warn(
|
|
93
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
94
|
-
mapOk(result.value as UnwrapOk<R>),
|
|
95
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
96
|
-
mapWarnFn(result.warning as UnwrapWarn<R>),
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
101
|
-
return err(mapErrFn(result.value as UnwrapErr<R>));
|
|
102
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type TernaryOk, type TernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { err } from './ternary-result-err.mjs';
|
|
3
|
-
import { ok } from './ternary-result-ok.mjs';
|
|
4
|
-
|
|
5
|
-
/** @internal Utility type extracting the resolved value from a Promise. */
|
|
6
|
-
type UnwrapPromise<P extends Promise<unknown>> =
|
|
7
|
-
P extends Promise<infer V> ? V : never;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Converts a Promise into a Promise that resolves to a `TernaryResult`.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const resolved = await TernaryResult.fromPromise(Promise.resolve('ok'));
|
|
16
|
-
*
|
|
17
|
-
* const rejected = await TernaryResult.fromPromise(
|
|
18
|
-
* Promise.reject(new Error('fail')),
|
|
19
|
-
* );
|
|
20
|
-
*
|
|
21
|
-
* assert.deepStrictEqual(resolved, TernaryResult.ok('ok'));
|
|
22
|
-
*
|
|
23
|
-
* assert.isTrue(TernaryResult.isErr(rejected));
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export const fromPromise = <P extends Promise<unknown>>(
|
|
27
|
-
promise: P,
|
|
28
|
-
): Promise<TernaryResult<UnwrapPromise<P>, unknown, never>> =>
|
|
29
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
30
|
-
promise.then((value) => ok(value) as TernaryOk<UnwrapPromise<P>>).catch(err);
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { isError } from '@sindresorhus/is';
|
|
2
|
-
import { unknownToString } from '../../../others/index.mjs';
|
|
3
|
-
import { type TernaryResult } from '../ternary-result.mjs';
|
|
4
|
-
import { err } from './ternary-result-err.mjs';
|
|
5
|
-
import { ok } from './ternary-result-ok.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Wraps a potentially-throwing function in a `TernaryResult`.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const success = TernaryResult.fromThrowable(() => 1 + 1);
|
|
14
|
-
*
|
|
15
|
-
* const failure = TernaryResult.fromThrowable(() => {
|
|
16
|
-
* throw new Error('boom');
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* assert.deepStrictEqual(success, TernaryResult.ok(2));
|
|
20
|
-
*
|
|
21
|
-
* assert.isTrue(TernaryResult.isErr(failure));
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const fromThrowable = <T,>(
|
|
25
|
-
fn: () => T,
|
|
26
|
-
): TernaryResult<T, Error, never> => {
|
|
27
|
-
try {
|
|
28
|
-
return ok(fn());
|
|
29
|
-
} catch (error) {
|
|
30
|
-
if (isError(error)) {
|
|
31
|
-
return err(error);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return err(new Error(unknownToString(error)));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { ErrTypeTagName } from './tag.mjs';
|
|
3
|
-
import { type NarrowToErr } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Type guard for the Err variant.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const maybeErr = TernaryResult.err('boom') as TernaryResult<
|
|
12
|
-
* number,
|
|
13
|
-
* string,
|
|
14
|
-
* string
|
|
15
|
-
* >;
|
|
16
|
-
*
|
|
17
|
-
* if (TernaryResult.isErr(maybeErr)) {
|
|
18
|
-
* assert.strictEqual(maybeErr.value, 'boom');
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export const isErr = <R extends UnknownTernaryResult>(
|
|
23
|
-
result: R,
|
|
24
|
-
): result is NarrowToErr<R> => result.$$tag === ErrTypeTagName;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { OkTypeTagName } from './tag.mjs';
|
|
3
|
-
import { type NarrowToOk } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Type guard for the Ok variant.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const maybeNumber = TernaryResult.ok(42) as TernaryResult<
|
|
12
|
-
* number,
|
|
13
|
-
* string,
|
|
14
|
-
* string
|
|
15
|
-
* >;
|
|
16
|
-
*
|
|
17
|
-
* if (TernaryResult.isOk(maybeNumber)) {
|
|
18
|
-
* const value: number = maybeNumber.value;
|
|
19
|
-
*
|
|
20
|
-
* assert.strictEqual(value, 42);
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const isOk = <R extends UnknownTernaryResult>(
|
|
25
|
-
result: R,
|
|
26
|
-
): result is NarrowToOk<R> => result.$$tag === OkTypeTagName;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { hasKey, isRecord } from '../../../guard/index.mjs';
|
|
2
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
3
|
-
import { ErrTypeTagName, OkTypeTagName, WarnTypeTagName } from './tag.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Checks whether the provided value is a {@link TernaryResult}.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const okValue = TernaryResult.ok('done');
|
|
12
|
-
*
|
|
13
|
-
* const warnValue = TernaryResult.warn('done', 'retry later');
|
|
14
|
-
*
|
|
15
|
-
* const notResult = { $$tag: 'ts-data-forge::Result.ok' } as const;
|
|
16
|
-
*
|
|
17
|
-
* assert.isTrue(TernaryResult.isTernaryResult(okValue));
|
|
18
|
-
*
|
|
19
|
-
* assert.isTrue(TernaryResult.isTernaryResult(warnValue));
|
|
20
|
-
*
|
|
21
|
-
* assert.isFalse(TernaryResult.isTernaryResult(notResult));
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const isTernaryResult = (
|
|
25
|
-
maybeResult: unknown,
|
|
26
|
-
): maybeResult is UnknownTernaryResult =>
|
|
27
|
-
isRecord(maybeResult) &&
|
|
28
|
-
hasKey(maybeResult, '$$tag') &&
|
|
29
|
-
hasKey(maybeResult, 'value') &&
|
|
30
|
-
((maybeResult.$$tag === WarnTypeTagName && hasKey(maybeResult, 'warning')) ||
|
|
31
|
-
maybeResult.$$tag === OkTypeTagName ||
|
|
32
|
-
maybeResult.$$tag === ErrTypeTagName);
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { WarnTypeTagName } from './tag.mjs';
|
|
3
|
-
import { type NarrowToWarn } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Type guard for the Warn variant.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const maybeWarn = TernaryResult.warn(
|
|
12
|
-
* 'value',
|
|
13
|
-
* 'check logs',
|
|
14
|
-
* ) as TernaryResult<string, string, string>;
|
|
15
|
-
*
|
|
16
|
-
* if (TernaryResult.isWarn(maybeWarn)) {
|
|
17
|
-
* assert.strictEqual(maybeWarn.value, 'value');
|
|
18
|
-
*
|
|
19
|
-
* assert.strictEqual(maybeWarn.warning, 'check logs');
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export const isWarn = <R extends UnknownTernaryResult>(
|
|
24
|
-
result: R,
|
|
25
|
-
): result is NarrowToWarn<R> => result.$$tag === WarnTypeTagName;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TernaryResult,
|
|
3
|
-
type UnknownTernaryResult,
|
|
4
|
-
} from '../ternary-result.mjs';
|
|
5
|
-
import { err } from './ternary-result-err.mjs';
|
|
6
|
-
import { isErr } from './ternary-result-is-err.mjs';
|
|
7
|
-
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Maps the Err variant while leaving Ok/Warn untouched.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const errValue = TernaryResult.err('boom');
|
|
16
|
-
*
|
|
17
|
-
* const mappedErr = TernaryResult.mapErr(errValue, (error) =>
|
|
18
|
-
* error.toUpperCase(),
|
|
19
|
-
* );
|
|
20
|
-
*
|
|
21
|
-
* const warnPassthrough = TernaryResult.mapErr(
|
|
22
|
-
* TernaryResult.warn(2, 'slow'),
|
|
23
|
-
* (error: string) => `${error}!`,
|
|
24
|
-
* );
|
|
25
|
-
*
|
|
26
|
-
* assert.deepStrictEqual(mappedErr, TernaryResult.err('BOOM'));
|
|
27
|
-
*
|
|
28
|
-
* assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(2, 'slow'));
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export function mapErr<R extends UnknownTernaryResult, E2>(
|
|
32
|
-
result: R,
|
|
33
|
-
mapFn: (error: UnwrapErr<R>) => E2,
|
|
34
|
-
): TernaryResult<UnwrapOk<R>, E2, UnwrapWarn<R>>;
|
|
35
|
-
|
|
36
|
-
// Curried version
|
|
37
|
-
export function mapErr<E, E2>(
|
|
38
|
-
mapFn: (error: E) => E2,
|
|
39
|
-
): <S, W>(result: TernaryResult<S, E, W>) => TernaryResult<S, E2, W>;
|
|
40
|
-
|
|
41
|
-
export function mapErr<R extends UnknownTernaryResult, E2>(
|
|
42
|
-
...args:
|
|
43
|
-
| readonly [result: R, mapFn: (error: UnwrapErr<R>) => E2]
|
|
44
|
-
| readonly [mapFn: (error: UnwrapErr<R>) => E2]
|
|
45
|
-
):
|
|
46
|
-
| TernaryResult<UnwrapOk<R>, E2, UnwrapWarn<R>>
|
|
47
|
-
| ((result: R) => TernaryResult<UnwrapOk<R>, E2, UnwrapWarn<R>>) {
|
|
48
|
-
switch (args.length) {
|
|
49
|
-
case 2: {
|
|
50
|
-
const [result, mapFn] = args;
|
|
51
|
-
|
|
52
|
-
return mapErrImpl(result, mapFn);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
case 1: {
|
|
56
|
-
const [mapFn] = args;
|
|
57
|
-
|
|
58
|
-
return (result: R) => mapErrImpl(result, mapFn);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const mapErrImpl = <R extends UnknownTernaryResult, E2>(
|
|
64
|
-
result: R,
|
|
65
|
-
mapFn: (error: UnwrapErr<R>) => E2,
|
|
66
|
-
): TernaryResult<UnwrapOk<R>, E2, UnwrapWarn<R>> => {
|
|
67
|
-
if (isErr(result)) {
|
|
68
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
69
|
-
return err(mapFn(result.value as UnwrapErr<R>));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
73
|
-
return result as TernaryResult<UnwrapOk<R>, E2, UnwrapWarn<R>>;
|
|
74
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TernaryResult,
|
|
3
|
-
type UnknownTernaryResult,
|
|
4
|
-
} from '../ternary-result.mjs';
|
|
5
|
-
import { isWarn } from './ternary-result-is-warn.mjs';
|
|
6
|
-
import { warn } from './ternary-result-warn.mjs';
|
|
7
|
-
import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Maps the Warn variant while leaving Ok/Err untouched.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const warnValue = TernaryResult.warn(2, 'slow');
|
|
16
|
-
*
|
|
17
|
-
* const mappedWarn = TernaryResult.mapWarn(
|
|
18
|
-
* warnValue,
|
|
19
|
-
* (warning) => `${warning}!`,
|
|
20
|
-
* );
|
|
21
|
-
*
|
|
22
|
-
* const okPassthrough = TernaryResult.mapWarn(
|
|
23
|
-
* TernaryResult.ok(3),
|
|
24
|
-
* (value: number) => value * 2,
|
|
25
|
-
* );
|
|
26
|
-
*
|
|
27
|
-
* assert.deepStrictEqual(mappedWarn, TernaryResult.warn(2, 'slow!'));
|
|
28
|
-
*
|
|
29
|
-
* assert.deepStrictEqual(okPassthrough, TernaryResult.ok(3));
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export function mapWarn<R extends UnknownTernaryResult, W2>(
|
|
33
|
-
result: R,
|
|
34
|
-
mapFn: (warning: UnwrapWarn<R>) => W2,
|
|
35
|
-
): TernaryResult<UnwrapOk<R>, UnwrapErr<R>, W2>;
|
|
36
|
-
|
|
37
|
-
// Curried version
|
|
38
|
-
export function mapWarn<W, W2>(
|
|
39
|
-
mapFn: (warning: W) => W2,
|
|
40
|
-
): <S, E>(result: TernaryResult<S, E, W>) => TernaryResult<S, E, W2>;
|
|
41
|
-
|
|
42
|
-
export function mapWarn<R extends UnknownTernaryResult, W2>(
|
|
43
|
-
...args:
|
|
44
|
-
| readonly [result: R, mapFn: (warning: UnwrapWarn<R>) => W2]
|
|
45
|
-
| readonly [mapFn: (warning: UnwrapWarn<R>) => W2]
|
|
46
|
-
):
|
|
47
|
-
| TernaryResult<UnwrapOk<R>, UnwrapErr<R>, W2>
|
|
48
|
-
| ((result: R) => TernaryResult<UnwrapOk<R>, UnwrapErr<R>, W2>) {
|
|
49
|
-
switch (args.length) {
|
|
50
|
-
case 2: {
|
|
51
|
-
const [result, mapFn] = args;
|
|
52
|
-
|
|
53
|
-
return mapWarnImpl(result, mapFn);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
case 1: {
|
|
57
|
-
const [mapFn] = args;
|
|
58
|
-
|
|
59
|
-
return (result: R) => mapWarnImpl(result, mapFn);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const mapWarnImpl = <R extends UnknownTernaryResult, W2>(
|
|
65
|
-
result: R,
|
|
66
|
-
mapFn: (warning: UnwrapWarn<R>) => W2,
|
|
67
|
-
): TernaryResult<UnwrapOk<R>, UnwrapErr<R>, W2> => {
|
|
68
|
-
if (isWarn(result)) {
|
|
69
|
-
return warn(
|
|
70
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
71
|
-
result.value as UnwrapOk<R>,
|
|
72
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
73
|
-
mapFn(result.warning as UnwrapWarn<R>),
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
78
|
-
return result as TernaryResult<UnwrapOk<R>, UnwrapErr<R>, W2>;
|
|
79
|
-
};
|