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,180 +0,0 @@
|
|
|
1
|
-
import { expectType } from '../expect-type.mjs';
|
|
2
|
-
import { match } from './match.mjs';
|
|
3
|
-
|
|
4
|
-
describe(match, () => {
|
|
5
|
-
type Direction = 'E' | 'N' | 'S' | 'W';
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
8
|
-
const direction: Direction = 'N' as Direction;
|
|
9
|
-
|
|
10
|
-
test('literal union', () => {
|
|
11
|
-
const res = match(direction, {
|
|
12
|
-
E: 2,
|
|
13
|
-
N: 3,
|
|
14
|
-
S: 4,
|
|
15
|
-
W: 5,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expectType<typeof res, 2 | 3 | 4 | 5>('=');
|
|
19
|
-
|
|
20
|
-
expect(res).toBe(3);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('Literal union with missing key - requires default', () => {
|
|
24
|
-
const res = match(
|
|
25
|
-
direction,
|
|
26
|
-
{
|
|
27
|
-
E: 2,
|
|
28
|
-
S: 4,
|
|
29
|
-
W: 5,
|
|
30
|
-
},
|
|
31
|
-
999,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
expectType<typeof res, 2 | 4 | 5 | 999>('=');
|
|
35
|
-
|
|
36
|
-
expect(res).toBe(999);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('Literal union with missing key - 2-arg form should cause type error', () => {
|
|
40
|
-
// @ts-expect-error Cannot use 2-argument form when not all cases are covered
|
|
41
|
-
const res = match(direction, {
|
|
42
|
-
E: 2,
|
|
43
|
-
S: 4,
|
|
44
|
-
W: 5,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expectType<typeof res, unknown>('=');
|
|
48
|
-
|
|
49
|
-
expect(res).toBeUndefined();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('Missing key cases with string - requires default', () => {
|
|
53
|
-
const res = match(
|
|
54
|
-
direction as string,
|
|
55
|
-
{
|
|
56
|
-
E: 2,
|
|
57
|
-
S: 4,
|
|
58
|
-
W: 5,
|
|
59
|
-
},
|
|
60
|
-
'default',
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expectType<typeof res, 2 | 4 | 5 | 'default'>('=');
|
|
64
|
-
|
|
65
|
-
expect(res).toBe('default');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('String type always requires default even with all keys', () => {
|
|
69
|
-
const res = match(
|
|
70
|
-
direction as string,
|
|
71
|
-
{
|
|
72
|
-
E: 2,
|
|
73
|
-
N: 3,
|
|
74
|
-
S: 4,
|
|
75
|
-
W: 5,
|
|
76
|
-
},
|
|
77
|
-
'default',
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
expectType<typeof res, 2 | 3 | 4 | 5 | 'default'>('=');
|
|
81
|
-
|
|
82
|
-
expect(res).toBe(3);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('A case with excess properties', () => {
|
|
86
|
-
// @ts-expect-error excess properties
|
|
87
|
-
const res = match(direction, {
|
|
88
|
-
E: 2,
|
|
89
|
-
N: 3,
|
|
90
|
-
S: 4,
|
|
91
|
-
W: 5,
|
|
92
|
-
X: 0,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
expectType<typeof res, 2 | 3 | 4 | 5>('=');
|
|
96
|
-
|
|
97
|
-
expect(res).toBe(3);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('with default case - all keys present should cause type error', () => {
|
|
101
|
-
const res = match(
|
|
102
|
-
direction,
|
|
103
|
-
{
|
|
104
|
-
E: 2,
|
|
105
|
-
N: 3,
|
|
106
|
-
S: 4,
|
|
107
|
-
W: 5,
|
|
108
|
-
},
|
|
109
|
-
// @ts-expect-error When all cases are covered, default value should not be allowed
|
|
110
|
-
999,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(res).toBe(3);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('all keys present without default - should work correctly', () => {
|
|
117
|
-
const res = match(direction, {
|
|
118
|
-
E: 2,
|
|
119
|
-
N: 3,
|
|
120
|
-
S: 4,
|
|
121
|
-
W: 5,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
expectType<typeof res, 2 | 3 | 4 | 5>('=');
|
|
125
|
-
|
|
126
|
-
expect(res).toBe(3);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('with default case - missing key', () => {
|
|
130
|
-
const res = match(
|
|
131
|
-
direction,
|
|
132
|
-
{
|
|
133
|
-
E: 2,
|
|
134
|
-
S: 4,
|
|
135
|
-
W: 5,
|
|
136
|
-
},
|
|
137
|
-
999,
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
expectType<typeof res, 2 | 4 | 5 | 999>('=');
|
|
141
|
-
|
|
142
|
-
expect(res).toBe(999);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test('with default case - string key', () => {
|
|
146
|
-
const res = match(
|
|
147
|
-
direction as string,
|
|
148
|
-
{
|
|
149
|
-
E: 2,
|
|
150
|
-
N: 3,
|
|
151
|
-
S: 4,
|
|
152
|
-
W: 5,
|
|
153
|
-
},
|
|
154
|
-
'default',
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
expectType<typeof res, 2 | 3 | 4 | 5 | 'default'>('=');
|
|
158
|
-
|
|
159
|
-
expect(res).toBe(3);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('with default case - string key missing', () => {
|
|
163
|
-
const unknownDirection = 'X' as string;
|
|
164
|
-
|
|
165
|
-
const res = match(
|
|
166
|
-
unknownDirection,
|
|
167
|
-
{
|
|
168
|
-
E: 2,
|
|
169
|
-
N: 3,
|
|
170
|
-
S: 4,
|
|
171
|
-
W: 5,
|
|
172
|
-
},
|
|
173
|
-
'default',
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
expectType<typeof res, 2 | 3 | 4 | 5 | 'default'>('=');
|
|
177
|
-
|
|
178
|
-
expect(res).toBe('default');
|
|
179
|
-
});
|
|
180
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export * from './optional-expect-to-be.mjs';
|
|
2
|
-
export * from './optional-filter.mjs';
|
|
3
|
-
export * from './optional-flat-map.mjs';
|
|
4
|
-
export * from './optional-from-nullable.mjs';
|
|
5
|
-
export * from './optional-is-none.mjs';
|
|
6
|
-
export * from './optional-is-optional.mjs';
|
|
7
|
-
export * from './optional-is-some.mjs';
|
|
8
|
-
export * from './optional-map.mjs';
|
|
9
|
-
export * from './optional-match.mjs';
|
|
10
|
-
export * from './optional-none.mjs';
|
|
11
|
-
export * from './optional-or-else.mjs';
|
|
12
|
-
export * from './optional-some.mjs';
|
|
13
|
-
export * from './optional-to-nullable.mjs';
|
|
14
|
-
export * from './optional-unwrap-or.mjs';
|
|
15
|
-
export * from './optional-unwrap-throw.mjs';
|
|
16
|
-
export * from './optional-unwrap.mjs';
|
|
17
|
-
export * from './optional-zip.mjs';
|
|
18
|
-
export * from './types.mjs';
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { type Optional, type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { isSome } from './optional-is-some.mjs';
|
|
3
|
-
import { unwrap } from './optional-unwrap.mjs';
|
|
4
|
-
import { type Unwrap } from './types.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Unwraps an `Optional`, returning the contained value or throwing an error
|
|
8
|
-
* with the provided message.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const optionalValue = Optional.some('data');
|
|
14
|
-
*
|
|
15
|
-
* assert.isTrue(
|
|
16
|
-
* Optional.expectToBe(optionalValue, 'value expected') === 'data',
|
|
17
|
-
* );
|
|
18
|
-
*
|
|
19
|
-
* const expectValue = Optional.expectToBe('missing optional');
|
|
20
|
-
*
|
|
21
|
-
* const throwTest = (): void => {
|
|
22
|
-
* expectValue(Optional.none);
|
|
23
|
-
* };
|
|
24
|
-
*
|
|
25
|
-
* assert.throws(throwTest, /missing optional/u);
|
|
26
|
-
*
|
|
27
|
-
* assert.isTrue(expectValue(Optional.some('present')) === 'present');
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @template O The `UnknownOptional` type to unwrap.
|
|
31
|
-
* @param optional The `Optional` to unwrap.
|
|
32
|
-
* @param message The error message to throw if the `Optional` is
|
|
33
|
-
* `None`.
|
|
34
|
-
* @returns The contained value if `Some`.
|
|
35
|
-
* @throws Error with the provided message if the `Optional` is
|
|
36
|
-
* `None`.
|
|
37
|
-
*/
|
|
38
|
-
export function expectToBe<O extends UnknownOptional>(
|
|
39
|
-
optional: O,
|
|
40
|
-
message: string,
|
|
41
|
-
): Unwrap<O>;
|
|
42
|
-
|
|
43
|
-
// Curried version
|
|
44
|
-
export function expectToBe(message: string): <O>(optional: Optional<O>) => O;
|
|
45
|
-
|
|
46
|
-
export function expectToBe<O extends UnknownOptional>(
|
|
47
|
-
...args: readonly [optional: O, message: string] | readonly [message: string]
|
|
48
|
-
): Unwrap<O> | ((optional: Optional<Unwrap<O>>) => Unwrap<O>) {
|
|
49
|
-
switch (args.length) {
|
|
50
|
-
case 2: {
|
|
51
|
-
const [optional, message] = args;
|
|
52
|
-
|
|
53
|
-
return expectToBeImpl(optional, message);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
case 1: {
|
|
57
|
-
// Curried version: first argument is message
|
|
58
|
-
const [message] = args;
|
|
59
|
-
|
|
60
|
-
return (optional: Optional<Unwrap<O>>): Unwrap<O> =>
|
|
61
|
-
expectToBeImpl(optional, message);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const expectToBeImpl = <O extends UnknownOptional>(
|
|
67
|
-
optional: O,
|
|
68
|
-
message: string,
|
|
69
|
-
): Unwrap<O> => {
|
|
70
|
-
if (isSome(optional)) {
|
|
71
|
-
return unwrap(optional);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw new Error(message);
|
|
75
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { type Optional, type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { isSome } from './optional-is-some.mjs';
|
|
3
|
-
import { none } from './optional-none.mjs';
|
|
4
|
-
import { some } from './optional-some.mjs';
|
|
5
|
-
import { unwrap } from './optional-unwrap.mjs';
|
|
6
|
-
import { type Unwrap } from './types.mjs';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Filters an `Optional` based on a predicate. If the `Optional` is `Some` and
|
|
10
|
-
* the predicate returns true, returns the original `Optional`. Otherwise
|
|
11
|
-
* returns `None`.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const even = Optional.filter(Optional.some(4), (value) => value % 2 === 0);
|
|
17
|
-
*
|
|
18
|
-
* const odd = Optional.filter(Optional.some(3), (value) => value % 2 === 0);
|
|
19
|
-
*
|
|
20
|
-
* assert.deepStrictEqual(even, Optional.some(4));
|
|
21
|
-
*
|
|
22
|
-
* assert.deepStrictEqual(odd, Optional.none);
|
|
23
|
-
*
|
|
24
|
-
* const filterEven = Optional.filter((value: number) => value % 2 === 0);
|
|
25
|
-
*
|
|
26
|
-
* assert.deepStrictEqual(filterEven(Optional.some(6)), Optional.some(6));
|
|
27
|
-
*
|
|
28
|
-
* assert.deepStrictEqual(filterEven(Optional.some(5)), Optional.none);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @template O The input `UnknownOptional` type.
|
|
32
|
-
* @param optional The `Optional` to filter.
|
|
33
|
-
* @param predicate The predicate function.
|
|
34
|
-
* @returns The filtered `Optional`.
|
|
35
|
-
*/
|
|
36
|
-
export function filter<O extends UnknownOptional>(
|
|
37
|
-
optional: O,
|
|
38
|
-
predicate: (value: Unwrap<O>) => boolean,
|
|
39
|
-
): Optional<Unwrap<O>>;
|
|
40
|
-
|
|
41
|
-
// Curried version
|
|
42
|
-
export function filter<S>(
|
|
43
|
-
predicate: (value: S) => boolean,
|
|
44
|
-
): (optional: Optional<S>) => Optional<S>;
|
|
45
|
-
|
|
46
|
-
export function filter<O extends UnknownOptional>(
|
|
47
|
-
...args:
|
|
48
|
-
| readonly [optional: O, predicate: (value: Unwrap<O>) => boolean]
|
|
49
|
-
| readonly [predicate: (value: Unwrap<O>) => boolean]
|
|
50
|
-
): Optional<Unwrap<O>> | ((optional: O) => Optional<Unwrap<O>>) {
|
|
51
|
-
switch (args.length) {
|
|
52
|
-
case 2: {
|
|
53
|
-
const [optional, predicate] = args;
|
|
54
|
-
|
|
55
|
-
return filterImpl(optional, predicate);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
case 1: {
|
|
59
|
-
// Curried version: first argument is predicate function
|
|
60
|
-
const [predicate] = args;
|
|
61
|
-
|
|
62
|
-
return (optional: O) => filterImpl(optional, predicate);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const filterImpl = <O extends UnknownOptional>(
|
|
68
|
-
optional: O,
|
|
69
|
-
predicate: (value: Unwrap<O>) => boolean,
|
|
70
|
-
): Optional<Unwrap<O>> => {
|
|
71
|
-
if (isSome(optional)) {
|
|
72
|
-
const value = unwrap(optional);
|
|
73
|
-
|
|
74
|
-
return predicate(value) ? some(value) : none;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return none;
|
|
78
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { type Optional, type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { isSome } from './optional-is-some.mjs';
|
|
3
|
-
import { none } from './optional-none.mjs';
|
|
4
|
-
import { unwrap } from './optional-unwrap.mjs';
|
|
5
|
-
import { type Unwrap } from './types.mjs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Applies a function that returns an `Optional` to the value in an
|
|
9
|
-
* `Some`. If the input is `None`, returns `None`.
|
|
10
|
-
* This is the monadic bind operation for `Optional`.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const parseNumber = (input: string): Optional<number> => {
|
|
16
|
-
* const num = Num.safeParseInt(input);
|
|
17
|
-
*
|
|
18
|
-
* return Result.isErr(num) ? Optional.none : Optional.some(num.value);
|
|
19
|
-
* };
|
|
20
|
-
*
|
|
21
|
-
* const parsed = Optional.flatMap(Optional.some('10'), parseNumber);
|
|
22
|
-
*
|
|
23
|
-
* assert.deepStrictEqual(parsed, Optional.some(10));
|
|
24
|
-
*
|
|
25
|
-
* const flatMapParse = Optional.flatMap(parseNumber);
|
|
26
|
-
*
|
|
27
|
-
* assert.deepStrictEqual(flatMapParse(Optional.some('5')), Optional.some(5));
|
|
28
|
-
*
|
|
29
|
-
* assert.deepStrictEqual(
|
|
30
|
-
* flatMapParse(Optional.some('invalid')),
|
|
31
|
-
* Optional.none,
|
|
32
|
-
* );
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @template O The input `UnknownOptional` type.
|
|
36
|
-
* @template S2 The value type of the `Optional` returned by the function.
|
|
37
|
-
* @param optional The `Optional` to flat map.
|
|
38
|
-
* @param flatMapFn The function to apply that returns an `Optional`.
|
|
39
|
-
* @returns The result of applying the function, or `None`.
|
|
40
|
-
*/
|
|
41
|
-
export function flatMap<O extends UnknownOptional, S2>(
|
|
42
|
-
optional: O,
|
|
43
|
-
flatMapFn: (value: Unwrap<O>) => Optional<S2>,
|
|
44
|
-
): Optional<S2>;
|
|
45
|
-
|
|
46
|
-
// Curried version
|
|
47
|
-
export function flatMap<S, S2>(
|
|
48
|
-
flatMapFn: (value: S) => Optional<S2>,
|
|
49
|
-
): (optional: Optional<S>) => Optional<S2>;
|
|
50
|
-
|
|
51
|
-
export function flatMap<O extends UnknownOptional, S2>(
|
|
52
|
-
...args:
|
|
53
|
-
| readonly [optional: O, flatMapFn: (value: Unwrap<O>) => Optional<S2>]
|
|
54
|
-
| readonly [flatMapFn: (value: Unwrap<O>) => Optional<S2>]
|
|
55
|
-
): Optional<S2> | ((optional: O) => Optional<S2>) {
|
|
56
|
-
switch (args.length) {
|
|
57
|
-
case 2: {
|
|
58
|
-
const [optional, flatMapFn] = args;
|
|
59
|
-
|
|
60
|
-
return flatMapImpl(optional, flatMapFn);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
case 1: {
|
|
64
|
-
// Curried version
|
|
65
|
-
const [flatMapFn] = args;
|
|
66
|
-
|
|
67
|
-
return (optional: O) => flatMapImpl(optional, flatMapFn);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const flatMapImpl = <O extends UnknownOptional, S2>(
|
|
73
|
-
optional: O,
|
|
74
|
-
flatMapFn: (value: Unwrap<O>) => Optional<S2>,
|
|
75
|
-
): Optional<S2> => (isSome(optional) ? flatMapFn(unwrap(optional)) : none);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type Optional } from '../optional.mjs';
|
|
2
|
-
import { none } from './optional-none.mjs';
|
|
3
|
-
import { some } from './optional-some.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Converts a nullable value to an `Optional`.
|
|
7
|
-
*
|
|
8
|
-
* This is the primary way to lift nullable values (null or undefined) into
|
|
9
|
-
* the Optional type system. The function treats both `null` and `undefined`
|
|
10
|
-
* as empty values, converting them to `None`.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const present = Optional.fromNullable('hello');
|
|
16
|
-
*
|
|
17
|
-
* const absent = Optional.fromNullable<string | null>(null);
|
|
18
|
-
*
|
|
19
|
-
* assert.deepStrictEqual(present, Optional.some('hello'));
|
|
20
|
-
*
|
|
21
|
-
* assert.deepStrictEqual(absent, Optional.none);
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @template T The type of the nullable value.
|
|
25
|
-
* @param value The nullable value to convert.
|
|
26
|
-
* @returns `Some<NonNullable<T>>` if the value is not null or
|
|
27
|
-
* undefined, otherwise `None`.
|
|
28
|
-
*/
|
|
29
|
-
export const fromNullable = <T,>(
|
|
30
|
-
value: T | null | undefined,
|
|
31
|
-
): Optional<NonNullable<T>> => (value == null ? none : some(value));
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { NoneTypeTagName } from './tag.mjs';
|
|
3
|
-
import { type NarrowToNone } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Checks if an {@link Optional} is {@link None}. Acts as a type guard.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const optionalValue = Optional.none as Optional<number>;
|
|
12
|
-
*
|
|
13
|
-
* if (Optional.isNone(optionalValue)) {
|
|
14
|
-
* // Type narrowed to None
|
|
15
|
-
* expectType<typeof optionalValue, None>('=');
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @template O The {@link UnknownOptional} type to check.
|
|
20
|
-
* @param optional The {@link Optional} to check.
|
|
21
|
-
* @returns `true` if the {@link Optional} is {@link None}, `false`
|
|
22
|
-
* otherwise.
|
|
23
|
-
*/
|
|
24
|
-
export const isNone = <O extends UnknownOptional>(
|
|
25
|
-
optional: O,
|
|
26
|
-
): optional is NarrowToNone<O> => optional.$$tag === NoneTypeTagName;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { hasKey, isRecord } from '../../../guard/index.mjs';
|
|
2
|
-
import { type Optional } from '../optional.mjs';
|
|
3
|
-
import { NoneTypeTagName, SomeTypeTagName } from './tag.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Checks if the given value is an {@link Optional}.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const maybeOptional = Optional.some('value');
|
|
12
|
-
*
|
|
13
|
-
* const notOptional = { $$tag: 'ts-data-forge::Optional.some' } as const;
|
|
14
|
-
*
|
|
15
|
-
* assert.isTrue(Optional.isOptional(maybeOptional));
|
|
16
|
-
*
|
|
17
|
-
* assert.isFalse(Optional.isOptional(notOptional));
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param maybeOptional The value to check.
|
|
21
|
-
* @returns `true` if the value is an {@link Optional}, otherwise `false`.
|
|
22
|
-
*/
|
|
23
|
-
export const isOptional = (
|
|
24
|
-
maybeOptional: unknown,
|
|
25
|
-
): maybeOptional is Optional<unknown> =>
|
|
26
|
-
isRecord(maybeOptional) &&
|
|
27
|
-
hasKey(maybeOptional, '$$tag') &&
|
|
28
|
-
((maybeOptional.$$tag === SomeTypeTagName &&
|
|
29
|
-
hasKey(maybeOptional, 'value')) ||
|
|
30
|
-
maybeOptional.$$tag === NoneTypeTagName);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { SomeTypeTagName } from './tag.mjs';
|
|
3
|
-
import { type NarrowToSome } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Checks if an {@link Optional} is {@link Some}. Acts as a type guard.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const optionalNumber = Optional.some(42);
|
|
12
|
-
*
|
|
13
|
-
* if (Optional.isSome(optionalNumber)) {
|
|
14
|
-
* const value: number = optionalNumber.value;
|
|
15
|
-
*
|
|
16
|
-
* assert.isTrue(value === 42);
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @template O The {@link UnknownOptional} type to check.
|
|
21
|
-
* @param optional The {@link Optional} to check.
|
|
22
|
-
* @returns `true` if the {@link Optional} is {@link Some}, `false`
|
|
23
|
-
* otherwise.
|
|
24
|
-
*/
|
|
25
|
-
export const isSome = <O extends UnknownOptional>(
|
|
26
|
-
optional: O,
|
|
27
|
-
): optional is NarrowToSome<O> => optional.$$tag === SomeTypeTagName;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { type Optional, type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { isSome } from './optional-is-some.mjs';
|
|
3
|
-
import { none } from './optional-none.mjs';
|
|
4
|
-
import { some } from './optional-some.mjs';
|
|
5
|
-
import { unwrap } from './optional-unwrap.mjs';
|
|
6
|
-
import { type Unwrap } from './types.mjs';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Maps an {@link Optional}<S> to {@link Optional}<S2> by applying a function to
|
|
10
|
-
* a contained value. If the {@link Optional} is {@link None}, it
|
|
11
|
-
* returns {@link Optional.none}. Otherwise, it applies the `mapFn` to the
|
|
12
|
-
* value in `Some` and returns a new `Some` with the result.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* const numberOptional = Optional.some(21);
|
|
18
|
-
*
|
|
19
|
-
* const mapped = Optional.map(numberOptional, (value) => value * 2);
|
|
20
|
-
*
|
|
21
|
-
* assert.deepStrictEqual(mapped, Optional.some(42));
|
|
22
|
-
*
|
|
23
|
-
* const mapToLength = Optional.map((text: string) => text.length);
|
|
24
|
-
*
|
|
25
|
-
* assert.deepStrictEqual(mapToLength(Optional.some('abc')), Optional.some(3));
|
|
26
|
-
*
|
|
27
|
-
* assert.deepStrictEqual(mapToLength(Optional.none), Optional.none);
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @template O The input `UnknownOptional` type.
|
|
31
|
-
* @template S2 The type of the value returned by the mapping function.
|
|
32
|
-
* @param optional The `Optional` to map.
|
|
33
|
-
* @param mapFn The function to apply to the value if it exists.
|
|
34
|
-
* @returns A new `Optional<S2>` resulting from the mapping, or
|
|
35
|
-
* `None` if the input was `None`.
|
|
36
|
-
*/
|
|
37
|
-
export function map<O extends UnknownOptional, S2>(
|
|
38
|
-
optional: O,
|
|
39
|
-
mapFn: (value: Unwrap<O>) => S2,
|
|
40
|
-
): Optional<S2>;
|
|
41
|
-
|
|
42
|
-
// Curried version
|
|
43
|
-
//
|
|
44
|
-
// The returned function is generic over the *whole* optional, mirroring the
|
|
45
|
-
// direct overload above, rather than fixing its parameter to `Optional<S>`.
|
|
46
|
-
// Fixing it makes the curried form unusable from a caller that is itself
|
|
47
|
-
// generic over the optional: with `S` bound to `Unwrap<O>` at currying time
|
|
48
|
-
// the parameter becomes `Optional<Unwrap<O>>`, and TypeScript cannot show a
|
|
49
|
-
// bare `O extends UnknownOptional` is assignable to that — although every
|
|
50
|
-
// concrete instantiation of `O` is.
|
|
51
|
-
//
|
|
52
|
-
// The conditional is what keeps the check: `O` is inferred from the argument
|
|
53
|
-
// and its value type still has to satisfy `S`, so mapping a `(s: string) =>
|
|
54
|
-
// …` over an `Optional<number>` stays an error. The cost is the message it
|
|
55
|
-
// produces — "not assignable to `never`" rather than naming the two optionals.
|
|
56
|
-
export function map<S, S2>(
|
|
57
|
-
mapFn: (value: S) => S2,
|
|
58
|
-
): <O extends UnknownOptional>(
|
|
59
|
-
optional: Unwrap<O> extends S ? O : never,
|
|
60
|
-
) => Optional<S2>;
|
|
61
|
-
|
|
62
|
-
export function map<O extends UnknownOptional, S2>(
|
|
63
|
-
...args:
|
|
64
|
-
| readonly [optional: O, mapFn: (value: Unwrap<O>) => S2]
|
|
65
|
-
| readonly [mapFn: (value: Unwrap<O>) => S2]
|
|
66
|
-
): Optional<S2> | ((optional: O) => Optional<S2>) {
|
|
67
|
-
switch (args.length) {
|
|
68
|
-
case 2: {
|
|
69
|
-
const [optional, mapFn] = args;
|
|
70
|
-
|
|
71
|
-
return mapImpl(optional, mapFn);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
case 1: {
|
|
75
|
-
// Curried version: first argument is mapping function
|
|
76
|
-
const [mapFn] = args;
|
|
77
|
-
|
|
78
|
-
return (optional: O) => mapImpl(optional, mapFn);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const mapImpl = <O extends UnknownOptional, S2>(
|
|
84
|
-
optional: O,
|
|
85
|
-
mapFn: (value: Unwrap<O>) => S2,
|
|
86
|
-
): Optional<S2> =>
|
|
87
|
-
isSome(optional)
|
|
88
|
-
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
89
|
-
some(mapFn(unwrap(optional)!))
|
|
90
|
-
: none;
|